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() {
User = new Commands.Config().Get("user.name"); if (Models.Preference.Instance.IsReady) {
Email = new Commands.Config().Get("user.email"); User = new Commands.Config().Get("user.name");
CRLF = new Commands.Config().Get("core.autocrlf"); Email = new Commands.Config().Get("user.email");
if (string.IsNullOrEmpty(CRLF)) CRLF = "false"; CRLF = new Commands.Config().Get("core.autocrlf");
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,15 +89,17 @@ namespace SourceGit.Views {
} }
private void Quit(object sender, RoutedEventArgs e) { private void Quit(object sender, RoutedEventArgs e) {
var cmd = new Commands.Config(); if (Models.Preference.Instance.IsReady) {
var oldUser = cmd.Get("user.name"); var cmd = new Commands.Config();
if (oldUser != User) cmd.Set("user.name", User); var oldUser = cmd.Get("user.name");
if (oldUser != User) cmd.Set("user.name", User);
var oldEmail = cmd.Get("user.email"); var oldEmail = cmd.Get("user.email");
if (oldEmail != Email) cmd.Set("user.email", Email); if (oldEmail != Email) cmd.Set("user.email", Email);
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();