2024-03-17 18:37:06 -07:00
|
|
|
|
using System;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Runtime.Versioning;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia;
|
|
|
|
|
using Avalonia.Media;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.Native
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
[SupportedOSPlatform("windows")]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
internal class Windows : OS.IBackend
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)]
|
|
|
|
|
private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs);
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void SetupApp(AppBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.With(new FontManagerOptions()
|
|
|
|
|
{
|
2024-03-07 20:22:22 -08:00
|
|
|
|
DefaultFamilyName = "Microsoft YaHei UI",
|
2024-03-24 19:39:36 -07:00
|
|
|
|
FontFallbacks = [new FontFallback { FontFamily = "Microsoft YaHei" }],
|
2024-03-07 20:22:22 -08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string FindGitExecutable()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var reg = Microsoft.Win32.RegistryKey.OpenBaseKey(
|
|
|
|
|
Microsoft.Win32.RegistryHive.LocalMachine,
|
|
|
|
|
Microsoft.Win32.RegistryView.Registry64);
|
|
|
|
|
|
|
|
|
|
var git = reg.OpenSubKey("SOFTWARE\\GitForWindows");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (git != null)
|
|
|
|
|
{
|
2024-02-20 19:29:28 -08:00
|
|
|
|
return Path.Combine(git.GetValue("InstallPath") as string, "bin", "git.exe");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var builder = new StringBuilder("git.exe", 259);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (!PathFindOnPath(builder, null))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var exePath = builder.ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(exePath)) return null;
|
|
|
|
|
|
2024-02-20 19:29:28 -08:00
|
|
|
|
return exePath;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string FindVSCode()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (vscode != null)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return vscode.GetValue("DisplayIcon") as string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (vscode != null)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return vscode.GetValue("DisplayIcon") as string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (vscode != null)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return vscode.GetValue("DisplayIcon") as string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{EA457B21-F73E-494C-ACAB-524FDE069978}_is1");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (vscode != null)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return vscode.GetValue("DisplayIcon") as string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void OpenBrowser(string url)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var info = new ProcessStartInfo("cmd", $"/c start {url}");
|
|
|
|
|
info.CreateNoWindow = true;
|
|
|
|
|
Process.Start(info);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void OpenTerminal(string workdir)
|
|
|
|
|
{
|
2024-02-20 19:29:28 -08:00
|
|
|
|
var bash = Path.Combine(Path.GetDirectoryName(OS.GitInstallPath), "bash.exe");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (!File.Exists(bash))
|
|
|
|
|
{
|
2024-02-20 19:29:28 -08:00
|
|
|
|
App.RaiseException(string.IsNullOrEmpty(workdir) ? "" : workdir, $"Can NOT found bash.exe under '{Path.GetDirectoryName(OS.GitInstallPath)}'");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var startInfo = new ProcessStartInfo();
|
|
|
|
|
startInfo.UseShellExecute = true;
|
|
|
|
|
startInfo.FileName = bash;
|
|
|
|
|
if (!string.IsNullOrEmpty(workdir) && Path.Exists(workdir)) startInfo.WorkingDirectory = workdir;
|
|
|
|
|
Process.Start(startInfo);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void OpenInFileManager(string path, bool select)
|
|
|
|
|
{
|
2024-03-01 01:40:17 -08:00
|
|
|
|
var fullpath = string.Empty;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
{
|
2024-03-01 01:40:17 -08:00
|
|
|
|
fullpath = new FileInfo(path).FullName;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-03-01 01:40:17 -08:00
|
|
|
|
fullpath = new DirectoryInfo(path).FullName;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (select)
|
|
|
|
|
{
|
2024-03-01 01:40:17 -08:00
|
|
|
|
Process.Start("explorer", $"/select,\"{fullpath}\"");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-03-01 01:40:17 -08:00
|
|
|
|
Process.Start("explorer", fullpath);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void OpenWithDefaultEditor(string file)
|
|
|
|
|
{
|
2024-03-01 01:40:17 -08:00
|
|
|
|
var info = new FileInfo(file);
|
|
|
|
|
var start = new ProcessStartInfo("cmd", $"/c start {info.FullName}");
|
|
|
|
|
start.CreateNoWindow = true;
|
|
|
|
|
Process.Start(start);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|