main
cs 135 lines 5.68 KB
Raw
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;
6 using System.Collections.Generic;
7 using System.Linq;
8 using WixToolset.Data;
9 using WixToolset.Data.Symbols;
10 using WixToolset.Extensibility;
11 using WixToolset.Extensibility.Data;
12 using WixToolset.Extensibility.Services;
13
14 /// <summary>
15 /// Initializes package state from the Bundle contents.
16 /// </summary>
17 internal class ProcessBundlePackageCommand
18 {
19 public ProcessBundlePackageCommand(IServiceProvider serviceProvider, IEnumerable<IBurnBackendBinderExtension> backendExtensions, IntermediateSection section, PackageFacade facade, Dictionary<string, WixBundlePayloadSymbol> packagePayloads, string intermediateFolder)
20 {
21 this.ServiceProvider = serviceProvider;
22 this.Messaging = serviceProvider.GetService<IMessaging>();
23 this.BackendExtensions = backendExtensions;
24 this.PackagePayloads = packagePayloads;
25 this.Section = section;
26 this.IntermediateFolder = intermediateFolder;
27
28 this.ChainPackage = facade.PackageSymbol;
29 this.BundlePackage = (WixBundleBundlePackageSymbol)facade.SpecificPackageSymbol;
30 this.BundlePackagePayload = (WixBundleBundlePackagePayloadSymbol)facade.SpecificPackagePayloadSymbol;
31 this.PackagePayload = packagePayloads[this.ChainPackage.PayloadRef];
32 }
33
34 private IServiceProvider ServiceProvider { get; }
35
36 private IMessaging Messaging { get; }
37
38 private IEnumerable<IBurnBackendBinderExtension> BackendExtensions { get; }
39
40 private Dictionary<string, WixBundlePayloadSymbol> PackagePayloads { get; }
41
42 private WixBundlePackageSymbol ChainPackage { get; }
43
44 private WixBundleBundlePackageSymbol BundlePackage { get; }
45
46 private WixBundleBundlePackagePayloadSymbol BundlePackagePayload { get; }
47
48 private string PackageId => this.ChainPackage.Id.Id;
49
50 private WixBundlePayloadSymbol PackagePayload { get; }
51
52 private IntermediateSection Section { get; }
53
54 private string IntermediateFolder { get; }
55
56 public List<ITrackedFile> TrackedFiles { get; } = new List<ITrackedFile>();
57
58 /// <summary>
59 /// Processes the Bundle packages to add properties and payloads from the Bundle packages.
60 /// </summary>
61 public void Execute()
62 {
63 var harvestedBundlePackage = this.Section.Symbols.OfType<WixBundleHarvestedBundlePackageSymbol>()
64 .Where(h => h.Id.Id == this.PackagePayload.Id.Id)
65 .SingleOrDefault();
66
67 if (harvestedBundlePackage == null)
68 {
69 harvestedBundlePackage = this.HarvestPackage();
70
71 if (harvestedBundlePackage == null)
72 {
73 return;
74 }
75 }
76
77 this.ChainPackage.Win64 = harvestedBundlePackage.Win64;
78 this.BundlePackage.BundleId = Guid.Parse(harvestedBundlePackage.BundleId).ToString("B").ToUpperInvariant();
79 this.BundlePackage.EngineVersion = harvestedBundlePackage.EngineVersion;
80 this.BundlePackage.SupportsBurnProtocol = harvestedBundlePackage.ProtocolVersion == BurnCommon.BURN_PROTOCOL_VERSION;
81
82 var supportsArpSystemComponent = BurnCommon.BurnV3Namespace != harvestedBundlePackage.ManifestNamespace;
83 if (!supportsArpSystemComponent && !this.ChainPackage.Visible)
84 {
85 this.Messaging.Write(BurnBackendWarnings.HiddenBundleNotSupported(this.PackagePayload.SourceLineNumbers, this.PackageId));
86
87 this.ChainPackage.Visible = true;
88 }
89
90 this.ChainPackage.PerMachine = harvestedBundlePackage.PerMachine;
91 this.PackagePayload.Version = harvestedBundlePackage.Version;
92 this.BundlePackage.Version = harvestedBundlePackage.Version;
93 this.ChainPackage.Version = harvestedBundlePackage.Version;
94
95 if (String.IsNullOrEmpty(this.ChainPackage.CacheId))
96 {
97 this.ChainPackage.CacheId = CacheIdGenerator.GenerateLocalCacheId(this.Messaging, harvestedBundlePackage, this.PackagePayload, this.BundlePackage.SourceLineNumbers, "BundlePackage");
98 }
99
100 if (String.IsNullOrEmpty(this.ChainPackage.DisplayName))
101 {
102 this.ChainPackage.DisplayName = harvestedBundlePackage.DisplayName;
103 }
104
105 this.ChainPackage.InstallSize = harvestedBundlePackage.InstallSize;
106 }
107
108 private WixBundleHarvestedBundlePackageSymbol HarvestPackage()
109 {
110 var command = new HarvestBundlePackageCommand(this.ServiceProvider, this.BackendExtensions, this.IntermediateFolder, this.PackagePayload, this.BundlePackagePayload, this.PackagePayloads);
111 command.Execute();
112
113 this.TrackedFiles.AddRange(command.TrackedFiles);
114 if (this.Messaging.EncounteredError)
115 {
116 return null;
117 }
118
119 this.Section.AddSymbol(command.HarvestedBundlePackage);
120 this.Section.AddSymbol(command.HarvestedDependencyProvider);
121
122 foreach (var payload in command.Payloads)
123 {
124 this.Section.AddSymbol(payload);
125 }
126
127 foreach (var relatedBundle in command.RelatedBundles)
128 {
129 this.Section.AddSymbol(relatedBundle);
130 }
131
132 return command.HarvestedBundlePackage;
133 }
134 }
135 }