mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
add some validation code to catch issues
This commit is contained in:
parent
d827151ee5
commit
256f4989f7
2 changed files with 58 additions and 6 deletions
|
|
@ -664,6 +664,15 @@ internal partial class PluginManager : IDisposable, IServiceType
|
||||||
this.PluginsReady = true;
|
this.PluginsReady = true;
|
||||||
this.NotifyinstalledPluginsListChanged();
|
this.NotifyinstalledPluginsListChanged();
|
||||||
sigScanner.Save();
|
sigScanner.Save();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.ParanoiaValidatePluginsAndProfiles();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "Plugin and profile validation failed!");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
tokenSource.Token);
|
tokenSource.Token);
|
||||||
}
|
}
|
||||||
|
|
@ -1256,6 +1265,30 @@ internal partial class PluginManager : IDisposable, IServiceType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if there are any inconsistencies with our plugins, their IDs, and our profiles.
|
||||||
|
/// </summary>
|
||||||
|
private void ParanoiaValidatePluginsAndProfiles()
|
||||||
|
{
|
||||||
|
var seenIds = new List<Guid>();
|
||||||
|
|
||||||
|
foreach (var installedPlugin in this.InstalledPlugins)
|
||||||
|
{
|
||||||
|
if (installedPlugin.Manifest.WorkingPluginId == Guid.Empty)
|
||||||
|
throw new Exception($"{(installedPlugin is LocalDevPlugin ? "DevPlugin" : "Plugin")} '{installedPlugin.Manifest.InternalName}' has an empty WorkingPluginId.");
|
||||||
|
|
||||||
|
if (seenIds.Contains(installedPlugin.Manifest.WorkingPluginId))
|
||||||
|
{
|
||||||
|
throw new Exception(
|
||||||
|
$"{(installedPlugin is LocalDevPlugin ? "DevPlugin" : "Plugin")} '{installedPlugin.Manifest.InternalName}' has a duplicate WorkingPluginId '{installedPlugin.Manifest.WorkingPluginId}'");
|
||||||
|
}
|
||||||
|
|
||||||
|
seenIds.Add(installedPlugin.Manifest.WorkingPluginId);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.profileManager.ParanoiaValidateProfiles();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<Stream> DownloadPluginAsync(RemotePluginManifest repoManifest, bool useTesting)
|
private async Task<Stream> DownloadPluginAsync(RemotePluginManifest repoManifest, bool useTesting)
|
||||||
{
|
{
|
||||||
var downloadUrl = useTesting ? repoManifest.DownloadLinkTesting : repoManifest.DownloadLinkInstall;
|
var downloadUrl = useTesting ? repoManifest.DownloadLinkTesting : repoManifest.DownloadLinkInstall;
|
||||||
|
|
|
||||||
|
|
@ -216,19 +216,18 @@ internal class ProfileManager : IServiceType
|
||||||
this.isBusy = true;
|
this.isBusy = true;
|
||||||
Log.Information("Getting want states...");
|
Log.Information("Getting want states...");
|
||||||
|
|
||||||
List<Guid> wantActive;
|
List<ProfilePluginEntry> wantActive;
|
||||||
lock (this.profiles)
|
lock (this.profiles)
|
||||||
{
|
{
|
||||||
wantActive = this.profiles
|
wantActive = this.profiles
|
||||||
.Where(x => x.IsEnabled)
|
.Where(x => x.IsEnabled)
|
||||||
.SelectMany(profile => profile.Plugins.Where(plugin => plugin.IsEnabled)
|
.SelectMany(profile => profile.Plugins.Where(plugin => plugin.IsEnabled))
|
||||||
.Select(plugin => plugin.WorkingPluginId))
|
|
||||||
.Distinct().ToList();
|
.Distinct().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var internalName in wantActive)
|
foreach (var profilePluginEntry in wantActive)
|
||||||
{
|
{
|
||||||
Log.Information("\t=> Want {Name}", internalName);
|
Log.Information("\t=> Want {Name}({WorkingPluginId})", profilePluginEntry.InternalName, profilePluginEntry.WorkingPluginId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Information("Applying want states...");
|
Log.Information("Applying want states...");
|
||||||
|
|
@ -238,7 +237,7 @@ internal class ProfileManager : IServiceType
|
||||||
var pm = Service<PluginManager>.Get();
|
var pm = Service<PluginManager>.Get();
|
||||||
foreach (var installedPlugin in pm.InstalledPlugins)
|
foreach (var installedPlugin in pm.InstalledPlugins)
|
||||||
{
|
{
|
||||||
var wantThis = wantActive.Contains(installedPlugin.Manifest.WorkingPluginId);
|
var wantThis = wantActive.Any(x => x.WorkingPluginId == installedPlugin.Manifest.WorkingPluginId);
|
||||||
switch (wantThis)
|
switch (wantThis)
|
||||||
{
|
{
|
||||||
case true when !installedPlugin.IsLoaded:
|
case true when !installedPlugin.IsLoaded:
|
||||||
|
|
@ -314,6 +313,26 @@ internal class ProfileManager : IServiceType
|
||||||
profile.MigrateProfilesToGuidsForPlugin(internalName, newGuid);
|
profile.MigrateProfilesToGuidsForPlugin(internalName, newGuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate profiles for errors.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="Exception">Thrown when a profile is not sane.</exception>
|
||||||
|
public void ParanoiaValidateProfiles()
|
||||||
|
{
|
||||||
|
foreach (var profile in this.profiles)
|
||||||
|
{
|
||||||
|
var seenIds = new List<Guid>();
|
||||||
|
|
||||||
|
foreach (var pluginEntry in profile.Plugins)
|
||||||
|
{
|
||||||
|
if (seenIds.Contains(pluginEntry.WorkingPluginId))
|
||||||
|
throw new Exception($"Plugin '{pluginEntry.WorkingPluginId}'('{pluginEntry.InternalName}') is twice in profile '{profile.Guid}'('{profile.Name}')");
|
||||||
|
|
||||||
|
seenIds.Add(pluginEntry.WorkingPluginId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private string GenerateUniqueProfileName(string startingWith)
|
private string GenerateUniqueProfileName(string startingWith)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue