diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 3ead8d5ea..664406157 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -790,8 +790,15 @@ internal partial class PluginManager : IDisposable, IServiceType // or the user removed the plugin manually in which case we don't care if (reason == PluginLoadReason.Installer) { - // We don't need to apply, it doesn't matter - await this.profileManager.DefaultProfile.RemoveAsync(repoManifest.InternalName, false, false); + try + { + // We don't need to apply, it doesn't matter + await this.profileManager.DefaultProfile.RemoveAsync(repoManifest.InternalName, false); + } + catch (ProfileOperationException) + { + // ignored + } } else { diff --git a/Dalamud/Plugin/Internal/Profiles/Profile.cs b/Dalamud/Plugin/Internal/Profiles/Profile.cs index 0b2d62ccf..592720c14 100644 --- a/Dalamud/Plugin/Internal/Profiles/Profile.cs +++ b/Dalamud/Plugin/Internal/Profiles/Profile.cs @@ -200,22 +200,17 @@ internal class Profile /// /// The internal name of the plugin. /// Whether or not the current state should immediately be applied. - /// - /// Throw if certain operations are invalid. - /// * Throw if the plugin is not in this profile. - /// * If this is the default profile, check if we are in any other, then throw if we aren't. - /// /// A representing the asynchronous operation. - public async Task RemoveAsync(string internalName, bool apply = true, bool guardrails = true) + public async Task RemoveAsync(string internalName, bool apply = true) { ProfileModelV1.ProfileModelV1Plugin entry; lock (this) { entry = this.modelV1.Plugins.FirstOrDefault(x => x.InternalName == internalName); - if (entry == null && guardrails) - throw new ArgumentException($"No plugin \"{internalName}\" in profile \"{this.Guid}\""); + if (entry == null) + throw new PluginNotFoundException(internalName); - if (!this.modelV1.Plugins.Remove(entry) && guardrails) + if (!this.modelV1.Plugins.Remove(entry)) throw new Exception("Couldn't remove plugin from model collection"); } @@ -226,9 +221,9 @@ internal class Profile { await this.manager.DefaultProfile.AddOrUpdateAsync(internalName, this.IsEnabled && entry.IsEnabled, false); } - else if (guardrails) + else { - throw new Exception("Removed plugin from default profile, but wasn't in any other profile"); + throw new PluginNotInDefaultProfileException(internalName); } } @@ -241,3 +236,48 @@ internal class Profile /// public override string ToString() => $"{this.Guid} ({this.Name})"; } + +/// +/// Exception indicating an issue during a profile operation. +/// +internal abstract class ProfileOperationException : Exception +{ + /// + /// Initializes a new instance of the class. + /// + /// Message to pass on. + protected ProfileOperationException(string message) + : base(message) + { + } +} + +/// +/// Exception indicating that a plugin was not found in the default profile. +/// +internal sealed class PluginNotInDefaultProfileException : ProfileOperationException +{ + /// + /// Initializes a new instance of the class. + /// + /// The internal name of the plugin causing the error. + public PluginNotInDefaultProfileException(string internalName) + : base($"The plugin '{internalName}' is not in the default profile, and cannot be removed") + { + } +} + +/// +/// Exception indicating that the plugin was not found. +/// +internal sealed class PluginNotFoundException : ProfileOperationException +{ + /// + /// Initializes a new instance of the class. + /// + /// The internal name of the plugin causing the error. + public PluginNotFoundException(string internalName) + : base($"The plugin '{internalName}' was not found in the profile") + { + } +}