private bool LoadCoopFile()
{
string file;
try
{
using (Stream Str = ScoringCoopFile.Open(FileMode.Open, FileAccess.ReadWrite))
using (StreamReader Rdr = new StreamReader(Str))
file = Rdr.ReadToEnd().Replace("SCORE_DEFENT", "SCORE_DEFEND");
}
catch (Exception e)
{
MessageBox.Show(
"Unable to Read/Write to the Coop scoring file:" + Environment.NewLine
+ Environment.NewLine + "File: " + ScoringCoopFile.FullName
+ Environment.NewLine + "Error: " + e.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Warning
);
this.Load += (s, ev) => this.Close();
return false;
}
// Process
if (!file.StartsWith("# BF2Statistics Formatted Coop Scoring"))
{
// We need to replace the default file with the embedded one that
// Correctly formats the AI_ Scores
string DefaultPath = Path.Combine(Program.RootPath, "Python", "ScoringFiles", "bf2_coop.py");
string ModPath = Path.Combine(Program.RootPath, "Python", "ScoringFiles", MainForm.SelectedMod.Name + "_coop.py");
if (!File.Exists(ModPath))
{
// Show warn dialog
if (MessageBox.Show(
"The Coop Scoring file needs to be formatted to use this feature. If you are using a third party mod,"
+ " then formatting can break the scoring. Do you want to Format now?",
"Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
this.Load += (s, e) => this.Close();
return false;
}
file = File.ReadAllText(DefaultPath);
}
else
{
// Show warn dialog
if (MessageBox.Show("The Coop Scoring file needs to be formatted to use this feature."
+ " Do you want to Format now?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
this.Load += (s, e) => this.Close();
return false;
}
file = File.ReadAllText(ModPath);
}
// Write formated data to the common soring file
using (Stream Str = ScoringCoopFile.Open(FileMode.Truncate, FileAccess.Write))
using (StreamWriter Wtr = new StreamWriter(Str))
{
Wtr.Write(file);
Wtr.Flush();
}
}
CoopScores = new Dictionary<string, string[]>();
MatchCollection Matches = Reg.Matches(file);
foreach (Match m in Matches)
CoopScores.Add(m.Groups["varname"].Value, new string[] { m.Groups["value"].Value, @"^" + m.Value + "(?:.*)$" });
return true;
}