2024-03-17 18:37:06 -07:00
|
|
|
|
using System;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia;
|
|
|
|
|
|
2024-03-27 22:49:32 -07:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
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; }
|
|
|
|
|
|
|
|
|
|
public enum Platforms
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-03-27 22:49:32 -07:00
|
|
|
|
Unknown = 0,
|
|
|
|
|
Windows = 1,
|
|
|
|
|
MacOS = 2,
|
|
|
|
|
Linux
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-27 22:49:32 -07:00
|
|
|
|
public static Platforms Platform => OperatingSystem.IsWindows() ? Platforms.Windows : OperatingSystem.IsMacOS() ? Platforms.MacOS : OperatingSystem.IsLinux() ? Platforms.Linux : Platforms.Unknown;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
static OS()
|
|
|
|
|
{
|
2024-03-27 22:49:32 -07:00
|
|
|
|
_backend = Platform switch
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-03-27 22:49:32 -07:00
|
|
|
|
#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!!!")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VSCodeExecutableFile = _backend.FindVSCode();
|
|
|
|
|
FleetExecutableFile = _backend.FindFleet();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void SetupApp(AppBuilder builder)
|
|
|
|
|
{
|
2024-03-14 03:23:36 -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-02-20 19:29:28 -08: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-02-05 23:08:37 -08:00
|
|
|
|
_backend?.OpenInFileManager(path, select);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void OpenBrowser(string url)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_backend?.OpenBrowser(url);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void OpenTerminal(string workdir)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_backend?.OpenTerminal(workdir);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void OpenWithDefaultEditor(string file)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_backend?.OpenWithDefaultEditor(file);
|
|
|
|
|
}
|
|
|
|
|
|
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-27 22:49:32 -07:00
|
|
|
|
WorkingDirectory = repo, FileName = VSCodeExecutableFile, Arguments = $"\"{repo}\"", UseShellExecute = false,
|
2024-02-05 23:08:37 -08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private static readonly IBackend _backend = null;
|
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()
|
|
|
|
|
{
|
|
|
|
|
WorkingDirectory = repo, FileName = FleetExecutableFile, Arguments = $"\"{repo}\"", UseShellExecute = false,
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|