From 9c2a55b75cefc8c7b2256e3fb14e0287239c8513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 8 Sep 2021 10:35:59 +0800 Subject: [PATCH] fix: fix crashes on .NET 4.8 --- .gitignore | 3 ++- src/Views/Preference.xaml.cs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 534c9c6f..f348333a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea .vs +.vscode bin obj publish -*.user \ No newline at end of file +*.user diff --git a/src/Views/Preference.xaml.cs b/src/Views/Preference.xaml.cs index 5cab241d..eb54cb44 100644 --- a/src/Views/Preference.xaml.cs +++ b/src/Views/Preference.xaml.cs @@ -17,12 +17,13 @@ namespace SourceGit.Views { public string CRLF { 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://www.pinvoke.net/default.aspx/shlwapi.PathFindOnPath [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)] 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() { UpdateGitInfo(false); @@ -64,7 +65,7 @@ namespace SourceGit.Views { } 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) ? sb.ToString() : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);