Plugins: Fail gracefully on multiple instances of same plugin
This commit is contained in:
@@ -121,6 +121,7 @@ namespace Il2CppInspector.CLI
|
||||
// Get plugin option classes
|
||||
public static Type[] GetPluginOptionTypes() {
|
||||
// Don't do anything if there are no loaded plugins
|
||||
try {
|
||||
var plugins = PluginManager.AvailablePlugins;
|
||||
|
||||
if (!plugins.Any())
|
||||
@@ -129,6 +130,13 @@ namespace Il2CppInspector.CLI
|
||||
// Create CommandLine-friendly option classes for each plugin
|
||||
return plugins.Select(p => CreateOptionsFromPlugin(p)).ToArray();
|
||||
}
|
||||
catch (InvalidOperationException ex) {
|
||||
Console.Error.WriteLine(ex.Message);
|
||||
Environment.Exit(1);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse all options for all plugins
|
||||
public static bool ParsePluginOptions(IEnumerable<string> pluginOptions, Type[] optionsTypes) {
|
||||
|
||||
@@ -174,6 +174,11 @@ namespace Il2CppInspector
|
||||
// Current version
|
||||
if (typeof(IPlugin).IsAssignableFrom(type) && !type.IsAbstract) {
|
||||
var plugin = (IPlugin) Activator.CreateInstance(type);
|
||||
|
||||
// Don't allow multiple identical plugins to load
|
||||
if (AsInstance.ManagedPlugins.Any(p => p.Plugin.Id == plugin.Id))
|
||||
throw new Exception($"Multiple copies of {plugin.Name} were found. Please ensure the plugins folder only contains one copy of each plugin.");
|
||||
|
||||
AsInstance.ManagedPlugins.Add(new ManagedPlugin { Plugin = plugin, Available = true, Enabled = false });
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,12 @@ namespace Il2CppInspectorGUI
|
||||
catch (NotSupportedException) { }
|
||||
|
||||
// Load plugins if they aren't already
|
||||
try {
|
||||
PluginManager.EnsureInit();
|
||||
} catch (InvalidOperationException ex) {
|
||||
MessageBox.Show(ex.Message, "Fatal error loading plugins");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
// Arrange plugins
|
||||
var loadedPlugins = PluginManager.AsInstance.ManagedPlugins;
|
||||
|
||||
Reference in New Issue
Block a user