/// <summary> /// Adds a Plugin to the Host specified in the PluginPointer Data /// </summary> /// <param name="plugin">Plugin to Add</param> /// <param name="data">The Plugin Pointer</param> public static void AddPlugin(IPlugin plugin, PluginAssemblyPointer data) { if (!IsInitialized) { throw new Exception("Can not use the plugin System when its not initialized."); } if (!LoadedPlugins.ContainsKey(data.Host)) { LoadPlugins(data.Host, false); } if (!LoadedPlugins[data.Host].Contains(plugin)) { if (!data.Host.IsAllowedPlugin(plugin)) { return; } AddPluginEventArgs args = new AddPluginEventArgs(data, plugin, true); OnAddPlugin?.Invoke(args); if (args.Cancel) { return; } SendLog($"Adding {plugin.GetType().Name} to {data.Host.GetType().Name}"); data.EnsureDirectoriesExist(); PointerMap[plugin] = data; LoadedPlugins[data.Host].Add(plugin); plugin.OnLoad(data); data.Host.OnPluginLoad(plugin, data); ProcessAttributes(plugin, data); AfterAddPlugin?.Invoke(new AddPluginEventArgs(data, plugin, false)); } }
/// <summary> /// Ensures that the Directory structure of a Pointer exists. /// Loads all Plugins From a Pointer. /// </summary> /// <param name="data">The Pointer to load.</param> private static void AddFromLoaderResult(PluginAssemblyPointer data) { data.EnsureDirectoriesExist(); PluginLoader.AddPluginsFromLoaderResult(data); }