From 9759ac6d115f03c77f6a6bf06892c87ae32a2c2c Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Fri, 16 Jul 2021 22:57:41 +0200
Subject: [PATCH 1/5] feat(PluginManager): add DeleteConfiguration() and UI
---
Dalamud/Configuration/PluginConfigurations.cs | 16 +++++++++++
.../Internal/Windows/PluginInstallerWindow.cs | 23 +++++++++++++++
Dalamud/Plugin/Internal/PluginManager.cs | 28 ++++++++++++++++++-
3 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/Dalamud/Configuration/PluginConfigurations.cs b/Dalamud/Configuration/PluginConfigurations.cs
index 1cadb2180..26577b8be 100644
--- a/Dalamud/Configuration/PluginConfigurations.cs
+++ b/Dalamud/Configuration/PluginConfigurations.cs
@@ -60,6 +60,22 @@ namespace Dalamud.Configuration
});
}
+ ///
+ /// Delete the configuration file and folder for the specified plugin.
+ /// This will throw an if the plugin did not correctly close its handles.
+ ///
+ /// The name of the plugin.
+ public void Delete(string pluginName)
+ {
+ var directory = this.GetDirectoryPath(pluginName);
+ if (directory.Exists)
+ directory.Delete(true);
+
+ var file = this.GetConfigFile(pluginName);
+ if (file.Exists)
+ file.Delete();
+ }
+
///
/// Get plugin directory.
///
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs
index e7f2f68fa..1b041ef35 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs
@@ -692,6 +692,25 @@ namespace Dalamud.Interface.Internal.Windows
ImGui.Unindent();
}
+
+ if (ImGui.BeginPopupContextItem("InstalledItemContextMenu"))
+ {
+ if (ImGui.Selectable(Locs.PluginContext_DeletePluginConfig))
+ {
+ Log.Debug($"Deleting config for {plugin.Manifest.InternalName}");
+
+ Task.Run(() => this.dalamud.PluginManager.DeleteConfiguration(plugin))
+ .ContinueWith(task =>
+ {
+ // There is no need to set as Complete for an individual plugin installation
+ this.installStatus = OperationStatus.Idle;
+
+ this.DisplayErrorContinuation(task, Locs.ErrorModal_DeleteConfigFail(plugin.Name));
+ });
+ }
+
+ ImGui.EndPopup();
+ }
}
private void DrawPluginControlButton(LocalPlugin plugin)
@@ -1125,6 +1144,8 @@ namespace Dalamud.Interface.Internal.Windows
public static string PluginContext_HidePlugin => Loc.Localize("InstallerHidePlugin", "Hide from installer");
+ public static string PluginContext_DeletePluginConfig => Loc.Localize("InstallerDeletePluginConfig", "Delete configuration data & reload");
+
#endregion
#region Plugin body
@@ -1199,6 +1220,8 @@ namespace Dalamud.Interface.Internal.Windows
public static string ErrorModal_SingleUpdateFail(string name) => Loc.Localize("InstallerSingleUpdateFail", "Failed to update plugin {0}.").Format(name);
+ public static string ErrorModal_DeleteConfigFail(string name) => Loc.Localize("InstallerDeleteConfigFail", "Failed to reset the plugin {0}.\n\nThe plugin may not support this action. You can try deleting the configuration manually while the game is shut down - please see the FAQ.").Format(name);
+
public static string ErrorModal_EnableFail(string name) => Loc.Localize("InstallerEnableFail", "Failed to enable plugin {0}.").Format(name);
public static string ErrorModal_DisableFail(string name) => Loc.Localize("InstallerDisableFail", "Failed to disable plugin {0}.").Format(name);
diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs
index 55078fb85..455074b7f 100644
--- a/Dalamud/Plugin/Internal/PluginManager.cs
+++ b/Dalamud/Plugin/Internal/PluginManager.cs
@@ -8,7 +8,7 @@ using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Reflection;
-using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using CheapLoc;
@@ -713,6 +713,32 @@ namespace Dalamud.Plugin.Internal
return updateStatus;
}
+ ///
+ /// Update a single plugin, provided a valid .
+ ///
+ /// The available plugin update.
+ /// Whether to notify that installed plugins have changed afterwards.
+ /// Whether or not to actually perform the update, or just indicate success.
+ /// The status of the update.
+ public void DeleteConfiguration(LocalPlugin plugin)
+ {
+ if (plugin.State == PluginState.InProgress)
+ throw new Exception("Cannot delete configuration for a loading/unloading plugin");
+
+ if (plugin.IsLoaded)
+ plugin.Unload();
+
+ // Let's wait so any handles on files in plugin configurations can be closed
+ Thread.Sleep(500);
+
+ this.PluginConfigs.Delete(plugin.Name);
+
+ Thread.Sleep(500);
+
+ // Let's indicate "installer" here since this is supposed to be a fresh install
+ plugin.Load(PluginLoadReason.Installer);
+ }
+
///
/// Print to chat any plugin updates and whether they were successful.
///
From 59ce9f94e23541384ebf6c63c43956a7a9b58693 Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Fri, 16 Jul 2021 23:00:10 +0200
Subject: [PATCH 2/5] fix xmldoc
---
Dalamud/Plugin/Internal/PluginManager.cs | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs
index 455074b7f..5f1165742 100644
--- a/Dalamud/Plugin/Internal/PluginManager.cs
+++ b/Dalamud/Plugin/Internal/PluginManager.cs
@@ -714,12 +714,10 @@ namespace Dalamud.Plugin.Internal
}
///
- /// Update a single plugin, provided a valid .
+ /// Unload the plugin, delete its configuration, and reload it.
///
- /// The available plugin update.
- /// Whether to notify that installed plugins have changed afterwards.
- /// Whether or not to actually perform the update, or just indicate success.
- /// The status of the update.
+ /// The plugin.
+ /// Throws if the plugin is still loading/unloading.
public void DeleteConfiguration(LocalPlugin plugin)
{
if (plugin.State == PluginState.InProgress)
From 01727929a5bf5e4671eb2158690664743b0293f5 Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Fri, 16 Jul 2021 23:01:37 +0200
Subject: [PATCH 3/5] fix(PluginConfigurations): add CanBeNullAttribute to
Load()
---
Dalamud/Configuration/PluginConfigurations.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Dalamud/Configuration/PluginConfigurations.cs b/Dalamud/Configuration/PluginConfigurations.cs
index 26577b8be..95f25b04a 100644
--- a/Dalamud/Configuration/PluginConfigurations.cs
+++ b/Dalamud/Configuration/PluginConfigurations.cs
@@ -1,5 +1,6 @@
using System.IO;
+using JetBrains.Annotations;
using Newtonsoft.Json;
namespace Dalamud.Configuration
@@ -44,6 +45,7 @@ namespace Dalamud.Configuration
///
/// Plugin name.
/// Plugin configuration.
+ [CanBeNull]
public IPluginConfiguration Load(string pluginName)
{
var path = this.GetConfigFile(pluginName);
From d43f07dc040087728ac3b49a31469b127c649d1a Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Fri, 16 Jul 2021 23:04:34 +0200
Subject: [PATCH 4/5] change wording for plugin resets
---
Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs
index 1b041ef35..0bdf48e1b 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs
@@ -1144,7 +1144,7 @@ namespace Dalamud.Interface.Internal.Windows
public static string PluginContext_HidePlugin => Loc.Localize("InstallerHidePlugin", "Hide from installer");
- public static string PluginContext_DeletePluginConfig => Loc.Localize("InstallerDeletePluginConfig", "Delete configuration data & reload");
+ public static string PluginContext_DeletePluginConfig => Loc.Localize("InstallerDeletePluginConfig", "Reset plugin settings & reload");
#endregion
From bf158c9386e2735b49cdf70a023ebee637c200b1 Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Fri, 16 Jul 2021 23:16:48 +0200
Subject: [PATCH 5/5] fix(PluginManager): allow LoadError state in Unload()
---
Dalamud/Plugin/Internal/LocalPlugin.cs | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/Dalamud/Plugin/Internal/LocalPlugin.cs b/Dalamud/Plugin/Internal/LocalPlugin.cs
index 9df84d35b..f7bbe9615 100644
--- a/Dalamud/Plugin/Internal/LocalPlugin.cs
+++ b/Dalamud/Plugin/Internal/LocalPlugin.cs
@@ -315,13 +315,11 @@ namespace Dalamud.Plugin.Internal
/// Unload while reloading.
public void Unload(bool reloading = false)
{
- // Allowed: Loaded
+ // Allowed: Loaded, LoadError(we are cleaning this up while we're at it)
switch (this.State)
{
case PluginState.InProgress:
throw new InvalidPluginOperationException($"Unable to unload {this.Name}, already working");
- case PluginState.LoadError:
- throw new InvalidPluginOperationException($"Unable to unload {this.Name}, load previously faulted, unload first");
case PluginState.Unloaded:
throw new InvalidPluginOperationException($"Unable to unload {this.Name}, already unloaded");
case PluginState.UnloadError: