| 9 |
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.IO;
|
|
|
10 |
using System.Xml.Linq;
|
|
|
11 |
|
|
|
12 |
namespace SWAT_Office_App
|
|
|
13 |
{
|
|
|
14 |
public partial class Settings_Form : Form
|
|
|
15 |
{
|
| 53 |
Kevin |
16 |
// Global static variables
|
| 57 |
Kevin |
17 |
private static string settingsLogLocation = "Settings.xml";
|
| 53 |
Kevin |
18 |
public static string globalAdminPassword = "tr33b3@rd";
|
| 9 |
Kevin |
19 |
public static bool defaultSettings { get; set; }
|
| 50 |
Kevin |
20 |
public static bool showFileSizes { get; set; }
|
| 9 |
Kevin |
21 |
public static List<string> systemAccounts = new List<string>();
|
|
|
22 |
public static List<string> hiddenAccounts = new List<string>();
|
|
|
23 |
public static string sharedFolderLocation { get; set; }
|
|
|
24 |
public static string usbMasterx32CopyLocation { get; set; }
|
|
|
25 |
public static string usbMasterx64CopyLocation { get; set; }
|
| 50 |
Kevin |
26 |
|
|
|
27 |
// Static variables for use by DriveLogger
|
|
|
28 |
public static int driveLoggerRefreshInterval { get; set; }
|
| 41 |
Kevin |
29 |
public static List<string> driveLoggerDockLabels = new List<string>();
|
| 48 |
Kevin |
30 |
public static List<string> driveLoggerDrivesToIgnore = new List<string>();
|
| 9 |
Kevin |
31 |
|
|
|
32 |
private static Settings_Form _Settings_Form = null;
|
| 45 |
Kevin |
33 |
// Singleton instance so the settings file isnt loaded every time
|
| 9 |
Kevin |
34 |
public static Settings_Form settings_Form_Instance
|
|
|
35 |
{
|
|
|
36 |
set
|
|
|
37 |
{
|
|
|
38 |
_Settings_Form = value;
|
|
|
39 |
}
|
|
|
40 |
get
|
|
|
41 |
{
|
|
|
42 |
if (_Settings_Form == null)
|
|
|
43 |
_Settings_Form = new Settings_Form();
|
|
|
44 |
return _Settings_Form;
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
public Settings_Form()
|
|
|
48 |
{
|
|
|
49 |
ImportSettings();
|
|
|
50 |
InitializeComponent();
|
|
|
51 |
|
|
|
52 |
this.listBox_SystemAccounts.SelectedIndexChanged += new EventHandler(this.listBox_SystemAccounts_SelectedIndexChanged);
|
|
|
53 |
this.listBox_HiddenAccounts.SelectedIndexChanged += new EventHandler(this.listBox_HiddenAccounts_SelectedIndexChanged);
|
| 48 |
Kevin |
54 |
this.Load += new EventHandler(Settings_Form_Load);
|
| 9 |
Kevin |
55 |
}
|
|
|
56 |
private void Settings_Form_Load(object sender, EventArgs e)
|
|
|
57 |
{
|
|
|
58 |
OpenUpdateSettings();
|
|
|
59 |
settings_Form_Instance.btn_SystemRemove.Enabled = false;
|
|
|
60 |
}
|
|
|
61 |
public void listBox_SystemAccounts_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
62 |
{
|
|
|
63 |
settings_Form_Instance.btn_SystemRemove.Enabled = true;
|
|
|
64 |
}
|
|
|
65 |
public void listBox_HiddenAccounts_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
66 |
{
|
|
|
67 |
settings_Form_Instance.btn_HiddenRemove.Enabled = true;
|
|
|
68 |
}
|
|
|
69 |
public static void ImportSettings()
|
|
|
70 |
{
|
| 45 |
Kevin |
71 |
// Imports settings from Settings.xml
|
| 9 |
Kevin |
72 |
try
|
|
|
73 |
{
|
| 57 |
Kevin |
74 |
if (File.Exists(settingsLogLocation))
|
| 9 |
Kevin |
75 |
{
|
|
|
76 |
// XML Parsing using System.XML.Linq
|
| 57 |
Kevin |
77 |
XElement Settings = XElement.Load(settingsLogLocation);
|
| 9 |
Kevin |
78 |
|
| 50 |
Kevin |
79 |
showFileSizes = bool.Parse(Settings.Element("ProgramSettings").Element("ShowFileSizes").Value);
|
|
|
80 |
|
| 9 |
Kevin |
81 |
systemAccounts.Clear();
|
|
|
82 |
string tempSystemAccounts = Settings.Element("ProgramSettings").Element("SystemAccounts").Value;
|
|
|
83 |
string[] tempStringArray = tempSystemAccounts.Split(new char[] { ',' });
|
|
|
84 |
foreach (string str in tempStringArray)
|
|
|
85 |
systemAccounts.Add(str.Trim());
|
|
|
86 |
|
|
|
87 |
hiddenAccounts.Clear();
|
|
|
88 |
string tempHiddenAccounts = Settings.Element("ProgramSettings").Element("HiddenAccounts").Value;
|
|
|
89 |
tempStringArray = tempHiddenAccounts.Split(new char[] { ',' });
|
|
|
90 |
foreach (string str in tempStringArray)
|
|
|
91 |
hiddenAccounts.Add(str.Trim());
|
|
|
92 |
|
| 41 |
Kevin |
93 |
driveLoggerDockLabels.Clear();
|
|
|
94 |
string tempDriveLoggerDockLabels = Settings.Element("ProgramSettings").Element("DockLabels").Value;
|
|
|
95 |
tempStringArray = tempDriveLoggerDockLabels.Split(new char[] { ',' });
|
|
|
96 |
foreach (string str in tempStringArray)
|
|
|
97 |
driveLoggerDockLabels.Add(str.Trim());
|
|
|
98 |
|
|
|
99 |
driveLoggerRefreshInterval = int.Parse(Settings.Element("ProgramSettings").Element("DockRefreshInterval").Value);
|
|
|
100 |
|
| 48 |
Kevin |
101 |
driveLoggerDrivesToIgnore.Clear();
|
|
|
102 |
string tempDrivesToIgnore = Settings.Element("ProgramSettings").Element("DockDrivesToIgnore").Value;
|
|
|
103 |
tempStringArray = tempDrivesToIgnore.Split(new char[] { ',' });
|
|
|
104 |
foreach (string str in tempStringArray)
|
|
|
105 |
driveLoggerDrivesToIgnore.Add(str.Trim());
|
|
|
106 |
|
| 9 |
Kevin |
107 |
sharedFolderLocation = Settings.Element("ProgramSettings").Element("SharedFolderLocation").Value;
|
|
|
108 |
usbMasterx32CopyLocation = Settings.Element("ProgramSettings").Element("USBMasterCopyx32Location").Value;
|
|
|
109 |
usbMasterx64CopyLocation = Settings.Element("ProgramSettings").Element("USBMasterCopyx64Location").Value;
|
| 63 |
Kevin |
110 |
Debug.appendText("Settings from " + settingsLogLocation + " has been imported");
|
| 9 |
Kevin |
111 |
}
|
|
|
112 |
else
|
|
|
113 |
{
|
| 53 |
Kevin |
114 |
MessageBox.Show("No existing setting file detected. Using default settings");
|
| 63 |
Kevin |
115 |
Debug.appendText("No existing setting file detected. Using default settings");
|
| 9 |
Kevin |
116 |
WriteDefaultConfigFile();
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
catch (Exception e)
|
|
|
120 |
{
|
| 53 |
Kevin |
121 |
//MessageBox.Show(e.ToString(), "Error");
|
| 63 |
Kevin |
122 |
Debug.appendText(e.ToString());
|
| 53 |
Kevin |
123 |
MessageBox.Show("An error has occured. Please notify a supervisor to debug.", "Error");
|
| 9 |
Kevin |
124 |
}
|
|
|
125 |
}
|
|
|
126 |
private static void OpenUpdateSettings()
|
|
|
127 |
{
|
|
|
128 |
// Update the buttons on the form with the imported settings
|
|
|
129 |
settings_Form_Instance.txt_ShareLocation.Text = sharedFolderLocation;
|
|
|
130 |
settings_Form_Instance.txt_USBMasterCopyLocation_x32.Text = usbMasterx32CopyLocation;
|
|
|
131 |
settings_Form_Instance.txt_USBMasterCopyLocation_x64.Text = usbMasterx64CopyLocation;
|
|
|
132 |
PaintListBox();
|
|
|
133 |
}
|
|
|
134 |
private static void ExitUpdateSettings()
|
|
|
135 |
{
|
|
|
136 |
// Update the static variables from the form
|
|
|
137 |
sharedFolderLocation = settings_Form_Instance.txt_ShareLocation.Text;
|
|
|
138 |
usbMasterx32CopyLocation = settings_Form_Instance.txt_USBMasterCopyLocation_x32.Text;
|
|
|
139 |
usbMasterx64CopyLocation = settings_Form_Instance.txt_USBMasterCopyLocation_x64.Text;
|
|
|
140 |
}
|
|
|
141 |
private static void ExportSettings()
|
|
|
142 |
{
|
| 45 |
Kevin |
143 |
// Exports all settings to Settings.xml
|
| 9 |
Kevin |
144 |
try
|
|
|
145 |
{
|
|
|
146 |
// XML Parsing using System.XML.Linq
|
| 57 |
Kevin |
147 |
XElement Settings = XElement.Load(settingsLogLocation);
|
| 9 |
Kevin |
148 |
|
|
|
149 |
string tempString = "";
|
|
|
150 |
foreach (string str in systemAccounts)
|
|
|
151 |
tempString = tempString.Insert(tempString.Length, str + ',');
|
|
|
152 |
if (tempString.Length > 0)
|
|
|
153 |
tempString = tempString.Remove(tempString.Length - 1, 1);
|
|
|
154 |
Settings.Element("ProgramSettings").SetElementValue("SystemAccounts", tempString);
|
|
|
155 |
|
|
|
156 |
tempString = "";
|
|
|
157 |
foreach (string str in hiddenAccounts)
|
|
|
158 |
tempString = tempString.Insert(tempString.Length, str + ',');
|
|
|
159 |
if (tempString.Length > 0)
|
|
|
160 |
tempString = tempString.Remove(tempString.Length - 1, 1);
|
|
|
161 |
Settings.Element("ProgramSettings").SetElementValue("HiddenAccounts", tempString);
|
|
|
162 |
|
|
|
163 |
Settings.Element("ProgramSettings").SetElementValue("SharedFolderLocation", sharedFolderLocation);
|
|
|
164 |
Settings.Element("ProgramSettings").SetElementValue("USBMasterCopyx32Location", usbMasterx32CopyLocation);
|
|
|
165 |
Settings.Element("ProgramSettings").SetElementValue("USBMasterCopyx64Location", usbMasterx64CopyLocation);
|
|
|
166 |
|
|
|
167 |
Settings.Save("Settings.xml");
|
| 63 |
Kevin |
168 |
Debug.appendText("Settings has been exported to " + settingsLogLocation);
|
| 9 |
Kevin |
169 |
}
|
|
|
170 |
catch (Exception e)
|
|
|
171 |
{
|
| 53 |
Kevin |
172 |
//MessageBox.Show(e.ToString(), "Error");
|
| 63 |
Kevin |
173 |
Debug.appendText(e.ToString());
|
| 53 |
Kevin |
174 |
MessageBox.Show("An error has occured. Please notify a supervisor to debug.", "Error");
|
| 9 |
Kevin |
175 |
}
|
|
|
176 |
}
|
|
|
177 |
private static void WriteDefaultConfigFile()
|
|
|
178 |
{
|
|
|
179 |
// Writes the default settings configuration
|
|
|
180 |
try
|
|
|
181 |
{
|
|
|
182 |
XElement Settings = new XElement("Settings",
|
|
|
183 |
new XElement("ProgramSettings",
|
| 55 |
Kevin |
184 |
new XElement("ShowFileSizes","true"),
|
| 9 |
Kevin |
185 |
new XElement("SystemAccounts", "Administrators,Administrator"),
|
|
|
186 |
new XElement("HiddenAccounts", "Administrator,Guest"),
|
|
|
187 |
new XElement("SharedFolderLocation", "C:\\"),
|
|
|
188 |
new XElement("USBMasterCopyx32Location", "C:\\"),
|
| 41 |
Kevin |
189 |
new XElement("USBMasterCopyx64Location", "C:\\"),
|
|
|
190 |
new XElement("DockLabels", "Dock 1,Dock 2,Dock 3,External USB"),
|
| 48 |
Kevin |
191 |
new XElement("DockRefreshInterval", 1000),
|
|
|
192 |
new XElement("DockDrivesToIgnore", "C:\\")
|
| 9 |
Kevin |
193 |
)
|
|
|
194 |
);
|
| 57 |
Kevin |
195 |
Settings.Save(settingsLogLocation);
|
| 63 |
Kevin |
196 |
Debug.appendText("A default settings file has been created");
|
| 9 |
Kevin |
197 |
}
|
|
|
198 |
catch (Exception e)
|
|
|
199 |
{
|
| 53 |
Kevin |
200 |
//MessageBox.Show(e.ToString(), "Error");
|
| 63 |
Kevin |
201 |
Debug.appendText(e.ToString());
|
| 53 |
Kevin |
202 |
MessageBox.Show("An error has occured. Please notify a supervisor to debug.", "Error");
|
| 9 |
Kevin |
203 |
}
|
|
|
204 |
}
|
|
|
205 |
private static void PaintListBox()
|
|
|
206 |
{
|
| 53 |
Kevin |
207 |
// Paints & Refreshes the listbox of system and hidden accounts
|
| 9 |
Kevin |
208 |
settings_Form_Instance.listBox_SystemAccounts.Items.Clear();
|
|
|
209 |
foreach (string user in systemAccounts)
|
|
|
210 |
settings_Form_Instance.listBox_SystemAccounts.Items.Add(user);
|
|
|
211 |
settings_Form_Instance.listBox_HiddenAccounts.Items.Clear();
|
|
|
212 |
foreach (string user in hiddenAccounts)
|
|
|
213 |
settings_Form_Instance.listBox_HiddenAccounts.Items.Add(user);
|
|
|
214 |
}
|
|
|
215 |
private void btn_Ok_Click(object sender, EventArgs e)
|
|
|
216 |
{
|
|
|
217 |
ExitUpdateSettings();
|
|
|
218 |
ExportSettings();
|
|
|
219 |
this.Close();
|
|
|
220 |
}
|
|
|
221 |
private void btn_Cancel_Click(object sender, EventArgs e)
|
|
|
222 |
{
|
|
|
223 |
this.Close();
|
|
|
224 |
}
|
|
|
225 |
private void btn_Default_Click(object sender, EventArgs e)
|
|
|
226 |
{
|
| 53 |
Kevin |
227 |
// Resets settings to default settings
|
| 9 |
Kevin |
228 |
try
|
|
|
229 |
{
|
|
|
230 |
if (MessageBox.Show("Reset configurations to the default settings?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|
|
231 |
{
|
| 57 |
Kevin |
232 |
File.Delete(settingsLogLocation);
|
| 9 |
Kevin |
233 |
WriteDefaultConfigFile();
|
|
|
234 |
ImportSettings();
|
|
|
235 |
OpenUpdateSettings();
|
|
|
236 |
}
|
|
|
237 |
}
|
|
|
238 |
catch (Exception ex)
|
|
|
239 |
{
|
| 53 |
Kevin |
240 |
//MessageBox.Show(e.ToString(), "Error");
|
| 63 |
Kevin |
241 |
Debug.appendText(ex.ToString());
|
| 53 |
Kevin |
242 |
MessageBox.Show("An error has occured. Please notify a supervisor to debug.", "Error");
|
| 9 |
Kevin |
243 |
}
|
|
|
244 |
}
|
|
|
245 |
private void btn_SystemAdd_Click(object sender, EventArgs e)
|
|
|
246 |
{
|
| 63 |
Kevin |
247 |
Add_System_Account_Form newForm = new Add_System_Account_Form();
|
| 9 |
Kevin |
248 |
newForm.ShowDialog();
|
|
|
249 |
PaintListBox();
|
|
|
250 |
}
|
|
|
251 |
private void btn_SystemRemove_Click(object sender, EventArgs e)
|
|
|
252 |
{
|
|
|
253 |
systemAccounts.Remove(this.listBox_SystemAccounts.SelectedItem.ToString());
|
|
|
254 |
PaintListBox();
|
|
|
255 |
}
|
|
|
256 |
private void btn_HiddenAdd_Click(object sender, EventArgs e)
|
|
|
257 |
{
|
| 63 |
Kevin |
258 |
Add_Hidden_Account_Form newForm = new Add_Hidden_Account_Form();
|
| 9 |
Kevin |
259 |
newForm.ShowDialog();
|
|
|
260 |
PaintListBox();
|
|
|
261 |
}
|
|
|
262 |
private void btn_HiddenRemove_Click(object sender, EventArgs e)
|
|
|
263 |
{
|
|
|
264 |
hiddenAccounts.Remove(this.listBox_HiddenAccounts.SelectedItem.ToString());
|
|
|
265 |
PaintListBox();
|
|
|
266 |
}
|
|
|
267 |
private void btn_ShareLocationChange_Click(object sender, EventArgs e)
|
|
|
268 |
{
|
|
|
269 |
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
|
|
270 |
{
|
|
|
271 |
this.txt_ShareLocation.Text = folderBrowserDialog.SelectedPath;
|
|
|
272 |
sharedFolderLocation = folderBrowserDialog.SelectedPath;
|
|
|
273 |
}
|
|
|
274 |
}
|
|
|
275 |
private void btn_USBLocationx32Change_Click(object sender, EventArgs e)
|
|
|
276 |
{
|
|
|
277 |
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
|
|
278 |
{
|
|
|
279 |
this.txt_USBMasterCopyLocation_x32.Text = folderBrowserDialog.SelectedPath;
|
|
|
280 |
usbMasterx32CopyLocation = folderBrowserDialog.SelectedPath;
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
private void btn_USBLocationx64Change_Click(object sender, EventArgs e)
|
|
|
284 |
{
|
|
|
285 |
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
|
|
286 |
{
|
|
|
287 |
this.txt_USBMasterCopyLocation_x64.Text = folderBrowserDialog.SelectedPath;
|
|
|
288 |
usbMasterx64CopyLocation = folderBrowserDialog.SelectedPath;
|
|
|
289 |
}
|
|
|
290 |
}
|
|
|
291 |
}
|
|
|
292 |
}
|