From b3740d0539e5a03d4a2a5c64c479be7c3ee10dd5 Mon Sep 17 00:00:00 2001 From: goaaats Date: Thu, 18 Jan 2024 22:03:14 +0100 Subject: [PATCH] add Profile.RemoveByInternalNameAsync() --- Dalamud/Plugin/Internal/PluginManager.cs | 2 +- Dalamud/Plugin/Internal/Profiles/Profile.cs | 36 ++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 20e2ea7af..5d250a533 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -1297,7 +1297,7 @@ internal partial class PluginManager : IDisposable, IServiceType try { // We don't need to apply, it doesn't matter - await this.profileManager.DefaultProfile.RemoveAsync(repoManifest.InternalName, false); + await this.profileManager.DefaultProfile.RemoveByInternalNameAsync(repoManifest.InternalName, false); } catch (ProfileOperationException) { diff --git a/Dalamud/Plugin/Internal/Profiles/Profile.cs b/Dalamud/Plugin/Internal/Profiles/Profile.cs index 3e7a2ed55..36cafa29b 100644 --- a/Dalamud/Plugin/Internal/Profiles/Profile.cs +++ b/Dalamud/Plugin/Internal/Profiles/Profile.cs @@ -208,7 +208,7 @@ internal class Profile { entry = this.modelV1.Plugins.FirstOrDefault(x => x.WorkingPluginId == workingPluginId); if (entry == null) - throw new PluginNotFoundException(workingPluginId.ToString()); + throw new PluginNotFoundException(workingPluginId); if (!this.modelV1.Plugins.Remove(entry)) throw new Exception("Couldn't remove plugin from model collection"); @@ -233,6 +233,31 @@ internal class Profile await this.manager.ApplyAllWantStatesAsync(); } + /// + /// Remove a plugin from this profile. + /// This will block until all states have been applied. + /// + /// The internal name of the plugin. + /// Whether or not the current state should immediately be applied. + /// A representing the asynchronous operation. + public async Task RemoveByInternalNameAsync(string internalName, bool apply = true) + { + Guid? pluginToRemove = null; + lock (this) + { + foreach (var plugin in this.Plugins) + { + if (plugin.InternalName.Equals(internalName, StringComparison.Ordinal)) + { + pluginToRemove = plugin.WorkingPluginId; + break; + } + } + } + + await this.RemoveAsync(pluginToRemove ?? throw new PluginNotFoundException(internalName), apply); + } + /// /// This function tries to migrate all plugins with this internalName which do not have /// a GUID to the specified GUID. @@ -308,4 +333,13 @@ internal sealed class PluginNotFoundException : ProfileOperationException : base($"The plugin '{internalName}' was not found in the profile") { } + + /// + /// Initializes a new instance of the class. + /// + /// The ID of the plugin causing the error. + public PluginNotFoundException(Guid workingPluginId) + : base($"The plugin '{workingPluginId}' was not found in the profile") + { + } }