Exemplo n.º 1
0
        public void UnloadPlugin(string name)
        {
            Logger.LogDebug("[CSharpPluginLoader] Unloading " + name + " plugin.");

            if (PluginLoader.GetInstance().Plugins.ContainsKey(name))
            {
                BasePlugin plugin = PluginLoader.GetInstance().Plugins[name];
                if (plugin.DontReload)
                {
                    return;
                }

                CSPlugin csPlugin = (CSPlugin)plugin;

                try
                {
                    csPlugin.Engine.DeInitialize();
                }
                catch (Exception ex)
                {
                    Logger.LogError(string.Format(
                                        "[Modules] Module \"{0}\" has thrown an exception while being deinitialized:\n{1}", csPlugin.Name, ex));
                }

                plugin.KillTimers();
                //PluginLoader.GetInstance().RemoveHooks(csPlugin);
                if (PluginLoader.GetInstance().Plugins.ContainsKey(name))
                {
                    PluginLoader.GetInstance().Plugins.Remove(name);
                }

                #pragma warning disable 618
                foreach (var x in ModuleManager.Plugins)
                {
                    if (x.Plugin == csPlugin.Engine)
                    {
                        ModuleManager.Modules.Remove(x);
                        #pragma warning restore 618
                        break;
                    }
                }

                Logger.LogDebug("[CSharpPluginLoader] " + name + " plugin was unloaded successfuly.");
            }
            else
            {
                Logger.LogError("[CSharpPluginLoader] Can't unload " + name + ". Plugin is not loaded.");
                throw new InvalidOperationException("[CSharpPluginLoader] Can't unload " + name +
                                                    ". Plugin is not loaded.");
            }
        }
Exemplo n.º 2
0
        public void LoadPlugins()
        {
            if (Fougerite.Config.GetBoolValue("Engines", "EnableCSharp"))
            {
                foreach (string name in GetPluginNames())
                {
                    LoadPlugin(name);
                }

                List <Module> OrderedModuleSelector = new List <Module>();
                foreach (var x in PluginLoader.GetInstance().Plugins.Values)
                {
                    CSPlugin plugin = x as CSPlugin;
                    if (plugin != null)
                    {
                        OrderedModuleSelector.Add(plugin.Engine);
                    }
                }

                OrderedModuleSelector = OrderedModuleSelector.OrderBy(x => x.Order).ToList();

                foreach (Module CurrentModule in OrderedModuleSelector)
                {
                    try
                    {
                        CurrentModule.Initialize();
                    }
                    catch (Exception ex)
                    {
                        // Broken modules better stop the entire server init.
                        Logger.LogError(string.Format(
                                            "[CSharpPlugin] Module \"{0}\" has thrown an exception during initialization. {1}", CurrentModule.Name, ex));
                    }

                    //Logger.Log(string.Format(
                    //    "[CSharpPlugin] Module {0} v{1} (by {2}) initiated.", CurrentModule.Name, CurrentModule.Version, CurrentModule.Author));
                }

                Hooks.ModulesLoaded();
            }
            else
            {
                Logger.LogDebug("[CSharpPluginLoader] C# plugins are disabled in Fougerite.cfg.");
            }
        }