From 6879c941119532d0ec7bf9f5c05faa2231553b57 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Sat, 21 Sep 2024 22:52:22 -0400 Subject: 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. --- src/api/wix/WixToolset.Data/Intermediate.cs | 14 ++++++++++ src/api/wix/WixToolset.Data/WixOutput.cs | 32 ++++++++++++++++++++-- .../WixToolset.Core/CommandLine/BuildCommand.cs | 2 +- 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 @@ -244,6 +244,20 @@ namespace WixToolset.Data } } + /// + /// Saves an intermediate that can only be written to to a path on disk. + /// + /// Path to save intermediate file to disk. + public void SaveNew(string path) + { + Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))); + + using (var wixout = WixOutput.CreateNew(path)) + { + this.Save(wixout); + } + } + /// /// Saves an intermediate to a WixOutput. /// 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 } /// - /// + /// /// public Uri Uri { get; } @@ -189,7 +189,10 @@ namespace WixToolset.Data /// Stream to the data of the file. public Stream CreateDataStream(string name) { - this.DeleteExistingEntry(name); + if (this.archive.Mode == ZipArchiveMode.Update) + { + this.DeleteExistingEntry(name); + } var entry = this.archive.CreateEntry(name); @@ -203,7 +206,10 @@ namespace WixToolset.Data /// Path to file on disk to include in the output. public void ImportDataStream(string name, string path) { - this.DeleteExistingEntry(name); + if (this.archive.Mode == ZipArchiveMode.Update) + { + this.DeleteExistingEntry(name); + } this.archive.CreateEntryFromFile(path, name, System.IO.Compression.CompressionLevel.Optimal); } @@ -240,6 +246,26 @@ namespace WixToolset.Data } } + /// + /// Creates a new file structure on disk that can only be written to. + /// + /// Path to write file structure to. + /// Newly created WixOutput. + internal static WixOutput CreateNew(string path) + { + var fullPath = Path.GetFullPath(path); + + Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); + + var uri = new Uri(fullPath); + + var stream = File.Create(path); + + var archive = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true); + + return new WixOutput(uri, archive, stream); + } + /// /// Disposes of the internal state of the file structure. /// 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 if (!this.Messaging.EncounteredError) { - result.Library.Save(outputPath); + result.Library.SaveNew(outputPath); this.LayoutFiles(result.TrackedFiles, null, cancellationToken); } -- cgit v1.2.3-55-g6feb