Skip to content

Commit 62c5807

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 62c5807

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-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: 40 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

@@ -60,6 +60,24 @@ public static WixOutput Create(string path)
6060
return WixOutput.Create(uri, stream);
6161
}
6262

63+
/// <summary>
64+
/// Creates a new file structure on disk that can only be written to.
65+
/// </summary>
66+
/// <param name="path">Path to write file structure to.</param>
67+
/// <returns>Newly created <c>WixOutput</c>.</returns>
68+
public static WixOutput CreateNew(string path)
69+
{
70+
var fullPath = Path.GetFullPath(path);
71+
72+
Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
73+
74+
var uri = new Uri(fullPath);
75+
76+
var stream = File.Create(path);
77+
78+
return WixOutput.CreateNew(uri, stream);
79+
}
80+
6381
/// <summary>
6482
/// Creates a new file structure.
6583
/// </summary>
@@ -73,6 +91,19 @@ public static WixOutput Create(Uri uri, Stream stream)
7391
return new WixOutput(uri, archive, stream);
7492
}
7593

94+
/// <summary>
95+
/// Creates a new file structure that can only be written to.
96+
/// </summary>
97+
/// <param name="uri"></param>
98+
/// <param name="stream">Stream to write the file structure to.</param>
99+
/// <returns>Newly created <c>WixOutput</c>.</returns>
100+
public static WixOutput CreateNew(Uri uri, Stream stream)
101+
{
102+
var archive = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true);
103+
104+
return new WixOutput(uri, archive, stream);
105+
}
106+
76107
/// <summary>
77108
/// Loads a wixout from a path on disk.
78109
/// </summary>
@@ -189,7 +220,10 @@ public void ExtractEmbeddedFile(string embeddedId, string outputPath)
189220
/// <returns>Stream to the data of the file.</returns>
190221
public Stream CreateDataStream(string name)
191222
{
192-
this.DeleteExistingEntry(name);
223+
if (this.archive.Mode == ZipArchiveMode.Update)
224+
{
225+
this.DeleteExistingEntry(name);
226+
}
193227

194228
var entry = this.archive.CreateEntry(name);
195229

@@ -203,7 +237,10 @@ public Stream CreateDataStream(string name)
203237
/// <param name="path">Path to file on disk to include in the output.</param>
204238
public void ImportDataStream(string name, string path)
205239
{
206-
this.DeleteExistingEntry(name);
240+
if (this.archive.Mode == ZipArchiveMode.Update)
241+
{
242+
this.DeleteExistingEntry(name);
243+
}
207244

208245
this.archive.CreateEntryFromFile(path, name, System.IO.Compression.CompressionLevel.Optimal);
209246
}

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)