/// <summary> /// Loads the plugin at the given path. /// </summary> /// <param name="path">The path to the plugin assembly.</param> /// <returns>Whether the plugin was loaded successfully or not.</returns> public static Exception Load(string path) { try { Assembly asm = Assembly.LoadFrom(path); TypeInfo type = asm.DefinedTypes.FirstOrDefault(t => t.IsSubclassOf(typeof(RPlugin))); if (type == null) { return(new Exception("Plugin class not found.")); } else { RPlugin plugin = Activator.CreateInstance(type) as RPlugin; if (plugin == null) { return(new Exception("Failed to create plugin instance.")); } else { PluginContainer container = new PluginContainer(plugin); _plugins.Add(plugin, container); plugin.Load(); container.Options.SetDefaults(); container.Options.Load(); PluginLoaded?.Invoke(container); return(null); } } } catch (Exception e) { return(e); } }
/// <summary> /// Unloads the given plugin. /// </summary> /// <param name="plugin">The plugin to unload.</param> public static void Unload(RPlugin plugin) { PluginUnloaded?.Invoke(_plugins[plugin]); plugin.Unload(); _plugins.Remove(plugin); }
/// <summary> /// Gets the container for the given plugin. /// </summary> /// <param name="plugin">The plugin to get the container for.</param> /// <returns>The plugin's container.</returns> public static PluginContainer GetContainer(RPlugin plugin) { return(_plugins.TryGetValue(plugin, out PluginContainer container) ? container : null); }
public PluginContainer(RPlugin plugin) { Plugin = plugin; Options.Options.AddRange(plugin.Options); Options.OptionsFile = OptionsFile; }