2024-03-17 18:37:06 -07:00
|
|
|
|
using System;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Diagnostics;
|
2024-04-02 21:17:20 -07:00
|
|
|
|
using System.IO;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.Native
|
|
|
|
|
{
|
|
|
|
|
public static class OS
|
|
|
|
|
{
|
|
|
|
|
public interface IBackend
|
|
|
|
|
{
|
2024-03-14 03:23:36 -07:00
|
|
|
|
void SetupApp(AppBuilder builder);
|
2024-03-07 20:22:22 -08:00
|
|
|
|
|
2024-02-20 19:29:28 -08:00
|
|
|
|
string FindGitExecutable();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
string FindVSCode();
|
2024-03-27 22:49:32 -07:00
|
|
|
|
string FindFleet();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
void OpenTerminal(string workdir);
|
|
|
|
|
void OpenInFileManager(string path, bool select);
|
|
|
|
|
void OpenBrowser(string url);
|
|
|
|
|
void OpenWithDefaultEditor(string file);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-27 22:49:32 -07:00
|
|
|
|
public static string GitInstallPath { get; set; }
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-27 22:49:32 -07:00
|
|
|
|
public static string VSCodeExecutableFile { get; set; }
|
|
|
|
|
|
|
|
|
|
public static string FleetExecutableFile { get; set; }
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
static OS()
|
|
|
|
|
{
|
2024-03-28 02:42:13 -07:00
|
|
|
|
if (OperatingSystem.IsWindows())
|
|
|
|
|
{
|
|
|
|
|
_backend = new Windows();
|
|
|
|
|
}
|
|
|
|
|
else if (OperatingSystem.IsMacOS())
|
|
|
|
|
{
|
|
|
|
|
_backend = new MacOS();
|
|
|
|
|
}
|
|
|
|
|
else if (OperatingSystem.IsLinux())
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-03-28 02:42:13 -07:00
|
|
|
|
_backend = new Linux();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Platform unsupported!!!");
|
|
|
|
|
}
|
2024-03-27 22:49:32 -07:00
|
|
|
|
|
|
|
|
|
VSCodeExecutableFile = _backend.FindVSCode();
|
2024-04-02 21:17:20 -07:00
|
|
|
|
if (string.IsNullOrEmpty(VSCodeExecutableFile))
|
|
|
|
|
VSCodeExecutableFile = GetPathFromEnvironmentVar("VSCODE_PATH");
|
|
|
|
|
|
2024-03-27 22:49:32 -07:00
|
|
|
|
FleetExecutableFile = _backend.FindFleet();
|
2024-04-02 21:17:20 -07:00
|
|
|
|
if (string.IsNullOrEmpty(FleetExecutableFile))
|
|
|
|
|
FleetExecutableFile = GetPathFromEnvironmentVar("FLEET_PATH");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void SetupApp(AppBuilder builder)
|
|
|
|
|
{
|
2024-03-28 02:48:46 -07:00
|
|
|
|
_backend.SetupApp(builder);
|
2024-03-07 20:22:22 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static string FindGitExecutable()
|
|
|
|
|
{
|
2024-03-28 02:48:46 -07:00
|
|
|
|
return _backend.FindGitExecutable();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void OpenInFileManager(string path, bool select = false)
|
|
|
|
|
{
|
2024-03-28 02:48:46 -07:00
|
|
|
|
_backend.OpenInFileManager(path, select);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void OpenBrowser(string url)
|
|
|
|
|
{
|
2024-03-28 02:48:46 -07:00
|
|
|
|
_backend.OpenBrowser(url);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void OpenTerminal(string workdir)
|
|
|
|
|
{
|
2024-03-28 02:48:46 -07:00
|
|
|
|
_backend.OpenTerminal(workdir);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void OpenWithDefaultEditor(string file)
|
|
|
|
|
{
|
2024-03-28 02:48:46 -07:00
|
|
|
|
_backend.OpenWithDefaultEditor(file);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void OpenInVSCode(string repo)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(VSCodeExecutableFile))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
App.RaiseException(repo, "Visual Studio Code can NOT be found in your system!!!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
Process.Start(new ProcessStartInfo()
|
|
|
|
|
{
|
2024-03-28 02:42:13 -07:00
|
|
|
|
WorkingDirectory = repo,
|
|
|
|
|
FileName = VSCodeExecutableFile,
|
|
|
|
|
Arguments = $"\"{repo}\"",
|
|
|
|
|
UseShellExecute = false,
|
2024-02-05 23:08:37 -08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-27 22:49:32 -07:00
|
|
|
|
public static void OpenInFleet(string repo)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(FleetExecutableFile))
|
|
|
|
|
{
|
|
|
|
|
App.RaiseException(repo, "Fleet can NOT be found in your system!!!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Process.Start(new ProcessStartInfo()
|
|
|
|
|
{
|
2024-03-28 02:42:13 -07:00
|
|
|
|
WorkingDirectory = repo,
|
|
|
|
|
FileName = FleetExecutableFile,
|
|
|
|
|
Arguments = $"\"{repo}\"",
|
|
|
|
|
UseShellExecute = false,
|
2024-03-27 22:49:32 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
2024-03-28 05:02:18 -07:00
|
|
|
|
|
2024-04-02 21:17:20 -07:00
|
|
|
|
private static string GetPathFromEnvironmentVar(string key)
|
|
|
|
|
{
|
|
|
|
|
var customPath = Environment.GetEnvironmentVariable(key);
|
|
|
|
|
if (!string.IsNullOrEmpty(customPath) && File.Exists(customPath))
|
|
|
|
|
{
|
|
|
|
|
return customPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-28 05:02:18 -07:00
|
|
|
|
private static readonly IBackend _backend;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|