mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-20 23:32:55 +00:00
Improve Pandoc download and extraction process; fixed *.tar.gz handling
This commit is contained in:
parent
df3c28e55f
commit
7f19a6b07d
@ -1,4 +1,5 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Formats.Tar;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@ -113,9 +114,15 @@ public static partial class Pandoc
|
|||||||
if (!Directory.Exists(installDir))
|
if (!Directory.Exists(installDir))
|
||||||
Directory.CreateDirectory(installDir);
|
Directory.CreateDirectory(installDir);
|
||||||
|
|
||||||
using var client = new HttpClient();
|
// Create a temporary file to download the archive to:
|
||||||
var uri = await GenerateArchiveUriAsync();
|
var pandocTempDownloadFile = Path.GetTempFileName();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Download the latest Pandoc archive from GitHub:
|
||||||
|
//
|
||||||
|
var uri = await GenerateArchiveUriAsync();
|
||||||
|
using (var client = new HttpClient())
|
||||||
|
{
|
||||||
var response = await client.GetAsync(uri);
|
var response = await client.GetAsync(uri);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
@ -124,21 +131,20 @@ public static partial class Pandoc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileBytes = await response.Content.ReadAsByteArrayAsync();
|
// Download the archive to the temporary file:
|
||||||
|
await using var tempFileStream = File.Create(pandocTempDownloadFile);
|
||||||
if (uri.Contains(".zip"))
|
await response.Content.CopyToAsync(tempFileStream);
|
||||||
{
|
|
||||||
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"))
|
|
||||||
|
if (uri.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var tempTarPath = Path.Join(Path.GetTempPath(), "pandoc.tar.gz");
|
ZipFile.ExtractToDirectory(pandocTempDownloadFile, installDir);
|
||||||
await File.WriteAllBytesAsync(tempTarPath, fileBytes);
|
}
|
||||||
ZipFile.ExtractToDirectory(tempTarPath, installDir);
|
else if (uri.EndsWith(".tar.gz", StringComparison.OrdinalIgnoreCase))
|
||||||
File.Delete(tempTarPath);
|
{
|
||||||
|
await using var tgzStream = File.Open(pandocTempDownloadFile, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||||
|
await using var uncompressedStream = new GZipStream(tgzStream, CompressionMode.Decompress);
|
||||||
|
await TarFile.ExtractToDirectoryAsync(uncompressedStream, installDir, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -147,6 +153,7 @@ public static partial class Pandoc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File.Delete(pandocTempDownloadFile);
|
||||||
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle, $"Pandoc {await FetchLatestVersionAsync()} was installed successfully."));
|
await MessageBus.INSTANCE.SendSuccess(new(Icons.Material.Filled.CheckCircle, $"Pandoc {await FetchLatestVersionAsync()} was installed successfully."));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
Loading…
Reference in New Issue
Block a user