aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Data/WindowsInstaller/Output.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/WixToolset.Data/WindowsInstaller/Output.cs56
1 files changed, 22 insertions, 34 deletions
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 }