diff options
| author | Rob Mensching <rob@firegiant.com> | 2019-10-25 00:23:42 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2019-10-25 00:25:53 -0700 |
| commit | 6c1ae2593faab59e1a01c96794e0835a6fcd0626 (patch) | |
| tree | c15fcb9a1f1c5bec846ba61f1f3dcd9a152bf701 /src/WixToolset.Data/WindowsInstaller | |
| parent | 0078364515ba1f7570f43d47e43bd359918cafd0 (diff) | |
| download | wix-6c1ae2593faab59e1a01c96794e0835a6fcd0626.tar.gz wix-6c1ae2593faab59e1a01c96794e0835a6fcd0626.tar.bz2 wix-6c1ae2593faab59e1a01c96794e0835a6fcd0626.zip | |
Implement WixOutput with support for multiple streams of data
Diffstat (limited to 'src/WixToolset.Data/WindowsInstaller')
| -rw-r--r-- | src/WixToolset.Data/WindowsInstaller/Field.cs | 4 | ||||
| -rw-r--r-- | src/WixToolset.Data/WindowsInstaller/ObjectField.cs | 2 | ||||
| -rw-r--r-- | src/WixToolset.Data/WindowsInstaller/Output.cs | 56 | ||||
| -rw-r--r-- | src/WixToolset.Data/WindowsInstaller/Pdb.cs | 155 | ||||
| -rw-r--r-- | src/WixToolset.Data/WindowsInstaller/Row.cs | 2 | ||||
| -rw-r--r-- | src/WixToolset.Data/WindowsInstaller/Table.cs | 2 | ||||
| -rw-r--r-- | src/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs | 2 |
7 files changed, 28 insertions, 195 deletions
diff --git a/src/WixToolset.Data/WindowsInstaller/Field.cs b/src/WixToolset.Data/WindowsInstaller/Field.cs index aa359c64..ac8df9a4 100644 --- a/src/WixToolset.Data/WindowsInstaller/Field.cs +++ b/src/WixToolset.Data/WindowsInstaller/Field.cs | |||
| @@ -154,7 +154,7 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 154 | // be enhanced if that ever changes. | 154 | // be enhanced if that ever changes. |
| 155 | if (value is int || value.GetType().IsEnum) | 155 | if (value is int || value.GetType().IsEnum) |
| 156 | { | 156 | { |
| 157 | int intValue = (int)value; | 157 | var intValue = (int)value; |
| 158 | 158 | ||
| 159 | // validate the value against the minimum allowed value | 159 | // validate the value against the minimum allowed value |
| 160 | if (column.MinValue.HasValue && column.MinValue > intValue) | 160 | if (column.MinValue.HasValue && column.MinValue > intValue) |
| @@ -275,7 +275,7 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 275 | /// <param name="writer">XmlWriter where the Field should persist itself as XML.</param> | 275 | /// <param name="writer">XmlWriter where the Field should persist itself as XML.</param> |
| 276 | internal virtual void Write(XmlWriter writer) | 276 | internal virtual void Write(XmlWriter writer) |
| 277 | { | 277 | { |
| 278 | writer.WriteStartElement("field", Intermediate.XmlNamespaceUri); | 278 | writer.WriteStartElement("field", Output.XmlNamespaceUri); |
| 279 | 279 | ||
| 280 | if (this.Modified) | 280 | if (this.Modified) |
| 281 | { | 281 | { |
diff --git a/src/WixToolset.Data/WindowsInstaller/ObjectField.cs b/src/WixToolset.Data/WindowsInstaller/ObjectField.cs index 016693f5..4e654dde 100644 --- a/src/WixToolset.Data/WindowsInstaller/ObjectField.cs +++ b/src/WixToolset.Data/WindowsInstaller/ObjectField.cs | |||
| @@ -130,7 +130,7 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 130 | /// <param name="writer">XmlWriter where the Field should persist itself as XML.</param> | 130 | /// <param name="writer">XmlWriter where the Field should persist itself as XML.</param> |
| 131 | internal override void Write(XmlWriter writer) | 131 | internal override void Write(XmlWriter writer) |
| 132 | { | 132 | { |
| 133 | writer.WriteStartElement("field", Intermediate.XmlNamespaceUri); | 133 | writer.WriteStartElement("field", Output.XmlNamespaceUri); |
| 134 | 134 | ||
| 135 | if (this.EmbeddedFileIndex.HasValue) | 135 | if (this.EmbeddedFileIndex.HasValue) |
| 136 | { | 136 | { |
diff --git a/src/WixToolset.Data/WindowsInstaller/Output.cs b/src/WixToolset.Data/WindowsInstaller/Output.cs index 7f2990f4..ee46c159 100644 --- a/src/WixToolset.Data/WindowsInstaller/Output.cs +++ b/src/WixToolset.Data/WindowsInstaller/Output.cs | |||
| @@ -5,7 +5,6 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 5 | using System; | 5 | using System; |
| 6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
| 7 | using System.Globalization; | 7 | using System.Globalization; |
| 8 | using System.IO; | ||
| 9 | using System.Linq; | 8 | using System.Linq; |
| 10 | using System.Xml; | 9 | using System.Xml; |
| 11 | 10 | ||
| @@ -16,6 +15,7 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 16 | { | 15 | { |
| 17 | public const string XmlNamespaceUri = "http://wixtoolset.org/schemas/v4/wixout"; | 16 | public const string XmlNamespaceUri = "http://wixtoolset.org/schemas/v4/wixout"; |
| 18 | private static readonly Version CurrentVersion = new Version("4.0.0.0"); | 17 | private static readonly Version CurrentVersion = new Version("4.0.0.0"); |
| 18 | private const string WixOutputStreamName = "wix-wi.xml"; | ||
| 19 | 19 | ||
| 20 | /// <summary> | 20 | /// <summary> |
| 21 | /// Creates a new empty output object. | 21 | /// Creates a new empty output object. |
| @@ -66,41 +66,29 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 66 | /// <returns>Output object.</returns> | 66 | /// <returns>Output object.</returns> |
| 67 | public static Output Load(string path, bool suppressVersionCheck) | 67 | public static Output Load(string path, bool suppressVersionCheck) |
| 68 | { | 68 | { |
| 69 | using (FileStream stream = File.OpenRead(path)) | 69 | using (var wixout = WixOutput.Read(path)) |
| 70 | using (FileStructure fs = FileStructure.Read(stream)) | 70 | using (var stream = wixout.GetDataStream(WixOutputStreamName)) |
| 71 | using (var reader = XmlReader.Create(stream, null, wixout.Uri.AbsoluteUri)) | ||
| 71 | { | 72 | { |
| 72 | if (FileFormat.Wixout != fs.FileFormat) | 73 | try |
| 73 | { | 74 | { |
| 74 | throw new WixUnexpectedFileFormatException(path, FileFormat.Wixout, fs.FileFormat); | 75 | reader.MoveToContent(); |
| 76 | return Output.Read(reader, suppressVersionCheck); | ||
| 75 | } | 77 | } |
| 76 | 78 | catch (XmlException xe) | |
| 77 | Uri uri = new Uri(Path.GetFullPath(path)); | ||
| 78 | using (XmlReader reader = XmlReader.Create(fs.GetDataStream(), null, uri.AbsoluteUri)) | ||
| 79 | { | 79 | { |
| 80 | try | 80 | throw new WixCorruptFileException(path, "wixout", xe); |
| 81 | { | ||
| 82 | reader.MoveToContent(); | ||
| 83 | return Output.Read(reader, suppressVersionCheck); | ||
| 84 | } | ||
| 85 | catch (XmlException xe) | ||
| 86 | { | ||
| 87 | throw new WixCorruptFileException(path, fs.FileFormat, xe); | ||
| 88 | } | ||
| 89 | } | 81 | } |
| 90 | } | 82 | } |
| 91 | } | 83 | } |
| 92 | 84 | ||
| 93 | /// <summary> | 85 | /// <summary> |
| 94 | /// Saves an output to a path on disk. | 86 | /// Saves an output to a <c>WixOutput</c> container. |
| 95 | /// </summary> | 87 | /// </summary> |
| 96 | /// <param name="path">Path to save output file to on disk.</param> | 88 | /// <param name="wixout">Container to save to.</param> |
| 97 | public void Save(string path) | 89 | public void Save(WixOutput wixout) |
| 98 | { | 90 | { |
| 99 | Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))); | 91 | using (var writer = XmlWriter.Create(wixout.CreateDataStream(WixOutputStreamName))) |
| 100 | |||
| 101 | using (FileStream stream = File.Create(path)) | ||
| 102 | using (FileStructure fs = FileStructure.Create(stream, FileFormat.Wixout, null)) | ||
| 103 | using (XmlWriter writer = XmlWriter.Create(fs.GetDataStream())) | ||
| 104 | { | 92 | { |
| 105 | writer.WriteStartDocument(); | 93 | writer.WriteStartDocument(); |
| 106 | this.Write(writer); | 94 | this.Write(writer); |
| @@ -121,8 +109,8 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 121 | throw new XmlException(); | 109 | throw new XmlException(); |
| 122 | } | 110 | } |
| 123 | 111 | ||
| 124 | bool empty = reader.IsEmptyElement; | 112 | var empty = reader.IsEmptyElement; |
| 125 | Output output = new Output(SourceLineNumber.CreateFromUri(reader.BaseURI)); | 113 | var output = new Output(SourceLineNumber.CreateFromUri(reader.BaseURI)); |
| 126 | Version version = null; | 114 | Version version = null; |
| 127 | 115 | ||
| 128 | while (reader.MoveToNextAttribute()) | 116 | while (reader.MoveToNextAttribute()) |
| @@ -170,10 +158,10 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 170 | 158 | ||
| 171 | // loop through the rest of the xml building up the Output object | 159 | // loop through the rest of the xml building up the Output object |
| 172 | TableDefinitionCollection tableDefinitions = null; | 160 | TableDefinitionCollection tableDefinitions = null; |
| 173 | List<Table> tables = new List<Table>(); | 161 | var tables = new List<Table>(); |
| 174 | if (!empty) | 162 | if (!empty) |
| 175 | { | 163 | { |
| 176 | bool done = false; | 164 | var done = false; |
| 177 | 165 | ||
| 178 | // loop through all the fields in a row | 166 | // loop through all the fields in a row |
| 179 | while (!done && reader.Read()) | 167 | while (!done && reader.Read()) |
| @@ -224,7 +212,7 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 224 | /// <returns>The table in this output.</returns> | 212 | /// <returns>The table in this output.</returns> |
| 225 | public Table EnsureTable(TableDefinition tableDefinition) | 213 | public Table EnsureTable(TableDefinition tableDefinition) |
| 226 | { | 214 | { |
| 227 | if (!this.Tables.TryGetTable(tableDefinition.Name, out Table table)) | 215 | if (!this.Tables.TryGetTable(tableDefinition.Name, out var table)) |
| 228 | { | 216 | { |
| 229 | table = new Table(tableDefinition); | 217 | table = new Table(tableDefinition); |
| 230 | this.Tables.Add(table); | 218 | this.Tables.Add(table); |
| @@ -251,19 +239,19 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 251 | writer.WriteAttributeString("version", Output.CurrentVersion.ToString()); | 239 | writer.WriteAttributeString("version", Output.CurrentVersion.ToString()); |
| 252 | 240 | ||
| 253 | // Collect all the table definitions and write them. | 241 | // Collect all the table definitions and write them. |
| 254 | TableDefinitionCollection tableDefinitions = new TableDefinitionCollection(); | 242 | var tableDefinitions = new TableDefinitionCollection(); |
| 255 | foreach (Table table in this.Tables) | 243 | foreach (var table in this.Tables) |
| 256 | { | 244 | { |
| 257 | tableDefinitions.Add(table.Definition); | 245 | tableDefinitions.Add(table.Definition); |
| 258 | } | 246 | } |
| 259 | tableDefinitions.Write(writer); | 247 | tableDefinitions.Write(writer); |
| 260 | 248 | ||
| 261 | foreach (Table table in this.Tables.OrderBy(t => t.Name)) | 249 | foreach (var table in this.Tables.OrderBy(t => t.Name)) |
| 262 | { | 250 | { |
| 263 | table.Write(writer); | 251 | table.Write(writer); |
| 264 | } | 252 | } |
| 265 | 253 | ||
| 266 | foreach (SubStorage subStorage in this.SubStorages) | 254 | foreach (var subStorage in this.SubStorages) |
| 267 | { | 255 | { |
| 268 | subStorage.Write(writer); | 256 | subStorage.Write(writer); |
| 269 | } | 257 | } |
diff --git a/src/WixToolset.Data/WindowsInstaller/Pdb.cs b/src/WixToolset.Data/WindowsInstaller/Pdb.cs deleted file mode 100644 index 574d5593..00000000 --- a/src/WixToolset.Data/WindowsInstaller/Pdb.cs +++ /dev/null | |||
| @@ -1,155 +0,0 @@ | |||
| 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.WindowsInstaller | ||
| 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 | /// Gets or sets the output that is a part of this pdb. | ||
| 19 | /// </summary> | ||
| 20 | /// <value>Type of the output.</value> | ||
| 21 | public Output Output { get; set; } | ||
| 22 | |||
| 23 | /// <summary> | ||
| 24 | /// Loads a pdb from a path on disk. | ||
| 25 | /// </summary> | ||
| 26 | /// <param name="path">Path to pdb file saved on disk.</param> | ||
| 27 | /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> | ||
| 28 | /// <returns>Pdb pdb.</returns> | ||
| 29 | public static Pdb Load(string path, bool suppressVersionCheck) | ||
| 30 | { | ||
| 31 | using (FileStream stream = File.OpenRead(path)) | ||
| 32 | using (FileStructure fs = FileStructure.Read(stream)) | ||
| 33 | { | ||
| 34 | if (FileFormat.Wixpdb != fs.FileFormat) | ||
| 35 | { | ||
| 36 | throw new WixUnexpectedFileFormatException(path, FileFormat.Wixpdb, fs.FileFormat); | ||
| 37 | } | ||
| 38 | |||
| 39 | Uri uri = new Uri(Path.GetFullPath(path)); | ||
| 40 | using (XmlReader reader = XmlReader.Create(fs.GetDataStream(), null, uri.AbsoluteUri)) | ||
| 41 | { | ||
| 42 | try | ||
| 43 | { | ||
| 44 | reader.MoveToContent(); | ||
| 45 | return Pdb.Read(reader, suppressVersionCheck); | ||
| 46 | } | ||
| 47 | catch (XmlException xe) | ||
| 48 | { | ||
| 49 | throw new WixCorruptFileException(path, fs.FileFormat, xe); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | /// <summary> | ||
| 56 | /// Saves a pdb to a path on disk. | ||
| 57 | /// </summary> | ||
| 58 | /// <param name="path">Path to save pdb file to on disk.</param> | ||
| 59 | public void Save(string path) | ||
| 60 | { | ||
| 61 | Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))); | ||
| 62 | |||
| 63 | using (FileStream stream = File.Create(path)) | ||
| 64 | using (FileStructure fs = FileStructure.Create(stream, FileFormat.Wixpdb, null)) | ||
| 65 | using (XmlWriter writer = XmlWriter.Create(fs.GetDataStream())) | ||
| 66 | { | ||
| 67 | writer.WriteStartDocument(); | ||
| 68 | this.Write(writer); | ||
| 69 | writer.WriteEndDocument(); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | /// <summary> | ||
| 74 | /// Processes an XmlReader and builds up the pdb object. | ||
| 75 | /// </summary> | ||
| 76 | /// <param name="reader">Reader to get data from.</param> | ||
| 77 | /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> | ||
| 78 | /// <returns>The Pdb represented by the Xml.</returns> | ||
| 79 | internal static Pdb Read(XmlReader reader, bool suppressVersionCheck) | ||
| 80 | { | ||
| 81 | if ("wixPdb" != reader.LocalName) | ||
| 82 | { | ||
| 83 | throw new XmlException(); | ||
| 84 | } | ||
| 85 | |||
| 86 | bool empty = reader.IsEmptyElement; | ||
| 87 | Pdb pdb = new Pdb(); | ||
| 88 | Version version = null; | ||
| 89 | |||
| 90 | while (reader.MoveToNextAttribute()) | ||
| 91 | { | ||
| 92 | switch (reader.LocalName) | ||
| 93 | { | ||
| 94 | case "version": | ||
| 95 | version = new Version(reader.Value); | ||
| 96 | break; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | if (!suppressVersionCheck && null != version && !Pdb.CurrentVersion.Equals(version)) | ||
| 101 | { | ||
| 102 | throw new WixException(ErrorMessages.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixPdb", version.ToString(), Pdb.CurrentVersion.ToString())); | ||
| 103 | } | ||
| 104 | |||
| 105 | // loop through the rest of the pdb building up the Output object | ||
| 106 | if (!empty) | ||
| 107 | { | ||
| 108 | bool done = false; | ||
| 109 | |||
| 110 | // loop through all the fields in a row | ||
| 111 | while (!done && reader.Read()) | ||
| 112 | { | ||
| 113 | switch (reader.NodeType) | ||
| 114 | { | ||
| 115 | case XmlNodeType.Element: | ||
| 116 | switch (reader.LocalName) | ||
| 117 | { | ||
| 118 | case "wixOutput": | ||
| 119 | pdb.Output = Output.Read(reader, suppressVersionCheck); | ||
| 120 | break; | ||
| 121 | default: | ||
| 122 | throw new XmlException(); | ||
| 123 | } | ||
| 124 | break; | ||
| 125 | case XmlNodeType.EndElement: | ||
| 126 | done = true; | ||
| 127 | break; | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | if (!done) | ||
| 132 | { | ||
| 133 | throw new XmlException(); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | return pdb; | ||
| 138 | } | ||
| 139 | |||
| 140 | /// <summary> | ||
| 141 | /// Persists a pdb in an XML format. | ||
| 142 | /// </summary> | ||
| 143 | /// <param name="writer">XmlWriter where the Pdb should persist itself as XML.</param> | ||
| 144 | internal void Write(XmlWriter writer) | ||
| 145 | { | ||
| 146 | writer.WriteStartElement("wixPdb", XmlNamespaceUri); | ||
| 147 | |||
| 148 | writer.WriteAttributeString("version", Pdb.CurrentVersion.ToString()); | ||
| 149 | |||
| 150 | this.Output.Write(writer); | ||
| 151 | |||
| 152 | writer.WriteEndElement(); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | } | ||
diff --git a/src/WixToolset.Data/WindowsInstaller/Row.cs b/src/WixToolset.Data/WindowsInstaller/Row.cs index af1af628..a267f04b 100644 --- a/src/WixToolset.Data/WindowsInstaller/Row.cs +++ b/src/WixToolset.Data/WindowsInstaller/Row.cs | |||
| @@ -354,7 +354,7 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 354 | /// <param name="writer">XmlWriter where the Row should persist itself as XML.</param> | 354 | /// <param name="writer">XmlWriter where the Row should persist itself as XML.</param> |
| 355 | internal void Write(XmlWriter writer) | 355 | internal void Write(XmlWriter writer) |
| 356 | { | 356 | { |
| 357 | writer.WriteStartElement("row", Intermediate.XmlNamespaceUri); | 357 | writer.WriteStartElement("row", Output.XmlNamespaceUri); |
| 358 | 358 | ||
| 359 | if (RowOperation.None != this.Operation) | 359 | if (RowOperation.None != this.Operation) |
| 360 | { | 360 | { |
diff --git a/src/WixToolset.Data/WindowsInstaller/Table.cs b/src/WixToolset.Data/WindowsInstaller/Table.cs index acb4b6fe..c7f2c8f2 100644 --- a/src/WixToolset.Data/WindowsInstaller/Table.cs +++ b/src/WixToolset.Data/WindowsInstaller/Table.cs | |||
| @@ -291,7 +291,7 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 291 | throw new ArgumentNullException("writer"); | 291 | throw new ArgumentNullException("writer"); |
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | writer.WriteStartElement("table", Intermediate.XmlNamespaceUri); | 294 | writer.WriteStartElement("table", Output.XmlNamespaceUri); |
| 295 | writer.WriteAttributeString("name", this.Name); | 295 | writer.WriteAttributeString("name", this.Name); |
| 296 | 296 | ||
| 297 | if (TableOperation.None != this.Operation) | 297 | if (TableOperation.None != this.Operation) |
diff --git a/src/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs b/src/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs index 619a5206..80303913 100644 --- a/src/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs +++ b/src/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs | |||
| @@ -227,7 +227,7 @@ namespace WixToolset.Data.WindowsInstaller | |||
| 227 | { | 227 | { |
| 228 | writer.WriteStartElement("tableDefinitions", XmlNamespaceUri); | 228 | writer.WriteStartElement("tableDefinitions", XmlNamespaceUri); |
| 229 | 229 | ||
| 230 | foreach (TableDefinition tableDefinition in this.collection.Values.OrderBy(t => t.Name)) | 230 | foreach (var tableDefinition in this.collection.Values.OrderBy(t => t.Name)) |
| 231 | { | 231 | { |
| 232 | tableDefinition.Write(writer); | 232 | tableDefinition.Write(writer); |
| 233 | } | 233 | } |
