From 98e72e29b6689e45f395bb2a133bba5c01f2dde5 Mon Sep 17 00:00:00 2001 From: bluepilledgreat <97983689+bluepilledgreat@users.noreply.github.com> Date: Sat, 28 Sep 2024 22:54:27 +0100 Subject: [PATCH] stop fastzip from extracting on cancellation --- Bloxstrap/Bootstrapper.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index a28ce228..44392c87 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -16,6 +16,9 @@ using Microsoft.Win32; +using ICSharpCode.SharpZipLib.Zip; +using ICSharpCode.SharpZipLib.Core; + using Bloxstrap.AppData; namespace Bloxstrap @@ -1048,6 +1051,12 @@ private async Task DownloadPackage(Package package) } } + private void OnFastZipProcessFile(object sender, ScanEventArgs e) + { + // stop extracting if cancellation requested + e.ContinueRunning = !_cancelTokenSource.IsCancellationRequested; + } + private void ExtractPackage(Package package, List? files = null) { const string LOG_IDENT = "Bootstrapper::ExtractPackage"; @@ -1068,7 +1077,10 @@ private void ExtractPackage(Package package, List? files = null) App.Logger.WriteLine(LOG_IDENT, $"Extracting {package.Name}..."); - var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip(); + var events = new FastZipEvents(); + events.ProcessFile += OnFastZipProcessFile; + + var fastZip = new FastZip(events); fastZip.ExtractZip(package.DownloadPath, packageFolder, fileFilter); App.Logger.WriteLine(LOG_IDENT, $"Finished extracting {package.Name}");