diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-12-30 17:09:15 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-12-30 17:09:15 -0800 |
| commit | c5190ae74ab8fe13609362efce88fa4b8cc24f34 (patch) | |
| tree | e7762224afad491c37b70bab13756552c72fdd26 /src/WixToolset.Core/Bind | |
| parent | d4f73e72985dc2f36e4228358f4dc9b6114414ab (diff) | |
| download | wix-c5190ae74ab8fe13609362efce88fa4b8cc24f34.tar.gz wix-c5190ae74ab8fe13609362efce88fa4b8cc24f34.tar.bz2 wix-c5190ae74ab8fe13609362efce88fa4b8cc24f34.zip | |
Fix resolution of localizations that are embedded in intermediates
Diffstat (limited to 'src/WixToolset.Core/Bind')
| -rw-r--r-- | src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs | 75 | ||||
| -rw-r--r-- | src/WixToolset.Core/Bind/ResolveFieldsCommand.cs | 4 |
2 files changed, 75 insertions, 4 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 | } |
diff --git a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs index 824eb9a5..744f022c 100644 --- a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs +++ b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs | |||
| @@ -18,7 +18,7 @@ namespace WixToolset.Core.Bind | |||
| 18 | 18 | ||
| 19 | public bool BuildingPatch { private get; set; } | 19 | public bool BuildingPatch { private get; set; } |
| 20 | 20 | ||
| 21 | public IBindVariableResolver BindVariableResolver { private get; set; } | 21 | public IVariableResolver VariableResolver { private get; set; } |
| 22 | 22 | ||
| 23 | public IEnumerable<BindPath> BindPaths { private get; set; } | 23 | public IEnumerable<BindPath> BindPaths { private get; set; } |
| 24 | 24 | ||
| @@ -62,7 +62,7 @@ namespace WixToolset.Core.Bind | |||
| 62 | var original = field.AsString(); | 62 | var original = field.AsString(); |
| 63 | if (!String.IsNullOrEmpty(original)) | 63 | if (!String.IsNullOrEmpty(original)) |
| 64 | { | 64 | { |
| 65 | var resolution = this.BindVariableResolver.ResolveVariables(row.SourceLineNumbers, original, false); | 65 | var resolution = this.VariableResolver.ResolveVariables(row.SourceLineNumbers, original, false); |
| 66 | if (resolution.UpdatedValue) | 66 | if (resolution.UpdatedValue) |
| 67 | { | 67 | { |
| 68 | field.Set(resolution.Value); | 68 | field.Set(resolution.Value); |
