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