mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-27 05:55:23 -05:00
Update plugin interface
now is notified during a file load event (can handle itself)
This commit is contained in:
@@ -2,9 +2,32 @@
|
||||
{
|
||||
public interface IPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Plugin Name
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Entrypoint for the parent to initialize the plugin with provided arguments.
|
||||
/// </summary>
|
||||
/// <param name="args">Arguments containing objects useful for initializing the plugin.</param>
|
||||
void Initialize(params object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Notifies the plugin that a save file was just loaded.
|
||||
/// </summary>
|
||||
void NotifySaveLoaded();
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to load a file using the plugin.
|
||||
/// </summary>
|
||||
/// <param name="filePath">Path to file to be loaded.</param>
|
||||
/// <returns></returns>
|
||||
bool TryLoadFile(string filePath);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="ISaveFileProvider"/> object which can provide a <see cref="SaveFile"/>.
|
||||
/// </summary>
|
||||
ISaveFileProvider SaveFileEditor { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,6 +456,9 @@ private void OpenQuick(string path, bool force = false)
|
||||
SystemSounds.Asterisk.Play();
|
||||
return;
|
||||
}
|
||||
if (Plugins.Any(p => p.TryLoadFile(path)))
|
||||
return; // handled by plugin
|
||||
|
||||
// detect if it is a folder (load into boxes or not)
|
||||
if (Directory.Exists(path))
|
||||
{ C_SAV.LoadBoxes(out string _, path); return; }
|
||||
|
||||
@@ -26,13 +26,22 @@ private static IEnumerable<Assembly> GetAssemblies(IEnumerable<string> dllFileNa
|
||||
private static IEnumerable<Type> GetPluginsOfType<T>(IEnumerable<Assembly> assemblies)
|
||||
{
|
||||
var pluginType = typeof(T);
|
||||
foreach (var type in assemblies.Where(z => z != null).SelectMany(a => a.GetTypes()))
|
||||
foreach (var z in assemblies.Where(z => z != null))
|
||||
{
|
||||
if (type.IsInterface || type.IsAbstract)
|
||||
Type[] types; try { types = z.GetTypes(); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Unable to load plugin [{pluginType.Name}]: {z.FullName}", ex.Message);
|
||||
continue;
|
||||
if (type.GetInterface(pluginType.FullName) == null)
|
||||
continue;
|
||||
yield return type;
|
||||
}
|
||||
foreach (Type type in types)
|
||||
{
|
||||
if (type.IsInterface || type.IsAbstract)
|
||||
continue;
|
||||
if (type.GetInterface(pluginType.FullName) == null)
|
||||
continue;
|
||||
yield return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user