aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.Burn/Bundles/CreateContainerCommand.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core.Burn/Bundles/CreateContainerCommand.cs')
-rw-r--r--src/WixToolset.Core.Burn/Bundles/CreateContainerCommand.cs59
1 files changed, 34 insertions, 25 deletions
diff --git a/src/WixToolset.Core.Burn/Bundles/CreateContainerCommand.cs b/src/WixToolset.Core.Burn/Bundles/CreateContainerCommand.cs
index c9dd2671..937721a6 100644
--- a/src/WixToolset.Core.Burn/Bundles/CreateContainerCommand.cs
+++ b/src/WixToolset.Core.Burn/Bundles/CreateContainerCommand.cs
@@ -4,24 +4,39 @@ namespace WixToolset.Core.Burn.Bundles
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.Diagnostics;
8 using System.IO; 7 using System.IO;
9 using System.Linq; 8 using System.Linq;
9 using WixToolset.Core.Native;
10 using WixToolset.Data; 10 using WixToolset.Data;
11 using WixToolset.Data.Tuples;
11 12
12 /// <summary> 13 /// <summary>
13 /// Creates cabinet files. 14 /// Creates cabinet files.
14 /// </summary> 15 /// </summary>
15 internal class CreateContainerCommand 16 internal class CreateContainerCommand
16 { 17 {
17#if TODO 18 public CreateContainerCommand(IEnumerable<WixBundlePayloadTuple> payloads, string outputPath, CompressionLevel? compressionLevel)
18 public CompressionLevel DefaultCompressionLevel { private get; set; } 19 {
20 this.Payloads = payloads;
21 this.OutputPath = outputPath;
22 this.CompressionLevel = compressionLevel;
23 }
24
25 public CreateContainerCommand(string manifestPath, IEnumerable<WixBundlePayloadTuple> payloads, string outputPath, CompressionLevel? compressionLevel)
26 {
27 this.ManifestFile = manifestPath;
28 this.Payloads = payloads;
29 this.OutputPath = outputPath;
30 this.CompressionLevel = compressionLevel;
31 }
32
33 private CompressionLevel? CompressionLevel { get; }
19 34
20 public IEnumerable<WixBundlePayloadRow> Payloads { private get; set; } 35 private string ManifestFile { get; }
21 36
22 public string ManifestFile { private get; set; } 37 private string OutputPath { get; }
23 38
24 public string OutputPath { private get; set; } 39 private IEnumerable<WixBundlePayloadTuple> Payloads { get; }
25 40
26 public string Hash { get; private set; } 41 public string Hash { get; private set; }
27 42
@@ -29,40 +44,34 @@ namespace WixToolset.Core.Burn.Bundles
29 44
30 public void Execute() 45 public void Execute()
31 { 46 {
32 int payloadCount = this.Payloads.Count(); // The number of embedded payloads 47 var payloadCount = this.Payloads.Count(); // The number of embedded payloads
33 48
34 if (!String.IsNullOrEmpty(this.ManifestFile)) 49 if (!String.IsNullOrEmpty(this.ManifestFile))
35 { 50 {
36 ++payloadCount; 51 ++payloadCount;
37 } 52 }
38 53
39 using (var cab = new WixCreateCab(Path.GetFileName(this.OutputPath), Path.GetDirectoryName(this.OutputPath), payloadCount, 0, 0, this.DefaultCompressionLevel)) 54 var cabinetPath = Path.GetFullPath(this.OutputPath);
40 {
41 // If a manifest was provided always add it as "payload 0" to the container.
42 if (!String.IsNullOrEmpty(this.ManifestFile))
43 {
44 cab.AddFile(this.ManifestFile, "0");
45 }
46 55
47 foreach (WixBundlePayloadRow payload in this.Payloads) 56 var files = new List<CabinetCompressFile>();
48 {
49 Debug.Assert(PackagingType.Embedded == payload.Packaging);
50 57
51 Messaging.Instance.OnMessage(WixVerboses.LoadingPayload(payload.FullFileName)); 58 // If a manifest was provided always add it as "payload 0" to the container.
59 if (!String.IsNullOrEmpty(this.ManifestFile))
60 {
61 files.Add(new CabinetCompressFile(this.ManifestFile, "0"));
62 }
52 63
53 cab.AddFile(payload.FullFileName, payload.EmbeddedId); 64 files.AddRange(this.Payloads.Select(p => new CabinetCompressFile(p.SourceFile.Path, p.EmbeddedId)));
54 }
55 65
56 cab.Complete(); 66 var cab = new Cabinet(cabinetPath);
57 } 67 cab.Compress(files, this.CompressionLevel ?? Data.CompressionLevel.Mszip);
58 68
59 // Now that the container is created, set the outputs of the command. 69 // Now that the container is created, set the outputs of the command.
60 FileInfo fileInfo = new FileInfo(this.OutputPath); 70 var fileInfo = new FileInfo(cabinetPath);
61 71
62 this.Hash = Common.GetFileHash(fileInfo.FullName); 72 this.Hash = BundleHashAlgorithm.Hash(fileInfo);
63 73
64 this.Size = fileInfo.Length; 74 this.Size = fileInfo.Length;
65 } 75 }
66#endif
67 } 76 }
68} 77}