WIP: Change pandocs download function to account for different cpu architectures

This commit is contained in:
krut_ni 2025-04-14 19:45:23 +02:00
parent b60d23a91b
commit 331c6caf4b

View File

@ -92,42 +92,64 @@ public static partial class Pandoc
Directory.CreateDirectory(installDir); Directory.CreateDirectory(installDir);
using var client = new HttpClient(); using var client = new HttpClient();
var response = await client.GetAsync(await GenerateUriAsync()); var uri = await GenerateUriAsync();
if (response.IsSuccessStatusCode)
var response = await client.GetAsync(uri);
if (!response.IsSuccessStatusCode)
{
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Error, $"Pandoc was not installed successfully, because the download archive was not found."));
LOG.LogError("Pandoc was not installed, the release archive was not found (Status Code {StatusCode}):\n{Uri}\n{Message}", response.StatusCode, uri, response.RequestMessage);
return;
}
var fileBytes = await response.Content.ReadAsByteArrayAsync();
if (uri.Contains(".zip"))
{ {
var fileBytes = await response.Content.ReadAsByteArrayAsync();
var tempZipPath = Path.Join(Path.GetTempPath(), "pandoc.zip"); var tempZipPath = Path.Join(Path.GetTempPath(), "pandoc.zip");
await File.WriteAllBytesAsync(tempZipPath, fileBytes); await File.WriteAllBytesAsync(tempZipPath, fileBytes);
ZipFile.ExtractToDirectory(tempZipPath, installDir); ZipFile.ExtractToDirectory(tempZipPath, installDir);
File.Delete(tempZipPath); File.Delete(tempZipPath);
}
var currentPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine); else if (uri.Contains(".tar.gz"))
var pandocDir = Path.Join(currentPath, "pandoc-3.6.4"); {
if (currentPath != null && !currentPath.Contains(pandocDir)) Console.WriteLine("is zip");
{
Environment.SetEnvironmentVariable(
"PATH",
$"{currentPath};{pandocDir}",
EnvironmentVariableTarget.Machine);
Console.WriteLine("Pandoc-Verzeichnis zum PATH hinzugefügt.");
}
else
{
Console.WriteLine("Pandoc-Verzeichnis ist bereits im PATH.");
}
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle, $"Pandoc {MINIMUM_REQUIRED_VERSION.ToString()} was installed successfully."));
} }
else else
{ {
Console.WriteLine("Fehler beim Herunterladen von Pandoc."); await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.Error, $"Pandoc was not installed successfully, because the download archive type is unknown."));
LOG.LogError("Pandoc was not installed, the download archive is unknown:\n {Uri}", uri);
return;
} }
var currentPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine);
var pandocDir = Path.Join(currentPath, "pandoc-3.6.4");
if (currentPath != null && !currentPath.Contains(pandocDir))
{
Environment.SetEnvironmentVariable(
"PATH",
$"{currentPath};{pandocDir}",
EnvironmentVariableTarget.Machine);
Console.WriteLine("Pandoc-Verzeichnis zum PATH hinzugefügt.");
}
else
{
Console.WriteLine("Pandoc-Verzeichnis ist bereits im PATH.");
}
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle,
$"Pandoc {MINIMUM_REQUIRED_VERSION.ToString()} was installed successfully."));
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"Fehler: {ex.Message}"); Console.WriteLine($"Fehler: {ex.Message}");
} }
} }
private static async Task ExtractZipAsync(string zipPath, string targetDir)
{
}
public static async Task<string> FetchLatestVersionAsync() { public static async Task<string> FetchLatestVersionAsync() {
using var client = new HttpClient(); using var client = new HttpClient();