From dbde9e7104b907bbbaea17e21247d8cafc8b3a4c Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 14 Oct 2017 16:12:07 -0700 Subject: Massive refactoring to introduce the concept of IBackend --- .../Bundles/CreateContainerCommand.cs | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/WixToolset.Core.Burn/Bundles/CreateContainerCommand.cs (limited to 'src/WixToolset.Core.Burn/Bundles/CreateContainerCommand.cs') diff --git a/src/WixToolset.Core.Burn/Bundles/CreateContainerCommand.cs b/src/WixToolset.Core.Burn/Bundles/CreateContainerCommand.cs new file mode 100644 index 00000000..75379713 --- /dev/null +++ b/src/WixToolset.Core.Burn/Bundles/CreateContainerCommand.cs @@ -0,0 +1,68 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Core.Burn.Bundles +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.IO; + using System.Linq; + using WixToolset.Core.Cab; + using WixToolset.Data; + using WixToolset.Data.Rows; + + /// + /// Creates cabinet files. + /// + internal class CreateContainerCommand + { + public CompressionLevel DefaultCompressionLevel { private get; set; } + + public IEnumerable Payloads { private get; set; } + + public string ManifestFile { private get; set; } + + public string OutputPath { private get; set; } + + public string Hash { get; private set; } + + public long Size { get; private set; } + + public void Execute() + { + int payloadCount = this.Payloads.Count(); // The number of embedded payloads + + if (!String.IsNullOrEmpty(this.ManifestFile)) + { + ++payloadCount; + } + + using (var cab = new WixCreateCab(Path.GetFileName(this.OutputPath), Path.GetDirectoryName(this.OutputPath), payloadCount, 0, 0, this.DefaultCompressionLevel)) + { + // If a manifest was provided always add it as "payload 0" to the container. + if (!String.IsNullOrEmpty(this.ManifestFile)) + { + cab.AddFile(this.ManifestFile, "0"); + } + + foreach (WixBundlePayloadRow payload in this.Payloads) + { + Debug.Assert(PackagingType.Embedded == payload.Packaging); + + Messaging.Instance.OnMessage(WixVerboses.LoadingPayload(payload.FullFileName)); + + cab.AddFile(payload.FullFileName, payload.EmbeddedId); + } + + cab.Complete(); + } + + // Now that the container is created, set the outputs of the command. + FileInfo fileInfo = new FileInfo(this.OutputPath); + + this.Hash = Common.GetFileHash(fileInfo.FullName); + + this.Size = fileInfo.Length; + } + } +} -- cgit v1.2.3-55-g6feb