diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-11-01 10:59:45 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-11-01 10:59:45 -0700 |
| commit | 2bb37beda887d120a0ddabf874ad25357101faa1 (patch) | |
| tree | c35e97b03274b86cfc9ff7fd2caeee211165a140 /src/WixToolset.Data.WindowsInstaller/Pdb.cs | |
| parent | df7413aeed3aea3425dff20ae0c8b1be3a3ab525 (diff) | |
| download | wix-2bb37beda887d120a0ddabf874ad25357101faa1.tar.gz wix-2bb37beda887d120a0ddabf874ad25357101faa1.tar.bz2 wix-2bb37beda887d120a0ddabf874ad25357101faa1.zip | |
Update to WiX Intermediate Representation
Diffstat (limited to 'src/WixToolset.Data.WindowsInstaller/Pdb.cs')
| -rw-r--r-- | src/WixToolset.Data.WindowsInstaller/Pdb.cs | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/src/WixToolset.Data.WindowsInstaller/Pdb.cs b/src/WixToolset.Data.WindowsInstaller/Pdb.cs new file mode 100644 index 00000000..03c3ddbb --- /dev/null +++ b/src/WixToolset.Data.WindowsInstaller/Pdb.cs | |||
| @@ -0,0 +1,163 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | namespace WixToolset.Data | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.IO; | ||
| 7 | using System.Xml; | ||
| 8 | |||
| 9 | /// <summary> | ||
| 10 | /// Pdb generated by the binder. | ||
| 11 | /// </summary> | ||
| 12 | public sealed class Pdb | ||
| 13 | { | ||
| 14 | public const string XmlNamespaceUri = "http://wixtoolset.org/schemas/v4/wixpdb"; | ||
| 15 | private static readonly Version CurrentVersion = new Version("4.0.0.0"); | ||
| 16 | |||
| 17 | /// <summary> | ||
| 18 | /// Creates a new empty pdb object. | ||
| 19 | /// </summary> | ||
| 20 | /// <param name="sourceLineNumbers">The source line information for the pdb.</param> | ||
| 21 | public Pdb() | ||
| 22 | { | ||
| 23 | } | ||
| 24 | |||
| 25 | /// <summary> | ||
| 26 | /// Gets or sets the output that is a part of this pdb. | ||
| 27 | /// </summary> | ||
| 28 | /// <value>Type of the output.</value> | ||
| 29 | public Output Output { get; set; } | ||
| 30 | |||
| 31 | /// <summary> | ||
| 32 | /// Loads a pdb from a path on disk. | ||
| 33 | /// </summary> | ||
| 34 | /// <param name="path">Path to pdb file saved on disk.</param> | ||
| 35 | /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> | ||
| 36 | /// <returns>Pdb pdb.</returns> | ||
| 37 | public static Pdb Load(string path, bool suppressVersionCheck) | ||
| 38 | { | ||
| 39 | using (FileStream stream = File.OpenRead(path)) | ||
| 40 | using (FileStructure fs = FileStructure.Read(stream)) | ||
| 41 | { | ||
| 42 | if (FileFormat.Wixpdb != fs.FileFormat) | ||
| 43 | { | ||
| 44 | throw new WixUnexpectedFileFormatException(path, FileFormat.Wixpdb, fs.FileFormat); | ||
| 45 | } | ||
| 46 | |||
| 47 | Uri uri = new Uri(Path.GetFullPath(path)); | ||
| 48 | using (XmlReader reader = XmlReader.Create(fs.GetDataStream(), null, uri.AbsoluteUri)) | ||
| 49 | { | ||
| 50 | try | ||
| 51 | { | ||
| 52 | reader.MoveToContent(); | ||
| 53 | return Pdb.Read(reader, suppressVersionCheck); | ||
| 54 | } | ||
| 55 | catch (XmlException xe) | ||
| 56 | { | ||
| 57 | throw new WixCorruptFileException(path, fs.FileFormat, xe); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | /// <summary> | ||
| 64 | /// Saves a pdb to a path on disk. | ||
| 65 | /// </summary> | ||
| 66 | /// <param name="path">Path to save pdb file to on disk.</param> | ||
| 67 | public void Save(string path) | ||
| 68 | { | ||
| 69 | Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))); | ||
| 70 | |||
| 71 | using (FileStream stream = File.Create(path)) | ||
| 72 | using (FileStructure fs = FileStructure.Create(stream, FileFormat.Wixpdb, null)) | ||
| 73 | using (XmlWriter writer = XmlWriter.Create(fs.GetDataStream())) | ||
| 74 | { | ||
| 75 | writer.WriteStartDocument(); | ||
| 76 | this.Write(writer); | ||
| 77 | writer.WriteEndDocument(); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | /// <summary> | ||
| 82 | /// Processes an XmlReader and builds up the pdb object. | ||
| 83 | /// </summary> | ||
| 84 | /// <param name="reader">Reader to get data from.</param> | ||
| 85 | /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> | ||
| 86 | /// <returns>The Pdb represented by the Xml.</returns> | ||
| 87 | internal static Pdb Read(XmlReader reader, bool suppressVersionCheck) | ||
| 88 | { | ||
| 89 | if ("wixPdb" != reader.LocalName) | ||
| 90 | { | ||
| 91 | throw new XmlException(); | ||
| 92 | } | ||
| 93 | |||
| 94 | bool empty = reader.IsEmptyElement; | ||
| 95 | Pdb pdb = new Pdb(); | ||
| 96 | Version version = null; | ||
| 97 | |||
| 98 | while (reader.MoveToNextAttribute()) | ||
| 99 | { | ||
| 100 | switch (reader.LocalName) | ||
| 101 | { | ||
| 102 | case "version": | ||
| 103 | version = new Version(reader.Value); | ||
| 104 | break; | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | if (!suppressVersionCheck && null != version && !Pdb.CurrentVersion.Equals(version)) | ||
| 109 | { | ||
| 110 | throw new WixException(WixDataErrors.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixPdb", version.ToString(), Pdb.CurrentVersion.ToString())); | ||
| 111 | } | ||
| 112 | |||
| 113 | // loop through the rest of the pdb building up the Output object | ||
| 114 | if (!empty) | ||
| 115 | { | ||
| 116 | bool done = false; | ||
| 117 | |||
| 118 | // loop through all the fields in a row | ||
| 119 | while (!done && reader.Read()) | ||
| 120 | { | ||
| 121 | switch (reader.NodeType) | ||
| 122 | { | ||
| 123 | case XmlNodeType.Element: | ||
| 124 | switch (reader.LocalName) | ||
| 125 | { | ||
| 126 | case "wixOutput": | ||
| 127 | pdb.Output = Output.Read(reader, suppressVersionCheck); | ||
| 128 | break; | ||
| 129 | default: | ||
| 130 | throw new XmlException(); | ||
| 131 | } | ||
| 132 | break; | ||
| 133 | case XmlNodeType.EndElement: | ||
| 134 | done = true; | ||
| 135 | break; | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | if (!done) | ||
| 140 | { | ||
| 141 | throw new XmlException(); | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | return pdb; | ||
| 146 | } | ||
| 147 | |||
| 148 | /// <summary> | ||
| 149 | /// Persists a pdb in an XML format. | ||
| 150 | /// </summary> | ||
| 151 | /// <param name="writer">XmlWriter where the Pdb should persist itself as XML.</param> | ||
| 152 | internal void Write(XmlWriter writer) | ||
| 153 | { | ||
| 154 | writer.WriteStartElement("wixPdb", XmlNamespaceUri); | ||
| 155 | |||
| 156 | writer.WriteAttributeString("version", Pdb.CurrentVersion.ToString()); | ||
| 157 | |||
| 158 | this.Output.Write(writer); | ||
| 159 | |||
| 160 | writer.WriteEndElement(); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | } | ||
