From 3dbe8d1757cadaf31ed80b35d749a72e5386e750 Mon Sep 17 00:00:00 2001 From: Goober5000 Date: Sat, 9 May 2026 21:01:47 -0400 Subject: [PATCH] fix task cancellation Removing `return false` in the second commit to #398 was the wrong fix; it should have been changed to `return null`. But this had an unexpected benefit as it turns out several other places in the code need proper handling of task cancellation. --- Knossos.NET/ViewModels/Templates/Tasks/InstallBuild.cs | 2 ++ Knossos.NET/ViewModels/Templates/Tasks/InstallMod.cs | 1 + Knossos.NET/ViewModels/Templates/Tasks/InstallTool.cs | 1 + 3 files changed, 4 insertions(+) diff --git a/Knossos.NET/ViewModels/Templates/Tasks/InstallBuild.cs b/Knossos.NET/ViewModels/Templates/Tasks/InstallBuild.cs index 54515fe4..835a1eb1 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/InstallBuild.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/InstallBuild.cs @@ -235,6 +235,7 @@ private async Task InstallVCRedist(bool is86 = false) { { Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.InstallBuild()", $"Unsafe dest path in build '{build.id}': {file.dest}"); CancelTaskCommand(); + return null; } Directory.CreateDirectory(modPath + Path.DirectorySeparatorChar + file.dest); } @@ -359,6 +360,7 @@ private async Task InstallVCRedist(bool is86 = false) { { Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.InstallBuild()", "Error while decompressing the file " + fileFullPath); CancelTaskCommand(); + throw new TaskCanceledException(); } //sender.ProgressBarCurrent = ++ProgressCurrent; ++ProgressCurrent; diff --git a/Knossos.NET/ViewModels/Templates/Tasks/InstallMod.cs b/Knossos.NET/ViewModels/Templates/Tasks/InstallMod.cs index 3e76f791..350806bc 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/InstallMod.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/InstallMod.cs @@ -415,6 +415,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource { Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.InstallMod()", "Error while decompressing the file " + fileFullPath); CancelTaskCommand(); + throw new TaskCanceledException(); } File.Delete(fileFullPath); ++ProgressCurrent; diff --git a/Knossos.NET/ViewModels/Templates/Tasks/InstallTool.cs b/Knossos.NET/ViewModels/Templates/Tasks/InstallTool.cs index a564e595..434999a8 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/InstallTool.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/InstallTool.cs @@ -110,6 +110,7 @@ public async Task InstallTool(Tool tool, Tool? updateFrom, Action fi { Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.InstallTool()", "Error while decompressing the file " + fileFullPath); CancelTaskCommand(); + throw new TaskCanceledException(); } if (cancellationTokenSource.IsCancellationRequested)