feat: let users delete policy-blocked and orphaned plugins

This commit is contained in:
goat 2022-07-13 21:29:01 +02:00
parent 098607cca8
commit 2c011b6bcd
No known key found for this signature in database
GPG key ID: 7773BB5B43BA52E5
3 changed files with 44 additions and 20 deletions

View file

@ -1724,7 +1724,6 @@ namespace Dalamud.Interface.Internal.Windows.PluginInstaller
}
else if (plugin.State == PluginState.Loaded || plugin.State == PluginState.LoadError || plugin.State == PluginState.DependencyResolutionFailed)
{
// TODO: We should draw the trash can button for policy-blocked plugins in safe mode, so plugins can be deleted
if (pluginManager.SafeMode)
{
ImGuiComponents.DisabledButton(Locs.PluginButton_SafeMode);
@ -1932,8 +1931,10 @@ namespace Dalamud.Interface.Internal.Windows.PluginInstaller
private void DrawDeletePluginButton(LocalPlugin plugin)
{
var unloaded = plugin.State == PluginState.Unloaded;
var showButton = unloaded && (plugin.IsDev || plugin.IsOutdated || plugin.IsBanned || plugin.IsOrphaned);
var unloaded = plugin.State == PluginState.Unloaded || plugin.State == PluginState.LoadError;
// When policy check fails, the plugin is never loaded
var showButton = unloaded && (plugin.IsDev || plugin.IsOutdated || plugin.IsBanned || plugin.IsOrphaned || !plugin.CheckPolicy());
if (!showButton)
return;
@ -1941,26 +1942,40 @@ namespace Dalamud.Interface.Internal.Windows.PluginInstaller
var pluginManager = Service<PluginManager>.Get();
ImGui.SameLine();
if (ImGuiComponents.IconButton(FontAwesomeIcon.TrashAlt))
if (plugin.HasEverStartedLoad)
{
try
{
plugin.DllFile.Delete();
pluginManager.RemovePlugin(plugin);
}
catch (Exception ex)
{
Log.Error(ex, $"Plugin installer threw an error during removal of {plugin.Name}");
ImGui.PushFont(InterfaceManager.IconFont);
ImGuiComponents.DisabledButton(FontAwesomeIcon.TrashAlt.ToIconString());
ImGui.PopFont();
this.errorModalMessage = Locs.ErrorModal_DeleteFail(plugin.Name);
this.errorModalDrawing = true;
this.errorModalOnNextFrame = true;
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip(Locs.PluginButtonToolTip_DeletePluginRestricted);
}
}
if (ImGui.IsItemHovered())
else
{
ImGui.SetTooltip(Locs.PluginButtonToolTip_DeletePlugin);
if (ImGuiComponents.IconButton(FontAwesomeIcon.TrashAlt))
{
try
{
plugin.DllFile.Delete();
pluginManager.RemovePlugin(plugin);
}
catch (Exception ex)
{
Log.Error(ex, $"Plugin installer threw an error during removal of {plugin.Name}");
this.errorModalMessage = Locs.ErrorModal_DeleteFail(plugin.Name);
this.errorModalDrawing = true;
this.errorModalOnNextFrame = true;
}
}
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip(Locs.PluginButtonToolTip_DeletePlugin);
}
}
}
@ -2369,6 +2384,8 @@ namespace Dalamud.Interface.Internal.Windows.PluginInstaller
public static string PluginButtonToolTip_DeletePlugin => Loc.Localize("InstallerDeletePlugin ", "Delete plugin");
public static string PluginButtonToolTip_DeletePluginRestricted => Loc.Localize("InstallerDeletePluginRestricted", "Cannot delete - please try restarting the game.");
public static string PluginButtonToolTip_VisitPluginUrl => Loc.Localize("InstallerVisitPluginUrl", "Visit plugin URL");
public static string PluginButtonToolTip_UpdateSingle(string version) => Loc.Localize("InstallerUpdateSingle", "Update to {0}").Format(version);

View file

@ -771,8 +771,8 @@ internal partial class PluginManager : IDisposable, IServiceType
/// <param name="plugin">Plugin to remove.</param>
public void RemovePlugin(LocalPlugin plugin)
{
if (plugin.State != PluginState.Unloaded)
throw new InvalidPluginOperationException($"Unable to remove {plugin.Name}, not unloaded");
if (plugin.State != PluginState.Unloaded && plugin.HasEverStartedLoad)
throw new InvalidPluginOperationException($"Unable to remove {plugin.Name}, not unloaded and had loaded before");
lock (this.pluginListLock)
{

View file

@ -189,6 +189,11 @@ internal class LocalPlugin : IDisposable
/// </summary>
public string BanReason { get; }
/// <summary>
/// Gets a value indicating whether the plugin has ever started to load.
/// </summary>
public bool HasEverStartedLoad { get; private set; }
/// <summary>
/// Gets a value indicating whether the plugin is loaded and running.
/// </summary>
@ -335,6 +340,8 @@ internal class LocalPlugin : IDisposable
"Please refer to https://github.com/goatcorp/Dalamud/discussions/603 for more information.");
}
this.HasEverStartedLoad = true;
this.loader ??= PluginLoader.CreateFromAssemblyFile(this.DllFile.FullName, SetupLoaderConfig);
if (reloading || this.IsDev)