Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overloads to support create-only Wixouts. #572

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
barnson committed Oct 4, 2024
commit f82e42264ce390940a430f4fb31ebc7f58bdd7d4
14 changes: 14 additions & 0 deletions src/api/wix/WixToolset.Data/Intermediate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ public void Save(string path)
}
}

/// <summary>
/// Saves an intermediate that can only be written to to a path on disk.
/// </summary>
/// <param name="path">Path to save intermediate file to disk.</param>
public void SaveNew(string path)
{
Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path)));

using (var wixout = WixOutput.CreateNew(path))
{
this.Save(wixout);
}
}

/// <summary>
/// Saves an intermediate to a WixOutput.
/// </summary>
Expand Down
32 changes: 29 additions & 3 deletions src/api/wix/WixToolset.Data/WixOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private WixOutput(Uri uri, ZipArchive archive, Stream stream)
}

/// <summary>
///
///
/// </summary>
public Uri Uri { get; }

Expand Down Expand Up @@ -189,7 +189,10 @@ public void ExtractEmbeddedFile(string embeddedId, string outputPath)
/// <returns>Stream to the data of the file.</returns>
public Stream CreateDataStream(string name)
{
this.DeleteExistingEntry(name);
if (this.archive.Mode == ZipArchiveMode.Update)
{
this.DeleteExistingEntry(name);
}

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

Expand All @@ -203,7 +206,10 @@ public Stream CreateDataStream(string name)
/// <param name="path">Path to file on disk to include in the output.</param>
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);
}
Expand Down Expand Up @@ -240,6 +246,26 @@ public string GetData(string name)
}
}

/// <summary>
/// Creates a new file structure on disk that can only be written to.
/// </summary>
/// <param name="path">Path to write file structure to.</param>
/// <returns>Newly created <c>WixOutput</c>.</returns>
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);
}

/// <summary>
/// Disposes of the internal state of the file structure.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/wix/WixToolset.Core/CommandLine/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private void LibraryPhase(IReadOnlyCollection<Intermediate> intermediates, IRead

if (!this.Messaging.EncounteredError)
{
result.Library.Save(outputPath);
result.Library.SaveNew(outputPath);

this.LayoutFiles(result.TrackedFiles, null, cancellationToken);
}
Expand Down
Loading