diff options
Diffstat (limited to 'src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs')
-rw-r--r-- | src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs | 78 |
1 files changed, 34 insertions, 44 deletions
diff --git a/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs index d05135cf..4585b71a 100644 --- a/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs +++ b/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs | |||
@@ -12,25 +12,28 @@ namespace WixToolset.Core.Bind | |||
12 | /// Resolves the fields which had variables that needed to be resolved after the file information | 12 | /// Resolves the fields which had variables that needed to be resolved after the file information |
13 | /// was loaded. | 13 | /// was loaded. |
14 | /// </summary> | 14 | /// </summary> |
15 | public class ResolveDelayedFieldsCommand : ICommand | 15 | public class ResolveDelayedFieldsCommand |
16 | { | 16 | { |
17 | public OutputType OutputType { private get; set;} | 17 | /// <summary> |
18 | 18 | /// Resolve delayed fields. | |
19 | public IEnumerable<IDelayedField> DelayedFields { private get; set;} | 19 | /// </summary> |
20 | /// <param name="delayedFields">The fields which had resolution delayed.</param> | ||
21 | /// <param name="variableCache">The file information to use when resolving variables.</param> | ||
22 | public ResolveDelayedFieldsCommand(IEnumerable<IDelayedField> delayedFields, Dictionary<string, string> variableCache) | ||
23 | { | ||
24 | this.DelayedFields = delayedFields; | ||
25 | this.VariableCache = variableCache; | ||
26 | } | ||
20 | 27 | ||
21 | public IDictionary<string, string> VariableCache { private get; set; } | 28 | private IEnumerable<IDelayedField> DelayedFields { get;} |
22 | 29 | ||
23 | public string ModularizationGuid { private get; set; } | 30 | private IDictionary<string, string> VariableCache { get; } |
24 | 31 | ||
25 | /// <param name="output">Internal representation of the msi database to operate upon.</param> | ||
26 | /// <param name="delayedFields">The fields which had resolution delayed.</param> | ||
27 | /// <param name="variableCache">The file information to use when resolving variables.</param> | ||
28 | /// <param name="modularizationGuid">The modularization guid (used in case of a merge module).</param> | ||
29 | public void Execute() | 32 | public void Execute() |
30 | { | 33 | { |
31 | var deferredFields = new List<IDelayedField>(); | 34 | var deferredFields = new List<IDelayedField>(); |
32 | 35 | ||
33 | foreach (IDelayedField delayedField in this.DelayedFields) | 36 | foreach (var delayedField in this.DelayedFields) |
34 | { | 37 | { |
35 | try | 38 | try |
36 | { | 39 | { |
@@ -42,7 +45,7 @@ namespace WixToolset.Core.Bind | |||
42 | var value = WixVariableResolver.ResolveDelayedVariables(propertyRow.SourceLineNumbers, delayedField.Field.AsString(), this.VariableCache); | 45 | var value = WixVariableResolver.ResolveDelayedVariables(propertyRow.SourceLineNumbers, delayedField.Field.AsString(), this.VariableCache); |
43 | 46 | ||
44 | // update the variable cache with the new value | 47 | // update the variable cache with the new value |
45 | var key = String.Concat("property.", Common.Demodularize(this.OutputType, this.ModularizationGuid, (string)propertyRow[0])); | 48 | var key = String.Concat("property.", propertyRow.AsString(0)); |
46 | this.VariableCache[key] = value; | 49 | this.VariableCache[key] = value; |
47 | 50 | ||
48 | // update the field data | 51 | // update the field data |
@@ -62,43 +65,31 @@ namespace WixToolset.Core.Bind | |||
62 | 65 | ||
63 | // add specialization for ProductVersion fields | 66 | // add specialization for ProductVersion fields |
64 | string keyProductVersion = "property.ProductVersion"; | 67 | string keyProductVersion = "property.ProductVersion"; |
65 | if (this.VariableCache.ContainsKey(keyProductVersion)) | 68 | if (this.VariableCache.TryGetValue(keyProductVersion, out var versionValue) && Version.TryParse(versionValue, out Version productVersion)) |
66 | { | 69 | { |
67 | string value = this.VariableCache[keyProductVersion]; | 70 | // Don't add the variable if it already exists (developer defined a property with the same name). |
68 | Version productVersion = null; | 71 | string fieldKey = String.Concat(keyProductVersion, ".Major"); |
69 | 72 | if (!this.VariableCache.ContainsKey(fieldKey)) | |
70 | try | ||
71 | { | 73 | { |
72 | productVersion = new Version(value); | 74 | this.VariableCache[fieldKey] = productVersion.Major.ToString(CultureInfo.InvariantCulture); |
73 | 75 | } | |
74 | // Don't add the variable if it already exists (developer defined a property with the same name). | ||
75 | string fieldKey = String.Concat(keyProductVersion, ".Major"); | ||
76 | if (!this.VariableCache.ContainsKey(fieldKey)) | ||
77 | { | ||
78 | this.VariableCache[fieldKey] = productVersion.Major.ToString(CultureInfo.InvariantCulture); | ||
79 | } | ||
80 | |||
81 | fieldKey = String.Concat(keyProductVersion, ".Minor"); | ||
82 | if (!this.VariableCache.ContainsKey(fieldKey)) | ||
83 | { | ||
84 | this.VariableCache[fieldKey] = productVersion.Minor.ToString(CultureInfo.InvariantCulture); | ||
85 | } | ||
86 | 76 | ||
87 | fieldKey = String.Concat(keyProductVersion, ".Build"); | 77 | fieldKey = String.Concat(keyProductVersion, ".Minor"); |
88 | if (!this.VariableCache.ContainsKey(fieldKey)) | 78 | if (!this.VariableCache.ContainsKey(fieldKey)) |
89 | { | 79 | { |
90 | this.VariableCache[fieldKey] = productVersion.Build.ToString(CultureInfo.InvariantCulture); | 80 | this.VariableCache[fieldKey] = productVersion.Minor.ToString(CultureInfo.InvariantCulture); |
91 | } | 81 | } |
92 | 82 | ||
93 | fieldKey = String.Concat(keyProductVersion, ".Revision"); | 83 | fieldKey = String.Concat(keyProductVersion, ".Build"); |
94 | if (!this.VariableCache.ContainsKey(fieldKey)) | 84 | if (!this.VariableCache.ContainsKey(fieldKey)) |
95 | { | 85 | { |
96 | this.VariableCache[fieldKey] = productVersion.Revision.ToString(CultureInfo.InvariantCulture); | 86 | this.VariableCache[fieldKey] = productVersion.Build.ToString(CultureInfo.InvariantCulture); |
97 | } | ||
98 | } | 87 | } |
99 | catch | 88 | |
89 | fieldKey = String.Concat(keyProductVersion, ".Revision"); | ||
90 | if (!this.VariableCache.ContainsKey(fieldKey)) | ||
100 | { | 91 | { |
101 | // Ignore the error introduced by new behavior. | 92 | this.VariableCache[fieldKey] = productVersion.Revision.ToString(CultureInfo.InvariantCulture); |
102 | } | 93 | } |
103 | } | 94 | } |
104 | 95 | ||
@@ -113,7 +104,6 @@ namespace WixToolset.Core.Bind | |||
113 | catch (WixException we) | 104 | catch (WixException we) |
114 | { | 105 | { |
115 | Messaging.Instance.OnMessage(we.Error); | 106 | Messaging.Instance.OnMessage(we.Error); |
116 | continue; | ||
117 | } | 107 | } |
118 | } | 108 | } |
119 | } | 109 | } |