Change SetVariable to format the value and convert it at search time.
Fixes #6724
Sean Hall committed
Feb 23, 2022 at 15:14 UTC
ab3daf1863af104523eadd3af143b835a81c2248
3 files changed
+38
-16
src/burn/engine/search.cpp
+31
-14
@@ -65,7 +65,6 @@ extern "C" HRESULT SearchesParseFromXml(
65
BSTR bstrNodeName = NULL;
66
BOOL fXmlFound = FALSE;
67
LPWSTR scz = NULL;
68
- BURN_VARIANT_TYPE valueType = BURN_VARIANT_TYPE_NONE;
68
69
// select search nodes
70
hr = XmlSelectNodes(pixnBundle, L"DirectorySearch|FileSearch|RegistrySearch|MsiComponentSearch|MsiProductSearch|MsiFeatureSearch|ExtensionSearch|SetVariable", &pixnNodes);
@@ -357,8 +356,8 @@ extern "C" HRESULT SearchesParseFromXml(
356
357
if (fXmlFound)
358
{
360
- hr = BVariantSetString(&pSearch->SetVariable.value, scz, 0, FALSE);
361
- ExitOnFailure(hr, "Failed to set variant value.");
359
+ pSearch->SetVariable.sczValue = scz;
360
+ scz = NULL;
361
362
// @Type
363
hr = XmlGetAttributeEx(pixnNode, L"Type", &scz);
@@ -366,19 +365,19 @@ extern "C" HRESULT SearchesParseFromXml(
365
366
if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"formatted", -1))
367
{
369
- valueType = BURN_VARIANT_TYPE_FORMATTED;
368
+ pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_FORMATTED;
369
}
370
else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"numeric", -1))
371
{
373
- valueType = BURN_VARIANT_TYPE_NUMERIC;
372
+ pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_NUMERIC;
373
}
374
else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"string", -1))
375
{
377
- valueType = BURN_VARIANT_TYPE_STRING;
376
+ pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_STRING;
377
}
378
else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"version", -1))
379
{
381
- valueType = BURN_VARIANT_TYPE_VERSION;
380
+ pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_VERSION;
381
}
382
else
383
{
@@ -387,12 +386,8 @@ extern "C" HRESULT SearchesParseFromXml(
386
}
387
else
388
{
390
- valueType = BURN_VARIANT_TYPE_NONE;
389
+ pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_NONE;
390
}
392
-
393
- // change value variant to correct type
394
- hr = BVariantChangeType(&pSearch->SetVariable.value, valueType);
395
- ExitOnFailure(hr, "Failed to change variant type.");
391
}
392
else
393
{
@@ -551,7 +546,7 @@ extern "C" void SearchesUninitialize(
546
ReleaseStr(pSearch->MsiProductSearch.sczGuid);
547
break;
548
case BURN_SEARCH_TYPE_SET_VARIABLE:
554
- BVariantUninitialize(&pSearch->SetVariable.value);
549
+ ReleaseStr(pSearch->SetVariable.sczValue);
550
break;
551
}
552
}
@@ -1207,10 +1202,32 @@ static HRESULT PerformSetVariable(
1202
)
1203
{
1204
HRESULT hr = S_OK;
1205
+ BURN_VARIANT newValue = { };
1206
+ LPWSTR sczFormattedValue = NULL;
1207
+ SIZE_T cchOut = 0;
1208
+
1209
+ if (BURN_VARIANT_TYPE_NONE == pSearch->SetVariable.targetType)
1210
+ {
1211
+ BVariantUninitialize(&newValue);
1212
+ }
1213
+ else
1214
+ {
1215
+ hr = VariableFormatString(pVariables, pSearch->SetVariable.sczValue, &sczFormattedValue, &cchOut);
1216
+ ExitOnFailure(hr, "Failed to format search value.");
1217
+
1218
+ hr = BVariantSetString(&newValue, sczFormattedValue, 0, FALSE);
1219
+ ExitOnFailure(hr, "Failed to set variant value.");
1220
1211
- hr = VariableSetVariant(pVariables, pSearch->sczVariable, &pSearch->SetVariable.value);
1221
+ // change value variant to correct type
1222
+ hr = BVariantChangeType(&newValue, pSearch->SetVariable.targetType);
1223
+ ExitOnFailure(hr, "Failed to change variant type.");
1224
+ }
1225
+
1226
+ hr = VariableSetVariant(pVariables, pSearch->sczVariable, &newValue);
1227
ExitOnFailure(hr, "Failed to set variable: %ls", pSearch->sczVariable);
1228
1229
LExit:
1230
+ BVariantUninitialize(&newValue);
1231
+
1232
return hr;
1233
}
src/burn/engine/search.h
+2
-1
@@ -117,7 +117,8 @@ typedef struct _BURN_SEARCH
117
} ExtensionSearch;
118
struct
119
{
120
- BURN_VARIANT value;
120
+ LPWSTR sczValue;
121
+ BURN_VARIANT_TYPE targetType;
122
} SetVariable;
123
};
124
} BURN_SEARCH;
src/burn/test/BurnUnitTest/SearchTest.cpp
+5
-1
@@ -523,7 +523,7 @@ namespace Bootstrapper
523
L" <SetVariable Id='Search6' Type='string' Value='VAL6' Variable='PROP6' />"
524
L" <SetVariable Id='Search7' Type='string' Value='7' Variable='PROP7' />"
525
L" <SetVariable Id='Search8' Type='version' Value='1.1.0.0' Variable='PROP8' />"
526
- L" <SetVariable Id='Search9' Type='formatted' Value='[VAL9]' Variable='PROP9' />"
526
+ L" <SetVariable Id='Search9' Type='formatted' Value='[\\[]VAL9[\\]]' Variable='PROP9' />"
527
L" <SetVariable Id='Search10' Type='numeric' Value='42' Variable='OVERWRITTEN_STRING' />"
528
L" <SetVariable Id='Search11' Type='string' Value='NEW' Variable='OVERWRITTEN_NUMBER' />"
529
L" <SetVariable Id='Search12' Variable='REMOVED_NUMBER' />"
@@ -549,7 +549,9 @@ namespace Bootstrapper
549
550
// check variable values
551
Assert::Equal<String^>(gcnew String(L"VAL1"), VariableGetStringHelper(&variables, L"PROP1"));
552
+ Assert::Equal((int)BURN_VARIANT_TYPE_STRING, VariableGetTypeHelper(&variables, L"PROP1"));
553
Assert::Equal(2ll, VariableGetNumericHelper(&variables, L"PROP2"));
554
+ Assert::Equal((int)BURN_VARIANT_TYPE_NUMERIC, VariableGetTypeHelper(&variables, L"PROP2"));
555
Assert::Equal<String^>(gcnew String(L"2"), VariableGetStringHelper(&variables, L"PROP2"));
556
Assert::Equal<String^>(gcnew String(L"VAL3"), VariableGetStringHelper(&variables, L"PROP3"));
557
Assert::Equal<String^>(gcnew String(L"VAL4"), VariableGetStringHelper(&variables, L"PROP4"));
@@ -557,8 +559,10 @@ namespace Bootstrapper
559
Assert::Equal<String^>(gcnew String(L"VAL6"), VariableGetStringHelper(&variables, L"PROP6"));
560
Assert::Equal(7ll, VariableGetNumericHelper(&variables, L"PROP7"));
561
Assert::Equal<String^>(gcnew String(L"1.1.0.0"), VariableGetVersionHelper(&variables, L"PROP8"));
562
+ Assert::Equal((int)BURN_VARIANT_TYPE_VERSION, VariableGetTypeHelper(&variables, L"PROP8"));
563
Assert::Equal<String^>(gcnew String(L"1.1.0.0"), VariableGetStringHelper(&variables, L"PROP8"));
564
Assert::Equal<String^>(gcnew String(L"[VAL9]"), VariableGetStringHelper(&variables, L"PROP9"));
565
+ Assert::Equal((int)BURN_VARIANT_TYPE_FORMATTED, VariableGetTypeHelper(&variables, L"PROP9"));
566
567
Assert::Equal(42ll, VariableGetNumericHelper(&variables, L"OVERWRITTEN_STRING"));
568
Assert::Equal<String^>(gcnew String(L"NEW"), VariableGetStringHelper(&variables, L"OVERWRITTEN_NUMBER"));