Exemplo n.º 1
0
        internal static void UnloadPlugin(DPlugin plugin)
        {
            if (activePlugins.Contains(plugin))
            {
                activePlugins.Remove(plugin);
            }

            plugin.Unload();
        }
Exemplo n.º 2
0
        internal static DPlugin LoadPlugin(string pluginName)
        {
            Logger.Log($"Attempting to load plugin: {pluginName}");

            // Get the plugin type by name
            DPluginDefinition pluginDefinition = FindPlugin(pluginName);

            // Create an instance of the plugin
            DPlugin plugin = (DPlugin)Activator.CreateInstance(pluginDefinition.plugin);

            // Assign the information to the plugin object
            plugin.information = pluginDefinition.information;

            // Call the plugins load function
            bool loadedSuccessfully = false;

            try
            {
                loadedSuccessfully = plugin.Load();
            }
            catch (Exception)
            {
                loadedSuccessfully = false;
            }

            if (loadedSuccessfully)
            {
                activePlugins.Add(plugin);
                Logger.Log($"Activated plugin: {plugin.information.name}");
            }
            else
            {
                Logger.Warning($"Unable to load plugin: {plugin.information.name}");
            }

            return(plugin);
        }