예제 #1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            path = Path.Combine(path, "modules");

            messager = new Messager(notifyIcon1);

            if (Directory.Exists(path) == false)
            {
                Directory.CreateDirectory(path);
            }
            else
            {
                moduleManager = new ModuleManager();

                var stringWriter = new StringWriter();

                moduleManager.Initialize(Directory.GetFiles(path, "*.dll", SearchOption.TopDirectoryOnly), stringWriter);
                moduleManagerLog = stringWriter.ToString();

                var extensionsMenu = new ToolStripMenuItem("Extensions");
                extensionsMenu.Click += (ss, ee) =>
                {
                    if (frmModules != null)
                    {
                        return;
                    }

                    frmModules = new frmModules(moduleManagerLog, moduleManager);
                    frmModules.ShowDialog(this);
                    frmModules = null;

                    moduleManager.SaveConfiguration();
                };

                ctxNotificationMenu.Items.Insert(0, new ToolStripSeparator());
                ctxNotificationMenu.Items.Insert(0, extensionsMenu);
            }

            Visible = false;

            devices = HID.GetDevices(0x0583, 0x2060).ToArray();

            if (devices.Length == 0)
            {
                MessageBox.Show("Impossible to detect the controller device.", "Device Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }

            if (devices.All(d => d.Start()) == false)
            {
                MessageBox.Show("Impossible to start the controller device.", "Device Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }

            RunDevices();
        }