@joebigelow / wix-1 / commits / a75f23d3

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.

Bob Arnson committed Sep 21, 2024 at 22:52 UTC a75f23d32c3892e9977e7a48b4b347342ab182a9
3 files changed +44 -4
src/api/wix/WixToolset.Data/Intermediate.cs
+14
@@ -246,6 +246,20 @@ namespace WixToolset.Data
246 }
247 }
248
249 + /// <summary>
250 + /// Saves an intermediate that can only be written to to a path on disk.
251 + /// </summary>
252 + /// <param name="path">Path to save intermediate file to disk.</param>
253 + public void SaveNew(string path)
254 + {
255 + Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path)));
256 +
257 + using (var wixout = WixOutput.CreateNew(path))
258 + {
259 + this.Save(wixout);
260 + }
261 + }
262 +
263 /// <summary>
264 /// Saves an intermediate to a WixOutput.
265 /// </summary>
src/api/wix/WixToolset.Data/WixOutput.cs
+29 -3
@@ -25,7 +25,7 @@ namespace WixToolset.Data
25 }
26
27 /// <summary>
28 - ///
28 + ///
29 /// </summary>
30 public Uri Uri { get; }
31
@@ -189,7 +189,10 @@ namespace WixToolset.Data
189 /// <returns>Stream to the data of the file.</returns>
190 public Stream CreateDataStream(string name)
191 {
192 - this.DeleteExistingEntry(name);
192 + if (this.archive.Mode == ZipArchiveMode.Update)
193 + {
194 + this.DeleteExistingEntry(name);
195 + }
196
197 var entry = this.archive.CreateEntry(name);
198
@@ -203,7 +206,10 @@ namespace WixToolset.Data
206 /// <param name="path">Path to file on disk to include in the output.</param>
207 public void ImportDataStream(string name, string path)
208 {
206 - this.DeleteExistingEntry(name);
209 + if (this.archive.Mode == ZipArchiveMode.Update)
210 + {
211 + this.DeleteExistingEntry(name);
212 + }
213
214 this.archive.CreateEntryFromFile(path, name, System.IO.Compression.CompressionLevel.Optimal);
215 }
@@ -240,6 +246,26 @@ namespace WixToolset.Data
246 }
247 }
248
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>
270 /// Disposes of the internal state of the file structure.
271 /// </summary>
src/wix/WixToolset.Core/CommandLine/BuildCommand.cs
+1 -1
@@ -248,7 +248,7 @@ namespace WixToolset.Core.CommandLine
248
249 if (!this.Messaging.EncounteredError)
250 {
251 - result.Library.Save(outputPath);
251 + result.Library.SaveNew(outputPath);
252
253 this.LayoutFiles(result.TrackedFiles, null, cancellationToken);
254 }