Exemplo n.º 1
0
 /// <summary>
 /// Loads the fomod info from the given info file into the given fomod info object.
 /// </summary>
 /// <param name="p_xmlInfo">The XML info file from which to read the info.</param>
 /// <param name="p_finFomodInfo">The fomod info object to populate with the info.</param>
 /// <param name="p_booOverwriteExisitngValues">Whether or not to overwrite any existing values
 /// in the given <see cref="IFomodInfo"/>.</param>
 public static void LoadInfo(XmlDocument p_xmlInfo, IFomodInfo p_finFomodInfo, bool p_booOverwriteExisitngValues)
 {
     XmlNode xndRoot = null;
     foreach (XmlNode xndNode in p_xmlInfo.ChildNodes)
         if (xndNode.NodeType == XmlNodeType.Element)
         {
             xndRoot = xndNode;
             break;
         }
     if (xndRoot == null)
         throw new fomodLoadException("Root node was missing from fomod info.xml");
     if (xndRoot.Name != "fomod")
         throw new fomodLoadException("Unexpected root node type in info.xml");
     foreach (XmlNode xndNode in xndRoot.ChildNodes)
     {
         if (xndNode.NodeType == XmlNodeType.Comment) continue;
         switch (xndNode.Name)
         {
             case "Name":
                 if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.ModName))
                     p_finFomodInfo.ModName = xndNode.InnerText;
                 break;
             case "Version":
                 if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.HumanReadableVersion))
                     p_finFomodInfo.HumanReadableVersion = xndNode.InnerText;
                 if (p_booOverwriteExisitngValues || (p_finFomodInfo.MachineVersion == DefaultVersion))
                 {
                     XmlNode xndMachineVersion = xndNode.Attributes.GetNamedItem("MachineVersion");
                     if (xndMachineVersion != null)
                         p_finFomodInfo.MachineVersion = new Version(xndMachineVersion.Value);
                 }
                 break;
             case "Author":
                 if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.Author))
                     p_finFomodInfo.Author = xndNode.InnerText;
                 break;
             case "Description":
                 if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.Description))
                     p_finFomodInfo.Description = xndNode.InnerText;
                 break;
             case "MinFommVersion":
                 if (p_booOverwriteExisitngValues || (p_finFomodInfo.MachineVersion == DefaultMinFommVersion))
                     p_finFomodInfo.MinFommVersion = new Version(xndNode.InnerText);
                 break;
             case "Email":
                 if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.Email))
                     p_finFomodInfo.Email = xndNode.InnerText;
                 break;
             case "Website":
                 if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.Website))
                     p_finFomodInfo.Website = xndNode.InnerText;
                 break;
             case "Groups":
                 if (p_booOverwriteExisitngValues || (p_finFomodInfo.Groups.Length == 0))
                 {
                     string[] strGroups = new string[xndNode.ChildNodes.Count];
                     for (int i = 0; i < xndNode.ChildNodes.Count; i++)
                         strGroups[i] = xndNode.ChildNodes[i].InnerText;
                     p_finFomodInfo.Groups = strGroups;
                 }
                 break;
             case "Id":
                 if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.NexusModsId))
                     p_finFomodInfo.NexusModsId = xndNode.InnerText;
                 break;
             case "LatestKnownVersion":
             case "CategoryId":
             case "CustomCategoryId":
             case "IsEndorsed":
             case "UpdateWarningEnabled":
                 // Ignoring (as for now) this nodes added by Nexus Mod Manager
                 break;
             default:
                 throw new fomodLoadException("Unexpected node type '" + xndNode.Name + "' in info.xml");
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Serializes the fomod info contained in the given fomod info object into an XML document.
        /// </summary>
        /// <param name="p_finFomodInfo">The fomod info object to serialize.</param>
        /// <returns>An XML file containing the fomod info.</returns>
        public static XmlDocument SaveInfo(IFomodInfo p_finFomodInfo)
        {
            XmlDocument xmlInfo = new XmlDocument();
            xmlInfo.AppendChild(xmlInfo.CreateXmlDeclaration("1.0", "UTF-16", null));
            XmlElement xelRoot = xmlInfo.CreateElement("fomod");
            XmlElement xelTemp = null;

            xmlInfo.AppendChild(xelRoot);
            if (!String.IsNullOrEmpty(p_finFomodInfo.ModName))
            {
                xelTemp = xmlInfo.CreateElement("Name");
                xelTemp.InnerText = p_finFomodInfo.ModName;
                xelRoot.AppendChild(xelTemp);
            }
            if (!String.IsNullOrEmpty(p_finFomodInfo.Author) && !DEFAULT_AUTHOR.Equals(p_finFomodInfo.Author))
            {
                xelTemp = xmlInfo.CreateElement("Author");
                xelTemp.InnerText = p_finFomodInfo.Author;
                xelRoot.AppendChild(xelTemp);
            }
            if (!String.IsNullOrEmpty(p_finFomodInfo.HumanReadableVersion) || (p_finFomodInfo.MachineVersion != DefaultVersion))
            {
                xelTemp = xmlInfo.CreateElement("Version");
                xelTemp.InnerText = String.IsNullOrEmpty(p_finFomodInfo.HumanReadableVersion) ? p_finFomodInfo.MachineVersion.ToString() : p_finFomodInfo.HumanReadableVersion;
                xelTemp.Attributes.Append(xmlInfo.CreateAttribute("MachineVersion"));
                xelTemp.Attributes[0].Value = p_finFomodInfo.MachineVersion.ToString();
                xelRoot.AppendChild(xelTemp);
            }
            if (!String.IsNullOrEmpty(p_finFomodInfo.Description))
            {
                xelTemp = xmlInfo.CreateElement("Description");
                xelTemp.InnerText = p_finFomodInfo.Description;
                xelRoot.AppendChild(xelTemp);
            }
            if (!String.IsNullOrEmpty(p_finFomodInfo.Email))
            {
                xelTemp = xmlInfo.CreateElement("Email");
                xelTemp.InnerText = p_finFomodInfo.Email;
                xelRoot.AppendChild(xelTemp);
            }
            if (!String.IsNullOrEmpty(p_finFomodInfo.Website))
            {
                xelTemp = xmlInfo.CreateElement("Website");
                xelTemp.InnerText = p_finFomodInfo.Website;
                xelRoot.AppendChild(xelTemp);
            }
            if (p_finFomodInfo.MinFommVersion != DefaultMinFommVersion)
            {
                xelTemp = xmlInfo.CreateElement("MinFommVersion");
                xelTemp.InnerText = p_finFomodInfo.MinFommVersion.ToString();
                xelRoot.AppendChild(xelTemp);
            }
            if ((p_finFomodInfo.Groups != null) && (p_finFomodInfo.Groups.Length > 0))
            {
                xelTemp = xmlInfo.CreateElement("Groups");
                for (int i = 0; i < p_finFomodInfo.Groups.Length; i++)
                    xelTemp.AppendChild(xmlInfo.CreateElement("element")).InnerText = p_finFomodInfo.Groups[i];
                xelRoot.AppendChild(xelTemp);
            }

            return xmlInfo;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Loads the fomod info from the given info file into the given fomod info object.
 /// </summary>
 /// <param name="p_xmlInfo">The XML info file from which to read the info.</param>
 /// <param name="p_finFomodInfo">The fomod info object to populate with the info.</param>
 public static void LoadInfo(XmlDocument p_xmlInfo, IFomodInfo p_finFomodInfo)
 {
     LoadInfo(p_xmlInfo, p_finFomodInfo, true);
 }
Exemplo n.º 4
0
 /// <summary>
 ///   Loads the fomod info from the given info file into the given fomod info object.
 /// </summary>
 /// <param name="p_xmlInfo">The XML info file from which to read the info.</param>
 /// <param name="p_finFomodInfo">The fomod info object to populate with the info.</param>
 /// <param name="p_booOverwriteExisitngValues">
 ///   Whether or not to overwrite any existing values
 ///   in the given <see cref="IFomodInfo" />.
 /// </param>
 public static void LoadInfo(XmlDocument p_xmlInfo, IFomodInfo p_finFomodInfo, bool p_booOverwriteExisitngValues)
 {
   XmlNode xndRoot = null;
   foreach (XmlNode xndNode in p_xmlInfo.ChildNodes)
   {
     if (xndNode.NodeType == XmlNodeType.Element)
     {
       xndRoot = xndNode;
       break;
     }
   }
   if (xndRoot == null)
   {
     throw new fomodLoadException("Root node was missing from fomod info.xml");
   }
   if (xndRoot.Name != "fomod")
   {
     throw new fomodLoadException("Unexpected root node type in info.xml");
   }
   foreach (XmlNode xndNode in xndRoot.ChildNodes)
   {
     if (xndNode.NodeType == XmlNodeType.Comment)
     {
       continue;
     }
     switch (xndNode.Name)
     {
       case "Name":
         if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.ModName))
         {
           p_finFomodInfo.ModName = xndNode.InnerText;
         }
         break;
       case "Version":
         if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.HumanReadableVersion))
         {
           p_finFomodInfo.HumanReadableVersion = xndNode.InnerText;
         }
         if (p_booOverwriteExisitngValues || (p_finFomodInfo.MachineVersion == DefaultVersion))
         {
           var xndMachineVersion = xndNode.Attributes.GetNamedItem("MachineVersion");
           if (xndMachineVersion != null)
           {
             p_finFomodInfo.MachineVersion = new Version(xndMachineVersion.Value);
           }
         }
         break;
       case "Author":
         if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.Author))
         {
           p_finFomodInfo.Author = xndNode.InnerText;
         }
         break;
       case "Description":
         if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.Description))
         {
           p_finFomodInfo.Description = xndNode.InnerText;
         }
         break;
       case "MinFommVersion":
         if (p_booOverwriteExisitngValues || (p_finFomodInfo.MachineVersion == DefaultMinFommVersion))
         {
           p_finFomodInfo.MinFommVersion = new Version(xndNode.InnerText);
         }
         break;
       case "Email":
         if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.Email))
         {
           p_finFomodInfo.Email = xndNode.InnerText;
         }
         break;
       case "Website":
         if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.Website))
         {
           p_finFomodInfo.Website = xndNode.InnerText;
         }
         break;
       case "Groups":
         if (p_booOverwriteExisitngValues || (p_finFomodInfo.Groups.Length == 0))
         {
           var strGroups = new string[xndNode.ChildNodes.Count];
           for (var i = 0; i < xndNode.ChildNodes.Count; i++)
           {
             strGroups[i] = xndNode.ChildNodes[i].InnerText;
           }
           p_finFomodInfo.Groups = strGroups;
         }
         break;
     }
   }
 }
