fix<Native>: fix wrong file filter on macOS platform.

This commit is contained in:
leo 2024-02-21 11:29:28 +08:00
parent dbd91c9b58
commit 353557ec10
10 changed files with 41 additions and 45 deletions

View file

@ -6,8 +6,8 @@ using System.Text;
namespace SourceGit.Native {
[SupportedOSPlatform("macOS")]
internal class MacOS : OS.IBackend {
public string FindGitInstallDir() {
if (File.Exists("/usr/bin/git")) return "/usr";
public string FindGitExecutable() {
if (File.Exists("/usr/bin/git")) return "/usr/bin/git";
return string.Empty;
}

View file

@ -5,7 +5,7 @@ using System.IO;
namespace SourceGit.Native {
public static class OS {
public interface IBackend {
string FindGitInstallDir();
string FindGitExecutable();
string FindVSCode();
void OpenTerminal(string workdir);
@ -14,15 +14,11 @@ namespace SourceGit.Native {
void OpenWithDefaultEditor(string file);
}
public static string GitInstallDir {
public static string GitInstallPath {
get;
set;
}
public static string GitExecutableFile {
get => Path.Combine(GitInstallDir, "bin", OperatingSystem.IsWindows() ? "git.exe" : "git");
}
public static string VSCodeExecutableFile {
get;
set;
@ -40,8 +36,8 @@ namespace SourceGit.Native {
}
}
public static string FindGitInstallDir() {
return _backend?.FindGitInstallDir();
public static string FindGitExecutable() {
return _backend?.FindGitExecutable();
}
public static void OpenInFileManager(string path, bool select = false) {

View file

@ -11,14 +11,14 @@ namespace SourceGit.Native {
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)]
private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs);
public string FindGitInstallDir() {
public string FindGitExecutable() {
var reg = Microsoft.Win32.RegistryKey.OpenBaseKey(
Microsoft.Win32.RegistryHive.LocalMachine,
Microsoft.Win32.RegistryView.Registry64);
var git = reg.OpenSubKey("SOFTWARE\\GitForWindows");
if (git != null) {
return git.GetValue("InstallPath") as string;
return Path.Combine(git.GetValue("InstallPath") as string, "bin", "git.exe");
}
var builder = new StringBuilder("git.exe", 259);
@ -29,15 +29,7 @@ namespace SourceGit.Native {
var exePath = builder.ToString();
if (string.IsNullOrEmpty(exePath)) return null;
var binDir = Path.GetDirectoryName(exePath);
var bashPath = Path.Combine(binDir, "bash.exe");
if (File.Exists(bashPath)) return Path.GetDirectoryName(binDir);
binDir = Path.Combine(Path.GetDirectoryName(binDir), "bin");
bashPath = Path.Combine(binDir, "bash.exe");
if (File.Exists(bashPath)) return Path.GetDirectoryName(binDir);
return null;
return exePath;
}
public string FindVSCode() {
@ -75,9 +67,9 @@ namespace SourceGit.Native {
}
public void OpenTerminal(string workdir) {
var bash = Path.Combine(ViewModels.Preference.Instance.GitInstallDir, "bin", "bash.exe");
var bash = Path.Combine(Path.GetDirectoryName(OS.GitInstallPath), "bash.exe");
if (!File.Exists(bash)) {
App.RaiseException("", $"Can NOT found bash.exe under '{ViewModels.Preference.Instance.GitInstallDir}'");
App.RaiseException(string.IsNullOrEmpty(workdir) ? "" : workdir, $"Can NOT found bash.exe under '{Path.GetDirectoryName(OS.GitInstallPath)}'");
return;
}