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,14 +92,35 @@ public static partial class Pandoc
Directory.CreateDirectory(installDir);
using var client = new HttpClient();
var response = await client.GetAsync(await GenerateUriAsync());
if (response.IsSuccessStatusCode)
var uri = await GenerateUriAsync();
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 tempZipPath = Path.Join(Path.GetTempPath(), "pandoc.zip");
await File.WriteAllBytesAsync(tempZipPath, fileBytes);
ZipFile.ExtractToDirectory(tempZipPath, installDir);
File.Delete(tempZipPath);
}
else if (uri.Contains(".tar.gz"))
{
Console.WriteLine("is zip");
}
else
{
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");
@ -116,12 +137,8 @@ public static partial class Pandoc
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
{
Console.WriteLine("Fehler beim Herunterladen von Pandoc.");
}
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle,
$"Pandoc {MINIMUM_REQUIRED_VERSION.ToString()} was installed successfully."));
}
catch (Exception ex)
{
@ -129,6 +146,11 @@ public static partial class Pandoc
}
}
private static async Task ExtractZipAsync(string zipPath, string targetDir)
{
}
public static async Task<string> FetchLatestVersionAsync() {
using var client = new HttpClient();
var response = await client.GetAsync(LATEST_URL);