| 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
|
|
|
31 |
SettingsParser.readSettingsFile();
|
|
|
32 |
}
|
|
|
33 |
private void btn_Main_Drivers_Click(object sender, EventArgs e)
|
|
|
34 |
{
|
|
|
35 |
Drivers_Form driverForm = new Drivers_Form();
|
|
|
36 |
this.WindowState = FormWindowState.Minimized;
|
|
|
37 |
driverForm.ShowDialog();
|
|
|
38 |
this.WindowState = FormWindowState.Normal;
|
|
|
39 |
}
|
|
|
40 |
private void btn_Main_Software_Click(object sender, EventArgs e)
|
|
|
41 |
{
|
|
|
42 |
Software_Form softwareForm = new Software_Form();
|
|
|
43 |
this.WindowState = FormWindowState.Minimized;
|
|
|
44 |
softwareForm.ShowDialog();
|
|
|
45 |
this.WindowState = FormWindowState.Normal;
|
|
|
46 |
}
|
|
|
47 |
private void btn_Main_Exit_Click(object sender, EventArgs e)
|
|
|
48 |
{
|
|
|
49 |
if (System.IO.File.Exists("Debug.txt"))
|
|
|
50 |
Debug.appendText("Closing main menu form");
|
|
|
51 |
this.Close();
|
|
|
52 |
}
|
|
|
53 |
private void form_Main_Menu_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
54 |
// Enables keyboard control for button navigation
|
|
|
55 |
{
|
|
|
56 |
switch (e.KeyChar)
|
|
|
57 |
{
|
|
|
58 |
case 'd':
|
|
|
59 |
case 'D':
|
|
|
60 |
Drivers_Form driverForm = new Drivers_Form();
|
|
|
61 |
driverForm.ShowDialog();
|
|
|
62 |
break;
|
|
|
63 |
case 's':
|
|
|
64 |
case 'S':
|
|
|
65 |
Software_Form softwareForm = new Software_Form();
|
|
|
66 |
softwareForm.ShowDialog();
|
|
|
67 |
break;
|
|
|
68 |
case '?':
|
|
|
69 |
About_Box_Form aboutForm = new About_Box_Form();
|
|
|
70 |
aboutForm.ShowDialog();
|
|
|
71 |
break;
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
void form_Main_Menu_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
75 |
{
|
|
|
76 |
try
|
|
|
77 |
{
|
|
|
78 |
// If the application is located in the startup folder, prompt for removal on exit
|
|
|
79 |
if (System.IO.Directory.GetCurrentDirectory() == System.Environment.SystemDirectory)
|
|
|
80 |
{
|
|
|
81 |
// If user chooses to remove the program from startup, initializes code to delete the exe after program exits
|
|
|
82 |
DialogResult result;
|
|
|
83 |
result = MessageBox.Show("Would you like to remove this menu from startup?", "Remove from startup?", MessageBoxButtons.YesNo);
|
|
|
84 |
if (result == DialogResult.Yes)
|
|
|
85 |
{
|
|
|
86 |
ProcessStartInfo Info = new ProcessStartInfo();
|
|
|
87 |
// Calls up a hidden command prompt with a timeout of 3 seconds, automatically chooses yes to delete
|
|
|
88 |
Info.Arguments = "/C choice /C Y /N /D Y /T 3 & Del \"" + Application.ExecutablePath + "\"";
|
|
|
89 |
Info.WindowStyle = ProcessWindowStyle.Hidden;
|
|
|
90 |
Info.CreateNoWindow = true;
|
|
|
91 |
Info.FileName = "cmd.exe";
|
|
|
92 |
Process.Start(Info);
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
catch (Exception ex)
|
|
|
97 |
{
|
|
|
98 |
Debug.appendText("Exception Thrown: " + ex.ToString());
|
|
|
99 |
MessageBox.Show(ex.ToString());
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
}
|