| 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 |
{
|
| 16 |
Kevin |
35 |
this.Load += new EventHandler(form_Drivers_Load);
|
|
|
36 |
InitializeComponent();
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
void form_Drivers_Load(object sender, EventArgs e)
|
|
|
40 |
{
|
| 10 |
Kevin |
41 |
try
|
|
|
42 |
{
|
| 16 |
Kevin |
43 |
if (driverList.Count == 0)
|
| 10 |
Kevin |
44 |
{
|
| 16 |
Kevin |
45 |
DebugText.appendText("No drivers were found in USBSettings.xml");
|
|
|
46 |
MessageBox.Show("No drivers were found in USBSettings.xml");
|
|
|
47 |
this.Close();
|
| 10 |
Kevin |
48 |
}
|
| 16 |
Kevin |
49 |
else
|
|
|
50 |
{
|
|
|
51 |
bool modelFound = false;
|
|
|
52 |
DebugText.appendText("Driver form initializing");
|
|
|
53 |
Initialization.GetModelNumber();
|
|
|
54 |
// Draws the form with a radiobutton for each driver specified in the text file
|
|
|
55 |
// Location placeholder
|
|
|
56 |
int nextXLocation = 6, nextYLocation = 19;
|
|
|
57 |
// Updates the groupbox size to hold all the radiobuttons
|
|
|
58 |
this.groupBox_DriverList.Size = new Size(149, 40 + (driverList.Count - 1) * 23);
|
|
|
59 |
// Updates the window size to hold all the radiobuttons + buttons
|
|
|
60 |
this.Size = new Size(180, 121 + (driverList.Count - 1) * 23);
|
|
|
61 |
formRadioButton.Clear();
|
|
|
62 |
// Adds a radiobutton for each software item, adds rdoBtn to list formRadioButton
|
|
|
63 |
foreach (string str in driverList)
|
|
|
64 |
{
|
|
|
65 |
RadioButton rdoBtn = new RadioButton();
|
|
|
66 |
rdoBtn.Name = "rdo_" + str;
|
|
|
67 |
rdoBtn.AutoSize = true;
|
|
|
68 |
// Removes the brackets from the name
|
|
|
69 |
rdoBtn.Text = str;
|
|
|
70 |
rdoBtn.Location = new Point(nextXLocation, nextYLocation);
|
|
|
71 |
// Increments the location placeholder for the next radiobutton
|
|
|
72 |
nextYLocation += 23;
|
|
|
73 |
this.groupBox_DriverList.Controls.Add(rdoBtn);
|
|
|
74 |
formRadioButton.Add(rdoBtn);
|
|
|
75 |
// If model is detected, check the correct entry
|
|
|
76 |
if (str.ToLower() == Initialization.computerModel.ToLower() && modelFound == false)
|
|
|
77 |
{
|
|
|
78 |
modelFound = true;
|
|
|
79 |
rdoBtn.Checked = true;
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
if (modelFound == true)
|
|
|
83 |
{
|
|
|
84 |
MessageBox.Show("Drivers were found for this computer.\n" +
|
|
|
85 |
"Press OK to continue then OK to install drivers.");
|
|
|
86 |
}
|
|
|
87 |
else
|
|
|
88 |
{
|
|
|
89 |
MessageBox.Show("Drivers were not found for this computer.\n" +
|
|
|
90 |
"Please go to the manufacturer's site and manually\n" +
|
|
|
91 |
"download the drivers for this computer.");
|
|
|
92 |
}
|
|
|
93 |
}
|
| 10 |
Kevin |
94 |
}
|
| 16 |
Kevin |
95 |
catch (Exception ex)
|
| 10 |
Kevin |
96 |
{
|
|
|
97 |
DebugText.appendText("Exception Thrown: " + e.ToString());
|
| 16 |
Kevin |
98 |
MessageBox.Show(ex.ToString());
|
| 10 |
Kevin |
99 |
}
|
|
|
100 |
}
|
|
|
101 |
private void updateToInstallList()
|
|
|
102 |
{
|
|
|
103 |
try
|
|
|
104 |
{
|
|
|
105 |
DebugText.appendText("Updating list of processes to run from list of drivers checked");
|
|
|
106 |
toInstall.Clear();
|
|
|
107 |
// Updates list toInstall with processes for each software checked
|
|
|
108 |
for (int i = 0; i < driverList.Count; i++)
|
|
|
109 |
{
|
|
|
110 |
if (formRadioButton[i].Checked)
|
|
|
111 |
{
|
|
|
112 |
string[] temp;
|
|
|
113 |
temp = SettingsParser.getSetupLocation(formRadioButton[i].Text);
|
|
|
114 |
for (int j = 0; j < temp.Count(); j += 2)
|
|
|
115 |
{
|
|
|
116 |
Process proc = new Process();
|
|
|
117 |
proc.StartInfo.FileName = Initialization.pathToSWATDrive + temp[j];
|
|
|
118 |
proc.StartInfo.Arguments = temp[j + 1];
|
|
|
119 |
toInstall.Add(proc);
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
catch (Exception e)
|
|
|
125 |
{
|
|
|
126 |
DebugText.appendText("Exception Thrown: " + e.ToString());
|
|
|
127 |
MessageBox.Show(e.ToString());
|
|
|
128 |
}
|
|
|
129 |
}
|
|
|
130 |
private void startDriverInstallation(List<Process> toInstall, int ID)
|
|
|
131 |
{
|
|
|
132 |
DebugText.appendText("Starting to install drivers from list of processes");
|
|
|
133 |
try
|
|
|
134 |
{
|
|
|
135 |
// Goes through list toInstall and runs each process after the previous one ends
|
|
|
136 |
int tempID = ID;
|
|
|
137 |
if (tempID < toInstall.Count)
|
|
|
138 |
{
|
|
|
139 |
DebugText.appendText("Running setup " + toInstall[ID].StartInfo.FileName + " with arguments " + toInstall[ID].StartInfo.Arguments);
|
|
|
140 |
toInstall[ID].Start();
|
|
|
141 |
while (!toInstall[ID].HasExited)
|
|
|
142 |
{
|
|
|
143 |
// Waits for installer to finish before starting the next one
|
|
|
144 |
Thread.Sleep(3000);
|
|
|
145 |
}
|
|
|
146 |
if (toInstall[ID].HasExited)
|
|
|
147 |
{
|
|
|
148 |
DebugText.appendText("Setup is detected as finished, running next setup");
|
|
|
149 |
tempID++;
|
|
|
150 |
startDriverInstallation(toInstall, tempID);
|
|
|
151 |
}
|
|
|
152 |
}
|
|
|
153 |
}
|
|
|
154 |
//catch (Win32Exception e)
|
|
|
155 |
//{
|
|
|
156 |
|
|
|
157 |
//}
|
|
|
158 |
catch (Exception e)
|
|
|
159 |
{
|
|
|
160 |
DebugText.appendText("Exception Thrown: " + e.ToString());
|
|
|
161 |
MessageBox.Show(e.ToString());
|
|
|
162 |
}
|
|
|
163 |
}
|
|
|
164 |
private void btn_Driver_Ok_Click(object sender, EventArgs e)
|
|
|
165 |
{
|
|
|
166 |
updateToInstallList();
|
|
|
167 |
startDriverInstallation(toInstall, 0);
|
|
|
168 |
this.Close();
|
|
|
169 |
}
|
|
|
170 |
private void btn_Driver_Cancel_Click(object sender, EventArgs e)
|
|
|
171 |
{
|
|
|
172 |
DebugText.appendText("Closing driver form");
|
|
|
173 |
driver_Form_Instance.Close();
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
}
|