- add: linux support

This commit is contained in:
2025-12-03 23:16:18 +03:00
parent 6eead05308
commit d7f775e80c
7 changed files with 946 additions and 57 deletions

View File

@@ -13,15 +13,17 @@ namespace Nebula.UpdateResolver;
public static class DotnetStandalone
{
private static readonly HttpClient HttpClient = new HttpClient();
private static readonly HttpClient HttpClient = new();
private static readonly string FullPath =
Path.Join(MainWindow.RootPath, "dotnet", DotnetUrlHelper.GetRuntimeIdentifier());
private static readonly string FullPath = Path.Join(MainWindow.RootPath, "dotnet", DotnetUrlHelper.GetRuntimeIdentifier());
private static readonly string ExecutePath = Path.Join(FullPath, "dotnet" + DotnetUrlHelper.GetExtension());
public static async Task<Process?> Run(string dllPath)
{
await EnsureDotnet();
return Process.Start(new ProcessStartInfo
{
FileName = ExecutePath,
@@ -33,22 +35,43 @@ public static class DotnetStandalone
StandardOutputEncoding = Encoding.UTF8
});
}
private static async Task EnsureDotnet(){
if(!Directory.Exists(FullPath))
private static async Task EnsureDotnet()
{
if (!Directory.Exists(FullPath))
await Download();
}
private static async Task Download(){
private static async Task Download()
{
LogStandalone.Log($"Downloading dotnet {DotnetUrlHelper.GetRuntimeIdentifier()}...");
var ridExt =
DotnetUrlHelper.GetCurrentPlatformDotnetUrl(ConfigurationStandalone.GetConfigValue(UpdateConVars.DotnetUrl)!);
using var response = await HttpClient.GetAsync(ridExt);
using var zipArchive = new ZipArchive(await response.Content.ReadAsStreamAsync());
var url = DotnetUrlHelper.GetCurrentPlatformDotnetUrl(
ConfigurationStandalone.GetConfigValue(UpdateConVars.DotnetUrl)!
);
using var response = await HttpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
await using var stream = await response.Content.ReadAsStreamAsync();
Directory.CreateDirectory(FullPath);
zipArchive.ExtractToDirectory(FullPath);
LogStandalone.Log($"Downloading dotnet complete.");
if (url.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
{
using var zipArchive = new ZipArchive(stream);
zipArchive.ExtractToDirectory(FullPath, true);
}
else if (url.EndsWith(".tar.gz", StringComparison.OrdinalIgnoreCase)
|| url.EndsWith(".tgz", StringComparison.OrdinalIgnoreCase))
{
TarUtils.ExtractTarGz(stream, FullPath);
}
else
{
throw new NotSupportedException("Unsupported archive format.");
}
LogStandalone.Log("Downloading dotnet complete.");
}
}
@@ -59,15 +82,12 @@ public static class DotnetUrlHelper
if (OperatingSystem.IsWindows()) return ".exe";
return "";
}
public static string GetCurrentPlatformDotnetUrl(Dictionary<string, string> dotnetUrl)
{
string? rid = GetRuntimeIdentifier();
var rid = GetRuntimeIdentifier();
if (dotnetUrl.TryGetValue(rid, out var url))
{
return url;
}
if (dotnetUrl.TryGetValue(rid, out var url)) return url;
throw new PlatformNotSupportedException($"No download URL available for the current platform: {rid}");
}
@@ -75,14 +95,9 @@ public static class DotnetUrlHelper
public static string GetRuntimeIdentifier()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return Environment.Is64BitProcess ? "win-x64" : "win-x86";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return "linux-x64";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return "linux-x64";
throw new PlatformNotSupportedException("Unsupported operating system");
}