main
cs 79 lines 3.2 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.WindowsInstaller.Bind
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.Services;
11
12 internal class ProcessPropertiesCommand
13 {
14 public ProcessPropertiesCommand(IntermediateSection section, WixPackageSymbol packageSymbol, int fallbackLcid, bool populateDelayedVariables, IBackendHelper backendHelper)
15 {
16 this.Section = section;
17 this.PackageSymbol = packageSymbol;
18 this.FallbackLcid = fallbackLcid;
19 this.PopulateDelayedVariables = populateDelayedVariables;
20 this.BackendHelper = backendHelper;
21 }
22
23 private IntermediateSection Section { get; }
24
25 private WixPackageSymbol PackageSymbol { get; }
26
27 private int FallbackLcid { get; }
28
29 private bool PopulateDelayedVariables { get; }
30
31 private IBackendHelper BackendHelper { get; }
32
33 public Dictionary<string, string> DelayedVariablesCache { get; private set; }
34
35 public string ProductLanguage { get; private set; }
36
37 public void Execute()
38 {
39 PropertySymbol languageSymbol = null;
40 var variableCache = this.PopulateDelayedVariables ? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) : null;
41
42 if (SectionType.Package == this.Section.Type || variableCache != null)
43 {
44 foreach (var propertySymbol in this.Section.Symbols.OfType<PropertySymbol>())
45 {
46 // Set the ProductCode if it is to be generated.
47 if ("ProductCode" == propertySymbol.Id.Id && "*".Equals(propertySymbol.Value, StringComparison.Ordinal))
48 {
49 propertySymbol.Value = this.BackendHelper.CreateGuid();
50 }
51 else if ("ProductLanguage" == propertySymbol.Id.Id)
52 {
53 languageSymbol = propertySymbol;
54 }
55
56 // Add the property name and value to the variableCache.
57 if (variableCache != null)
58 {
59 variableCache[$"property.{propertySymbol.Id.Id}"] = propertySymbol.Value;
60 }
61 }
62
63 if (this.Section.Type == SectionType.Package && String.IsNullOrEmpty(languageSymbol?.Value))
64 {
65 if (languageSymbol == null)
66 {
67 languageSymbol = this.Section.AddSymbol(new PropertySymbol(this.PackageSymbol.SourceLineNumbers, new Identifier(AccessModifier.Section, "ProductLanguage")));
68 }
69
70 this.PackageSymbol.Language = this.FallbackLcid.ToString();
71 languageSymbol.Value = this.FallbackLcid.ToString();
72 }
73 }
74
75 this.DelayedVariablesCache = variableCache;
76 this.ProductLanguage = languageSymbol?.Value;
77 }
78 }
79 }