private void ImportSettingsMenuItem_Click(object sender, EventArgs e)
{
// Define our file path and
string file = Path.Combine(Paths.DocumentsFolder, "ScoringSettings.xml");
// Make sure the file exists
if (!File.Exists(file))
{
MessageBox.Show(
"There are currently no exported savings to import.",
"No Saved Settings", MessageBoxButtons.OK, MessageBoxIcon.Information
);
return;
}
//=== Load the file, and import
// Generate our mappings
Dictionary<string, string[]>[] types = { Scores, ConqScores, CoopScores };
string[] names = { "general", "conquest", "coop" };
// Itterate through all of our saved settings, and set them in the
// correct scoring dictionary
try
{
using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read))
{
// Load the XML file
XDocument Doc = XDocument.Load(stream);
for (int i = 0; i < 3; i++)
{
// Load element
XElement element = Doc.Root.Element(names[i]);
// Add each scoring item to the XML
foreach (XElement item in element.Elements())
{
string itemName = item.FirstAttribute.Value;
switch (i)
{
case 0:
Scores[itemName][0] = item.Value;
break;
case 1:
ConqScores[itemName][0] = item.Value;
break;
case 2:
CoopScores[itemName][0] = item.Value;
break;
}
}
}
}
// Fill form values
FillFormFields();
}
catch
{
throw;
}
}