42 lines
1.3 KiB
C#
Raw Normal View History

2022-05-14 02:58:38 +01:00
using SharpCompress.Archives;
using SharpCompress.Archives.Zip;
using SharpCompress.Common;
using Spectre.Console;
using System.Linq;
2022-05-13 22:41:15 +01:00
2022-05-14 02:58:38 +01:00
namespace SPT_AKI_Installer.Aki.Helper
2022-05-13 22:41:15 +01:00
{
public static class ZipHelper
{
/// <summary>
2022-05-14 02:58:38 +01:00
/// will extract Zips in LZMA compression format, using Zips path
2022-05-13 22:41:15 +01:00
/// to new path
/// </summary>
2022-05-14 02:58:38 +01:00
public static void Decompress(string ArchivePath, string OutputFolderPath)
2022-05-13 22:41:15 +01:00
{
2022-05-14 02:58:38 +01:00
AnsiConsole.Progress().Columns(
new PercentageColumn(),
new TaskDescriptionColumn(),
new ProgressBarColumn(),
new ElapsedTimeColumn()
).Start((ProgressContext context) =>
2022-05-13 22:41:15 +01:00
{
2022-05-14 02:58:38 +01:00
using var archive = ZipArchive.Open(ArchivePath);
var entries = archive.Entries.Where(entry => !entry.IsDirectory);
var task = context.AddTask("Extracting", true, entries.Count());
foreach (var entry in entries)
2022-05-13 22:41:15 +01:00
{
2022-05-14 02:58:38 +01:00
entry.WriteToDirectory($"{OutputFolderPath}", new ExtractionOptions()
2022-05-13 22:41:15 +01:00
{
ExtractFullPath = true,
Overwrite = true
});
2022-05-14 02:58:38 +01:00
task.Increment(1);
2022-05-13 22:41:15 +01:00
}
2022-05-14 02:58:38 +01:00
});
2022-05-13 22:41:15 +01:00
}
}
}