Skip to content

Commit f82e422

Browse files
committed
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.
1 parent dd2fe20 commit f82e422

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

src/api/wix/WixToolset.Data/Intermediate.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,20 @@ public void Save(string path)
246246
}
247247
}
248248

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+
249263
/// <summary>
250264
/// Saves an intermediate to a WixOutput.
251265
/// </summary>

src/api/wix/WixToolset.Data/WixOutput.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private WixOutput(Uri uri, ZipArchive archive, Stream stream)
2525
}
2626

2727
/// <summary>
28-
///
28+
///
2929
/// </summary>
3030
public Uri Uri { get; }
3131

@@ -189,7 +189,10 @@ public void ExtractEmbeddedFile(string embeddedId, string outputPath)
189189
/// <returns>Stream to the data of the file.</returns>
190190
public Stream CreateDataStream(string name)
191191
{
192-
this.DeleteExistingEntry(name);
192+
if (this.archive.Mode == ZipArchiveMode.Update)
193+
{
194+
this.DeleteExistingEntry(name);
195+
}
193196

194197
var entry = this.archive.CreateEntry(name);
195198

@@ -203,7 +206,10 @@ public Stream CreateDataStream(string name)
203206
/// <param name="path">Path to file on disk to include in the output.</param>
204207
public void ImportDataStream(string name, string path)
205208
{
206-
this.DeleteExistingEntry(name);
209+
if (this.archive.Mode == ZipArchiveMode.Update)
210+
{
211+
this.DeleteExistingEntry(name);
212+
}
207213

208214
this.archive.CreateEntryFromFile(path, name, System.IO.Compression.CompressionLevel.Optimal);
209215
}
@@ -240,6 +246,26 @@ public string GetData(string name)
240246
}
241247
}
242248

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+
243269
/// <summary>
244270
/// Disposes of the internal state of the file structure.
245271
/// </summary>

src/wix/WixToolset.Core/CommandLine/BuildCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private void LibraryPhase(IReadOnlyCollection<Intermediate> intermediates, IRead
248248

249249
if (!this.Messaging.EncounteredError)
250250
{
251-
result.Library.Save(outputPath);
251+
result.Library.SaveNew(outputPath);
252252

253253
this.LayoutFiles(result.TrackedFiles, null, cancellationToken);
254254
}

0 commit comments

Comments
 (0)