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