BF2Statistics.ScoreSettings.LoadScoringCommon C# (CSharp) Method

LoadScoringCommon() private method

Loads the scoring files, and initializes the values of all the input fields
private LoadScoringCommon ( ) : bool
return bool
        private bool LoadScoringCommon()
        {
            // First, we need to parse all 3 scoring files
            string file;
            string ModPath = Path.Combine(Program.RootPath, "Python", "ScoringFiles", MainForm.SelectedMod.Name + "_scoringCommon.py");
            string DefaultPath = Path.Combine(Program.RootPath, "Python", "ScoringFiles", "bf2_scoringCommon.py");

            // Scoring Common. Check for Read and Write access
            try
            {
                using (Stream Str = ScoringCommonFile.Open(FileMode.Open, FileAccess.ReadWrite))
                using (StreamReader Rdr = new StreamReader(Str))
                    file = Rdr.ReadToEnd();
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    "Unable to Read/Write to the Common scoring file:" + Environment.NewLine
                    + Environment.NewLine + "File: " + ScoringCommonFile.FullName
                    + Environment.NewLine + "Error: " + e.Message,
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning
                    );

                this.Load += (s, ev) => this.Close();
                return false;
            }

            // First, we are going to check for a certain string... if it exists
            // Then these config file has been reformated already, else we need
            // to reformat it now
            if (!file.StartsWith("# BF2Statistics Formatted Common Scoring"))
            {
                if (!File.Exists(ModPath))
                {
                    // Show warn dialog
                    if (MessageBox.Show(
                        "The scoringCommon.py 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 scoringCommon.py 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 = ScoringCommonFile.Open(FileMode.Truncate, FileAccess.Write))
                using (StreamWriter Wtr = new StreamWriter(Str))
                {
                    Wtr.Write(file);
                    Wtr.Flush();
                }
            }

            // Build our regex for getting scoring values
            Scores = new Dictionary<string, string[]>();

            // Get all matches for the ScoringCommon.py
            MatchCollection Matches = Reg.Matches(file);
            foreach (Match m in Matches)
                Scores.Add(m.Groups["varname"].Value, new string[] { m.Groups["value"].Value, @"^" + m.Value + "(?:.*)$" });

            return true;
        }