/// <summary> /// Loads an output from a path on disk. /// </summary> /// <param name="path">Path to output file saved on disk.</param> /// <param name="tableDefinitions">Table definitions to use for creating strongly-typed rows.</param> /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> /// <returns>Output object.</returns> public static WindowsInstallerData Load(string path, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck = false) { using (var wixOutput = WixOutput.Read(path)) { return(WindowsInstallerData.Load(wixOutput, tableDefinitions, suppressVersionCheck)); } }
/// <summary> /// Creates a SubStorage from the XmlReader. /// </summary> /// <param name="reader">Reader to get data from.</param> /// <param name="tableDefinitions">Table definitions to use for strongly-typed rows.</param> /// <returns>New SubStorage object.</returns> internal static SubStorage Read(XmlReader reader, TableDefinitionCollection tableDefinitions) { if (reader.LocalName != "subStorage") { throw new XmlException(); } WindowsInstallerData data = null; string name = null; var empty = reader.IsEmptyElement; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "name": name = reader.Value; break; } } if (!empty) { var done = false; while (!done && reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.LocalName) { case WindowsInstallerData.XmlElementName: data = WindowsInstallerData.Read(reader, tableDefinitions, true); break; default: throw new XmlException(); } break; case XmlNodeType.EndElement: done = true; break; } } if (!done) { throw new XmlException(); } } return(new SubStorage(name, data)); }
/// <summary> /// Loads an output from a WixOutput object. /// </summary> /// <param name="wixOutput">WixOutput object.</param> /// <param name="tableDefinitions">Table definitions to use for creating strongly-typed rows.</param> /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> /// <returns>Output object.</returns> public static WindowsInstallerData Load(WixOutput wixOutput, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck = false) { using (var stream = wixOutput.GetDataStream(WixOutputStreamName)) using (var reader = XmlReader.Create(stream, null, wixOutput.Uri.AbsoluteUri)) { try { reader.MoveToContent(); return(WindowsInstallerData.Read(reader, tableDefinitions, suppressVersionCheck)); } catch (XmlException xe) { throw new WixCorruptFileException(wixOutput.Uri.AbsoluteUri, "wixout", xe); } } }
public void CanSaveAndLoadWindowsInstallerData() { var sln = new SourceLineNumber("test.wxs", 1); var windowsInstallerData = new Wid.WindowsInstallerData(sln) { Type = OutputType.Product, }; var fileTable = windowsInstallerData.EnsureTable(Wid.WindowsInstallerTableDefinitions.File); var fileRow = (FileRow)fileTable.CreateRow(sln); fileRow.File = "TestFile"; var path = Path.GetTempFileName(); try { using (var wixout = WixOutput.Create(path)) { windowsInstallerData.Save(wixout); } var loaded = Wid.WindowsInstallerData.Load(path); var loadedTable = Assert.Single(loaded.Tables); Assert.Equal(Wid.WindowsInstallerTableDefinitions.File.Name, loadedTable.Name); var loadedRow = Assert.Single(loadedTable.Rows); var loadedFileRow = Assert.IsType <FileRow>(loadedRow); Assert.Equal("TestFile", loadedFileRow.File); } finally { File.Delete(path); } }
/// <summary> /// Instantiate a new substorage. /// </summary> /// <param name="name">The substorage name.</param> /// <param name="data">The substorage data.</param> public SubStorage(string name, WindowsInstallerData data) { this.Name = name; this.Data = data; }
/// <summary> /// Processes an XmlReader and builds up the output object. /// </summary> /// <param name="reader">Reader to get data from.</param> /// <param name="tableDefinitions">Table definitions to use for creating strongly-typed rows.</param> /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> /// <returns>The Output represented by the Xml.</returns> internal static WindowsInstallerData Read(XmlReader reader, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck) { if (!reader.LocalName.Equals(WindowsInstallerData.XmlElementName)) { throw new XmlException(); } var empty = reader.IsEmptyElement; var output = new WindowsInstallerData(SourceLineNumber.CreateFromUri(reader.BaseURI)); Version version = null; while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "codepage": output.Codepage = Convert.ToInt32(reader.Value, CultureInfo.InvariantCulture.NumberFormat); break; case "type": switch (reader.Value) { case "Bundle": output.Type = OutputType.Bundle; break; case "Module": output.Type = OutputType.Module; break; case "Patch": output.Type = OutputType.Patch; break; case "PatchCreation": output.Type = OutputType.PatchCreation; break; case "Product": output.Type = OutputType.Product; break; case "Transform": output.Type = OutputType.Transform; break; default: throw new XmlException(); } break; case "version": version = new Version(reader.Value); break; } } if (!suppressVersionCheck && null != version && !WindowsInstallerData.CurrentVersion.Equals(version)) { throw new WixException(ErrorMessages.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), WindowsInstallerData.XmlElementName, version.ToString(), WindowsInstallerData.CurrentVersion.ToString())); } // loop through the rest of the xml building up the Output object TableDefinitionCollection xmlTableDefinitions = null; var tables = new List <Table>(); if (!empty) { var done = false; // loop through all the fields in a row while (!done && reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.LocalName) { case "subStorage": output.SubStorages.Add(SubStorage.Read(reader, tableDefinitions)); break; case "table": if (null == xmlTableDefinitions) { throw new XmlException(); } tables.Add(Table.Read(reader, xmlTableDefinitions)); break; case "tableDefinitions": xmlTableDefinitions = TableDefinitionCollection.Read(reader, tableDefinitions); break; default: throw new XmlException(); } break; case XmlNodeType.EndElement: done = true; break; } } if (!done) { throw new XmlException(); } } output.Tables = new TableIndexedCollection(tables); return(output); }
/// <summary> /// Loads an output from a WixOutput object. /// </summary> /// <param name="wixOutput">WixOutput object.</param> /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param> /// <returns>Output object.</returns> public static WindowsInstallerData Load(WixOutput wixOutput, bool suppressVersionCheck = false) { var tableDefinitions = new TableDefinitionCollection(WindowsInstallerTableDefinitions.All); return(WindowsInstallerData.Load(wixOutput, tableDefinitions, suppressVersionCheck)); }