/* * ------------------- * Main Business Logic * ------------------- */ /// <summary> /// Retrieves the list of plugins from their configurations. /// </summary> private void LoadPluginList() { // Clear the current listview. box_PluginList.Rows.Clear(); try { // Retrieve current theme list into Global. Global.PluginConfigurations = PluginConfig.GetAllConfigs(); Global.PluginConfigurations = Global.PluginConfigurations.OrderBy(x => x.Enabled ? 0 : 1).ToList(); // Add all of the plugins. foreach (var pluginConfig in Global.PluginConfigurations) { box_PluginList.Rows.Add ( pluginConfig.Enabled ? TextButtons.ButtonEnabled : TextButtons.ButtonDisabled, pluginConfig.Name, pluginConfig.Description, pluginConfig.Author, pluginConfig.Version ); } } catch { } }
/// <summary> /// Gets all plugins for Reloaded /// </summary> public static void Initialize() { var pluginConfigs = PluginConfig.GetAllConfigs(); List <ILoaderEventsV1> loaderEventPlugins = new List <ILoaderEventsV1>(); List <ILoaderBehaviourV1> loaderConfigPlugins = new List <ILoaderBehaviourV1>(); List <ILauncherEventsV1> launcherEventPlugins = new List <ILauncherEventsV1>(); List <IUpdateSourceV1> updateSourcePlugins = new List <IUpdateSourceV1>(); // Load every DLL belonging to a plugin and populate the plugin list. foreach (var pluginConfig in pluginConfigs) { if (pluginConfig.Enabled) { string dllPath = pluginConfig.GetDllPath(); if (File.Exists(dllPath)) { var pluginDll = Assembly.LoadFrom(dllPath); // Get all classes implementing interfaces, create them and populate lists. foreach (var classType in pluginDll.GetTypes()) { if (classType.GetInterfaces().Contains(typeof(ILoaderEventsV1))) { loaderEventPlugins.Add(Activator.CreateInstance(classType) as ILoaderEventsV1); } if (classType.GetInterfaces().Contains(typeof(ILoaderBehaviourV1))) { loaderConfigPlugins.Add(Activator.CreateInstance(classType) as ILoaderBehaviourV1); } if (classType.GetInterfaces().Contains(typeof(ILauncherEventsV1))) { launcherEventPlugins.Add(Activator.CreateInstance(classType) as ILauncherEventsV1); } if (classType.GetInterfaces().Contains(typeof(IUpdateSourceV1))) { updateSourcePlugins.Add(Activator.CreateInstance(classType) as IUpdateSourceV1); } } } else { MessageBox.Show($"The file path for the plugin {pluginConfig.Name} does not exist. Illegal path: {dllPath}"); } } } // Replace the new event and config plugins. LoaderEventPlugins.Clear(); LoaderConfigPlugins.Clear(); LauncherEventPlugins.Clear(); UpdateSourcePlugins.Clear(); UpdateSourcePlugins = updateSourcePlugins; LoaderEventPlugins = loaderEventPlugins; LoaderConfigPlugins = loaderConfigPlugins; LauncherEventPlugins = launcherEventPlugins; }