GUI: Don't allow plugins to run without validating options at least once

This commit is contained in:
Katy Coe
2020-12-26 00:05:48 +01:00
parent 1527c9fe17
commit 94f13c35df
3 changed files with 49 additions and 6 deletions

View File

@@ -50,6 +50,13 @@ namespace Il2CppInspector
public string Operation { get; set; }
}
// Event arguments for option handler
public class PluginOptionErrorEventArgs : PluginErrorEventArgs
{
// The option causing the problem
public IPluginOption Option { get; set; }
}
// Event arguments for the status handler
public class PluginStatusEventArgs : EventArgs
{
@@ -247,6 +254,24 @@ namespace Il2CppInspector
return eventInfo;
}
// Validate all options for enabled plugins
public static PluginOptionsChangedEventInfo ValidateAllOptions() {
// Enforce this by causing each option's setter to run
var eventInfo = new PluginOptionsChangedEventInfo();
foreach (var plugin in EnabledPlugins)
foreach (var option in plugin.Options)
try {
option.Value = option.Value;
}
catch (Exception ex) {
eventInfo.Error = new PluginOptionErrorEventArgs { Plugin = plugin, Exception = ex, Option = option, Operation = "options update" };
ErrorHandler?.Invoke(AsInstance, eventInfo);
break;
}
return eventInfo;
}
// Try to cast each enabled plugin to a specific interface type, and for those supporting the interface, execute the supplied delegate
// Errors will be forwarded to the error handler
internal static E Try<I, E>(Action<I, E> action) where E : PluginEventInfo, new()