From f684cdb0511e2a2e2438b9ae3bb5e432336e4dde Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:41:34 +0100 Subject: [PATCH] Show error when failing to delete plugin files --- .../Plugins/PluginManager.xaml.cs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/DesktopMagic/Plugins/PluginManager.xaml.cs b/src/DesktopMagic/Plugins/PluginManager.xaml.cs index 8b9bb92..7217664 100644 --- a/src/DesktopMagic/Plugins/PluginManager.xaml.cs +++ b/src/DesktopMagic/Plugins/PluginManager.xaml.cs @@ -58,16 +58,24 @@ public partial class PluginManager : Window PluginEntryDataContext? pluginEntryDataContext = pluginManagerDataContext.InstalledPlugins.FirstOrDefault(p => p.Id == id); + if (Directory.Exists(pluginPath)) + { + try + { + Directory.Delete(pluginPath, true); + } + catch (Exception ex) + { + _ = MessageBox.Show(ex.Message, "Plugin Manager", MessageBoxButton.OK, MessageBoxImage.Error); + App.Logger.LogError(ex.Message, source: "PluginManager"); + } + } + if (pluginEntryDataContext is not null) { _ = pluginManagerDataContext.InstalledPlugins.Remove(pluginEntryDataContext); } - if (Directory.Exists(pluginPath)) - { - Directory.Delete(pluginPath, true); - } - pluginManagerDataContext.IsLoading = false; } @@ -85,7 +93,7 @@ public partial class PluginManager : Window continue; } - PluginMetadata? pluginMetadata = JsonSerializer.Deserialize(File.ReadAllText(pluginMetadataPath)); + PluginMetadata? pluginMetadata = JsonSerializer.Deserialize(await File.ReadAllTextAsync(pluginMetadataPath)); if (pluginMetadata is not null) { @@ -141,7 +149,7 @@ public partial class PluginManager : Window } string pluginMetadataPath = Path.Combine(pluginPath, "metadata.json"); - File.WriteAllText(pluginMetadataPath, JsonSerializer.Serialize(new PluginMetadata(mod))); + await File.WriteAllTextAsync(pluginMetadataPath, JsonSerializer.Serialize(new PluginMetadata(mod))); File.Delete(zipFilePath);