예제 #1
0
        /// <summary>
        /// Loads a pdb from a path on disk.
        /// </summary>
        /// <param name="path">Path to pdb file saved on disk.</param>
        /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param>
        /// <returns>Pdb pdb.</returns>
        public static Pdb Load(string path, bool suppressVersionCheck)
        {
            using (FileStream stream = File.OpenRead(path))
                using (FileStructure fs = FileStructure.Read(stream))
                {
                    if (FileFormat.Wixpdb != fs.FileFormat)
                    {
                        throw new WixUnexpectedFileFormatException(path, FileFormat.Wixpdb, fs.FileFormat);
                    }

                    Uri uri = new Uri(Path.GetFullPath(path));
                    using (XmlReader reader = XmlReader.Create(fs.GetDataStream(), null, uri.AbsoluteUri))
                    {
                        try
                        {
                            reader.MoveToContent();
                            return(Pdb.Read(reader, suppressVersionCheck));
                        }
                        catch (XmlException xe)
                        {
                            throw new WixCorruptFileException(path, fs.FileFormat, xe);
                        }
                    }
                }
        }
예제 #2
0
        /// <summary>
        /// Processes an XmlReader and builds up the pdb object.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param>
        /// <returns>The Pdb represented by the Xml.</returns>
        internal static Pdb Read(XmlReader reader, bool suppressVersionCheck)
        {
            if ("wixPdb" != reader.LocalName)
            {
                throw new XmlException();
            }

            bool    empty   = reader.IsEmptyElement;
            Pdb     pdb     = new Pdb();
            Version version = null;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "version":
                    version = new Version(reader.Value);
                    break;
                }
            }

            if (!suppressVersionCheck && null != version && !Pdb.CurrentVersion.Equals(version))
            {
                throw new WixException(WixDataErrors.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixPdb", version.ToString(), Pdb.CurrentVersion.ToString()));
            }

            // loop through the rest of the pdb building up the Output object
            if (!empty)
            {
                bool done = false;

                // loop through all the fields in a row
                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "wixOutput":
                            pdb.Output = Output.Read(reader, suppressVersionCheck);
                            break;

                        default:
                            throw new XmlException();
                        }
                        break;

                    case XmlNodeType.EndElement:
                        done = true;
                        break;
                    }
                }

                if (!done)
                {
                    throw new XmlException();
                }
            }

            return(pdb);
        }