AA2Install.formMain.formMain_Shown C# (CSharp) Method

formMain_Shown() public method

public formMain_Shown ( object sender, EventArgs events ) : void
sender object
events EventArgs
return void
        public void formMain_Shown(object sender, EventArgs events)
        {
            //Hide();
            bool done = false;
            currentOwner = this;

            //Change title
            this.Text = "AA2Install v" + formAbout.AssemblyVersion;

            //Show splash
            ThreadPool.QueueUserWorkItem((x) =>
            {
                using (var splashForm = new formSplash())
                {
                    currentOwner = splashForm;
                    splashForm.lblVer.Text = "AA2Install v" + formAbout.AssemblyVersion;
                    splashForm.Visible = true;
                    splashForm.CreateControl();
                    statusUpdated += (s) =>
                    {
                        splashForm.BeginInvoke(new MethodInvoker(() =>
                        {
                            splashForm.lblStatus.Text = s;
                        }));
                    };
                    splashForm.Show();
                    while (!done)
                        Application.DoEvents();

                    statusUpdated = null;
                    currentOwner = this;
                    splashForm.Close();
                    this.BeginInvoke(new MethodInvoker((() => { this.Activate(); })));
                }
            });

            //Create necessary folders
            if (!Directory.Exists(Paths.BACKUP)) { Directory.CreateDirectory(Paths.BACKUP + @"\"); }
            if (!Directory.Exists(Paths.MODS)) { Directory.CreateDirectory(Paths.MODS + @"\"); }
            if (!Directory.Exists(Paths.CACHE)) { Directory.CreateDirectory(Paths.CACHE + @"\"); }
            if (!Directory.Exists(Paths.PLUGINS)) { Directory.CreateDirectory(Paths.PLUGINS + @"\"); }

            //Load plugins
            ICollection<IPlugin> plugins;

            if (PluginLoader.PluginLoader.LoadAllDLLs(Paths.PLUGINS + "\\", out plugins))
                Plugins.AddRange(plugins);
            else
                currentOwner.InvokeMessageBox("One or more plugin .dll files are blocked. Plugins will not be loaded.", "Blocked DLL files", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            foreach (IPlugin plugin in Plugins)
            {
                switch (plugin.Type)
                {
                    case PluginType.StartupScript:
                        Method script = (Method)plugin.Payload;

                        script.Invoke();
                        break;
                    case PluginType.MenuStripButton:
                        MenuStripMethod strip = (MenuStripMethod)plugin.Payload;

                        ToolStripMenuItem button = new ToolStripMenuItem();
                        button.Text = strip.Text;
                        button.AutoSize = true;
                        button.Click += new EventHandler((s, ev) =>
                        {
                            strip.Method.Invoke();
                        });

                        pluginsToolStripMenuItem.DropDownItems.Add(button);
                        break;
                    case PluginType.UserControl:
                        UserControlMethod control = (UserControlMethod)plugin.Payload;

                        TabPage page = new TabPage(control.Text);
                        page.Controls.Add(control.Method);
                        page.Controls[0].Dock = DockStyle.Fill;

                        tabControl1.TabPages.Add(page);
                        break;
                }
            }

            //Resize the column
            lsvMods_SizeChanged(null, null);

            //Check if installed
            if (!(Directory.Exists(Paths.AA2Play) && Directory.Exists(Paths.AA2Edit)))
            {
                currentOwner.InvokeMessageBox("You don't seem to have AA2Play and/or AA2Edit (properly) installed.\nPlease install it, use the registry fixer (if you've already installed it) or manually specify the install path in the preferences.", "AA2 Not Installed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            //Setup sorting
            lsvMods.ListViewItemSorter = new CustomListViewSorter(int.Parse(Configuration.ReadSetting("SORTMODE") ?? "0"));
            cmbSorting.SelectedIndex = int.Parse(Configuration.ReadSetting("SORTMODE") ?? "0");

            //Start program
            refreshModList();

            //Hide splash
            done = true;
            loadUIConfiguration();
            Show();
            change = new formChanges(pendingChangesToolStripMenuItem);
            change.Show();
            change.Activate();
        }
        #endregion