mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-23 08:59:17 +01:00
prevent iteration errors
no need to make a copy.
This commit is contained in:
parent
e7b7da7cca
commit
058522edec
1 changed files with 12 additions and 24 deletions
|
|
@ -41,10 +41,6 @@ namespace Dalamud.Plugin.Internal
|
||||||
private readonly DirectoryInfo devPluginDirectory;
|
private readonly DirectoryInfo devPluginDirectory;
|
||||||
private readonly BannedPlugin[] bannedPlugins;
|
private readonly BannedPlugin[] bannedPlugins;
|
||||||
|
|
||||||
private readonly List<LocalPlugin> installedPlugins = new();
|
|
||||||
private List<RemotePluginManifest> availablePlugins = new();
|
|
||||||
private List<AvailablePluginUpdate> updatablePlugins = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="PluginManager"/> class.
|
/// Initializes a new instance of the <see cref="PluginManager"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -130,7 +126,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
foreach (var plugin in this.installedPlugins.ToArray())
|
foreach (var plugin in this.InstalledPlugins)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -271,10 +267,8 @@ namespace Dalamud.Plugin.Internal
|
||||||
{
|
{
|
||||||
var aggregate = new List<Exception>();
|
var aggregate = new List<Exception>();
|
||||||
|
|
||||||
for (var i = 0; i < this.installedPlugins.Count; i++)
|
foreach (var plugin in this.InstalledPlugins)
|
||||||
{
|
{
|
||||||
var plugin = this.installedPlugins[i];
|
|
||||||
|
|
||||||
if (plugin.IsLoaded)
|
if (plugin.IsLoaded)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -314,11 +308,11 @@ namespace Dalamud.Plugin.Internal
|
||||||
/// <param name="notify">Whether to notify that available plugins have changed afterwards.</param>
|
/// <param name="notify">Whether to notify that available plugins have changed afterwards.</param>
|
||||||
public void RefilterPluginMasters(bool notify = true)
|
public void RefilterPluginMasters(bool notify = true)
|
||||||
{
|
{
|
||||||
this.availablePlugins = this.Repos
|
this.AvailablePlugins = this.Repos
|
||||||
.SelectMany(repo => repo.PluginMaster)
|
.SelectMany(repo => repo.PluginMaster)
|
||||||
.Where(this.IsManifestEligible)
|
.Where(this.IsManifestEligible)
|
||||||
.Where(this.IsManifestVisible)
|
.Where(this.IsManifestVisible)
|
||||||
.ToList();
|
.ToImmutableList();
|
||||||
|
|
||||||
if (notify)
|
if (notify)
|
||||||
{
|
{
|
||||||
|
|
@ -570,7 +564,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.installedPlugins.Add(plugin);
|
this.InstalledPlugins = this.InstalledPlugins.Add(plugin);
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -583,7 +577,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
if (plugin.State != PluginState.Unloaded)
|
if (plugin.State != PluginState.Unloaded)
|
||||||
throw new InvalidPluginOperationException($"Unable to remove {plugin.Name}, not unloaded");
|
throw new InvalidPluginOperationException($"Unable to remove {plugin.Name}, not unloaded");
|
||||||
|
|
||||||
this.installedPlugins.Remove(plugin);
|
this.InstalledPlugins = this.InstalledPlugins.Remove(plugin);
|
||||||
PluginLocations.Remove(plugin.AssemblyName.FullName);
|
PluginLocations.Remove(plugin.AssemblyName.FullName);
|
||||||
|
|
||||||
this.NotifyInstalledPluginsChanged();
|
this.NotifyInstalledPluginsChanged();
|
||||||
|
|
@ -696,9 +690,9 @@ namespace Dalamud.Plugin.Internal
|
||||||
var updatedList = new List<PluginUpdateStatus>();
|
var updatedList = new List<PluginUpdateStatus>();
|
||||||
|
|
||||||
// Prevent collection was modified errors
|
// Prevent collection was modified errors
|
||||||
for (var i = 0; i < this.updatablePlugins.Count; i++)
|
foreach (var plugin in this.UpdatablePlugins)
|
||||||
{
|
{
|
||||||
var result = await this.UpdateSinglePluginAsync(this.updatablePlugins[i], false, dryRun);
|
var result = await this.UpdateSinglePluginAsync(plugin, false, dryRun);
|
||||||
if (result != null)
|
if (result != null)
|
||||||
updatedList.Add(result);
|
updatedList.Add(result);
|
||||||
}
|
}
|
||||||
|
|
@ -758,7 +752,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plugin.Disable();
|
plugin.Disable();
|
||||||
this.installedPlugins.Remove(plugin);
|
this.InstalledPlugins = this.InstalledPlugins.Remove(plugin);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -930,15 +924,13 @@ namespace Dalamud.Plugin.Internal
|
||||||
{
|
{
|
||||||
var updatablePlugins = new List<AvailablePluginUpdate>();
|
var updatablePlugins = new List<AvailablePluginUpdate>();
|
||||||
|
|
||||||
for (var i = 0; i < this.installedPlugins.Count; i++)
|
foreach (var plugin in this.InstalledPlugins)
|
||||||
{
|
{
|
||||||
var plugin = this.installedPlugins[i];
|
|
||||||
|
|
||||||
var installedVersion = plugin.IsTesting
|
var installedVersion = plugin.IsTesting
|
||||||
? plugin.Manifest.TestingAssemblyVersion
|
? plugin.Manifest.TestingAssemblyVersion
|
||||||
: plugin.Manifest.AssemblyVersion;
|
: plugin.Manifest.AssemblyVersion;
|
||||||
|
|
||||||
var updates = this.availablePlugins
|
var updates = this.AvailablePlugins
|
||||||
.Where(remoteManifest => plugin.Manifest.InternalName == remoteManifest.InternalName)
|
.Where(remoteManifest => plugin.Manifest.InternalName == remoteManifest.InternalName)
|
||||||
.Select(remoteManifest =>
|
.Select(remoteManifest =>
|
||||||
{
|
{
|
||||||
|
|
@ -960,7 +952,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updatablePlugins = updatablePlugins;
|
this.UpdatablePlugins = updatablePlugins.ToImmutableList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NotifyAvailablePluginsChanged()
|
private void NotifyAvailablePluginsChanged()
|
||||||
|
|
@ -969,8 +961,6 @@ namespace Dalamud.Plugin.Internal
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.AvailablePlugins = ImmutableList.CreateRange(this.availablePlugins);
|
|
||||||
this.UpdatablePlugins = ImmutableList.CreateRange(this.updatablePlugins);
|
|
||||||
this.OnAvailablePluginsChanged?.Invoke();
|
this.OnAvailablePluginsChanged?.Invoke();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -985,8 +975,6 @@ namespace Dalamud.Plugin.Internal
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.InstalledPlugins = ImmutableList.CreateRange(this.installedPlugins);
|
|
||||||
this.UpdatablePlugins = ImmutableList.CreateRange(this.updatablePlugins);
|
|
||||||
this.OnInstalledPluginsChanged?.Invoke();
|
this.OnInstalledPluginsChanged?.Invoke();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue