diff options
Diffstat (limited to 'src/WixToolset.Core.Burn/Bundles/CreateNonUXContainers.cs')
-rw-r--r-- | src/WixToolset.Core.Burn/Bundles/CreateNonUXContainers.cs | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/src/WixToolset.Core.Burn/Bundles/CreateNonUXContainers.cs b/src/WixToolset.Core.Burn/Bundles/CreateNonUXContainers.cs new file mode 100644 index 00000000..612e0e11 --- /dev/null +++ b/src/WixToolset.Core.Burn/Bundles/CreateNonUXContainers.cs | |||
@@ -0,0 +1,134 @@ | |||
1 | // 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. | ||
2 | |||
3 | namespace WixToolset.Core.Burn.Bundles | ||
4 | { | ||
5 | using System.Collections.Generic; | ||
6 | using System.Diagnostics; | ||
7 | using System.IO; | ||
8 | using System.Linq; | ||
9 | using WixToolset.Data; | ||
10 | using WixToolset.Data.Burn; | ||
11 | using WixToolset.Data.Tuples; | ||
12 | using WixToolset.Extensibility.Data; | ||
13 | using WixToolset.Extensibility.Services; | ||
14 | |||
15 | internal class CreateNonUXContainers | ||
16 | { | ||
17 | public CreateNonUXContainers(IBackendHelper backendHelper, IntermediateSection section, WixBootstrapperApplicationTuple bootstrapperApplicationTuple, Dictionary<string, WixBundlePayloadTuple> payloadTuples, string intermediateFolder, string layoutFolder, CompressionLevel? defaultCompressionLevel) | ||
18 | { | ||
19 | this.BackendHelper = backendHelper; | ||
20 | this.Section = section; | ||
21 | this.BootstrapperApplicationTuple = bootstrapperApplicationTuple; | ||
22 | this.PayloadTuples = payloadTuples; | ||
23 | this.IntermediateFolder = intermediateFolder; | ||
24 | this.LayoutFolder = layoutFolder; | ||
25 | this.DefaultCompressionLevel = defaultCompressionLevel; | ||
26 | } | ||
27 | |||
28 | public IEnumerable<IFileTransfer> FileTransfers { get; private set; } | ||
29 | |||
30 | public WixBundleContainerTuple UXContainer { get; set; } | ||
31 | |||
32 | public IEnumerable<WixBundlePayloadTuple> UXContainerPayloads { get; private set; } | ||
33 | |||
34 | public IEnumerable<WixBundleContainerTuple> Containers { get; private set; } | ||
35 | |||
36 | private IBackendHelper BackendHelper { get; } | ||
37 | |||
38 | private IntermediateSection Section { get; } | ||
39 | |||
40 | private WixBootstrapperApplicationTuple BootstrapperApplicationTuple { get; } | ||
41 | |||
42 | private Dictionary<string, WixBundlePayloadTuple> PayloadTuples { get; } | ||
43 | |||
44 | private string IntermediateFolder { get; } | ||
45 | |||
46 | private string LayoutFolder { get; } | ||
47 | |||
48 | private CompressionLevel? DefaultCompressionLevel { get; } | ||
49 | |||
50 | public void Execute() | ||
51 | { | ||
52 | var fileTransfers = new List<IFileTransfer>(); | ||
53 | |||
54 | var uxPayloadTuples = new List<WixBundlePayloadTuple>(); | ||
55 | |||
56 | var attachedContainerIndex = 1; // count starts at one because UX container is "0". | ||
57 | |||
58 | var containerTuples = this.Section.Tuples.OfType<WixBundleContainerTuple>().ToList(); | ||
59 | |||
60 | var payloadsByContainer = this.PayloadTuples.Values.ToLookup(p => p.ContainerRef); | ||
61 | |||
62 | foreach (var container in containerTuples) | ||
63 | { | ||
64 | var containerId = container.Id.Id; | ||
65 | |||
66 | var containerPayloads = payloadsByContainer[containerId]; | ||
67 | |||
68 | if (!containerPayloads.Any()) | ||
69 | { | ||
70 | if (containerId != BurnConstants.BurnDefaultAttachedContainerName) | ||
71 | { | ||
72 | // TODO: display warning that we're ignoring container that ended up with no paylods in it. | ||
73 | } | ||
74 | } | ||
75 | else if (BurnConstants.BurnUXContainerName == containerId) | ||
76 | { | ||
77 | this.UXContainer = container; | ||
78 | |||
79 | container.WorkingPath = Path.Combine(this.IntermediateFolder, container.Name); | ||
80 | container.AttachedContainerIndex = 0; | ||
81 | |||
82 | // Gather the list of UX payloads but ensure the BootstrapperApplication Payload is the first | ||
83 | // in the list since that is the Payload that Burn attempts to load. | ||
84 | var baPayloadId = this.BootstrapperApplicationTuple.Id.Id; | ||
85 | |||
86 | foreach (var uxPayload in containerPayloads) | ||
87 | { | ||
88 | if (uxPayload.Id.Id == baPayloadId) | ||
89 | { | ||
90 | uxPayloadTuples.Insert(0, uxPayload); | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | uxPayloadTuples.Add(uxPayload); | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | container.WorkingPath = Path.Combine(this.IntermediateFolder, container.Name); | ||
101 | |||
102 | // Add detached containers to the list of file transfers. | ||
103 | if (ContainerType.Detached == container.Type) | ||
104 | { | ||
105 | var transfer = this.BackendHelper.CreateFileTransfer(container.WorkingPath, Path.Combine(this.LayoutFolder, container.Name), true, container.SourceLineNumbers); | ||
106 | fileTransfers.Add(transfer); | ||
107 | } | ||
108 | else // update the attached container index. | ||
109 | { | ||
110 | Debug.Assert(ContainerType.Attached == container.Type); | ||
111 | |||
112 | container.AttachedContainerIndex = attachedContainerIndex; | ||
113 | ++attachedContainerIndex; | ||
114 | } | ||
115 | |||
116 | this.CreateContainer(container, containerPayloads, null); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | this.Containers = containerTuples; | ||
121 | this.UXContainerPayloads = uxPayloadTuples; | ||
122 | this.FileTransfers = fileTransfers; | ||
123 | } | ||
124 | |||
125 | private void CreateContainer(WixBundleContainerTuple container, IEnumerable<WixBundlePayloadTuple> containerPayloads, string manifestFile) | ||
126 | { | ||
127 | var command = new CreateContainerCommand(containerPayloads, container.WorkingPath, this.DefaultCompressionLevel); | ||
128 | command.Execute(); | ||
129 | |||
130 | container.Hash = command.Hash; | ||
131 | container.Size = command.Size; | ||
132 | } | ||
133 | } | ||
134 | } | ||