Exemple #1
0
        /*  skbtServerControl(frmMainWindow FormWindowHandle)
         *
         * Constructs and Sets all memebrs for use
         * Loads config class
         * Refreshes List box after potentially loading new list items
         *
         * [FormWindowHandle] Handle to the Main Form Window Class
         */
        public skbtServerControl(frmMainWindow f)
        {
            // Set the form handle
            this.frmMainWindowHandle   = f;
            this.frmConfigWindowHandle = new frmConfigWindow(this);

            // Load Config
            CoreConfig = new skbtCoreConfig(this);

            // Refresh List Box Items
            this.refreshListBox();

            // Refresh Buttons
            this.refreshButtons();
        }
        private void btnUninstall_Click(object sender, EventArgs e)
        {
            String thisIdentifier = this.getSelectedPathValue();

            // TODO: Show small dialog containing:
            // - ChkBox Delete Batch_Lib Folder
            // - ChkBox Delete Batch_Settings File
            // (unchecked = Keep both)
            // DEFAULT: Delete Both

            if (this.IsKeepaliveActive(this.sc.CoreConfig.getServerConfigList()[thisIdentifier]))
            {
                MessageBox.Show("KEEPALIVE ACTIVE" + Environment.NewLine + "You must close the keepalive for this config and wait 15 seconds before uninstalling it.");
                return;
            }

            // To Push first release, quick n dirty
            if (MessageBox.Show("Are you sure you wish to delete your config for this server?\nThis will also delete your batch_lib folder, and remove this config from your installer.", "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                // delete settings
                string sFile = this.sc.CoreConfig.getServerMetaObject(thisIdentifier).PathToConfig;
                if (sFile != null)
                {
                    sFile = sFile.Trim('"');
                    File.Delete(sFile);
                }

                skbtCoreConfig cC      = this.sc.CoreConfig;
                skbtServerMeta sM      = cC.getServerMetaObject(thisIdentifier);
                string         exePath = sM.PathToEXE;
                string         exeDir  = Path.GetDirectoryName(exePath);

                string dir = Path.GetFullPath(Path.Combine(exeDir, "batch_lib"));
                if (Directory.Exists(dir))
                {
                    // delete batch_lib
                    Directory.Delete(
                        dir,
                        true
                        );
                }

                // Delete Shrotcuts/Program Group
                String StartMenuProgName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "Programs", skbtServerControl.ProgramGroupName, this.sc.CoreConfig.getServerMetaObject(this.getSelectedPathValue()).textualName);

                Dictionary <UInt32, String> Shortcuts = new Dictionary <uint, string>()
                {
                    { 0, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Start Keepalive (" + this.sc.CoreConfig.getServerMetaObject(this.getSelectedPathValue()).textualName + ").lnk") },
                    { 1, Path.Combine(StartMenuProgName, "Start Keepalive.lnk") },
                    { 2, Path.Combine(StartMenuProgName, "Auto Restart Test.lnk") },
                    { 3, Path.Combine(StartMenuProgName, "Manual Restart.lnk") },
                    { 4, Path.Combine(StartMenuProgName, "Manual Start.lnk") },
                    { 5, Path.Combine(StartMenuProgName, "Manual Stop.lnk") }
                };
                foreach (KeyValuePair <UInt32, String> shortcut in Shortcuts)
                {
                    if (File.Exists(shortcut.Value))
                    {
                        File.Delete(shortcut.Value);
                    }
                }

                // Remove Program Folder if Last config
                if (this.cBoxArmaPath.Items.Count <= 1)
                {
                    if (Directory.Exists(StartMenuProgName))
                    {
                        Directory.Delete(StartMenuProgName, true);
                    }
                }

                // remove from config list
                this.sc.CoreConfig.deleteConfigById(thisIdentifier);

                // save core config
                this.sc.CoreConfig.saveCoreConfig();

                // Update List
                this.sc.refreshListBox();

                // Update Buttons
                this.sc.refreshButtons();
            }
        }