2024-04-07 02:56:53 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2024-04-05 22:14:22 -07:00
|
|
|
|
|
2024-04-09 00:00:52 -07:00
|
|
|
|
using Avalonia.Media.Imaging;
|
|
|
|
|
using Avalonia.Platform;
|
|
|
|
|
|
2024-04-05 22:14:22 -07:00
|
|
|
|
namespace SourceGit.Models
|
|
|
|
|
{
|
2024-04-08 02:39:52 -07:00
|
|
|
|
public class ExternalTool
|
2024-04-05 22:14:22 -07:00
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; } = string.Empty;
|
2024-04-06 00:01:07 -07:00
|
|
|
|
public string Icon { get; set; } = string.Empty;
|
2024-04-05 22:14:22 -07:00
|
|
|
|
public string Executable { get; set; } = string.Empty;
|
|
|
|
|
public string OpenCmdArgs { get; set; } = string.Empty;
|
|
|
|
|
|
2024-04-09 00:00:52 -07:00
|
|
|
|
public Bitmap IconImage
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{Icon}.png", UriKind.RelativeOrAbsolute));
|
|
|
|
|
return new Bitmap(icon);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-05 22:14:22 -07:00
|
|
|
|
public void Open(string repo)
|
|
|
|
|
{
|
|
|
|
|
Process.Start(new ProcessStartInfo()
|
|
|
|
|
{
|
|
|
|
|
WorkingDirectory = repo,
|
|
|
|
|
FileName = Executable,
|
|
|
|
|
Arguments = string.Format(OpenCmdArgs, repo),
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-07 02:56:53 -07:00
|
|
|
|
|
2024-04-08 02:39:52 -07:00
|
|
|
|
public class ExternalToolsFinder
|
2024-04-07 02:56:53 -07:00
|
|
|
|
{
|
2024-04-08 02:39:52 -07:00
|
|
|
|
public List<ExternalTool> Founded
|
2024-04-07 02:56:53 -07:00
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
2024-04-08 02:39:52 -07:00
|
|
|
|
} = new List<ExternalTool>();
|
2024-04-07 02:56:53 -07:00
|
|
|
|
|
|
|
|
|
public void VSCode(Func<string> platform_finder)
|
|
|
|
|
{
|
2024-04-09 00:00:52 -07:00
|
|
|
|
TryAdd("Visual Studio Code", "vscode", "\"{0}\"", "VSCODE_PATH", platform_finder);
|
2024-04-07 02:56:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void VSCodeInsiders(Func<string> platform_finder)
|
|
|
|
|
{
|
2024-04-09 00:00:52 -07:00
|
|
|
|
TryAdd("Visual Studio Code - Insiders", "vscode_insiders", "\"{0}\"", "VSCODE_INSIDERS_PATH", platform_finder);
|
2024-04-07 02:56:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Fleet(Func<string> platform_finder)
|
|
|
|
|
{
|
2024-04-09 00:00:52 -07:00
|
|
|
|
TryAdd("JetBrains Fleet", "fleet", "\"{0}\"", "FLEET_PATH", platform_finder);
|
2024-04-07 02:56:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SublimeText(Func<string> platform_finder)
|
|
|
|
|
{
|
2024-04-09 00:00:52 -07:00
|
|
|
|
TryAdd("Sublime Text", "sublime_text", "\"{0}\"", "SUBLIME_TEXT_PATH", platform_finder);
|
2024-04-07 02:56:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-08 02:39:52 -07:00
|
|
|
|
public void TryAdd(string name, string icon, string args, string env, Func<string> finder)
|
2024-04-07 02:56:53 -07:00
|
|
|
|
{
|
|
|
|
|
var path = Environment.GetEnvironmentVariable(env);
|
|
|
|
|
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
path = finder();
|
|
|
|
|
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-08 02:39:52 -07:00
|
|
|
|
Founded.Add(new ExternalTool
|
2024-04-07 02:56:53 -07:00
|
|
|
|
{
|
|
|
|
|
Name = name,
|
|
|
|
|
Icon = icon,
|
|
|
|
|
OpenCmdArgs = args,
|
|
|
|
|
Executable = path,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-05 22:14:22 -07:00
|
|
|
|
}
|