| 10 |
Kevin |
1 |
using System;
|
|
|
2 |
using System.Collections.Generic;
|
|
|
3 |
using System.Linq;
|
|
|
4 |
using System.Text;
|
|
|
5 |
using System.IO;
|
|
|
6 |
using System.Windows.Forms;
|
|
|
7 |
using System.Diagnostics;
|
|
|
8 |
|
|
|
9 |
namespace SWAT_USB_App
|
|
|
10 |
{
|
|
|
11 |
public static class Initialization
|
|
|
12 |
{
|
|
|
13 |
public static string pathToSWATDrive { get; set; }
|
|
|
14 |
public static void Initialize()
|
|
|
15 |
{
|
|
|
16 |
try
|
|
|
17 |
{
|
|
|
18 |
// Pulls information from all drives on the running computer
|
|
|
19 |
DriveInfo[] allDrives = DriveInfo.GetDrives();
|
|
|
20 |
// Looks for a drive with the correct label, updates pathToSWATDrive with the drive letter
|
|
|
21 |
foreach (DriveInfo drive in allDrives)
|
|
|
22 |
{
|
|
|
23 |
if (drive.IsReady == true)
|
|
|
24 |
// Drive label for the USB drives is set here.
|
|
|
25 |
if (
|
|
|
26 |
((drive.VolumeLabel.ToUpper() == "SWAT DRIVE X32")
|
|
|
27 |
|| (drive.VolumeLabel.ToUpper() == "SWAT DRIVE X64")
|
|
|
28 |
) && drive.DriveType == DriveType.Removable)
|
|
|
29 |
{
|
|
|
30 |
pathToSWATDrive = drive.Name;
|
|
|
31 |
break;
|
|
|
32 |
}
|
|
|
33 |
}
|
|
|
34 |
// Prompts for drive to be inserted if none found
|
|
|
35 |
if (pathToSWATDrive == null)
|
|
|
36 |
{
|
|
|
37 |
DialogResult result;
|
|
|
38 |
result = MessageBox.Show("Unable to locate the SWAT USB drive.", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation);
|
|
|
39 |
if (result == DialogResult.Retry)
|
|
|
40 |
Initialize();
|
|
|
41 |
else if (result == DialogResult.Cancel)
|
|
|
42 |
{
|
|
|
43 |
if (System.IO.Directory.GetCurrentDirectory() == System.Environment.SystemDirectory)
|
|
|
44 |
{
|
|
|
45 |
// If user chooses to remove the program from startup, initializes code to delete the exe after program exits
|
|
|
46 |
result = MessageBox.Show("Would you like to remove this menu from startup?", "Remove from startup?", MessageBoxButtons.YesNo);
|
|
|
47 |
if (result == DialogResult.Yes)
|
|
|
48 |
{
|
|
|
49 |
// Calls up a hidden command prompt with a timeout of 3 seconds, automatically chooses yes to delete
|
|
|
50 |
ProcessStartInfo Info = new ProcessStartInfo();
|
|
|
51 |
Info.Arguments = "/C choice /C Y /N /D Y /T 3 & Del \"" + Application.ExecutablePath + "\"";
|
|
|
52 |
Info.WindowStyle = ProcessWindowStyle.Hidden;
|
|
|
53 |
Info.CreateNoWindow = true;
|
|
|
54 |
Info.FileName = "cmd.exe";
|
|
|
55 |
Process.Start(Info);
|
|
|
56 |
Environment.Exit(1);
|
|
|
57 |
}
|
|
|
58 |
else
|
|
|
59 |
Environment.Exit(1);
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
catch (Exception e)
|
|
|
65 |
{
|
|
|
66 |
MessageBox.Show(e.ToString());
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
}
|