fix<Preference>: fix open Preference crash when git.exe is not configured

This commit is contained in:
leo 2021-05-21 12:43:41 +08:00
parent a70152ee8a
commit ad0d1f0ab8

View file

@ -16,10 +16,16 @@ namespace SourceGit.Views {
public string MergeCmd { get; set; } public string MergeCmd { get; set; }
public Preference() { public Preference() {
if (Models.Preference.Instance.IsReady) {
User = new Commands.Config().Get("user.name"); User = new Commands.Config().Get("user.name");
Email = new Commands.Config().Get("user.email"); Email = new Commands.Config().Get("user.email");
CRLF = new Commands.Config().Get("core.autocrlf"); CRLF = new Commands.Config().Get("core.autocrlf");
if (string.IsNullOrEmpty(CRLF)) CRLF = "false"; if (string.IsNullOrEmpty(CRLF)) CRLF = "false";
} else {
User = "";
Email = "";
CRLF = "false";
}
var merger = Models.MergeTool.Supported.Find(x => x.Type == Models.Preference.Instance.MergeTool.Type); var merger = Models.MergeTool.Supported.Find(x => x.Type == Models.Preference.Instance.MergeTool.Type);
if (merger != null) MergeCmd = merger.Cmd; if (merger != null) MergeCmd = merger.Cmd;
@ -83,6 +89,7 @@ namespace SourceGit.Views {
} }
private void Quit(object sender, RoutedEventArgs e) { private void Quit(object sender, RoutedEventArgs e) {
if (Models.Preference.Instance.IsReady) {
var cmd = new Commands.Config(); var cmd = new Commands.Config();
var oldUser = cmd.Get("user.name"); var oldUser = cmd.Get("user.name");
if (oldUser != User) cmd.Set("user.name", User); if (oldUser != User) cmd.Set("user.name", User);
@ -92,6 +99,7 @@ namespace SourceGit.Views {
var oldCRLF = cmd.Get("core.autocrlf"); var oldCRLF = cmd.Get("core.autocrlf");
if (oldCRLF != CRLF) cmd.Set("core.autocrlf", CRLF); if (oldCRLF != CRLF) cmd.Set("core.autocrlf", CRLF);
}
Models.Preference.Save(); Models.Preference.Save();
Close(); Close();