From 6c1ae2593faab59e1a01c96794e0835a6fcd0626 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 25 Oct 2019 00:23:42 -0700 Subject: Implement WixOutput with support for multiple streams of data --- src/WixToolset.Data/WindowsInstaller/Field.cs | 4 +- .../WindowsInstaller/ObjectField.cs | 2 +- src/WixToolset.Data/WindowsInstaller/Output.cs | 56 +++----- src/WixToolset.Data/WindowsInstaller/Pdb.cs | 155 --------------------- src/WixToolset.Data/WindowsInstaller/Row.cs | 2 +- src/WixToolset.Data/WindowsInstaller/Table.cs | 2 +- .../WindowsInstaller/TableDefinitionCollection.cs | 2 +- 7 files changed, 28 insertions(+), 195 deletions(-) delete mode 100644 src/WixToolset.Data/WindowsInstaller/Pdb.cs (limited to 'src/WixToolset.Data/WindowsInstaller') 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 // be enhanced if that ever changes. if (value is int || value.GetType().IsEnum) { - int intValue = (int)value; + var intValue = (int)value; // validate the value against the minimum allowed value if (column.MinValue.HasValue && column.MinValue > intValue) @@ -275,7 +275,7 @@ namespace WixToolset.Data.WindowsInstaller /// XmlWriter where the Field should persist itself as XML. internal virtual void Write(XmlWriter writer) { - writer.WriteStartElement("field", Intermediate.XmlNamespaceUri); + writer.WriteStartElement("field", Output.XmlNamespaceUri); if (this.Modified) { 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 /// XmlWriter where the Field should persist itself as XML. internal override void Write(XmlWriter writer) { - writer.WriteStartElement("field", Intermediate.XmlNamespaceUri); + writer.WriteStartElement("field", Output.XmlNamespaceUri); if (this.EmbeddedFileIndex.HasValue) { 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 using System; using System.Collections.Generic; using System.Globalization; - using System.IO; using System.Linq; using System.Xml; @@ -16,6 +15,7 @@ namespace WixToolset.Data.WindowsInstaller { public const string XmlNamespaceUri = "http://wixtoolset.org/schemas/v4/wixout"; private static readonly Version CurrentVersion = new Version("4.0.0.0"); + private const string WixOutputStreamName = "wix-wi.xml"; /// /// Creates a new empty output object. @@ -66,41 +66,29 @@ namespace WixToolset.Data.WindowsInstaller /// Output object. public static Output Load(string path, bool suppressVersionCheck) { - using (FileStream stream = File.OpenRead(path)) - using (FileStructure fs = FileStructure.Read(stream)) + using (var wixout = WixOutput.Read(path)) + using (var stream = wixout.GetDataStream(WixOutputStreamName)) + using (var reader = XmlReader.Create(stream, null, wixout.Uri.AbsoluteUri)) { - if (FileFormat.Wixout != fs.FileFormat) + try { - throw new WixUnexpectedFileFormatException(path, FileFormat.Wixout, fs.FileFormat); + reader.MoveToContent(); + return Output.Read(reader, suppressVersionCheck); } - - Uri uri = new Uri(Path.GetFullPath(path)); - using (XmlReader reader = XmlReader.Create(fs.GetDataStream(), null, uri.AbsoluteUri)) + catch (XmlException xe) { - try - { - reader.MoveToContent(); - return Output.Read(reader, suppressVersionCheck); - } - catch (XmlException xe) - { - throw new WixCorruptFileException(path, fs.FileFormat, xe); - } + throw new WixCorruptFileException(path, "wixout", xe); } } } /// - /// Saves an output to a path on disk. + /// Saves an output to a WixOutput container. /// - /// Path to save output file to on disk. - public void Save(string path) + /// Container to save to. + public void Save(WixOutput wixout) { - Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))); - - using (FileStream stream = File.Create(path)) - using (FileStructure fs = FileStructure.Create(stream, FileFormat.Wixout, null)) - using (XmlWriter writer = XmlWriter.Create(fs.GetDataStream())) + using (var writer = XmlWriter.Create(wixout.CreateDataStream(WixOutputStreamName))) { writer.WriteStartDocument(); this.Write(writer); @@ -121,8 +109,8 @@ namespace WixToolset.Data.WindowsInstaller throw new XmlException(); } - bool empty = reader.IsEmptyElement; - Output output = new Output(SourceLineNumber.CreateFromUri(reader.BaseURI)); + var empty = reader.IsEmptyElement; + var output = new Output(SourceLineNumber.CreateFromUri(reader.BaseURI)); Version version = null; while (reader.MoveToNextAttribute()) @@ -170,10 +158,10 @@ namespace WixToolset.Data.WindowsInstaller // loop through the rest of the xml building up the Output object TableDefinitionCollection tableDefinitions = null; - List tables = new List
(); + var tables = new List
(); if (!empty) { - bool done = false; + var done = false; // loop through all the fields in a row while (!done && reader.Read()) @@ -224,7 +212,7 @@ namespace WixToolset.Data.WindowsInstaller /// The table in this output. public Table EnsureTable(TableDefinition tableDefinition) { - if (!this.Tables.TryGetTable(tableDefinition.Name, out Table table)) + if (!this.Tables.TryGetTable(tableDefinition.Name, out var table)) { table = new Table(tableDefinition); this.Tables.Add(table); @@ -251,19 +239,19 @@ namespace WixToolset.Data.WindowsInstaller writer.WriteAttributeString("version", Output.CurrentVersion.ToString()); // Collect all the table definitions and write them. - TableDefinitionCollection tableDefinitions = new TableDefinitionCollection(); - foreach (Table table in this.Tables) + var tableDefinitions = new TableDefinitionCollection(); + foreach (var table in this.Tables) { tableDefinitions.Add(table.Definition); } tableDefinitions.Write(writer); - foreach (Table table in this.Tables.OrderBy(t => t.Name)) + foreach (var table in this.Tables.OrderBy(t => t.Name)) { table.Write(writer); } - foreach (SubStorage subStorage in this.SubStorages) + foreach (var subStorage in this.SubStorages) { subStorage.Write(writer); } 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 @@ -// 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. - -namespace WixToolset.Data.WindowsInstaller -{ - using System; - using System.IO; - using System.Xml; - - /// - /// Pdb generated by the binder. - /// - public sealed class Pdb - { - public const string XmlNamespaceUri = "http://wixtoolset.org/schemas/v4/wixpdb"; - private static readonly Version CurrentVersion = new Version("4.0.0.0"); - - /// - /// Gets or sets the output that is a part of this pdb. - /// - /// Type of the output. - public Output Output { get; set; } - - /// - /// Loads a pdb from a path on disk. - /// - /// Path to pdb file saved on disk. - /// Suppresses wix.dll version mismatch check. - /// Pdb pdb. - 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); - } - } - } - } - - /// - /// Saves a pdb to a path on disk. - /// - /// Path to save pdb file to on disk. - public void Save(string path) - { - Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))); - - using (FileStream stream = File.Create(path)) - using (FileStructure fs = FileStructure.Create(stream, FileFormat.Wixpdb, null)) - using (XmlWriter writer = XmlWriter.Create(fs.GetDataStream())) - { - writer.WriteStartDocument(); - this.Write(writer); - writer.WriteEndDocument(); - } - } - - /// - /// Processes an XmlReader and builds up the pdb object. - /// - /// Reader to get data from. - /// Suppresses wix.dll version mismatch check. - /// The Pdb represented by the Xml. - 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(ErrorMessages.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; - } - - /// - /// Persists a pdb in an XML format. - /// - /// XmlWriter where the Pdb should persist itself as XML. - internal void Write(XmlWriter writer) - { - writer.WriteStartElement("wixPdb", XmlNamespaceUri); - - writer.WriteAttributeString("version", Pdb.CurrentVersion.ToString()); - - this.Output.Write(writer); - - writer.WriteEndElement(); - } - } -} 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 /// XmlWriter where the Row should persist itself as XML. internal void Write(XmlWriter writer) { - writer.WriteStartElement("row", Intermediate.XmlNamespaceUri); + writer.WriteStartElement("row", Output.XmlNamespaceUri); if (RowOperation.None != this.Operation) { 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 throw new ArgumentNullException("writer"); } - writer.WriteStartElement("table", Intermediate.XmlNamespaceUri); + writer.WriteStartElement("table", Output.XmlNamespaceUri); writer.WriteAttributeString("name", this.Name); 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 { writer.WriteStartElement("tableDefinitions", XmlNamespaceUri); - foreach (TableDefinition tableDefinition in this.collection.Values.OrderBy(t => t.Name)) + foreach (var tableDefinition in this.collection.Values.OrderBy(t => t.Name)) { tableDefinition.Write(writer); } -- cgit v1.2.3-55-g6feb