| 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 |
using System.Threading;
|
|
|
11 |
|
|
|
12 |
namespace SWAT_USB_App
|
|
|
13 |
{
|
|
|
14 |
public partial class form_Drivers : Form
|
|
|
15 |
{
|
|
|
16 |
public static List<string> driverList = new List<string>();
|
|
|
17 |
private static List<Process> toInstall = new List<Process>();
|
|
|
18 |
private static List<RadioButton> formRadioButton = new List<RadioButton>();
|
|
|
19 |
private static form_Drivers _driver_Form = null;
|
|
|
20 |
public static form_Drivers driver_Form_Instance
|
|
|
21 |
{
|
|
|
22 |
set
|
|
|
23 |
{
|
|
|
24 |
_driver_Form = value;
|
|
|
25 |
}
|
|
|
26 |
get
|
|
|
27 |
{
|
|
|
28 |
if (_driver_Form == null)
|
|
|
29 |
_driver_Form = new form_Drivers();
|
|
|
30 |
return _driver_Form;
|
|
|
31 |
}
|
|
|
32 |
}
|
|
|
33 |
public form_Drivers()
|
|
|
34 |
{
|
|
|
35 |
try
|
|
|
36 |
{
|
|
|
37 |
DebugText.appendText("Driver form initializing");
|
|
|
38 |
// Draws the form with a radiobutton for each driver specified in the text file
|
|
|
39 |
InitializeComponent();
|
|
|
40 |
// Location placeholder
|
|
|
41 |
int nextXLocation = 6, nextYLocation = 19;
|
|
|
42 |
// Updates the groupbox size to hold all the radiobuttons
|
|
|
43 |
this.groupBox_DriverList.Size = new Size(149, 40 + (driverList.Count - 1) * 23);
|
|
|
44 |
// Updates the window size to hold all the radiobuttons + buttons
|
|
|
45 |
this.Size = new Size(180, 121 + (driverList.Count - 1) * 23);
|
|
|
46 |
formRadioButton.Clear();
|
|
|
47 |
// Adds a radiobutton for each software item, adds rdoBtn to list formRadioButton
|
|
|
48 |
foreach (string str in driverList)
|
|
|
49 |
{
|
|
|
50 |
RadioButton rdoBtn = new RadioButton();
|
|
|
51 |
rdoBtn.Name = "rdo_" + str;
|
|
|
52 |
rdoBtn.AutoSize = true;
|
|
|
53 |
// Removes the brackets from the name
|
|
|
54 |
rdoBtn.Text = str;
|
|
|
55 |
rdoBtn.Location = new Point(nextXLocation, nextYLocation);
|
|
|
56 |
// Increments the location placeholder for the next radiobutton
|
|
|
57 |
nextYLocation += 23;
|
|
|
58 |
this.groupBox_DriverList.Controls.Add(rdoBtn);
|
|
|
59 |
formRadioButton.Add(rdoBtn);
|
|
|
60 |
}
|
|
|
61 |
if (driverList.Count > 0)
|
|
|
62 |
formRadioButton[0].Checked = true;
|
|
|
63 |
}
|
|
|
64 |
catch (Exception e)
|
|
|
65 |
{
|
|
|
66 |
DebugText.appendText("Exception Thrown: " + e.ToString());
|
|
|
67 |
MessageBox.Show(e.ToString());
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
private void updateToInstallList()
|
|
|
71 |
{
|
|
|
72 |
try
|
|
|
73 |
{
|
|
|
74 |
DebugText.appendText("Updating list of processes to run from list of drivers checked");
|
|
|
75 |
toInstall.Clear();
|
|
|
76 |
// Updates list toInstall with processes for each software checked
|
|
|
77 |
for (int i = 0; i < driverList.Count; i++)
|
|
|
78 |
{
|
|
|
79 |
if (formRadioButton[i].Checked)
|
|
|
80 |
{
|
|
|
81 |
string[] temp;
|
|
|
82 |
temp = SettingsParser.getSetupLocation(formRadioButton[i].Text);
|
|
|
83 |
for (int j = 0; j < temp.Count(); j += 2)
|
|
|
84 |
{
|
|
|
85 |
Process proc = new Process();
|
|
|
86 |
proc.StartInfo.FileName = Initialization.pathToSWATDrive + temp[j];
|
|
|
87 |
proc.StartInfo.Arguments = temp[j + 1];
|
|
|
88 |
toInstall.Add(proc);
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
catch (Exception e)
|
|
|
94 |
{
|
|
|
95 |
DebugText.appendText("Exception Thrown: " + e.ToString());
|
|
|
96 |
MessageBox.Show(e.ToString());
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
private void startDriverInstallation(List<Process> toInstall, int ID)
|
|
|
100 |
{
|
|
|
101 |
DebugText.appendText("Starting to install drivers from list of processes");
|
|
|
102 |
try
|
|
|
103 |
{
|
|
|
104 |
// Goes through list toInstall and runs each process after the previous one ends
|
|
|
105 |
int tempID = ID;
|
|
|
106 |
if (tempID < toInstall.Count)
|
|
|
107 |
{
|
|
|
108 |
DebugText.appendText("Running setup " + toInstall[ID].StartInfo.FileName + " with arguments " + toInstall[ID].StartInfo.Arguments);
|
|
|
109 |
toInstall[ID].Start();
|
|
|
110 |
while (!toInstall[ID].HasExited)
|
|
|
111 |
{
|
|
|
112 |
// Waits for installer to finish before starting the next one
|
|
|
113 |
Thread.Sleep(3000);
|
|
|
114 |
}
|
|
|
115 |
if (toInstall[ID].HasExited)
|
|
|
116 |
{
|
|
|
117 |
DebugText.appendText("Setup is detected as finished, running next setup");
|
|
|
118 |
tempID++;
|
|
|
119 |
startDriverInstallation(toInstall, tempID);
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
//catch (Win32Exception e)
|
|
|
124 |
//{
|
|
|
125 |
|
|
|
126 |
//}
|
|
|
127 |
catch (Exception e)
|
|
|
128 |
{
|
|
|
129 |
DebugText.appendText("Exception Thrown: " + e.ToString());
|
|
|
130 |
MessageBox.Show(e.ToString());
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
private void btn_Driver_Ok_Click(object sender, EventArgs e)
|
|
|
134 |
{
|
|
|
135 |
updateToInstallList();
|
|
|
136 |
startDriverInstallation(toInstall, 0);
|
|
|
137 |
this.Close();
|
|
|
138 |
}
|
|
|
139 |
private void btn_Driver_Cancel_Click(object sender, EventArgs e)
|
|
|
140 |
{
|
|
|
141 |
DebugText.appendText("Closing driver form");
|
|
|
142 |
driver_Form_Instance.Close();
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
}
|