From adce866716a95029bb164eb4b27f6b52802c9f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 3 Sep 2021 22:22:53 +0800 Subject: [PATCH] feature: try finding `git.exe` automatically --- src/Views/Preference.xaml.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Views/Preference.xaml.cs b/src/Views/Preference.xaml.cs index 1ec52efe..bc5b4d4c 100644 --- a/src/Views/Preference.xaml.cs +++ b/src/Views/Preference.xaml.cs @@ -49,12 +49,18 @@ namespace SourceGit.Views { } private void SelectGitPath(object sender, RoutedEventArgs e) { - var dialog = new OpenFileDialog(); - dialog.Filter = "Git Executable|git.exe"; - dialog.FileName = "git.exe"; - dialog.Title = App.Text("Preference.Dialog.GitExe"); - dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); - dialog.CheckFileExists = true; + var sb = new StringBuilder("git.exe"); + string dir = PathFindOnPath(sb, null) + ? sb.ToString() + : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); + + var dialog = new OpenFileDialog { + Filter = "Git Executable|git.exe", + FileName = "git.exe", + Title = App.Text("Preference.Dialog.GitExe"), + InitialDirectory = dir, + CheckFileExists = true, + }; if (dialog.ShowDialog() == true) { Models.Preference.Instance.Git.Path = dialog.FileName;