Exemplo n.º 1
0
 public void Initilze(HandlerBundle _handlers)
 {
     Handlers = _handlers;
     PluginInstance.PluginLoad(Handlers.Bot, Handlers.UI, Permissions);
     Enabled = true;
 }
Exemplo n.º 2
0
        public MainWindow()
        {
            using (LoadBotForm lbf = new LoadBotForm())
            {
                if(lbf.ShowDialog() != DialogResult.OK)
                {
                    Environment.Exit(0);
                    return;
                }
                bot = new IRCBot(lbf.BotLogin);
            }
            InitializeComponent();

            DirectoryInfo PluginDirectory;
            try
            {
                PluginDirectory = new DirectoryInfo("Plugins");
                if (!PluginDirectory.Exists)
                    PluginDirectory.Create();
            }
            catch
            {
                MessageBox.Show("No access to \"Plugin\" Directory.");
                return;
            }
            foreach (FileInfo pluginFile in PluginDirectory.GetFiles("*.dll"))
            {
                try
                {
                    LoadedPlugin plugin = PluginHandler.LoadPlugin(pluginFile.FullName);
                    plugin.OnException += Plugin_OnException;
                    if (!PluginIDList.Add(plugin.PluginID))
                        throw new Exception("Duplicate id");

                    HandlerBundle handlers = new HandlerBundle();

                    handlers.Bot = new BotHandler(plugin);
                    handlers.Bot.OnException += OnException;
                    handlers.Bot.OnSayMessage += Bot_OnSayMessage;

                    handlers.UI = new BotUIHandler(plugin);
                    handlers.UI.OnTabAdd += UI_OnTabAdd;

                    plugin.Initilze(handlers);

                    foreach (var command in plugin.Details.LoadedCommands)
                    {
                        var handler = new CommandHandler(plugin, command);
                        if (!HandlerList.ContainsKey(handler.ID))
                        {
                            HandlerList.Add(handler.ID, handler);
                        }
                    }

                    PluginDisplayControl display = new PluginDisplayControl(plugin);
                    display.Parent = PluginDisplayPanel;
                    display.Width = PluginDisplayPanel.Width;
                    display.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
                    display.Location = new Point(0, PluginList.Count * display.Height);
                    PluginDisplayPanel.Controls.Add(display);

                    PluginList.Add(plugin);
                }
                catch
                {
                    Debug.WriteLine("Error on file {0}", pluginFile.Name);
                }

                LoadSettings();
            }
        }