/// <summary> /// Opens the Maplist form /// </summary> private void EditMapListBtn_Click(object sender, EventArgs e) { MapList Form = new MapList(); Form.ShowDialog(); // Update maplist ModSelectList_SelectedIndexChanged(this, new EventArgs()); }
/// <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(); }
/// <summary> /// Constructs a new BF2Mod object /// </summary> /// <param name="ModsPath">The full path to the Mods folder</param> /// <param name="ModName">THe mod's folder name</param> public BF2Mod(string ModsPath, string ModName) { // Set internal vars this.Name = ModName; this.RootPath = Path.Combine(ModsPath, ModName); this.LevelsPath = Path.Combine(RootPath, "levels"); this.MaplistFilePath = Path.Combine(RootPath, "settings", "maplist.con"); string DescFile = Path.Combine(ModsPath, ModName, "mod.desc"); // Make sure we have a mod description file if (!File.Exists(DescFile)) { Program.ErrorLog.Write("NOTICE: Mod \"" + ModName + "\" Does not contain mod.desc file"); throw new InvalidModException("Mod \"" + ModName + "\" does not contain a mod.desc file"); } // Make sure we have a levels directory if (!Directory.Exists(LevelsPath)) { Program.ErrorLog.Write("NOTICE: Mod \"" + ModName + "\" Does not contain a Levels folder"); throw new InvalidModException("Mod \"" + ModName + "\" does not contain a levels folder"); } // Make sure we have a maplist! if (!File.Exists(MaplistFilePath)) { Program.ErrorLog.Write("NOTICE: Mod \"" + ModName + "\" Does not contain a maplist.con file"); throw new InvalidModException("Mod \"" + ModName + "\" does not contain a maplist.con file"); } // Get the actual name of the mod try { XmlDocument Desc = new XmlDocument(); Desc.Load(DescFile); XmlNodeList Node = Desc.GetElementsByTagName("title"); string Name = Node[0].InnerText.Trim(); if (Name == "MODDESC_BF2_TITLE") this.Title = "Battlefield 2"; else if (Name == "MODDESC_XP_TITLE") this.Title = "Battlefield 2: Special Forces"; else this.Title = Name; } catch(Exception E) { throw new InvalidModException( "Mod \"" + ModName + "\" contains an invalid Mod.desc file: " + Environment.NewLine + " " + E.Message, E ); } // Load the levels Levels = new List<string>(from dir in Directory.GetDirectories(LevelsPath) select dir.Substring(LevelsPath.Length + 1)); LoadedLevels = new Dictionary<string, BF2Map>(); // Load the maplist MapList = new MapList(MaplistFilePath); }
/// <summary> /// Constructs a new BF2Mod object /// </summary> /// <param name="ModsPath">The full path to the Mods folder</param> /// <param name="ModName">THe mod's folder name</param> public BF2Mod(string ModsPath, string ModName) { // Set internal vars this.Name = ModName; this.RootPath = Path.Combine(ModsPath, ModName); this.LevelsPath = Path.Combine(RootPath, "levels"); this.MaplistFilePath = Path.Combine(RootPath, "settings", "maplist.con"); string DescFile = Path.Combine(ModsPath, ModName, "mod.desc"); // Make sure we have a mod description file if (!File.Exists(DescFile)) { Program.ErrorLog.Write("NOTICE: Mod \"" + ModName + "\" Does not contain mod.desc file"); throw new InvalidModException("Mod \"" + ModName + "\" does not contain a mod.desc file"); } // Make sure we have a levels directory if (!Directory.Exists(LevelsPath)) { Program.ErrorLog.Write("NOTICE: Mod \"" + ModName + "\" Does not contain a Levels folder"); throw new InvalidModException("Mod \"" + ModName + "\" does not contain a levels folder"); } // Make sure we have a maplist! if (!File.Exists(MaplistFilePath)) { Program.ErrorLog.Write("NOTICE: Mod \"" + ModName + "\" Does not contain a maplist.con file"); throw new InvalidModException("Mod \"" + ModName + "\" does not contain a maplist.con file"); } // Get the actual name of the mod try { XmlDocument Desc = new XmlDocument(); Desc.Load(DescFile); XmlNodeList Node = Desc.GetElementsByTagName("title"); string Name = Node[0].InnerText.Trim(); if (Name == "MODDESC_BF2_TITLE") { this.Title = "Battlefield 2"; } else if (Name == "MODDESC_XP_TITLE") { this.Title = "Battlefield 2: Special Forces"; } else { this.Title = Name; } } catch (Exception E) { throw new InvalidModException( "Mod \"" + ModName + "\" contains an invalid Mod.desc file: " + Environment.NewLine + " " + E.Message, E ); } // Load the levels Levels = new List <string>(from dir in Directory.GetDirectories(LevelsPath) select dir.Substring(LevelsPath.Length + 1)); LoadedLevels = new Dictionary <string, BF2Map>(); // Load the maplist MapList = new MapList(MaplistFilePath); }