Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <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);
        }