diff options
Diffstat (limited to 'src/WixToolset.Core/Bind')
| -rw-r--r-- | src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs | 73 |
1 files changed, 25 insertions, 48 deletions
diff --git a/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs index a10b98dc..ebabed47 100644 --- a/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs +++ b/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs | |||
| @@ -69,11 +69,11 @@ namespace WixToolset.Core.Bind | |||
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | // add specialization for ProductVersion fields | 71 | // add specialization for ProductVersion fields |
| 72 | string keyProductVersion = "property.ProductVersion"; | 72 | var keyProductVersion = "property.ProductVersion"; |
| 73 | if (this.VariableCache.TryGetValue(keyProductVersion, out var versionValue) && Version.TryParse(versionValue, out Version productVersion)) | 73 | if (this.VariableCache.TryGetValue(keyProductVersion, out var versionValue) && Version.TryParse(versionValue, out Version productVersion)) |
| 74 | { | 74 | { |
| 75 | // Don't add the variable if it already exists (developer defined a property with the same name). | 75 | // Don't add the variable if it already exists (developer defined a property with the same name). |
| 76 | string fieldKey = String.Concat(keyProductVersion, ".Major"); | 76 | var fieldKey = String.Concat(keyProductVersion, ".Major"); |
| 77 | if (!this.VariableCache.ContainsKey(fieldKey)) | 77 | if (!this.VariableCache.ContainsKey(fieldKey)) |
| 78 | { | 78 | { |
| 79 | this.VariableCache[fieldKey] = productVersion.Major.ToString(CultureInfo.InvariantCulture); | 79 | this.VariableCache[fieldKey] = productVersion.Major.ToString(CultureInfo.InvariantCulture); |
| @@ -115,68 +115,45 @@ namespace WixToolset.Core.Bind | |||
| 115 | 115 | ||
| 116 | private static string ResolveDelayedVariables(SourceLineNumber sourceLineNumbers, string value, IDictionary<string, string> resolutionData) | 116 | private static string ResolveDelayedVariables(SourceLineNumber sourceLineNumbers, string value, IDictionary<string, string> resolutionData) |
| 117 | { | 117 | { |
| 118 | var matches = Common.WixVariableRegex.Matches(value); | 118 | var start = 0; |
| 119 | 119 | ||
| 120 | if (0 < matches.Count) | 120 | while (Common.TryParseWixVariable(value, start, out var parsed)) |
| 121 | { | 121 | { |
| 122 | var sb = new StringBuilder(value); | 122 | if (parsed.Namespace == "bind") |
| 123 | |||
| 124 | // notice how this code walks backward through the list | ||
| 125 | // because it modifies the string as we go through it | ||
| 126 | for (int i = matches.Count - 1; 0 <= i; i--) | ||
| 127 | { | 123 | { |
| 128 | string variableNamespace = matches[i].Groups["namespace"].Value; | 124 | var key = String.Concat(parsed.Name, ".", parsed.Scope); |
| 129 | string variableId = matches[i].Groups["fullname"].Value; | ||
| 130 | string variableDefaultValue = null; | ||
| 131 | string variableScope = null; | ||
| 132 | 125 | ||
| 133 | // get the default value if one was specified | 126 | if (!resolutionData.TryGetValue(key, out var resolvedValue)) |
| 134 | if (matches[i].Groups["value"].Success) | ||
| 135 | { | 127 | { |
| 136 | variableDefaultValue = matches[i].Groups["value"].Value; | 128 | resolvedValue = parsed.DefaultValue; |
| 137 | } | 129 | } |
| 138 | 130 | ||
| 139 | // get the scope if one was specified | 131 | // insert the resolved value if it was found or display an error |
| 140 | if (matches[i].Groups["scope"].Success) | 132 | if (null != resolvedValue) |
| 141 | { | 133 | { |
| 142 | variableScope = matches[i].Groups["scope"].Value; | 134 | if (parsed.Index == 0 && parsed.Length == value.Length) |
| 143 | if ("bind" == variableNamespace) | ||
| 144 | { | 135 | { |
| 145 | variableId = matches[i].Groups["name"].Value; | 136 | value = resolvedValue; |
| 137 | } | ||
| 138 | else | ||
| 139 | { | ||
| 140 | var sb = new StringBuilder(value); | ||
| 141 | sb.Remove(parsed.Index, parsed.Length); | ||
| 142 | sb.Insert(parsed.Index, resolvedValue); | ||
| 143 | value = sb.ToString(); | ||
| 146 | } | 144 | } |
| 147 | } | ||
| 148 | 145 | ||
| 149 | // check for an escape sequence of !! indicating the match is not a variable expression | 146 | start = parsed.Index; |
| 150 | if (0 < matches[i].Index && '!' == sb[matches[i].Index - 1]) | ||
| 151 | { | ||
| 152 | sb.Remove(matches[i].Index - 1, 1); | ||
| 153 | } | 147 | } |
| 154 | else | 148 | else |
| 155 | { | 149 | { |
| 156 | var key = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", variableId, variableScope).ToLower(CultureInfo.InvariantCulture); | 150 | throw new WixException(ErrorMessages.UnresolvedBindReference(sourceLineNumbers, value)); |
| 157 | |||
| 158 | if (!resolutionData.TryGetValue(key, out var resolvedValue)) | ||
| 159 | { | ||
| 160 | resolvedValue = variableDefaultValue; | ||
| 161 | } | ||
| 162 | |||
| 163 | if ("bind" == variableNamespace) | ||
| 164 | { | ||
| 165 | // insert the resolved value if it was found or display an error | ||
| 166 | if (null != resolvedValue) | ||
| 167 | { | ||
| 168 | sb.Remove(matches[i].Index, matches[i].Length); | ||
| 169 | sb.Insert(matches[i].Index, resolvedValue); | ||
| 170 | } | ||
| 171 | else | ||
| 172 | { | ||
| 173 | throw new WixException(ErrorMessages.UnresolvedBindReference(sourceLineNumbers, value)); | ||
| 174 | } | ||
| 175 | } | ||
| 176 | } | 151 | } |
| 177 | } | 152 | } |
| 178 | 153 | else | |
| 179 | value = sb.ToString(); | 154 | { |
| 155 | start = parsed.Index + parsed.Length; | ||
| 156 | } | ||
| 180 | } | 157 | } |
| 181 | 158 | ||
| 182 | return value; | 159 | return value; |
