aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/WixVariableResolver.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/WixVariableResolver.cs')
-rw-r--r--src/WixToolset.Core/WixVariableResolver.cs77
1 files changed, 17 insertions, 60 deletions
diff --git a/src/WixToolset.Core/WixVariableResolver.cs b/src/WixToolset.Core/WixVariableResolver.cs
index f8bccef0..7339840e 100644
--- a/src/WixToolset.Core/WixVariableResolver.cs
+++ b/src/WixToolset.Core/WixVariableResolver.cs
@@ -9,8 +9,6 @@ namespace WixToolset.Core
9 using System.Text; 9 using System.Text;
10 using System.Text.RegularExpressions; 10 using System.Text.RegularExpressions;
11 using WixToolset.Data; 11 using WixToolset.Data;
12 using WixToolset.Data.Tuples;
13 using WixToolset.Extensibility;
14 using WixToolset.Extensibility.Services; 12 using WixToolset.Extensibility.Services;
15 13
16 /// <summary> 14 /// <summary>
@@ -37,14 +35,15 @@ namespace WixToolset.Core
37 /// <summary> 35 /// <summary>
38 /// Gets the count of variables added to the resolver. 36 /// Gets the count of variables added to the resolver.
39 /// </summary> 37 /// </summary>
40 public int VariableCount => this.wixVariables.Count; 38 public int VariableCount => this.wixVariables.Count;
41 39
42 /// <summary> 40 /// <summary>
43 /// Add a variable. 41 /// Add a variable.
44 /// </summary> 42 /// </summary>
45 /// <param name="name">The name of the variable.</param> 43 /// <param name="name">The name of the variable.</param>
46 /// <param name="value">The value of the variable.</param> 44 /// <param name="value">The value of the variable.</param>
47 public void AddVariable(string name, string value) 45 /// <param name="overridable">Indicates whether the variable can be overridden by an existing variable.</param>
46 public void AddVariable(string name, string value, bool overridable)
48 { 47 {
49 try 48 try
50 { 49 {
@@ -52,25 +51,9 @@ namespace WixToolset.Core
52 } 51 }
53 catch (ArgumentException) 52 catch (ArgumentException)
54 { 53 {
55 this.Messaging.Write(ErrorMessages.WixVariableCollision(null, name)); 54 if (!overridable)
56 }
57 }
58
59 /// <summary>
60 /// Add a variable.
61 /// </summary>
62 /// <param name="wixVariableRow">The WixVariableRow to add.</param>
63 public void AddVariable(WixVariableTuple wixVariableRow)
64 {
65 try
66 {
67 this.wixVariables.Add(wixVariableRow.WixVariable, wixVariableRow.Value);
68 }
69 catch (ArgumentException)
70 {
71 if (!wixVariableRow.Overridable) // collision
72 { 55 {
73 this.Messaging.Write(ErrorMessages.WixVariableCollision(wixVariableRow.SourceLineNumbers, wixVariableRow.WixVariable)); 56 throw;
74 } 57 }
75 } 58 }
76 } 59 }
@@ -82,37 +65,9 @@ namespace WixToolset.Core
82 /// <param name="value">The value to resolve.</param> 65 /// <param name="value">The value to resolve.</param>
83 /// <param name="localizationOnly">true to only resolve localization variables; false otherwise.</param> 66 /// <param name="localizationOnly">true to only resolve localization variables; false otherwise.</param>
84 /// <returns>The resolved value.</returns> 67 /// <returns>The resolved value.</returns>
85 public string ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly) 68 public BindVariableResolution ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly)
86 { 69 {
87 return this.ResolveVariables(sourceLineNumbers, value, localizationOnly, out var defaultIgnored, out var delayedIgnored); 70 return this.ResolveVariables(sourceLineNumbers, value, localizationOnly, true);
88 }
89
90 /// <summary>
91 /// Resolve the wix variables in a value.
92 /// </summary>
93 /// <param name="sourceLineNumbers">The source line information for the value.</param>
94 /// <param name="value">The value to resolve.</param>
95 /// <param name="localizationOnly">true to only resolve localization variables; false otherwise.</param>
96 /// <param name="isDefault">true if the resolved value was the default.</param>
97 /// <returns>The resolved value.</returns>
98 public string ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly, out bool isDefault)
99 {
100 return this.ResolveVariables(sourceLineNumbers, value, localizationOnly, out isDefault, out var ignored);
101 }
102
103 /// <summary>
104 /// Resolve the wix variables in a value.
105 /// </summary>
106 /// <param name="sourceLineNumbers">The source line information for the value.</param>
107 /// <param name="value">The value to resolve.</param>
108 /// <param name="localizationOnly">true to only resolve localization variables; false otherwise.</param>
109 /// <param name="errorOnUnknown">true if unknown variables should throw errors.</param>
110 /// <param name="isDefault">true if the resolved value was the default.</param>
111 /// <param name="delayedResolve">true if the value has variables that cannot yet be resolved.</param>
112 /// <returns>The resolved value.</returns>
113 public string ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly, out bool isDefault, out bool delayedResolve)
114 {
115 return this.ResolveVariables(sourceLineNumbers, value, localizationOnly, true, out isDefault, out delayedResolve);
116 } 71 }
117 72
118 /// <summary> 73 /// <summary>
@@ -125,13 +80,12 @@ namespace WixToolset.Core
125 /// <param name="isDefault">true if the resolved value was the default.</param> 80 /// <param name="isDefault">true if the resolved value was the default.</param>
126 /// <param name="delayedResolve">true if the value has variables that cannot yet be resolved.</param> 81 /// <param name="delayedResolve">true if the value has variables that cannot yet be resolved.</param>
127 /// <returns>The resolved value.</returns> 82 /// <returns>The resolved value.</returns>
128 public string ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly, bool errorOnUnknown, out bool isDefault, out bool delayedResolve) 83 internal BindVariableResolution ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly, bool errorOnUnknown)
129 { 84 {
130 MatchCollection matches = Common.WixVariableRegex.Matches(value); 85 MatchCollection matches = Common.WixVariableRegex.Matches(value);
131 86
132 // the value is the default unless its substituted further down 87 // the value is the default unless its substituted further down
133 isDefault = true; 88 var result = new BindVariableResolution { IsDefault = true, Value = value };
134 delayedResolve = false;
135 89
136 if (0 < matches.Count) 90 if (0 < matches.Count)
137 { 91 {
@@ -172,6 +126,8 @@ namespace WixToolset.Core
172 if (!localizationOnly) 126 if (!localizationOnly)
173 { 127 {
174 sb.Remove(matches[i].Index - 1, 1); 128 sb.Remove(matches[i].Index - 1, 1);
129
130 result.UpdatedValue = true;
175 } 131 }
176 } 132 }
177 else 133 else
@@ -200,7 +156,7 @@ namespace WixToolset.Core
200 if (this.wixVariables.TryGetValue(variableId, out resolvedValue)) 156 if (this.wixVariables.TryGetValue(variableId, out resolvedValue))
201 { 157 {
202 resolvedValue = resolvedValue ?? String.Empty; 158 resolvedValue = resolvedValue ?? String.Empty;
203 isDefault = false; 159 result.IsDefault = false;
204 } 160 }
205 else if (null != variableDefaultValue) // default the resolved value to the inline value if one was specified 161 else if (null != variableDefaultValue) // default the resolved value to the inline value if one was specified
206 { 162 {
@@ -212,16 +168,17 @@ namespace WixToolset.Core
212 if ("bind" == variableNamespace) 168 if ("bind" == variableNamespace)
213 { 169 {
214 // can't resolve these yet, but keep track of where we find them so they can be resolved later with less effort 170 // can't resolve these yet, but keep track of where we find them so they can be resolved later with less effort
215 delayedResolve = true; 171 result.DelayedResolve = true;
216 } 172 }
217 else 173 else
218 { 174 {
219
220 // insert the resolved value if it was found or display an error 175 // insert the resolved value if it was found or display an error
221 if (null != resolvedValue) 176 if (null != resolvedValue)
222 { 177 {
223 sb.Remove(matches[i].Index, matches[i].Length); 178 sb.Remove(matches[i].Index, matches[i].Length);
224 sb.Insert(matches[i].Index, resolvedValue); 179 sb.Insert(matches[i].Index, resolvedValue);
180
181 result.UpdatedValue = true;
225 } 182 }
226 else if ("loc" == variableNamespace && errorOnUnknown) // unresolved loc variable 183 else if ("loc" == variableNamespace && errorOnUnknown) // unresolved loc variable
227 { 184 {
@@ -235,10 +192,10 @@ namespace WixToolset.Core
235 } 192 }
236 } 193 }
237 194
238 value = sb.ToString(); 195 result.Value = sb.ToString();
239 } 196 }
240 197
241 return value; 198 return result;
242 } 199 }
243 200
244 /// <summary> 201 /// <summary>