feat(PluginManager): add DeleteConfiguration() and UI

This commit is contained in:
goat 2021-07-16 22:57:41 +02:00
parent 68142da426
commit 9759ac6d11
No known key found for this signature in database
GPG key ID: F18F057873895461
3 changed files with 66 additions and 1 deletions

View file

@ -60,6 +60,22 @@ namespace Dalamud.Configuration
});
}
/// <summary>
/// Delete the configuration file and folder for the specified plugin.
/// This will throw an <see cref="IOException"/> if the plugin did not correctly close its handles.
/// </summary>
/// <param name="pluginName">The name of the plugin.</param>
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();
}
/// <summary>
/// Get plugin directory.
/// </summary>

View file

@ -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);

View file

@ -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;
}
/// <summary>
/// Update a single plugin, provided a valid <see cref="AvailablePluginUpdate"/>.
/// </summary>
/// <param name="metadata">The available plugin update.</param>
/// <param name="notify">Whether to notify that installed plugins have changed afterwards.</param>
/// <param name="dryRun">Whether or not to actually perform the update, or just indicate success.</param>
/// <returns>The status of the update.</returns>
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);
}
/// <summary>
/// Print to chat any plugin updates and whether they were successful.
/// </summary>