stop fastzip from extracting on cancellation

This commit is contained in:
bluepilledgreat 2024-09-28 22:54:27 +01:00
parent 55f5ef48e8
commit 98e72e29b6

View File

@ -16,6 +16,9 @@ using System.Windows.Forms;
using Microsoft.Win32; using Microsoft.Win32;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Core;
using Bloxstrap.AppData; using Bloxstrap.AppData;
namespace Bloxstrap namespace Bloxstrap
@ -1048,6 +1051,12 @@ namespace Bloxstrap
} }
} }
private void OnFastZipProcessFile(object sender, ScanEventArgs e)
{
// stop extracting if cancellation requested
e.ContinueRunning = !_cancelTokenSource.IsCancellationRequested;
}
private void ExtractPackage(Package package, List<string>? files = null) private void ExtractPackage(Package package, List<string>? files = null)
{ {
const string LOG_IDENT = "Bootstrapper::ExtractPackage"; const string LOG_IDENT = "Bootstrapper::ExtractPackage";
@ -1068,7 +1077,10 @@ namespace Bloxstrap
App.Logger.WriteLine(LOG_IDENT, $"Extracting {package.Name}..."); 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); fastZip.ExtractZip(package.DownloadPath, packageFolder, fileFilter);
App.Logger.WriteLine(LOG_IDENT, $"Finished extracting {package.Name}"); App.Logger.WriteLine(LOG_IDENT, $"Finished extracting {package.Name}");