aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Arnson <bob@firegiant.com>2024-09-21 22:52:22 -0400
committerRob Mensching <rob@firegiant.com>2024-10-04 13:31:17 -0700
commit6879c941119532d0ec7bf9f5c05faa2231553b57 (patch)
tree36a635a64a687bea335a36cc69a5e31d69ee1ed6
parent72085cbf1e359428457f82f84c2e19ed37b10aec (diff)
downloadwix-6879c941119532d0ec7bf9f5c05faa2231553b57.tar.gz
wix-6879c941119532d0ec7bf9f5c05faa2231553b57.tar.bz2
wix-6879c941119532d0ec7bf9f5c05faa2231553b57.zip
Add overloads to support create-only Wixouts.
This prevents the .NET ZipArchive (and friends) from keeping the whole thing in memory, to support updating when we don't need to update the Wixout when building a binary Wixlib.
-rw-r--r--src/api/wix/WixToolset.Data/Intermediate.cs14
-rw-r--r--src/api/wix/WixToolset.Data/WixOutput.cs32
-rw-r--r--src/wix/WixToolset.Core/CommandLine/BuildCommand.cs2
3 files changed, 44 insertions, 4 deletions
diff --git a/src/api/wix/WixToolset.Data/Intermediate.cs b/src/api/wix/WixToolset.Data/Intermediate.cs
index 64f9810d..ad4e49f9 100644
--- a/src/api/wix/WixToolset.Data/Intermediate.cs
+++ b/src/api/wix/WixToolset.Data/Intermediate.cs
@@ -245,6 +245,20 @@ namespace WixToolset.Data
245 } 245 }
246 246
247 /// <summary> 247 /// <summary>
248 /// Saves an intermediate that can only be written to to a path on disk.
249 /// </summary>
250 /// <param name="path">Path to save intermediate file to disk.</param>
251 public void SaveNew(string path)
252 {
253 Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path)));
254
255 using (var wixout = WixOutput.CreateNew(path))
256 {
257 this.Save(wixout);
258 }
259 }
260
261 /// <summary>
248 /// Saves an intermediate to a WixOutput. 262 /// Saves an intermediate to a WixOutput.
249 /// </summary> 263 /// </summary>
250 /// <param name="wixout">Destination to save.</param> 264 /// <param name="wixout">Destination to save.</param>
diff --git a/src/api/wix/WixToolset.Data/WixOutput.cs b/src/api/wix/WixToolset.Data/WixOutput.cs
index 43359f24..72b922c9 100644
--- a/src/api/wix/WixToolset.Data/WixOutput.cs
+++ b/src/api/wix/WixToolset.Data/WixOutput.cs
@@ -25,7 +25,7 @@ namespace WixToolset.Data
25 } 25 }
26 26
27 /// <summary> 27 /// <summary>
28 /// 28 ///
29 /// </summary> 29 /// </summary>
30 public Uri Uri { get; } 30 public Uri Uri { get; }
31 31
@@ -189,7 +189,10 @@ namespace WixToolset.Data
189 /// <returns>Stream to the data of the file.</returns> 189 /// <returns>Stream to the data of the file.</returns>
190 public Stream CreateDataStream(string name) 190 public Stream CreateDataStream(string name)
191 { 191 {
192 this.DeleteExistingEntry(name); 192 if (this.archive.Mode == ZipArchiveMode.Update)
193 {
194 this.DeleteExistingEntry(name);
195 }
193 196
194 var entry = this.archive.CreateEntry(name); 197 var entry = this.archive.CreateEntry(name);
195 198
@@ -203,7 +206,10 @@ namespace WixToolset.Data
203 /// <param name="path">Path to file on disk to include in the output.</param> 206 /// <param name="path">Path to file on disk to include in the output.</param>
204 public void ImportDataStream(string name, string path) 207 public void ImportDataStream(string name, string path)
205 { 208 {
206 this.DeleteExistingEntry(name); 209 if (this.archive.Mode == ZipArchiveMode.Update)
210 {
211 this.DeleteExistingEntry(name);
212 }
207 213
208 this.archive.CreateEntryFromFile(path, name, System.IO.Compression.CompressionLevel.Optimal); 214 this.archive.CreateEntryFromFile(path, name, System.IO.Compression.CompressionLevel.Optimal);
209 } 215 }
@@ -241,6 +247,26 @@ namespace WixToolset.Data
241 } 247 }
242 248
243 /// <summary> 249 /// <summary>
250 /// Creates a new file structure on disk that can only be written to.
251 /// </summary>
252 /// <param name="path">Path to write file structure to.</param>
253 /// <returns>Newly created <c>WixOutput</c>.</returns>
254 internal static WixOutput CreateNew(string path)
255 {
256 var fullPath = Path.GetFullPath(path);
257
258 Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
259
260 var uri = new Uri(fullPath);
261
262 var stream = File.Create(path);
263
264 var archive = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true);
265
266 return new WixOutput(uri, archive, stream);
267 }
268
269 /// <summary>
244 /// Disposes of the internal state of the file structure. 270 /// Disposes of the internal state of the file structure.
245 /// </summary> 271 /// </summary>
246 public void Dispose() 272 public void Dispose()
diff --git a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs
index 9ed68d81..13b4bb1a 100644
--- a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs
+++ b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs
@@ -234,7 +234,7 @@ namespace WixToolset.Core.CommandLine
234 234
235 if (!this.Messaging.EncounteredError) 235 if (!this.Messaging.EncounteredError)
236 { 236 {
237 result.Library.Save(outputPath); 237 result.Library.SaveNew(outputPath);
238 238
239 this.LayoutFiles(result.TrackedFiles, null, cancellationToken); 239 this.LayoutFiles(result.TrackedFiles, null, cancellationToken);
240 } 240 }