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