Subversion Repositories Code-Repo

Rev

Rev 67 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
65 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 Main_Menu_Form : Form
14
    {
15
        public Main_Menu_Form()
16
        {
17
            Initialization.Initialize();
18
            Debug.startNewSession();
19
            Debug.appendText("Main menu form initializing");
20
            Debug.appendText("SWAT Drive detected as drive " + Initialization.pathToSWATDrive);
21
            InitializeComponent();
22
            this.KeyPreview = true;
23
            this.KeyPress += new KeyPressEventHandler(this.form_Main_Menu_KeyPress);
24
            this.FormClosing += new FormClosingEventHandler(form_Main_Menu_FormClosing);
25
            if (!SettingsParser.settingsFileExist())
26
            {
27
                Debug.appendText("USBSettings.xml cannot be found");
28
                MessageBox.Show("USBSettings.xml cannot be found.", "Error");
29
            }
30
            else
70 Kevin 31
            {
65 Kevin 32
                SettingsParser.readSettingsFile();
70 Kevin 33
            }
65 Kevin 34
        }
35
        private void btn_Main_Drivers_Click(object sender, EventArgs e)
36
        {
70 Kevin 37
            if (SettingsParser.DriversList.Count() == 0)
38
            {
39
                Debug.appendText("No drivers were found in USBSettings.xml or file does not exist");
40
                MessageBox.Show("No drivers were found in USBSettings.xml or file does not exist");
41
            }
42
            else
43
            {
44
                Drivers_Form driverForm = new Drivers_Form();
45
                //this.WindowState = FormWindowState.Minimized;
46
                driverForm.ShowDialog();
47
                //this.WindowState = FormWindowState.Normal;
48
            }
65 Kevin 49
        }
50
        private void btn_Main_Software_Click(object sender, EventArgs e)
51
        {
70 Kevin 52
            if (SettingsParser.ApplicationsList.Count() == 0)
53
            {
54
                Debug.appendText("No drivers were found in USBSettings.xml or file does not exist");
55
                MessageBox.Show("No drivers were found in USBSettings.xml or file does not exist");
56
            }
57
            else
58
            {
59
                Software_Form softwareForm = new Software_Form();
60
                //this.WindowState = FormWindowState.Minimized;
61
                softwareForm.ShowDialog();
62
                //this.WindowState = FormWindowState.Normal;
63
            }
65 Kevin 64
        }
65
        private void btn_Main_Exit_Click(object sender, EventArgs e)
66
        {
67
            if (System.IO.File.Exists("Debug.txt"))
68
                Debug.appendText("Closing main menu form");
69
            this.Close();
70
        }
71
        private void form_Main_Menu_KeyPress(object sender, KeyPressEventArgs e)
72
        // Enables keyboard control for button navigation
73
        {
74
            switch (e.KeyChar)
75
            {
76
                case 'd':
77
                case 'D':
78
                    Drivers_Form driverForm = new Drivers_Form();
79
                    driverForm.ShowDialog();
80
                    break;
81
                case 's':
82
                case 'S':
83
                    Software_Form softwareForm = new Software_Form();
84
                    softwareForm.ShowDialog();
85
                    break;
86
                case '?':
87
                    About_Box_Form aboutForm = new About_Box_Form();
88
                    aboutForm.ShowDialog();
89
                    break;
90
            }
91
        }
92
        void form_Main_Menu_FormClosing(object sender, FormClosingEventArgs e)
93
        {
94
            try
95
            {
96
                // If the application is located in the startup folder, prompt for removal on exit
97
                if (System.IO.Directory.GetCurrentDirectory() == System.Environment.SystemDirectory)
98
                {
99
                    // If user chooses to remove the program from startup, initializes code to delete the exe after program exits
100
                    DialogResult result;
101
                    result = MessageBox.Show("Would you like to remove this menu from startup?", "Remove from startup?", MessageBoxButtons.YesNo);
102
                    if (result == DialogResult.Yes)
103
                    {
104
                        ProcessStartInfo Info = new ProcessStartInfo();
105
                        // Calls up a hidden command prompt with a timeout of 3 seconds, automatically chooses yes to delete
106
                        Info.Arguments = "/C choice /C Y /N /D Y /T 3 & Del \"" + Application.ExecutablePath + "\"";
107
                        Info.WindowStyle = ProcessWindowStyle.Hidden;
108
                        Info.CreateNoWindow = true;
109
                        Info.FileName = "cmd.exe";
110
                        Process.Start(Info);
111
                    }
112
                }
113
            }
114
            catch (Exception ex)
115
            {
116
                Debug.appendText("Exception Thrown: " + ex.ToString());
117
                MessageBox.Show(ex.ToString());
118
            }
119
        }
120
    }
121
}