code_review: code review for PR #33

* use PNG instead of SVG for external tool icons and remove dependency `Avalonia.SVG`
* remove unused property `IsVSCodeFound` and `IsFleetFound`
* find VS from registry first
* remove compile warning CA1416
* remove unused enum `OS.Platforms`
This commit is contained in:
leo 2024-03-28 17:42:13 +08:00
parent 370b9bd31e
commit 4659fbd901
10 changed files with 85 additions and 162 deletions

View file

@ -3,8 +3,6 @@ using System.Diagnostics;
using Avalonia;
// ReSharper disable InconsistentNaming
namespace SourceGit.Native
{
public static class OS
@ -29,27 +27,24 @@ namespace SourceGit.Native
public static string FleetExecutableFile { get; set; }
public enum Platforms
{
Unknown = 0,
Windows = 1,
MacOS = 2,
Linux
}
public static Platforms Platform => OperatingSystem.IsWindows() ? Platforms.Windows : OperatingSystem.IsMacOS() ? Platforms.MacOS : OperatingSystem.IsLinux() ? Platforms.Linux : Platforms.Unknown;
static OS()
{
_backend = Platform switch
if (OperatingSystem.IsWindows())
{
#pragma warning disable CA1416
Platforms.Windows => new Windows(),
Platforms.MacOS => new MacOS(),
Platforms.Linux => new Linux(),
#pragma warning restore CA1416
_ => throw new Exception("Platform unsupported!!!")
};
_backend = new Windows();
}
else if (OperatingSystem.IsMacOS())
{
_backend = new MacOS();
}
else if (OperatingSystem.IsLinux())
{
_backend = new Linux();
}
else
{
throw new Exception("Platform unsupported!!!");
}
VSCodeExecutableFile = _backend.FindVSCode();
FleetExecutableFile = _backend.FindFleet();
@ -95,7 +90,10 @@ namespace SourceGit.Native
Process.Start(new ProcessStartInfo()
{
WorkingDirectory = repo, FileName = VSCodeExecutableFile, Arguments = $"\"{repo}\"", UseShellExecute = false,
WorkingDirectory = repo,
FileName = VSCodeExecutableFile,
Arguments = $"\"{repo}\"",
UseShellExecute = false,
});
}
@ -111,7 +109,10 @@ namespace SourceGit.Native
Process.Start(new ProcessStartInfo()
{
WorkingDirectory = repo, FileName = FleetExecutableFile, Arguments = $"\"{repo}\"", UseShellExecute = false,
WorkingDirectory = repo,
FileName = FleetExecutableFile,
Arguments = $"\"{repo}\"",
UseShellExecute = false,
});
}
}

View file

@ -103,11 +103,21 @@ namespace SourceGit.Native
public string FindVSCode()
{
var root = Microsoft.Win32.RegistryKey.OpenBaseKey(
Microsoft.Win32.RegistryHive.LocalMachine,
Environment.Is64BitOperatingSystem ? Microsoft.Win32.RegistryView.Registry64 : Microsoft.Win32.RegistryView.Registry32);
var vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{EA457B21-F73E-494C-ACAB-524FDE069978}_is1");
if (vscode != null)
{
return vscode.GetValue("DisplayIcon") as string;
}
var toolPath = Environment.ExpandEnvironmentVariables($"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe");
if (File.Exists(toolPath)) return toolPath;
return string.Empty;
}
public string FindFleet()
{
var toolPath = Environment.ExpandEnvironmentVariables($"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\AppData\\Local\\Programs\\Fleet\\Fleet.exe");