Subversion Repositories Code-Repo

Rev

Rev 10 | Blame | Last modification | View Log | RSS feed

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace SWAT_USB_App
{
    public partial class form_Main_Menu : Form
    {
        public form_Main_Menu()
        {
            Initialization.Initialize();
            DebugText.startNewSession();
            DebugText.appendText("Main menu form initializing");
            DebugText.appendText("SWAT Drive detected as drive " + Initialization.pathToSWATDrive);
            // Debug: Shows the drive letter of the USB drive detected at startup
            //DEBUG: MessageBox.Show(Initialization.pathToSWATDrive, "Drive Letter", MessageBoxButtons.OK);
            InitializeComponent();
            this.KeyPreview = true;
            this.KeyPress += new KeyPressEventHandler(this.form_Main_Menu_KeyPress);
            this.FormClosing += new FormClosingEventHandler(form_Main_Menu_FormClosing);
            if (!SettingsParser.settingsFileExist())
            {
                DebugText.appendText("USBSettings.xml cannot be found");
                MessageBox.Show("USBSettings.xml cannot be found.", "Error");
            }
            else
                SettingsParser.readSettingsFile();
        }
        private void btn_Main_Drivers_Click(object sender, EventArgs e)
        {
            form_Drivers.driver_Form_Instance.ShowDialog();
        }
        private void btn_Main_Software_Click(object sender, EventArgs e)
        {
            form_Software.software_Form_Instance.ShowDialog();
        }
        private void btn_Main_Exit_Click(object sender, EventArgs e)
        {
            if (System.IO.File.Exists("Debug.txt"))
                DebugText.appendText("Closing main menu form");
            this.Close();
        }
        private void form_Main_Menu_KeyPress(object sender, KeyPressEventArgs e)
        // Enables keyboard control for button navigation
        {
            switch (e.KeyChar)
            {
                case 'd':
                case 'D':
                    form_Drivers.driver_Form_Instance.ShowDialog();
                    break;
                case 's':
                case 'S':
                    form_Software.software_Form_Instance.ShowDialog();
                    break;
                case '?':
                    AboutBox newForm = new AboutBox();
                    newForm.ShowDialog();
                    break;
            }
        }
        void form_Main_Menu_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                // If the application is located in the startup folder, prompt for removal on exit
                if (System.IO.Directory.GetCurrentDirectory() == System.Environment.SystemDirectory)
                {
                    // If user chooses to remove the program from startup, initializes code to delete the exe after program exits
                    DialogResult result;
                    result = MessageBox.Show("Would you like to remove this menu from startup?", "Remove from startup?", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        ProcessStartInfo Info = new ProcessStartInfo();
                        // Calls up a hidden command prompt with a timeout of 3 seconds, automatically chooses yes to delete
                        Info.Arguments = "/C choice /C Y /N /D Y /T 3 & Del \"" + Application.ExecutablePath + "\"";
                        Info.WindowStyle = ProcessWindowStyle.Hidden;
                        Info.CreateNoWindow = true;
                        Info.FileName = "cmd.exe";
                        Process.Start(Info);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugText.appendText("Exception Thrown: " + ex.ToString());
                MessageBox.Show(ex.ToString());
            }
        }
    }
}