| 10 |
Kevin |
1 |
using System;
|
|
|
2 |
using System.Collections.Generic;
|
|
|
3 |
using System.Linq;
|
|
|
4 |
using System.Text;
|
|
|
5 |
using System.IO;
|
|
|
6 |
using System.Xml.Linq;
|
|
|
7 |
using System.Windows.Forms;
|
|
|
8 |
|
|
|
9 |
namespace SWAT_USB_App
|
|
|
10 |
{
|
| 19 |
Kevin |
11 |
public struct Applications
|
|
|
12 |
{
|
|
|
13 |
public string Name;
|
|
|
14 |
public bool Default;
|
|
|
15 |
public string Group;
|
|
|
16 |
public string[] SetupFileLocation;
|
|
|
17 |
}
|
|
|
18 |
public struct Drivers
|
|
|
19 |
{
|
|
|
20 |
public string Name;
|
|
|
21 |
public string[] SetupFileLocation;
|
|
|
22 |
}
|
| 10 |
Kevin |
23 |
class SettingsParser
|
|
|
24 |
{
|
| 19 |
Kevin |
25 |
public static List<Applications> ApplicationsList = new List<Applications>();
|
|
|
26 |
public static List<Drivers> DriversList = new List<Drivers>();
|
|
|
27 |
public static int softwareFormWidth;
|
|
|
28 |
public static int driverFormWidth;
|
|
|
29 |
public static bool driverCheckForMatchingModel;
|
| 10 |
Kevin |
30 |
private static string settingsFileLocation = Initialization.pathToSWATDrive + "USBSettings.xml";
|
|
|
31 |
private static XElement Settings;
|
|
|
32 |
|
|
|
33 |
public static bool settingsFileExist()
|
|
|
34 |
{
|
|
|
35 |
if (File.Exists(Initialization.pathToSWATDrive + "USBSettings.xml"))
|
|
|
36 |
return true;
|
|
|
37 |
else
|
|
|
38 |
return false;
|
|
|
39 |
}
|
|
|
40 |
public static void readSettingsFile()
|
|
|
41 |
{
|
|
|
42 |
try
|
|
|
43 |
{
|
| 65 |
Kevin |
44 |
Debug.appendText("Parsing USBSettings.xml");
|
| 10 |
Kevin |
45 |
// Clears the lists for software and drivers
|
| 19 |
Kevin |
46 |
ApplicationsList.Clear();
|
|
|
47 |
DriversList.Clear();
|
| 10 |
Kevin |
48 |
|
|
|
49 |
Settings = XElement.Load(settingsFileLocation);
|
|
|
50 |
|
| 19 |
Kevin |
51 |
// Reads program settings
|
| 65 |
Kevin |
52 |
Debug.appendText("Reading program settings");
|
| 29 |
Kevin |
53 |
XElement temp = Settings.Element("Program").Element("SoftwareFormWidth");
|
|
|
54 |
if (temp == null)
|
| 65 |
Kevin |
55 |
Debug.appendText("Setting SoftwareFormWidth not found. Using default value of 210");
|
| 29 |
Kevin |
56 |
else
|
|
|
57 |
softwareFormWidth = int.Parse(Settings.Element("Program").Element("SoftwareFormWidth").Value);
|
| 19 |
Kevin |
58 |
|
| 29 |
Kevin |
59 |
temp = Settings.Element("Program").Element("DriverFormWidth");
|
|
|
60 |
if (temp == null)
|
| 65 |
Kevin |
61 |
Debug.appendText("Setting DriverFormWidth not found. Using default value of 180");
|
| 29 |
Kevin |
62 |
else
|
|
|
63 |
driverFormWidth = int.Parse(Settings.Element("Program").Element("DriverFormWidth").Value);
|
|
|
64 |
|
|
|
65 |
temp = Settings.Element("Program").Element("CheckForMatchingModel");
|
|
|
66 |
if (temp == null)
|
| 65 |
Kevin |
67 |
Debug.appendText("Setting CheckForMatchingModel not found. Using default value of false");
|
| 29 |
Kevin |
68 |
else
|
|
|
69 |
driverCheckForMatchingModel = bool.Parse(Settings.Element("Program").Element("CheckForMatchingModel").Value);
|
|
|
70 |
|
| 10 |
Kevin |
71 |
// Reads the list of applications from the USBSettings.xml file into form_Software.softwareList
|
| 65 |
Kevin |
72 |
Debug.appendText("Parsing list of applications");
|
| 16 |
Kevin |
73 |
foreach (XElement elem in Settings.Elements("Applications").Elements("Application"))
|
| 10 |
Kevin |
74 |
{
|
| 65 |
Kevin |
75 |
Debug.appendText("Adding application " + elem.Element("Name").Value);
|
| 19 |
Kevin |
76 |
// Creates new Applications struct for holding app info
|
|
|
77 |
Applications structElem = new Applications();
|
|
|
78 |
// Sets Name value
|
|
|
79 |
structElem.Name = elem.Element("Name").Value;
|
|
|
80 |
// Sets Default value
|
|
|
81 |
if (elem.Element("Default") != null)
|
|
|
82 |
if (elem.Element("Default").Value.ToLower() == "yes")
|
|
|
83 |
structElem.Default = true;
|
|
|
84 |
// Sets Group value
|
|
|
85 |
if (elem.Element("Group") != null)
|
|
|
86 |
structElem.Group = elem.Element("Group").Value;
|
|
|
87 |
// Sets SetupFileLocation value
|
|
|
88 |
string[] setupLocation = new string[elem.Element("Setup").Elements("Location").Count() * 2];
|
|
|
89 |
int counter = 0;
|
|
|
90 |
foreach (XElement element in elem.Elements("Setup").Elements("Location"))
|
|
|
91 |
{
|
| 65 |
Kevin |
92 |
Debug.appendText("Reading setup locations for application " + structElem.Name);
|
| 19 |
Kevin |
93 |
setupLocation[counter] = (string)element.Value;
|
|
|
94 |
setupLocation[counter + 1] = (string)element.Attribute("Args");
|
|
|
95 |
counter += 2;
|
|
|
96 |
}
|
|
|
97 |
structElem.SetupFileLocation = setupLocation;
|
|
|
98 |
// Adds created struct to struct list
|
|
|
99 |
ApplicationsList.Add(structElem);
|
| 10 |
Kevin |
100 |
}
|
|
|
101 |
|
|
|
102 |
// Reads the list of drivers from the USBSettings.xml file into form_Drivers.driverList
|
| 65 |
Kevin |
103 |
Debug.appendText("Parsing list of drivers");
|
| 16 |
Kevin |
104 |
foreach (XElement elem in Settings.Elements("Drivers").Elements("Driver"))
|
| 10 |
Kevin |
105 |
{
|
| 65 |
Kevin |
106 |
Debug.appendText("Adding driver " + elem.Element("Name").Value);
|
| 19 |
Kevin |
107 |
// Creates new Drivers struct for holding driver info
|
|
|
108 |
Drivers structElem = new Drivers();
|
|
|
109 |
// Sets Name value
|
|
|
110 |
structElem.Name = elem.Element("Name").Value;
|
|
|
111 |
// Sets SetupFileLocation value
|
|
|
112 |
string[] setupLocation = new string[elem.Element("Setup").Elements("Location").Count() * 2];
|
|
|
113 |
int counter = 0;
|
|
|
114 |
foreach (XElement element in elem.Elements("Setup").Elements("Location"))
|
|
|
115 |
{
|
| 65 |
Kevin |
116 |
Debug.appendText("Reading setup locations for driver " + structElem.Name);
|
| 19 |
Kevin |
117 |
setupLocation[counter] = (string)element.Value;
|
|
|
118 |
setupLocation[counter + 1] = (string)element.Attribute("Args");
|
|
|
119 |
counter += 2;
|
|
|
120 |
}
|
|
|
121 |
structElem.SetupFileLocation = setupLocation;
|
|
|
122 |
// Adds created struct into struct list
|
|
|
123 |
DriversList.Add(structElem);
|
| 10 |
Kevin |
124 |
}
|
|
|
125 |
}
|
|
|
126 |
catch (Exception e)
|
|
|
127 |
{
|
| 65 |
Kevin |
128 |
Debug.appendText("Exception Thrown: " + e.ToString());
|
| 10 |
Kevin |
129 |
MessageBox.Show(e.ToString());
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
}
|