BF2Statistics.MapList.AddFromString C# (CSharp) Method

AddFromString() public method

Parses a line in con file format, and adds the map to the entry list if its valid
public AddFromString ( string Line ) : bool
Line string The con file formated string to parse
return bool
        public bool AddFromString(string Line)
        {
            // Parse the 1st line of the con file
            Match M = Regex.Match(Line, Expression, RegexOptions.IgnoreCase);
            if (M.Success)
            {
                MapListEntry Entry = new MapListEntry();
                Entry.MapName = M.Groups["Mapname"].Value;
                Entry.GameMode = M.Groups["Gamemode"].Value;
                Entry.MapSize = Int32.Parse(M.Groups["Size"].Value);
                Entries.Add(Entry);
            }

            return M.Success;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Saves the current generated maplist into the maplist.con file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            // Make sure we have at least 1 map :/
            int Len = MapListBox.Lines.Length - 1;

            if (Len == 0 || String.IsNullOrWhiteSpace(MapListBox.Text))
            {
                MessageBox.Show("There must be at least 1 map before saving!", "User Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // Append the prefix to each map line
            MapList List = MainForm.SelectedMod.MapList;

            // Clear out old Junk, and add new
            List.Entries.Clear();
            for (int i = 0; i < Len; i++)
            {
                List.AddFromString("mapList.append " + MapListBox.Lines[i]);
            }

            // Save and close
            List.SaveToFile(MainForm.SelectedMod.MaplistFilePath);
            this.Close();
        }