From 0cfbc70286a30661e16f7bf879bfd9c623500d62 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 20 Sep 2021 19:42:50 -0400 Subject: [PATCH 1/5] formatting --- .../Internal/Windows/PluginInstallerWindow.cs | 4 ++-- Dalamud/Plugin/Internal/LocalDevPlugin.cs | 10 ++++------ Dalamud/Plugin/Internal/LocalPlugin.cs | 13 ++++++------- Dalamud/Plugin/Internal/PluginManager.cs | 4 ++-- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs index c7fc934a1..84ca51b42 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs @@ -873,8 +873,8 @@ namespace Dalamud.Interface.Internal.Windows // Download count var downloadCountText = manifest.DownloadCount > 0 - ? Locs.PluginBody_AuthorWithDownloadCount(manifest.Author, manifest.DownloadCount) - : Locs.PluginBody_AuthorWithDownloadCountUnavailable(manifest.Author); + ? Locs.PluginBody_AuthorWithDownloadCount(manifest.Author, manifest.DownloadCount) + : Locs.PluginBody_AuthorWithDownloadCountUnavailable(manifest.Author); ImGui.SameLine(); ImGui.TextColored(ImGuiColors.DalamudGrey3, downloadCountText); diff --git a/Dalamud/Plugin/Internal/LocalDevPlugin.cs b/Dalamud/Plugin/Internal/LocalDevPlugin.cs index d8e0d94e0..3615c01a9 100644 --- a/Dalamud/Plugin/Internal/LocalDevPlugin.cs +++ b/Dalamud/Plugin/Internal/LocalDevPlugin.cs @@ -145,19 +145,17 @@ namespace Dalamud.Plugin.Internal return; } + var notificationManager = Service.Get(); + try { this.Reload(); - Service.Get() - .AddNotification( - $"The DevPlugin '{this.Name} was reloaded successfully.", "Plugin reloaded!", NotificationType.Success); + notificationManager.AddNotification($"The DevPlugin '{this.Name} was reloaded successfully.", "Plugin reloaded!", NotificationType.Success); } catch (Exception ex) { Log.Error(ex, "DevPlugin reload failed."); - Service.Get() - .AddNotification( - $"The DevPlugin '{this.Name} could not be reloaded.", "Plugin reload failed!", NotificationType.Error); + notificationManager.AddNotification($"The DevPlugin '{this.Name} could not be reloaded.", "Plugin reload failed!", NotificationType.Error); } }, this.fileWatcherTokenSource.Token); diff --git a/Dalamud/Plugin/Internal/LocalPlugin.cs b/Dalamud/Plugin/Internal/LocalPlugin.cs index d51b14303..0d9985602 100644 --- a/Dalamud/Plugin/Internal/LocalPlugin.cs +++ b/Dalamud/Plugin/Internal/LocalPlugin.cs @@ -86,10 +86,8 @@ namespace Dalamud.Plugin.Internal var assemblyVersion = this.pluginAssembly.GetName().Version; - // Files that may or may not exist + // Although it is conditionally used here, we need to set the initial value regardless. this.manifestFile = LocalPluginManifest.GetManifestFile(this.DllFile); - this.disabledFile = LocalPluginManifest.GetDisabledFile(this.DllFile); - this.testingFile = LocalPluginManifest.GetTestingFile(this.DllFile); // If the parameter manifest was null if (manifest == null) @@ -108,22 +106,23 @@ namespace Dalamud.Plugin.Internal // Save the manifest to disk so there won't be any problems later. // We'll update the name property after it can be retrieved from the instance. - var manifestFile = LocalPluginManifest.GetManifestFile(this.DllFile); - this.Manifest.Save(manifestFile); + this.Manifest.Save(this.manifestFile); } else { this.Manifest = manifest; } - // This bit converts from ".disabled" functionality to using the manifest. + // This converts from the ".disabled" file feature to the manifest instead. + this.disabledFile = LocalPluginManifest.GetDisabledFile(this.DllFile); if (this.disabledFile.Exists) { this.Manifest.Disabled = true; this.disabledFile.Delete(); } - // This bit converts from ".testing" functionality to using the manifest. + // This converts from the ".testing" file feature to the manifest instead. + this.testingFile = LocalPluginManifest.GetTestingFile(this.DllFile); if (this.testingFile.Exists) { this.Manifest.Testing = true; diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 81d5b92a8..47e3ca478 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -553,13 +553,13 @@ namespace Dalamud.Plugin.Internal if (plugin.IsDev) { // Dev plugins always get added to the list so they can be fiddled with in the UI - Log.Information(ex, $"Dev plugin failed to load, adding anyways: {dllFile.Name}"); + Log.Information(ex, $"Dev plugin failed to load, adding anyways: {dllFile.Name}"); plugin.Disable(); // Disable here, otherwise you can't enable+load later } else if (plugin.Manifest.DalamudApiLevel < DalamudApiLevel) { // Out of date plugins get added so they can be updated. - Log.Information(ex, $"Plugin was outdated, adding anyways: {dllFile.Name}"); + Log.Information(ex, $"Plugin was outdated, adding anyways: {dllFile.Name}"); // plugin.Disable(); // Don't disable, or it gets deleted next boot. } else From c34d4dfd8714813e49c8f71cd71b864ab86be796 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 20 Sep 2021 17:09:34 -0400 Subject: [PATCH 2/5] treat banned plugins like out of date, dont load but allow update --- .../Exceptions/BannedPluginException.cs | 22 +++++++++++++++++++ Dalamud/Plugin/Internal/LocalPlugin.cs | 3 +++ Dalamud/Plugin/Internal/PluginManager.cs | 12 +++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 Dalamud/Plugin/Internal/Exceptions/BannedPluginException.cs diff --git a/Dalamud/Plugin/Internal/Exceptions/BannedPluginException.cs b/Dalamud/Plugin/Internal/Exceptions/BannedPluginException.cs new file mode 100644 index 000000000..e4418b6d3 --- /dev/null +++ b/Dalamud/Plugin/Internal/Exceptions/BannedPluginException.cs @@ -0,0 +1,22 @@ +namespace Dalamud.Plugin.Internal.Exceptions +{ + /// + /// This represents a banned plugin that attempted an operation. + /// + internal class BannedPluginException : PluginException + { + /// + /// Initializes a new instance of the class. + /// + /// The message describing the invalid operation. + public BannedPluginException(string message) + { + this.Message = message; + } + + /// + /// Gets the message describing the invalid operation. + /// + public override string Message { get; } + } +} diff --git a/Dalamud/Plugin/Internal/LocalPlugin.cs b/Dalamud/Plugin/Internal/LocalPlugin.cs index 0d9985602..e5f26c418 100644 --- a/Dalamud/Plugin/Internal/LocalPlugin.cs +++ b/Dalamud/Plugin/Internal/LocalPlugin.cs @@ -222,6 +222,9 @@ namespace Dalamud.Plugin.Internal throw new InvalidPluginOperationException($"Unable to load {this.Name}, unload previously faulted, restart Dalamud"); } + if (pluginManager.IsManifestBanned(this.Manifest)) + throw new BannedPluginException($"Unable to load {this.Name}, banned"); + if (this.Manifest.ApplicableVersion < startInfo.GameVersion) throw new InvalidPluginOperationException($"Unable to load {this.Name}, no applicable version"); diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 47e3ca478..5b87abbb1 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -548,6 +548,11 @@ namespace Dalamud.Plugin.Internal PluginLocations.Remove(plugin.AssemblyName.FullName); throw; } + catch (BannedPluginException) + { + // Out of date plugins get added so they can be updated. + Log.Information($"Plugin was banned, adding anyways: {dllFile.Name}"); + } catch (Exception ex) { if (plugin.IsDev) @@ -936,7 +941,12 @@ namespace Dalamud.Plugin.Internal return true; } - private bool IsManifestBanned(PluginManifest manifest) + /// + /// Determine if a plugin has been banned by inspecting the manifest. + /// + /// Manifest to inspect. + /// A value indicating whether the plugin/manifest has been banned. + public bool IsManifestBanned(PluginManifest manifest) { return this.bannedPlugins.Any(ban => ban.Name == manifest.InternalName && ban.AssemblyVersion == manifest.AssemblyVersion); } From cb1761f9982dcad254dfce5046c2e9c49518d6fd Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 20 Sep 2021 16:32:01 -0400 Subject: [PATCH 3/5] add LocalPlugin.IsOutdated shortcut --- Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs | 6 +++--- Dalamud/Plugin/Internal/LocalPlugin.cs | 5 +++++ Dalamud/Plugin/Internal/PluginManager.cs | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs index 84ca51b42..e6c842eae 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs @@ -1124,7 +1124,7 @@ namespace Dalamud.Interface.Internal.Windows } // Outdated API level - if (plugin.Manifest.DalamudApiLevel < PluginManager.DalamudApiLevel) + if (plugin.IsOutdated) { label += Locs.PluginTitleMod_OutdatedError; trouble = true; @@ -1174,7 +1174,7 @@ namespace Dalamud.Interface.Internal.Windows ImGui.TextWrapped(manifest.Description); } - if (plugin.Manifest.DalamudApiLevel < PluginManager.DalamudApiLevel) + if (plugin.IsOutdated) { ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed); ImGui.TextWrapped(Locs.PluginBody_Outdated); @@ -1263,7 +1263,7 @@ namespace Dalamud.Interface.Internal.Windows var disabled = this.updateStatus == OperationStatus.InProgress || this.installStatus == OperationStatus.InProgress; // Disable everything if the plugin is outdated - disabled = disabled || (plugin.Manifest.DalamudApiLevel < PluginManager.DalamudApiLevel && !configuration.LoadAllApiLevels); + disabled = disabled || (plugin.IsOutdated && !configuration.LoadAllApiLevels); if (plugin.State == PluginState.InProgress) { diff --git a/Dalamud/Plugin/Internal/LocalPlugin.cs b/Dalamud/Plugin/Internal/LocalPlugin.cs index e5f26c418..0b2b1d91f 100644 --- a/Dalamud/Plugin/Internal/LocalPlugin.cs +++ b/Dalamud/Plugin/Internal/LocalPlugin.cs @@ -173,6 +173,11 @@ namespace Dalamud.Plugin.Internal /// public bool IsDisabled => this.Manifest.Disabled; + /// + /// Gets a value indicating whether this plugin's API level is out of date. + /// + public bool IsOutdated => this.Manifest.DalamudApiLevel < PluginManager.DalamudApiLevel; + /// /// Gets a value indicating whether the plugin is for testing use only. /// diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 5b87abbb1..d8bf6b802 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -561,7 +561,7 @@ namespace Dalamud.Plugin.Internal Log.Information(ex, $"Dev plugin failed to load, adding anyways: {dllFile.Name}"); plugin.Disable(); // Disable here, otherwise you can't enable+load later } - else if (plugin.Manifest.DalamudApiLevel < DalamudApiLevel) + else if (plugin.IsOutdated) { // Out of date plugins get added so they can be updated. Log.Information(ex, $"Plugin was outdated, adding anyways: {dllFile.Name}"); From f1e5a21494087e67b472ae090193ad70c418d906 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 20 Sep 2021 16:32:47 -0400 Subject: [PATCH 4/5] Extract DeletePlugin from dev, show if outdated or dev --- .../Internal/Windows/PluginInstallerWindow.cs | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs index e6c842eae..c5c56a137 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs @@ -1201,6 +1201,7 @@ namespace Dalamud.Interface.Internal.Windows // Controls this.DrawPluginControlButton(plugin); this.DrawDevPluginButtons(plugin); + this.DrawDeletePluginButton(plugin); this.DrawVisitRepoUrlButton(plugin.Manifest.RepoUrl); if (availablePluginUpdate != default) @@ -1411,7 +1412,6 @@ namespace Dalamud.Interface.Internal.Windows private void DrawDevPluginButtons(LocalPlugin localPlugin) { var configuration = Service.Get(); - var pluginManager = Service.Get(); if (localPlugin is LocalDevPlugin plugin) { @@ -1454,33 +1454,40 @@ namespace Dalamud.Interface.Internal.Windows { ImGui.SetTooltip(Locs.PluginButtonToolTip_AutomaticReloading); } + } + } - // Delete - if (plugin.State == PluginState.Unloaded) + private void DrawDeletePluginButton(LocalPlugin plugin) + { + var unloaded = plugin.State == PluginState.Unloaded; + var showButton = unloaded && (plugin.IsDev || plugin.IsOutdated); + + if (!showButton) + return; + + var pluginManager = Service.Get(); + + ImGui.SameLine(); + if (ImGuiComponents.IconButton(FontAwesomeIcon.TrashAlt)) + { + try { - ImGui.SameLine(); - 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.PluginBody_DeleteDevPlugin); - } + 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); } } From f98193a06dc740a31d6901deeeed7bd9628d3460 Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 21 Sep 2021 10:15:51 -0400 Subject: [PATCH 5/5] Display banned plugins for updating --- .../Internal/Windows/PluginInstallerWindow.cs | 23 +++++++++++++++++-- Dalamud/Plugin/Internal/LocalPlugin.cs | 10 ++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs index c5c56a137..b244c33f3 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs @@ -868,6 +868,7 @@ namespace Dalamud.Interface.Internal.Windows ImGui.SameLine(); var cursor = ImGui.GetCursorPos(); + // Name ImGui.Text(label); @@ -1130,6 +1131,13 @@ namespace Dalamud.Interface.Internal.Windows trouble = true; } + // Banned + if (plugin.IsBanned) + { + label += Locs.PluginTitleMod_BannedError; + trouble = true; + } + ImGui.PushID($"installed{index}{plugin.Manifest.InternalName}"); if (this.DrawPluginCollapsingHeader(label, plugin.Manifest, trouble, availablePluginUpdate != default, false, () => this.DrawInstalledPluginContextMenu(plugin), index)) @@ -1181,6 +1189,13 @@ namespace Dalamud.Interface.Internal.Windows ImGui.PopStyleColor(); } + if (plugin.IsBanned) + { + ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed); + ImGui.TextWrapped(Locs.PluginBody_Banned); + ImGui.PopStyleColor(); + } + // Available commands (if loaded) if (plugin.IsLoaded) { @@ -1264,7 +1279,7 @@ namespace Dalamud.Interface.Internal.Windows var disabled = this.updateStatus == OperationStatus.InProgress || this.installStatus == OperationStatus.InProgress; // Disable everything if the plugin is outdated - disabled = disabled || (plugin.IsOutdated && !configuration.LoadAllApiLevels); + disabled = disabled || (plugin.IsOutdated && !configuration.LoadAllApiLevels) || plugin.IsBanned; if (plugin.State == PluginState.InProgress) { @@ -1460,7 +1475,7 @@ namespace Dalamud.Interface.Internal.Windows private void DrawDeletePluginButton(LocalPlugin plugin) { var unloaded = plugin.State == PluginState.Unloaded; - var showButton = unloaded && (plugin.IsDev || plugin.IsOutdated); + var showButton = unloaded && (plugin.IsDev || plugin.IsOutdated || plugin.IsBanned); if (!showButton) return; @@ -1926,6 +1941,8 @@ namespace Dalamud.Interface.Internal.Windows public static string PluginTitleMod_OutdatedError => Loc.Localize("InstallerOutdatedError", " (outdated)"); + public static string PluginTitleMod_BannedError => Loc.Localize("InstallerOutdatedError", " (banned)"); + public static string PluginTitleMod_New => Loc.Localize("InstallerNewPlugin ", " New!"); #endregion @@ -1960,6 +1977,8 @@ namespace Dalamud.Interface.Internal.Windows public static string PluginBody_Outdated => Loc.Localize("InstallerOutdatedPluginBody ", "This plugin is outdated and incompatible at the moment. Please wait for it to be updated by its author."); + public static string PluginBody_Banned => Loc.Localize("InstallerBannedPluginBody ", "This plugin version is banned and not available at the moment. Please wait for it to be updated by its author."); + #endregion #region Plugin buttons diff --git a/Dalamud/Plugin/Internal/LocalPlugin.cs b/Dalamud/Plugin/Internal/LocalPlugin.cs index 0b2b1d91f..c06c12c08 100644 --- a/Dalamud/Plugin/Internal/LocalPlugin.cs +++ b/Dalamud/Plugin/Internal/LocalPlugin.cs @@ -129,6 +129,9 @@ namespace Dalamud.Plugin.Internal this.testingFile.Delete(); } + var pluginManager = Service.Get(); + this.IsBanned = pluginManager.IsManifestBanned(this.Manifest); + this.SaveManifest(); } @@ -183,6 +186,11 @@ namespace Dalamud.Plugin.Internal /// public bool IsTesting => this.Manifest.IsTestingExclusive || this.Manifest.Testing; + /// + /// Gets a value indicating whether this plugin has been banned. + /// + public bool IsBanned { get; } + /// /// Gets a value indicating whether this plugin is dev plugin. /// @@ -262,7 +270,9 @@ namespace Dalamud.Plugin.Internal { var manifestFile = LocalPluginManifest.GetManifestFile(this.DllFile); if (manifestFile.Exists) + { this.Manifest = LocalPluginManifest.Load(manifestFile); + } } }