Exemplo n.º 5
0
        /// <summary>
        ///   Serializes the fomod info contained in the given fomod info object into an XML document.
        /// </summary>
        /// <param name="p_finFomodInfo">The fomod info object to serialize.</param>
        /// <returns>An XML file containing the fomod info.</returns>
        public static XmlDocument SaveInfo(IFomodInfo p_finFomodInfo)
        {
            var xmlInfo = new XmlDocument();

            xmlInfo.AppendChild(xmlInfo.CreateXmlDeclaration("1.0", "UTF-16", null));
            var        xelRoot = xmlInfo.CreateElement("fomod");
            XmlElement xelTemp;

            xmlInfo.AppendChild(xelRoot);
            if (!String.IsNullOrEmpty(p_finFomodInfo.ModName))
            {
                xelTemp           = xmlInfo.CreateElement("Name");
                xelTemp.InnerText = p_finFomodInfo.ModName;
                xelRoot.AppendChild(xelTemp);
            }
            if (!String.IsNullOrEmpty(p_finFomodInfo.Author) && !DEFAULT_AUTHOR.Equals(p_finFomodInfo.Author))
            {
                xelTemp           = xmlInfo.CreateElement("Author");
                xelTemp.InnerText = p_finFomodInfo.Author;
                xelRoot.AppendChild(xelTemp);
            }
            if (!String.IsNullOrEmpty(p_finFomodInfo.HumanReadableVersion) ||
                (p_finFomodInfo.MachineVersion != DefaultVersion))
            {
                xelTemp           = xmlInfo.CreateElement("Version");
                xelTemp.InnerText = String.IsNullOrEmpty(p_finFomodInfo.HumanReadableVersion)
          ? p_finFomodInfo.MachineVersion.ToString()
          : p_finFomodInfo.HumanReadableVersion;
                xelTemp.Attributes.Append(xmlInfo.CreateAttribute("MachineVersion"));
                xelTemp.Attributes[0].Value = p_finFomodInfo.MachineVersion.ToString();
                xelRoot.AppendChild(xelTemp);
            }
            if (!String.IsNullOrEmpty(p_finFomodInfo.Description))
            {
                xelTemp           = xmlInfo.CreateElement("Description");
                xelTemp.InnerText = p_finFomodInfo.Description;
                xelRoot.AppendChild(xelTemp);
            }
            if (!String.IsNullOrEmpty(p_finFomodInfo.Email))
            {
                xelTemp           = xmlInfo.CreateElement("Email");
                xelTemp.InnerText = p_finFomodInfo.Email;
                xelRoot.AppendChild(xelTemp);
            }
            if (!String.IsNullOrEmpty(p_finFomodInfo.Website))
            {
                xelTemp           = xmlInfo.CreateElement("Website");
                xelTemp.InnerText = p_finFomodInfo.Website;
                xelRoot.AppendChild(xelTemp);
            }
            if (p_finFomodInfo.MinFommVersion != DefaultMinFommVersion)
            {
                xelTemp           = xmlInfo.CreateElement("MinFommVersion");
                xelTemp.InnerText = p_finFomodInfo.MinFommVersion.ToString();
                xelRoot.AppendChild(xelTemp);
            }
            if ((p_finFomodInfo.Groups != null) && (p_finFomodInfo.Groups.Length > 0))
            {
                xelTemp = xmlInfo.CreateElement("Groups");
                foreach (var group in p_finFomodInfo.Groups)
                {
                    xelTemp.AppendChild(xmlInfo.CreateElement("element")).InnerText = group;
                }
                xelRoot.AppendChild(xelTemp);
            }

            return(xmlInfo);
        }
Exemplo n.º 6
0
        /// <summary>
        ///   Loads the fomod info from the given info file into the given fomod info object.
        /// </summary>
        /// <param name="p_xmlInfo">The XML info file from which to read the info.</param>
        /// <param name="p_finFomodInfo">The fomod info object to populate with the info.</param>
        /// <param name="p_booOverwriteExisitngValues">
        ///   Whether or not to overwrite any existing values
        ///   in the given <see cref="IFomodInfo" />.
        /// </param>
        public static void LoadInfo(XmlDocument p_xmlInfo, IFomodInfo p_finFomodInfo, bool p_booOverwriteExisitngValues)
        {
            XmlNode xndRoot = null;

            foreach (XmlNode xndNode in p_xmlInfo.ChildNodes)
            {
                if (xndNode.NodeType == XmlNodeType.Element)
                {
                    xndRoot = xndNode;
                    break;
                }
            }
            if (xndRoot == null)
            {
                throw new fomodLoadException("Root node was missing from fomod info.xml");
            }
            if (xndRoot.Name != "fomod")
            {
                throw new fomodLoadException("Unexpected root node type in info.xml");
            }
            foreach (XmlNode xndNode in xndRoot.ChildNodes)
            {
                if (xndNode.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                switch (xndNode.Name)
                {
                case "Name":
                    if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.ModName))
                    {
                        p_finFomodInfo.ModName = xndNode.InnerText;
                    }
                    break;

                case "Version":
                    if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.HumanReadableVersion))
                    {
                        p_finFomodInfo.HumanReadableVersion = xndNode.InnerText;
                    }
                    if (p_booOverwriteExisitngValues || (p_finFomodInfo.MachineVersion == DefaultVersion))
                    {
                        var xndMachineVersion = xndNode.Attributes.GetNamedItem("MachineVersion");
                        if (xndMachineVersion != null)
                        {
                            p_finFomodInfo.MachineVersion = new Version(xndMachineVersion.Value);
                        }
                    }
                    break;

                case "Author":
                    if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.Author))
                    {
                        p_finFomodInfo.Author = xndNode.InnerText;
                    }
                    break;

                case "Description":
                    if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.Description))
                    {
                        p_finFomodInfo.Description = xndNode.InnerText;
                    }
                    break;

                case "MinFommVersion":
                    if (p_booOverwriteExisitngValues || (p_finFomodInfo.MachineVersion == DefaultMinFommVersion))
                    {
                        p_finFomodInfo.MinFommVersion = new Version(xndNode.InnerText);
                    }
                    break;

                case "Email":
                    if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.Email))
                    {
                        p_finFomodInfo.Email = xndNode.InnerText;
                    }
                    break;

                case "Website":
                    if (p_booOverwriteExisitngValues || String.IsNullOrEmpty(p_finFomodInfo.Website))
                    {
                        p_finFomodInfo.Website = xndNode.InnerText;
                    }
                    break;

                case "Groups":
                    if (p_booOverwriteExisitngValues || (p_finFomodInfo.Groups.Length == 0))
                    {
                        var strGroups = new string[xndNode.ChildNodes.Count];
                        for (var i = 0; i < xndNode.ChildNodes.Count; i++)
                        {
                            strGroups[i] = xndNode.ChildNodes[i].InnerText;
                        }
                        p_finFomodInfo.Groups = strGroups;
                    }
                    break;
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 ///   Loads the fomod info from the given info file into the given fomod info object.
 /// </summary>
 /// <param name="p_xmlInfo">The XML info file from which to read the info.</param>
 /// <param name="p_finFomodInfo">The fomod info object to populate with the info.</param>
 public static void LoadInfo(XmlDocument p_xmlInfo, IFomodInfo p_finFomodInfo)
 {
     LoadInfo(p_xmlInfo, p_finFomodInfo, true);
 }