diff options
author | Bob Arnson <bob@firegiant.com> | 2024-09-21 22:52:22 -0400 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2024-10-04 12:22:15 -0700 |
commit | a75f23d32c3892e9977e7a48b4b347342ab182a9 (patch) | |
tree | 13e4110306da2674216e2e2e67c1dd1c14166827 | |
parent | 29d555a7c1f8ca660177035265624644a5c6d374 (diff) | |
download | wix-a75f23d32c3892e9977e7a48b4b347342ab182a9.tar.gz wix-a75f23d32c3892e9977e7a48b4b347342ab182a9.tar.bz2 wix-a75f23d32c3892e9977e7a48b4b347342ab182a9.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.cs | 14 | ||||
-rw-r--r-- | src/api/wix/WixToolset.Data/WixOutput.cs | 32 | ||||
-rw-r--r-- | src/wix/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 977f894a..5dc38980 100644 --- a/src/api/wix/WixToolset.Data/Intermediate.cs +++ b/src/api/wix/WixToolset.Data/Intermediate.cs | |||
@@ -247,6 +247,20 @@ namespace WixToolset.Data | |||
247 | } | 247 | } |
248 | 248 | ||
249 | /// <summary> | 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> | ||
250 | /// Saves an intermediate to a WixOutput. | 264 | /// Saves an intermediate to a WixOutput. |
251 | /// </summary> | 265 | /// </summary> |
252 | /// <param name="wixout">Destination to save.</param> | 266 | /// <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 d07dd6aa..0db39480 100644 --- a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs | |||
@@ -248,7 +248,7 @@ namespace WixToolset.Core.CommandLine | |||
248 | 248 | ||
249 | if (!this.Messaging.EncounteredError) | 249 | if (!this.Messaging.EncounteredError) |
250 | { | 250 | { |
251 | result.Library.Save(outputPath); | 251 | result.Library.SaveNew(outputPath); |
252 | 252 | ||
253 | this.LayoutFiles(result.TrackedFiles, null, cancellationToken); | 253 | this.LayoutFiles(result.TrackedFiles, null, cancellationToken); |
254 | } | 254 | } |