aboutsummaryrefslogtreecommitdiff
path: root/src/wixext/BalBurnBackendExtension.cs
blob: 71cd2d92254f7db2d1014b277e13cae077aeb9e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// 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.Bal
{
    using System;
    using System.Linq;
    using WixToolset.Bal.Tuples;
    using WixToolset.Data;
    using WixToolset.Data.Burn;
    using WixToolset.Data.Tuples;
    using WixToolset.Extensibility;

    public class BalBurnBackendExtension : BaseBurnBackendExtension
    {
        public override void BundleFinalize()
        {
            base.BundleFinalize();

            var intermediate = this.Context.IntermediateRepresentation;
            var section = intermediate.Sections.Single();

            var baTuple = section.Tuples.OfType<WixBootstrapperApplicationTuple>().SingleOrDefault();
            var baId = baTuple?.Id?.Id;
            if (null == baId)
            {
                return;
            }

            var isStdBA = baId.StartsWith("WixStandardBootstrapperApplication");
            var isMBA = baId.StartsWith("ManagedBootstrapperApplicationHost");

            if (isStdBA || isMBA)
            {
                this.VerifyBAFunctions(section);
            }

            if (isMBA)
            {
                this.VerifyPrereqPackages(section);
            }
        }

        private void VerifyBAFunctions(IntermediateSection section)
        {
            WixBalBAFunctionsTuple baFunctionsTuple = null;
            foreach (var tuple in section.Tuples.OfType<WixBalBAFunctionsTuple>())
            {
                if (null == baFunctionsTuple)
                {
                    baFunctionsTuple = tuple;
                }
                else
                {
                    this.Messaging.Write(BalErrors.MultipleBAFunctions(tuple.SourceLineNumbers));
                }
            }

            var payloadPropertiesTuples = section.Tuples.OfType<WixBundlePayloadTuple>().ToList();
            if (null == baFunctionsTuple)
            {
                foreach (var payloadPropertiesTuple in payloadPropertiesTuples)
                {
                    // TODO: Make core WiX canonicalize Name (this won't catch '.\bafunctions.dll').
                    if (string.Equals(payloadPropertiesTuple.Name, "bafunctions.dll", StringComparison.OrdinalIgnoreCase))
                    {
                        this.Messaging.Write(BalWarnings.UnmarkedBAFunctionsDLL(payloadPropertiesTuple.SourceLineNumbers));
                    }
                }
            }
            else
            {
                var payloadId = baFunctionsTuple.Id;
                var bundlePayloadTuple = payloadPropertiesTuples.Single(x => payloadId == x.Id);
                if (BurnConstants.BurnUXContainerName != bundlePayloadTuple.ContainerRef)
                {
                    this.Messaging.Write(BalErrors.BAFunctionsPayloadRequiredInUXContainer(baFunctionsTuple.SourceLineNumbers));
                }
            }
        }

        private void VerifyPrereqPackages(IntermediateSection section)
        {
            var prereqInfoTuples = section.Tuples.OfType<WixMbaPrereqInformationTuple>().ToList();
            if (prereqInfoTuples.Count == 0)
            {
                this.Messaging.Write(BalErrors.MissingPrereq());
                return;
            }

            var foundLicenseFile = false;
            var foundLicenseUrl = false;

            foreach (var prereqInfoTuple in prereqInfoTuples)
            {
                if (null != prereqInfoTuple.LicenseFile)
                {
                    if (foundLicenseFile || foundLicenseUrl)
                    {
                        this.Messaging.Write(BalErrors.MultiplePrereqLicenses(prereqInfoTuple.SourceLineNumbers));
                        return;
                    }

                    foundLicenseFile = true;
                }

                if (null != prereqInfoTuple.LicenseUrl)
                {
                    if (foundLicenseFile || foundLicenseUrl)
                    {
                        this.Messaging.Write(BalErrors.MultiplePrereqLicenses(prereqInfoTuple.SourceLineNumbers));
                        return;
                    }

                    foundLicenseUrl = true;
                }
            }
        }
    }
}