diff options
Diffstat (limited to 'src/WixToolset.Core/WixVariableResolver.cs')
-rw-r--r-- | src/WixToolset.Core/WixVariableResolver.cs | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/WixToolset.Core/WixVariableResolver.cs b/src/WixToolset.Core/WixVariableResolver.cs index d437423c..357ff700 100644 --- a/src/WixToolset.Core/WixVariableResolver.cs +++ b/src/WixToolset.Core/WixVariableResolver.cs | |||
@@ -1,6 +1,6 @@ | |||
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. | 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 | 2 | ||
3 | namespace WixToolset | 3 | namespace WixToolset.Core |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
@@ -10,11 +10,12 @@ namespace WixToolset | |||
10 | using System.Text.RegularExpressions; | 10 | using System.Text.RegularExpressions; |
11 | using WixToolset.Data; | 11 | using WixToolset.Data; |
12 | using WixToolset.Data.Rows; | 12 | using WixToolset.Data.Rows; |
13 | using WixToolset.Extensibility; | ||
13 | 14 | ||
14 | /// <summary> | 15 | /// <summary> |
15 | /// WiX variable resolver. | 16 | /// WiX variable resolver. |
16 | /// </summary> | 17 | /// </summary> |
17 | public sealed class WixVariableResolver | 18 | internal sealed class WixVariableResolver : IBindVariableResolver |
18 | { | 19 | { |
19 | private Dictionary<string, string> wixVariables; | 20 | private Dictionary<string, string> wixVariables; |
20 | 21 | ||
@@ -31,7 +32,7 @@ namespace WixToolset | |||
31 | /// Gets or sets the localizer. | 32 | /// Gets or sets the localizer. |
32 | /// </summary> | 33 | /// </summary> |
33 | /// <value>The localizer.</value> | 34 | /// <value>The localizer.</value> |
34 | public Localizer Localizer { get; private set; } | 35 | private Localizer Localizer { get; } |
35 | 36 | ||
36 | /// <summary> | 37 | /// <summary> |
37 | /// Gets the count of variables added to the resolver. | 38 | /// Gets the count of variables added to the resolver. |
@@ -83,10 +84,7 @@ namespace WixToolset | |||
83 | /// <returns>The resolved value.</returns> | 84 | /// <returns>The resolved value.</returns> |
84 | public string ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly) | 85 | public string ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly) |
85 | { | 86 | { |
86 | bool isDefault = false; | 87 | return this.ResolveVariables(sourceLineNumbers, value, localizationOnly, out var defaultIgnored, out var delayedIgnored); |
87 | bool delayedResolve = false; | ||
88 | |||
89 | return this.ResolveVariables(sourceLineNumbers, value, localizationOnly, ref isDefault, ref delayedResolve); | ||
90 | } | 88 | } |
91 | 89 | ||
92 | /// <summary> | 90 | /// <summary> |
@@ -97,11 +95,9 @@ namespace WixToolset | |||
97 | /// <param name="localizationOnly">true to only resolve localization variables; false otherwise.</param> | 95 | /// <param name="localizationOnly">true to only resolve localization variables; false otherwise.</param> |
98 | /// <param name="isDefault">true if the resolved value was the default.</param> | 96 | /// <param name="isDefault">true if the resolved value was the default.</param> |
99 | /// <returns>The resolved value.</returns> | 97 | /// <returns>The resolved value.</returns> |
100 | public string ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly, ref bool isDefault) | 98 | public string ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly, out bool isDefault) |
101 | { | 99 | { |
102 | bool delayedResolve = false; | 100 | return this.ResolveVariables(sourceLineNumbers, value, localizationOnly, out isDefault, out var ignored); |
103 | |||
104 | return this.ResolveVariables(sourceLineNumbers, value, localizationOnly, ref isDefault, ref delayedResolve); | ||
105 | } | 101 | } |
106 | 102 | ||
107 | /// <summary> | 103 | /// <summary> |
@@ -114,9 +110,9 @@ namespace WixToolset | |||
114 | /// <param name="isDefault">true if the resolved value was the default.</param> | 110 | /// <param name="isDefault">true if the resolved value was the default.</param> |
115 | /// <param name="delayedResolve">true if the value has variables that cannot yet be resolved.</param> | 111 | /// <param name="delayedResolve">true if the value has variables that cannot yet be resolved.</param> |
116 | /// <returns>The resolved value.</returns> | 112 | /// <returns>The resolved value.</returns> |
117 | public string ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly, ref bool isDefault, ref bool delayedResolve) | 113 | public string ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly, out bool isDefault, out bool delayedResolve) |
118 | { | 114 | { |
119 | return this.ResolveVariables(sourceLineNumbers, value, localizationOnly, true, ref isDefault, ref delayedResolve); | 115 | return this.ResolveVariables(sourceLineNumbers, value, localizationOnly, true, out isDefault, out delayedResolve); |
120 | } | 116 | } |
121 | 117 | ||
122 | /// <summary> | 118 | /// <summary> |
@@ -129,7 +125,7 @@ namespace WixToolset | |||
129 | /// <param name="isDefault">true if the resolved value was the default.</param> | 125 | /// <param name="isDefault">true if the resolved value was the default.</param> |
130 | /// <param name="delayedResolve">true if the value has variables that cannot yet be resolved.</param> | 126 | /// <param name="delayedResolve">true if the value has variables that cannot yet be resolved.</param> |
131 | /// <returns>The resolved value.</returns> | 127 | /// <returns>The resolved value.</returns> |
132 | public string ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly, bool errorOnUnknown, ref bool isDefault, ref bool delayedResolve) | 128 | public string ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly, bool errorOnUnknown, out bool isDefault, out bool delayedResolve) |
133 | { | 129 | { |
134 | MatchCollection matches = Common.WixVariableRegex.Matches(value); | 130 | MatchCollection matches = Common.WixVariableRegex.Matches(value); |
135 | 131 | ||
@@ -190,10 +186,7 @@ namespace WixToolset | |||
190 | Messaging.Instance.OnMessage(WixWarnings.DeprecatedLocalizationVariablePrefix(sourceLineNumbers, variableId)); | 186 | Messaging.Instance.OnMessage(WixWarnings.DeprecatedLocalizationVariablePrefix(sourceLineNumbers, variableId)); |
191 | } | 187 | } |
192 | 188 | ||
193 | if (null != this.Localizer) | 189 | resolvedValue = this.Localizer?.GetLocalizedValue(variableId); |
194 | { | ||
195 | resolvedValue = this.Localizer.GetLocalizedValue(variableId); | ||
196 | } | ||
197 | } | 190 | } |
198 | else if (!localizationOnly && "wix" == variableNamespace) | 191 | else if (!localizationOnly && "wix" == variableNamespace) |
199 | { | 192 | { |
@@ -223,6 +216,7 @@ namespace WixToolset | |||
223 | } | 216 | } |
224 | else | 217 | else |
225 | { | 218 | { |
219 | |||
226 | // insert the resolved value if it was found or display an error | 220 | // insert the resolved value if it was found or display an error |
227 | if (null != resolvedValue) | 221 | if (null != resolvedValue) |
228 | { | 222 | { |
@@ -248,6 +242,19 @@ namespace WixToolset | |||
248 | } | 242 | } |
249 | 243 | ||
250 | /// <summary> | 244 | /// <summary> |
245 | /// Try to find localization information for dialog and (optional) control. | ||
246 | /// </summary> | ||
247 | /// <param name="dialog">Dialog identifier.</param> | ||
248 | /// <param name="control">Optional control identifier.</param> | ||
249 | /// <param name="localizedControl">Found localization information.</param> | ||
250 | /// <returns>True if localized control was found, otherwise false.</returns> | ||
251 | public bool TryGetLocalizedControl(string dialog, string control, out LocalizedControl localizedControl) | ||
252 | { | ||
253 | localizedControl = this.Localizer?.GetLocalizedControl(dialog, control); | ||
254 | return localizedControl != null; | ||
255 | } | ||
256 | |||
257 | /// <summary> | ||
251 | /// Resolve the delay variables in a value. | 258 | /// Resolve the delay variables in a value. |
252 | /// </summary> | 259 | /// </summary> |
253 | /// <param name="sourceLineNumbers">The source line information for the value.</param> | 260 | /// <param name="sourceLineNumbers">The source line information for the value.</param> |