!27 修复使用 NET4.8 时打开配置窗口crash的bug

Merge pull request !27 from carterl/preference
This commit is contained in:
ZCShou 2021-09-08 02:45:49 +00:00 committed by Gitee
commit b6532c063d
2 changed files with 5 additions and 3 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
.idea .idea
.vs .vs
.vscode
bin bin
obj obj
publish publish

View file

@ -17,12 +17,13 @@ namespace SourceGit.Views {
public string CRLF { get; set; } public string CRLF { get; set; }
public string Version { get; set; } public string Version { get; set; }
const int MAX_PATH = 260;
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfindonpathw // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfindonpathw
// https://www.pinvoke.net/default.aspx/shlwapi.PathFindOnPath // https://www.pinvoke.net/default.aspx/shlwapi.PathFindOnPath
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)] [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)]
private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs); private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs);
public bool EnableWindowsTerminal { get; set; } = PathFindOnPath(new StringBuilder("wt.exe"), null); public bool EnableWindowsTerminal { get; set; } = PathFindOnPath(new StringBuilder("wt.exe", MAX_PATH), null);
public Preference() { public Preference() {
UpdateGitInfo(false); UpdateGitInfo(false);
@ -64,7 +65,7 @@ namespace SourceGit.Views {
} }
private void SelectGitPath(object sender, RoutedEventArgs e) { private void SelectGitPath(object sender, RoutedEventArgs e) {
var sb = new StringBuilder("git.exe"); var sb = new StringBuilder("git.exe", MAX_PATH);
string dir = PathFindOnPath(sb, null) string dir = PathFindOnPath(sb, null)
? sb.ToString() ? sb.ToString()
: Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);