39 lines
1.2 KiB
C#
Raw Permalink 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
{
public static void ZipDecompress(string ArchivePath, string OutputFolderPath)
2022-05-13 22:41:15 +01:00
{
2022-05-14 02:58:38 +01:00
AnsiConsole.Progress().Columns(
2022-05-19 14:41:44 +01:00
new PercentageColumn(),
2022-05-14 02:58:38 +01:00
new TaskDescriptionColumn(),
new ProgressBarColumn(),
2022-05-19 14:41:44 +01:00
new ElapsedTimeColumn(),
new SpinnerColumn()
2022-05-14 02:58:38 +01:00
).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);
2022-05-19 14:41:44 +01:00
var task = context.AddTask("Extracting Files", true, entries.Count());
2022-05-14 02:58:38 +01:00
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
}
}
}