mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Merge pull request #416 from goaaats/feature/delete_config
This commit is contained in:
commit
cb1f06ae76
4 changed files with 67 additions and 4 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System.IO;
|
||||
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Configuration
|
||||
|
|
@ -44,6 +45,7 @@ namespace Dalamud.Configuration
|
|||
/// </summary>
|
||||
/// <param name="pluginName">Plugin name.</param>
|
||||
/// <returns>Plugin configuration.</returns>
|
||||
[CanBeNull]
|
||||
public IPluginConfiguration Load(string pluginName)
|
||||
{
|
||||
var path = this.GetConfigFile(pluginName);
|
||||
|
|
@ -60,6 +62,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>
|
||||
|
|
|
|||
|
|
@ -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", "Reset plugin settings & 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);
|
||||
|
|
|
|||
|
|
@ -315,13 +315,11 @@ namespace Dalamud.Plugin.Internal
|
|||
/// <param name="reloading">Unload while reloading.</param>
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -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,30 @@ namespace Dalamud.Plugin.Internal
|
|||
return updateStatus;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unload the plugin, delete its configuration, and reload it.
|
||||
/// </summary>
|
||||
/// <param name="plugin">The plugin.</param>
|
||||
/// <exception cref="Exception">Throws if the plugin is still loading/unloading.</exception>
|
||||
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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue