예제 #1
0
파일: Package.cs 프로젝트: Dilute/libdilute
        /// <summary>
        /// Parses the specified XML node into a package.
        /// </summary>
        /// <param name="node">The XML node containing the package information.</param>
        public Package(XmlNode node)
        {
            foreach (XmlNode attrib in node.ChildNodes)
            {
                switch (attrib.Name)
                {
                case "id":
                    if (id == null)
                    {
                        id = attrib.Value;
                    }
                    else
                    {
                        Dilute.Error("Duplicate 'id' tag in package node");
                    }
                    break;

                case "type":
                    if (type == PackageType.UNASSIGNED)
                    {
                        type = Package
                    }
                    else
                    {
                        Dilute.Error("Duplicate 'id' tag in package node");
                    }
                    break;

                default:
                    Dilute.Error("Unknown tag '" + attrib.Name + "' in package node");
                    break;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Parses a library_info or mod_info file.
        /// </summary>
        /// <param name="stream">The stream to read the XML file from.</param>
        /// <returns>A <see cref="Package"/> instance describing the information in the XML document.</returns>
        // TODO Probably useless now that library_info and mod_info have been changed
        public static Package ParsePackage(Stream stream)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(stream);
            if (doc.FirstChild != null)
            {
                if (doc.FirstChild.Name.Equals(XML_PACKAGE))
                {
                    return(new Package(doc.FirstChild));
                }
                Dilute.Error("Failed to parse Package XML: Expected top-level 'package' tag, but got top-level '" + doc.FirstChild.Name + "' tag instead");
                return(null);
            }
            Dilute.Error("Failed to parse Package XML: Expected top-level 'package' tag, but got null instead");
            return(null);
        }
예제 #3
0
        /// <summary>
        /// Parses a package-list file.
        /// </summary>
        /// <param name="stream">The stream to read the XML file from.</param>
        /// <returns>A list <see cref="Package"/> instances describing the information in the XML document.</returns>
        public static List <Package> ParsePackageList(Stream stream)
        {
            List <Package> ret = new List <Package>();
            XmlDocument    doc = new XmlDocument();

            doc.Load(stream);

            if (doc.FirstChild != null)
            {
                if (doc.FirstChild.Name.Equals(XML_PACKAGE_LIST))
                {
                    foreach (XmlNode node in doc.FirstChild.ChildNodes)
                    {
                        ret.Add(new Package(node));
                    }
                    return(ret);
                }
                Dilute.Error("Failed to parse PackageList XML: Expected top-level 'packagelist' tag, but got top-level '" + doc.FirstChild.Name + "' tag instead");
                return(null);
            }
            Dilute.Error("Failed to parse PackageList XML: Expected top-level 'packagelist' tag, but got null instead");
            return(null);
        }