8,8 → 8,25 |
|
namespace SWAT_USB_App |
{ |
public struct Applications |
{ |
public string Name; |
public bool Default; |
public string Group; |
public string[] SetupFileLocation; |
} |
public struct Drivers |
{ |
public string Name; |
public string[] SetupFileLocation; |
} |
class SettingsParser |
{ |
public static List<Applications> ApplicationsList = new List<Applications>(); |
public static List<Drivers> DriversList = new List<Drivers>(); |
public static int softwareFormWidth; |
public static int driverFormWidth; |
public static bool driverCheckForMatchingModel; |
private static string settingsFileLocation = Initialization.pathToSWATDrive + "USBSettings.xml"; |
private static XElement Settings; |
|
26,44 → 43,71 |
{ |
DebugText.appendText("Parsing USBSettings.xml"); |
// Clears the lists for software and drivers |
form_Software.softwareList.Clear(); |
form_Drivers.driverList.Clear(); |
ApplicationsList.Clear(); |
DriversList.Clear(); |
|
Settings = XElement.Load(settingsFileLocation); |
|
// Reads program settings |
DebugText.appendText("Reading program settings"); |
softwareFormWidth = int.Parse(Settings.Element("Program").Element("SoftwareFormWidth").Value); |
driverFormWidth = int.Parse(Settings.Element("Program").Element("DriverFormWidth").Value); |
driverCheckForMatchingModel = bool.Parse(Settings.Element("Program").Element("CheckForMatchingModel").Value); |
|
// Reads the list of applications from the USBSettings.xml file into form_Software.softwareList |
DebugText.appendText("Parsing list of applications into List softwareList"); |
DebugText.appendText("Parsing list of applications"); |
foreach (XElement elem in Settings.Elements("Applications").Elements("Application")) |
{ |
DebugText.appendText("Adding application " + elem.Element("Name").Value + " into softwareList"); |
form_Software.softwareList.Add(elem.Element("Name").Value); |
DebugText.appendText("Adding application " + elem.Element("Name").Value); |
// Creates new Applications struct for holding app info |
Applications structElem = new Applications(); |
// Sets Name value |
structElem.Name = elem.Element("Name").Value; |
// Sets Default value |
if (elem.Element("Default") != null) |
if (elem.Element("Default").Value.ToLower() == "yes") |
structElem.Default = true; |
// Sets Group value |
if (elem.Element("Group") != null) |
structElem.Group = elem.Element("Group").Value; |
// Sets SetupFileLocation value |
string[] setupLocation = new string[elem.Element("Setup").Elements("Location").Count() * 2]; |
int counter = 0; |
foreach (XElement element in elem.Elements("Setup").Elements("Location")) |
{ |
DebugText.appendText("Reading setup locations for application " + structElem.Name); |
setupLocation[counter] = (string)element.Value; |
setupLocation[counter + 1] = (string)element.Attribute("Args"); |
counter += 2; |
} |
structElem.SetupFileLocation = setupLocation; |
// Adds created struct to struct list |
ApplicationsList.Add(structElem); |
} |
// Alternate way of reading list of applications |
//IEnumerable<XElement> app = |
// from el in Settings.Elements("Applications").Elements("Application") |
// select el; |
//foreach (XElement el in app) |
//{ |
// DebugText.appendText("Adding application " + el.Element("Name").Value + " into softwareList"); |
// form_Software.softwareList.Add(el.Element("Name").Value); |
//} |
|
// Reads the list of drivers from the USBSettings.xml file into form_Drivers.driverList |
DebugText.appendText("Parsing list of drivers into List driverList"); |
DebugText.appendText("Parsing list of drivers"); |
foreach (XElement elem in Settings.Elements("Drivers").Elements("Driver")) |
{ |
DebugText.appendText("Adding driver " + elem.Element("Name").Value + " into driverList"); |
form_Drivers.driverList.Add(elem.Element("Name").Value); |
DebugText.appendText("Adding driver " + elem.Element("Name").Value); |
// Creates new Drivers struct for holding driver info |
Drivers structElem = new Drivers(); |
// Sets Name value |
structElem.Name = elem.Element("Name").Value; |
// Sets SetupFileLocation value |
string[] setupLocation = new string[elem.Element("Setup").Elements("Location").Count() * 2]; |
int counter = 0; |
foreach (XElement element in elem.Elements("Setup").Elements("Location")) |
{ |
DebugText.appendText("Reading setup locations for driver " + structElem.Name); |
setupLocation[counter] = (string)element.Value; |
setupLocation[counter + 1] = (string)element.Attribute("Args"); |
counter += 2; |
} |
structElem.SetupFileLocation = setupLocation; |
// Adds created struct into struct list |
DriversList.Add(structElem); |
} |
// Alternate way of reading list of drivers |
//IEnumerable<XElement> driv = |
// from el in Settings.Elements("Drivers").Elements("Driver") |
// select el; |
//foreach (XElement el in driv) |
//{ |
// DebugText.appendText("Adding driver " + el.Element("Name").Value + " into driverList"); |
// form_Drivers.driverList.Add(el.Element("Name").Value); |
//} |
} |
catch (Exception e) |
{ |
71,74 → 115,5 |
MessageBox.Show(e.ToString()); |
} |
} |
public static bool isDefaultCheck(string applicationName) |
{ |
try |
{ |
// Checks if passed application name is marked as default |
bool isDefault = false; |
foreach (XElement elem in Settings.Elements("Applications").Elements("Application")) |
{ |
if (elem.Element("Name").Value == applicationName) |
if (elem.Element("Default").Value.ToLower() == "yes") |
{ |
isDefault = true; |
break; |
} |
} |
// Alternate method of finding if default is marked |
//IEnumerable<XElement> def = |
// from el in Settings.Elements("Applications").Elements("Application") |
// where (string)el.Element("Name") == applicationName |
// select el; |
//if ((string)def.First().Element("Default").Value.ToLower() == "yes") |
// isDefault = true; |
return isDefault; |
} |
catch (Exception e) |
{ |
DebugText.appendText("Exception Thrown: " + e.ToString()); |
MessageBox.Show(e.ToString()); |
return false; |
} |
} |
public static string[] getSetupLocation(string fileName) |
{ |
try |
{ |
// Pulls the location and arguments for the specified application/driver from USBSettings.xml |
DebugText.appendText("Getting setup locations for application " + fileName); |
IEnumerable<XElement> loc = |
from el in Settings.Elements("Applications").Elements("Application") |
where (string)el.Element("Name") == fileName |
select el; |
// Checks drivers if fileName is not found in Applications |
if (loc.Count() == 0) |
{ |
loc = |
from el in Settings.Elements("Drivers").Elements("Driver") |
where (string)el.Element("Name") == fileName |
select el; |
} |
// Creates a string array holding alternating lines of setup locations and arguments for that setup file |
string[] appSetupFile = new string[loc.Elements("Setup").Elements("Location").Count() * 2]; |
int counter = 0; |
foreach (XElement elem in loc.Elements("Setup").Elements("Location")) |
{ |
DebugText.appendText("Setup location for " + fileName + " is at " + (string)elem.Value + " with arguments " + (string)elem.Attribute("Args")); |
appSetupFile[counter] = (string)elem.Value; |
appSetupFile[counter + 1] = (string)elem.Attribute("Args"); |
counter += 2; |
} |
|
return appSetupFile; |
} |
catch (Exception e) |
{ |
DebugText.appendText("Exception Thrown: " + e.ToString()); |
MessageBox.Show(e.ToString()); |
return null; |
} |
} |
} |
} |