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;
62
            }
63
        }
64
        void form_Main_Menu_FormClosing(object sender, FormClosingEventArgs e)
65
        {
66
            try
67
            {
68
                // If the application is located in the startup folder, prompt for removal on exit
69
                if (System.IO.Directory.GetCurrentDirectory() == System.Environment.SystemDirectory)
70
                {
71
                    // If user chooses to remove the program from startup, initializes code to delete the exe after program exits
72
                    DialogResult result;
73
                    result = MessageBox.Show("Would you like to remove this menu from startup?", "Remove from startup?", MessageBoxButtons.YesNo);
74
                    if (result == DialogResult.Yes)
75
                    {
76
                        ProcessStartInfo Info = new ProcessStartInfo();
77
                        // Calls up a hidden command prompt with a timeout of 3 seconds, automatically chooses yes to delete
78
                        Info.Arguments = "/C choice /C Y /N /D Y /T 3 & Del \"" + Application.ExecutablePath + "\"";
79
                        Info.WindowStyle = ProcessWindowStyle.Hidden;
80
                        Info.CreateNoWindow = true;
81
                        Info.FileName = "cmd.exe";
82
                        Process.Start(Info);
83
                    }
84
                }
85
            }
86
            catch (Exception ex)
87
            {
88
                DebugText.appendText("Exception Thrown: " + ex.ToString());
89
                MessageBox.Show(ex.ToString());
90
            }
91
        }
92
    }
93
}