From 88c96dd217a3821f6598256f2fb975d6c8913ae4 Mon Sep 17 00:00:00 2001 From: Goober5000 Date: Sun, 9 Mar 2025 22:32:30 -0400 Subject: [PATCH 1/3] when deleting mods, delete them to the Recycle Bin It's possible to delete files to the Recycle Bin, as shown here: https://www.csharp.com/blogs/extension-methods-for-delete-files-and-folders-to-recycle-bin Documentation here: https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.fileio.filesystem.deletedirectory?view=net-9.0 Motivated by the sad story of 'In the Beginning' posted here: https://www.hard-light.net/forums/index.php?topic=98100.msg1921007#msg1921007 --- Knossos.NET/Classes/Knossos.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Knossos.NET/Classes/Knossos.cs b/Knossos.NET/Classes/Knossos.cs index 62aa3169..184830f0 100644 --- a/Knossos.NET/Classes/Knossos.cs +++ b/Knossos.NET/Classes/Knossos.cs @@ -3,6 +3,7 @@ using Knossos.NET.Models; using Knossos.NET.ViewModels; using Knossos.NET.Views; +using Microsoft.VisualBasic.FileIO; using System.Diagnostics; using System.Collections.Generic; using System.Threading.Tasks; @@ -1660,7 +1661,7 @@ public static void RemoveMod(string modId) foreach (var mod in delete) { Log.Add(Log.LogSeverity.Information, "Knossos.RemoveMod()", "Deleting mod: "+mod.title + " " +mod.version); - Directory.Delete(mod.fullPath, true); + FileSystem.DeleteDirectory(mod.fullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); installedMods.Remove(mod); } } @@ -1682,7 +1683,7 @@ public static void RemoveMod(Mod mod) try { Log.Add(Log.LogSeverity.Information, "Knossos.RemoveMod()", "Deleting mod: " + mod.title + " " + mod.version); - Directory.Delete(mod.fullPath, true); + FileSystem.DeleteDirectory(mod.fullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); installedMods.Remove(mod); } catch (Exception ex) From 502cf60b4e195b15842a7e5af423acd7a81bd5ff Mon Sep 17 00:00:00 2001 From: Goober5000 Date: Wed, 12 Mar 2025 22:27:21 -0400 Subject: [PATCH 2/3] make it cross-platform --- Knossos.NET/Classes/Knossos.cs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Knossos.NET/Classes/Knossos.cs b/Knossos.NET/Classes/Knossos.cs index 184830f0..81e1c31f 100644 --- a/Knossos.NET/Classes/Knossos.cs +++ b/Knossos.NET/Classes/Knossos.cs @@ -1661,7 +1661,16 @@ public static void RemoveMod(string modId) foreach (var mod in delete) { Log.Add(Log.LogSeverity.Information, "Knossos.RemoveMod()", "Deleting mod: "+mod.title + " " +mod.version); - FileSystem.DeleteDirectory(mod.fullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); + try + { + // this might only work on Windows + FileSystem.DeleteDirectory(mod.fullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); + } + catch (PlatformNotSupportedException pnse) + { + // this should work on all platforms but doesn't use the Recycle Bin / Trash + Directory.Delete(mod.fullPath, true); + } installedMods.Remove(mod); } } @@ -1683,7 +1692,16 @@ public static void RemoveMod(Mod mod) try { Log.Add(Log.LogSeverity.Information, "Knossos.RemoveMod()", "Deleting mod: " + mod.title + " " + mod.version); - FileSystem.DeleteDirectory(mod.fullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); + try + { + // this might only work on Windows + FileSystem.DeleteDirectory(mod.fullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); + } + catch (PlatformNotSupportedException pnse) + { + // this should work on all platforms but doesn't use the Recycle Bin / Trash + Directory.Delete(mod.fullPath, true); + } installedMods.Remove(mod); } catch (Exception ex) From 8b6a8d4fcc5dd5b39d492de5cd46c2fde561dff7 Mon Sep 17 00:00:00 2001 From: Goober5000 Date: Thu, 13 Mar 2025 13:58:20 -0400 Subject: [PATCH 3/3] no need for unused variable --- Knossos.NET/Classes/Knossos.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Knossos.NET/Classes/Knossos.cs b/Knossos.NET/Classes/Knossos.cs index 81e1c31f..959d8292 100644 --- a/Knossos.NET/Classes/Knossos.cs +++ b/Knossos.NET/Classes/Knossos.cs @@ -1666,7 +1666,7 @@ public static void RemoveMod(string modId) // this might only work on Windows FileSystem.DeleteDirectory(mod.fullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } - catch (PlatformNotSupportedException pnse) + catch (PlatformNotSupportedException) { // this should work on all platforms but doesn't use the Recycle Bin / Trash Directory.Delete(mod.fullPath, true); @@ -1697,7 +1697,7 @@ public static void RemoveMod(Mod mod) // this might only work on Windows FileSystem.DeleteDirectory(mod.fullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } - catch (PlatformNotSupportedException pnse) + catch (PlatformNotSupportedException) { // this should work on all platforms but doesn't use the Recycle Bin / Trash Directory.Delete(mod.fullPath, true);