Plugins: Add IPlugin.OptionsChanged
This commit is contained in:
@@ -181,10 +181,9 @@ namespace Il2CppInspector.CLI
|
||||
}
|
||||
}
|
||||
|
||||
// Enable plugin
|
||||
// Enable plugin and inform of options
|
||||
PluginManager.AsInstance.ManagedPlugins.First(p => p.Plugin == plugin).Enabled = true;
|
||||
|
||||
// TODO: Plugin hook OptionsChanged
|
||||
PluginManager.OptionsChanged(plugin);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,20 @@ using System.IO;
|
||||
using NoisyCowStudios.Bin2Object;
|
||||
using Il2CppInspector.Reflection;
|
||||
|
||||
// Hooks we provide to plugins which can choose whether or not to provide implementations
|
||||
namespace Il2CppInspector.PluginAPI.V100
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes when the plugin's options are updated by the user
|
||||
/// Not called on first load (with the default, possibly incomplete options provided by the plugin author)
|
||||
/// Do not perform any long-running operations here
|
||||
/// Implementation is optional - the default is to do nothing
|
||||
/// </summary>
|
||||
public partial interface IPlugin
|
||||
{
|
||||
void OptionsChanged(PluginOptionsChangedEventInfo e) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process global-metadata.dat when it is first opened as a sequence of bytes
|
||||
/// Seek cursor will be at the start of the file
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Il2CppInspector.PluginAPI.V100
|
||||
/// <summary>
|
||||
/// Core interface that all plugins must implement
|
||||
/// </summary>
|
||||
public interface IPlugin
|
||||
public partial interface IPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin name for CLI and unique ID
|
||||
|
||||
@@ -61,6 +61,11 @@ namespace Il2CppInspector.PluginAPI.V100
|
||||
public bool SkipValidation { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event info for OptionsChanged
|
||||
/// </summary>
|
||||
public class PluginOptionsChangedEventInfo : PluginEventInfo { }
|
||||
|
||||
/// <summary>
|
||||
/// Event info for PostProcessMetadata
|
||||
/// </summary>
|
||||
|
||||
@@ -12,7 +12,8 @@ using Il2CppInspector.Reflection;
|
||||
|
||||
namespace Il2CppInspector
|
||||
{
|
||||
// Hooks we provide to plugins which can choose whether or not to provide implementations
|
||||
// Internal helpers to call the same hook on every plugin
|
||||
// Does not include hooks that should be called individually, eg. OptionsChanged
|
||||
internal static class PluginHooks
|
||||
{
|
||||
public static PluginPreProcessMetadataEventInfo PreProcessMetadata(BinaryObjectStream stream)
|
||||
|
||||
@@ -220,6 +220,21 @@ namespace Il2CppInspector
|
||||
}
|
||||
}
|
||||
|
||||
// Commit options change for the specified plugin
|
||||
public static PluginOptionsChangedEventInfo OptionsChanged(IPlugin plugin) {
|
||||
var eventInfo = new PluginOptionsChangedEventInfo();
|
||||
|
||||
try {
|
||||
plugin.OptionsChanged(eventInfo);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
eventInfo.Error = new PluginErrorEventArgs { Plugin = plugin, Exception = ex, Operation = "options update" };
|
||||
ErrorHandler?.Invoke(AsInstance, eventInfo.Error);
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
@@ -24,6 +24,7 @@ using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
using Il2CppInspector.PluginAPI.V100;
|
||||
using Il2CppInspector.Reflection;
|
||||
using Il2CppInspector;
|
||||
|
||||
namespace Il2CppInspectorGUI
|
||||
{
|
||||
@@ -126,8 +127,6 @@ namespace Il2CppInspectorGUI
|
||||
private void okButton_Click(object sender, RoutedEventArgs e) {
|
||||
// Close dialog box but call OnClosing first to validate all the options
|
||||
DialogResult = true;
|
||||
|
||||
// TODO: Plugin hook OptionsChanged (and make sure it works when clicking close icon as well)
|
||||
}
|
||||
|
||||
// Select a file path
|
||||
@@ -168,6 +167,7 @@ namespace Il2CppInspectorGUI
|
||||
MessageBox.Show("One or more options are invalid.", "Il2CppInspector Plugin Configuration");
|
||||
e.Cancel = true;
|
||||
}
|
||||
PluginManager.OptionsChanged(Plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +107,5 @@ namespace Il2CppInspector.GUI
|
||||
private void getPluginsButton_Click(object sender, RoutedEventArgs e) {
|
||||
Process.Start(new ProcessStartInfo { FileName = @"https://github.com/djkaty/Il2CppInspectorPlugins", UseShellExecute = true });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,8 +107,8 @@ namespace Il2CppInspector
|
||||
ourPlugin[key] = Convert.ChangeType(value, targetType);
|
||||
}
|
||||
}
|
||||
// TODO: Plugin hook OptionsChanged
|
||||
}
|
||||
PluginManager.OptionsChanged(plugin);
|
||||
}
|
||||
|
||||
List<Il2CppInspector> inspectors;
|
||||
|
||||
Reference in New Issue
Block a user