From 331c6caf4b7e2c20dce581b5116945948d39219f Mon Sep 17 00:00:00 2001 From: krut_ni Date: Mon, 14 Apr 2025 19:45:23 +0200 Subject: [PATCH] WIP: Change pandocs download function to account for different cpu architectures --- app/MindWork AI Studio/Tools/Pandoc.cs | 64 +++++++++++++++++--------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/app/MindWork AI Studio/Tools/Pandoc.cs b/app/MindWork AI Studio/Tools/Pandoc.cs index c4e28a37..d89a430a 100644 --- a/app/MindWork AI Studio/Tools/Pandoc.cs +++ b/app/MindWork AI Studio/Tools/Pandoc.cs @@ -92,42 +92,64 @@ 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 fileBytes = await response.Content.ReadAsByteArrayAsync(); var tempZipPath = Path.Join(Path.GetTempPath(), "pandoc.zip"); await File.WriteAllBytesAsync(tempZipPath, fileBytes); ZipFile.ExtractToDirectory(tempZipPath, installDir); File.Delete(tempZipPath); - - 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.")); + } + else if (uri.Contains(".tar.gz")) + { + Console.WriteLine("is zip"); } 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) { Console.WriteLine($"Fehler: {ex.Message}"); } } + + private static async Task ExtractZipAsync(string zipPath, string targetDir) + { + + } public static async Task FetchLatestVersionAsync() { using var client = new HttpClient();