aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/ProcessPropertiesCommand.cs
blob: 217609be16d2ec757e0dc811656b6e64599d6260 (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
// 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.WindowsInstaller.Bind
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using WixToolset.Data;
    using WixToolset.Data.Symbols;
    using WixToolset.Extensibility.Services;

    internal class ProcessPropertiesCommand
    {
        public ProcessPropertiesCommand(IntermediateSection section, WixPackageSymbol packageSymbol, int fallbackLcid, bool populateDelayedVariables, IBackendHelper backendHelper)
        {
            this.Section = section;
            this.PackageSymbol = packageSymbol;
            this.FallbackLcid = fallbackLcid;
            this.PopulateDelayedVariables = populateDelayedVariables;
            this.BackendHelper = backendHelper;
        }

        private IntermediateSection Section { get; }

        private WixPackageSymbol PackageSymbol { get; }

        private int FallbackLcid { get; }

        private bool PopulateDelayedVariables { get; }

        private IBackendHelper BackendHelper { get; }

        public Dictionary<string, string> DelayedVariablesCache { get; private set; }

        public string ProductLanguage { get; private set; }

        public void Execute()
        {
            PropertySymbol languageSymbol = null;
            var variableCache = this.PopulateDelayedVariables ? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) : null;

            if (SectionType.Product == this.Section.Type || variableCache != null)
            {
                foreach (var propertySymbol in this.Section.Symbols.OfType<PropertySymbol>())
                {
                    // Set the ProductCode if it is to be generated.
                    if ("ProductCode" == propertySymbol.Id.Id && "*".Equals(propertySymbol.Value, StringComparison.Ordinal))
                    {
                        propertySymbol.Value = this.BackendHelper.CreateGuid();

#if TODO_PATCHING // Is this still necessary?
                        // Update the target ProductCode in any instance transforms.
                        foreach (SubStorage subStorage in this.Output.SubStorages)
                        {
                            Output subStorageOutput = subStorage.Data;
                            if (OutputType.Transform != subStorageOutput.Type)
                            {
                                continue;
                            }

                            Table instanceSummaryInformationTable = subStorageOutput.Tables["_SummaryInformation"];
                            foreach (Row row in instanceSummaryInformationTable.Rows)
                            {
                                if ((int)SummaryInformation.Transform.ProductCodes == row.FieldAsInteger(0))
                                {
                                    row[1] = row.FieldAsString(1).Replace("*", propertyRow.Value);
                                    break;
                                }
                            }
                        }
#endif
                    }
                    else if ("ProductLanguage" == propertySymbol.Id.Id)
                    {
                        languageSymbol = propertySymbol;
                    }

                    // Add the property name and value to the variableCache.
                    if (variableCache != null)
                    {
                        variableCache[$"property.{propertySymbol.Id.Id}"] = propertySymbol.Value;
                    }
                }

                if (this.Section.Type == SectionType.Product && String.IsNullOrEmpty(languageSymbol?.Value))
                {
                    if (languageSymbol == null)
                    {
                        languageSymbol = this.Section.AddSymbol(new PropertySymbol(this.PackageSymbol.SourceLineNumbers, new Identifier(AccessModifier.Section, "ProductLanguage")));
                    }

                    this.PackageSymbol.Language = this.FallbackLcid.ToString();
                    languageSymbol.Value = this.FallbackLcid.ToString();
                }
            }

            this.DelayedVariablesCache = variableCache;
            this.ProductLanguage = languageSymbol?.Value;
        }
    }
}