Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 Kevin 1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Linq;
7
using System.Text;
8
using System.Windows.Forms;
9
using System.Diagnostics;
10
 
11
namespace SWAT_USB_App
12
{
13
    public partial class form_Main_Menu : Form
14
    {
15
        public form_Main_Menu()
16
        {
17
            Initialization.Initialize();
18
            DebugText.startNewSession();
19
            DebugText.appendText("Main menu form initializing");
20
            DebugText.appendText("SWAT Drive detected as drive " + Initialization.pathToSWATDrive);
21
            // Debug: Shows the drive letter of the USB drive detected at startup
22
            //DEBUG: MessageBox.Show(Initialization.pathToSWATDrive, "Drive Letter", MessageBoxButtons.OK);
23
            InitializeComponent();
24
            this.KeyPreview = true;
25
            this.KeyPress += new KeyPressEventHandler(this.form_Main_Menu_KeyPress);
26
            this.FormClosing += new FormClosingEventHandler(form_Main_Menu_FormClosing);
27
            if (!SettingsParser.settingsFileExist())
28
            {
29
                DebugText.appendText("USBSettings.xml cannot be found");
30
                MessageBox.Show("USBSettings.xml cannot be found.", "Error");
31
            }
32
            else
33
                SettingsParser.readSettingsFile();
34
        }
35
        private void btn_Main_Drivers_Click(object sender, EventArgs e)
36
        {
37
            form_Drivers.driver_Form_Instance.ShowDialog();
38
        }
39
        private void btn_Main_Software_Click(object sender, EventArgs e)
40
        {
41
            form_Software.software_Form_Instance.ShowDialog();
42
        }
43
        private void btn_Main_Exit_Click(object sender, EventArgs e)
44
        {
45
            if (System.IO.File.Exists("Debug.txt"))
46
                DebugText.appendText("Closing main menu form");
47
            this.Close();
48
        }
49
        private void form_Main_Menu_KeyPress(object sender, KeyPressEventArgs e)
50
        // Enables keyboard control for button navigation
51
        {
52
            switch (e.KeyChar)
53
            {
54
                case 'd':
55
                case 'D':
56
                    form_Drivers.driver_Form_Instance.ShowDialog();
57
                    break;
58
                case 's':
59
                case 'S':
60
                    form_Software.software_Form_Instance.ShowDialog();
61
                    break;
16 Kevin 62
                case '?':
63
                    AboutBox newForm = new AboutBox();
64
                    newForm.ShowDialog();
65
                    break;
10 Kevin 66
            }
67
        }
68
        void form_Main_Menu_FormClosing(object sender, FormClosingEventArgs e)
69
        {
70
            try
71
            {
72
                // If the application is located in the startup folder, prompt for removal on exit
73
                if (System.IO.Directory.GetCurrentDirectory() == System.Environment.SystemDirectory)
74
                {
75
                    // If user chooses to remove the program from startup, initializes code to delete the exe after program exits
76
                    DialogResult result;
77
                    result = MessageBox.Show("Would you like to remove this menu from startup?", "Remove from startup?", MessageBoxButtons.YesNo);
78
                    if (result == DialogResult.Yes)
79
                    {
80
                        ProcessStartInfo Info = new ProcessStartInfo();
81
                        // Calls up a hidden command prompt with a timeout of 3 seconds, automatically chooses yes to delete
82
                        Info.Arguments = "/C choice /C Y /N /D Y /T 3 & Del \"" + Application.ExecutablePath + "\"";
83
                        Info.WindowStyle = ProcessWindowStyle.Hidden;
84
                        Info.CreateNoWindow = true;
85
                        Info.FileName = "cmd.exe";
86
                        Process.Start(Info);
87
                    }
88
                }
89
            }
90
            catch (Exception ex)
91
            {
92
                DebugText.appendText("Exception Thrown: " + ex.ToString());
93
                MessageBox.Show(ex.ToString());
94
            }
95
        }
96
    }
97
}