diff options
Diffstat (limited to 'src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs')
-rw-r--r-- | src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs index 3ded9a87..6f8da9ec 100644 --- a/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs +++ b/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs | |||
@@ -5,6 +5,7 @@ namespace WixToolset.Core.Bind | |||
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
7 | using System.Globalization; | 7 | using System.Globalization; |
8 | using System.Text; | ||
8 | using WixToolset.Data; | 9 | using WixToolset.Data; |
9 | using WixToolset.Extensibility; | 10 | using WixToolset.Extensibility; |
10 | using WixToolset.Extensibility.Services; | 11 | using WixToolset.Extensibility.Services; |
@@ -46,7 +47,7 @@ namespace WixToolset.Core.Bind | |||
46 | // process properties first in case they refer to other binder variables | 47 | // process properties first in case they refer to other binder variables |
47 | if (delayedField.Row.Definition.Type == TupleDefinitionType.Property) | 48 | if (delayedField.Row.Definition.Type == TupleDefinitionType.Property) |
48 | { | 49 | { |
49 | var value = WixVariableResolver.ResolveDelayedVariables(propertyRow.SourceLineNumbers, delayedField.Field.AsString(), this.VariableCache); | 50 | var value = ResolveDelayedVariables(propertyRow.SourceLineNumbers, delayedField.Field.AsString(), this.VariableCache); |
50 | 51 | ||
51 | // update the variable cache with the new value | 52 | // update the variable cache with the new value |
52 | var key = String.Concat("property.", propertyRow.AsString(0)); | 53 | var key = String.Concat("property.", propertyRow.AsString(0)); |
@@ -102,7 +103,7 @@ namespace WixToolset.Core.Bind | |||
102 | { | 103 | { |
103 | try | 104 | try |
104 | { | 105 | { |
105 | var value = WixVariableResolver.ResolveDelayedVariables(delayedField.Row.SourceLineNumbers, delayedField.Field.AsString(), this.VariableCache); | 106 | var value = ResolveDelayedVariables(delayedField.Row.SourceLineNumbers, delayedField.Field.AsString(), this.VariableCache); |
106 | delayedField.Field.Set(value); | 107 | delayedField.Field.Set(value); |
107 | } | 108 | } |
108 | catch (WixException we) | 109 | catch (WixException we) |
@@ -111,5 +112,75 @@ namespace WixToolset.Core.Bind | |||
111 | } | 112 | } |
112 | } | 113 | } |
113 | } | 114 | } |
115 | |||
116 | public static string ResolveDelayedVariables(SourceLineNumber sourceLineNumbers, string value, IDictionary<string, string> resolutionData) | ||
117 | { | ||
118 | var matches = Common.WixVariableRegex.Matches(value); | ||
119 | |||
120 | if (0 < matches.Count) | ||
121 | { | ||
122 | var sb = new StringBuilder(value); | ||
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 | { | ||
128 | string variableNamespace = matches[i].Groups["namespace"].Value; | ||
129 | string variableId = matches[i].Groups["fullname"].Value; | ||
130 | string variableDefaultValue = null; | ||
131 | string variableScope = null; | ||
132 | |||
133 | // get the default value if one was specified | ||
134 | if (matches[i].Groups["value"].Success) | ||
135 | { | ||
136 | variableDefaultValue = matches[i].Groups["value"].Value; | ||
137 | } | ||
138 | |||
139 | // get the scope if one was specified | ||
140 | if (matches[i].Groups["scope"].Success) | ||
141 | { | ||
142 | variableScope = matches[i].Groups["scope"].Value; | ||
143 | if ("bind" == variableNamespace) | ||
144 | { | ||
145 | variableId = matches[i].Groups["name"].Value; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | // check for an escape sequence of !! indicating the match is not a variable expression | ||
150 | if (0 < matches[i].Index && '!' == sb[matches[i].Index - 1]) | ||
151 | { | ||
152 | sb.Remove(matches[i].Index - 1, 1); | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | string key = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", variableId, variableScope).ToLower(CultureInfo.InvariantCulture); | ||
157 | string resolvedValue = variableDefaultValue; | ||
158 | |||
159 | if (resolutionData.ContainsKey(key)) | ||
160 | { | ||
161 | resolvedValue = resolutionData[key]; | ||
162 | } | ||
163 | |||
164 | if ("bind" == variableNamespace) | ||
165 | { | ||
166 | // insert the resolved value if it was found or display an error | ||
167 | if (null != resolvedValue) | ||
168 | { | ||
169 | sb.Remove(matches[i].Index, matches[i].Length); | ||
170 | sb.Insert(matches[i].Index, resolvedValue); | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | throw new WixException(ErrorMessages.UnresolvedBindReference(sourceLineNumbers, value)); | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | |||
180 | value = sb.ToString(); | ||
181 | } | ||
182 | |||
183 | return value; | ||
184 | } | ||
114 | } | 185 | } |
115 | } | 186 | } |