mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
add Profile.RemoveByInternalNameAsync()
This commit is contained in:
parent
b446fcc191
commit
b3740d0539
2 changed files with 36 additions and 2 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a plugin from this profile.
|
||||
/// This will block until all states have been applied.
|
||||
/// </summary>
|
||||
/// <param name="internalName">The internal name of the plugin.</param>
|
||||
/// <param name="apply">Whether or not the current state should immediately be applied.</param>
|
||||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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")
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginNotFoundException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="workingPluginId">The ID of the plugin causing the error.</param>
|
||||
public PluginNotFoundException(Guid workingPluginId)
|
||||
: base($"The plugin '{workingPluginId}' was not found in the profile")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue