diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2022-02-23 15:14:46 -0600 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-02-23 16:03:11 -0600 |
commit | ab3daf1863af104523eadd3af143b835a81c2248 (patch) | |
tree | 03e87e91c1dfe693c81196240c02f04030b4a648 | |
parent | b30c6891216770adb9c46c9904c681dc3ccb1011 (diff) | |
download | wix-ab3daf1863af104523eadd3af143b835a81c2248.tar.gz wix-ab3daf1863af104523eadd3af143b835a81c2248.tar.bz2 wix-ab3daf1863af104523eadd3af143b835a81c2248.zip |
Change SetVariable to format the value and convert it at search time.
Fixes #6724
-rw-r--r-- | src/burn/engine/search.cpp | 45 | ||||
-rw-r--r-- | src/burn/engine/search.h | 3 | ||||
-rw-r--r-- | src/burn/test/BurnUnitTest/SearchTest.cpp | 6 |
3 files changed, 38 insertions, 16 deletions
diff --git a/src/burn/engine/search.cpp b/src/burn/engine/search.cpp index 46dd2395..a57e703e 100644 --- a/src/burn/engine/search.cpp +++ b/src/burn/engine/search.cpp | |||
@@ -65,7 +65,6 @@ extern "C" HRESULT SearchesParseFromXml( | |||
65 | BSTR bstrNodeName = NULL; | 65 | BSTR bstrNodeName = NULL; |
66 | BOOL fXmlFound = FALSE; | 66 | BOOL fXmlFound = FALSE; |
67 | LPWSTR scz = NULL; | 67 | LPWSTR scz = NULL; |
68 | BURN_VARIANT_TYPE valueType = BURN_VARIANT_TYPE_NONE; | ||
69 | 68 | ||
70 | // select search nodes | 69 | // select search nodes |
71 | hr = XmlSelectNodes(pixnBundle, L"DirectorySearch|FileSearch|RegistrySearch|MsiComponentSearch|MsiProductSearch|MsiFeatureSearch|ExtensionSearch|SetVariable", &pixnNodes); | 70 | hr = XmlSelectNodes(pixnBundle, L"DirectorySearch|FileSearch|RegistrySearch|MsiComponentSearch|MsiProductSearch|MsiFeatureSearch|ExtensionSearch|SetVariable", &pixnNodes); |
@@ -357,8 +356,8 @@ extern "C" HRESULT SearchesParseFromXml( | |||
357 | 356 | ||
358 | if (fXmlFound) | 357 | if (fXmlFound) |
359 | { | 358 | { |
360 | hr = BVariantSetString(&pSearch->SetVariable.value, scz, 0, FALSE); | 359 | pSearch->SetVariable.sczValue = scz; |
361 | ExitOnFailure(hr, "Failed to set variant value."); | 360 | scz = NULL; |
362 | 361 | ||
363 | // @Type | 362 | // @Type |
364 | hr = XmlGetAttributeEx(pixnNode, L"Type", &scz); | 363 | hr = XmlGetAttributeEx(pixnNode, L"Type", &scz); |
@@ -366,19 +365,19 @@ extern "C" HRESULT SearchesParseFromXml( | |||
366 | 365 | ||
367 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"formatted", -1)) | 366 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"formatted", -1)) |
368 | { | 367 | { |
369 | valueType = BURN_VARIANT_TYPE_FORMATTED; | 368 | pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_FORMATTED; |
370 | } | 369 | } |
371 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"numeric", -1)) | 370 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"numeric", -1)) |
372 | { | 371 | { |
373 | valueType = BURN_VARIANT_TYPE_NUMERIC; | 372 | pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_NUMERIC; |
374 | } | 373 | } |
375 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"string", -1)) | 374 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"string", -1)) |
376 | { | 375 | { |
377 | valueType = BURN_VARIANT_TYPE_STRING; | 376 | pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_STRING; |
378 | } | 377 | } |
379 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"version", -1)) | 378 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"version", -1)) |
380 | { | 379 | { |
381 | valueType = BURN_VARIANT_TYPE_VERSION; | 380 | pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_VERSION; |
382 | } | 381 | } |
383 | else | 382 | else |
384 | { | 383 | { |
@@ -387,12 +386,8 @@ extern "C" HRESULT SearchesParseFromXml( | |||
387 | } | 386 | } |
388 | else | 387 | else |
389 | { | 388 | { |
390 | valueType = BURN_VARIANT_TYPE_NONE; | 389 | pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_NONE; |
391 | } | 390 | } |
392 | |||
393 | // change value variant to correct type | ||
394 | hr = BVariantChangeType(&pSearch->SetVariable.value, valueType); | ||
395 | ExitOnFailure(hr, "Failed to change variant type."); | ||
396 | } | 391 | } |
397 | else | 392 | else |
398 | { | 393 | { |
@@ -551,7 +546,7 @@ extern "C" void SearchesUninitialize( | |||
551 | ReleaseStr(pSearch->MsiProductSearch.sczGuid); | 546 | ReleaseStr(pSearch->MsiProductSearch.sczGuid); |
552 | break; | 547 | break; |
553 | case BURN_SEARCH_TYPE_SET_VARIABLE: | 548 | case BURN_SEARCH_TYPE_SET_VARIABLE: |
554 | BVariantUninitialize(&pSearch->SetVariable.value); | 549 | ReleaseStr(pSearch->SetVariable.sczValue); |
555 | break; | 550 | break; |
556 | } | 551 | } |
557 | } | 552 | } |
@@ -1207,10 +1202,32 @@ static HRESULT PerformSetVariable( | |||
1207 | ) | 1202 | ) |
1208 | { | 1203 | { |
1209 | HRESULT hr = S_OK; | 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."); | ||
1210 | 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); | ||
1212 | ExitOnFailure(hr, "Failed to set variable: %ls", pSearch->sczVariable); | 1227 | ExitOnFailure(hr, "Failed to set variable: %ls", pSearch->sczVariable); |
1213 | 1228 | ||
1214 | LExit: | 1229 | LExit: |
1230 | BVariantUninitialize(&newValue); | ||
1231 | |||
1215 | return hr; | 1232 | return hr; |
1216 | } | 1233 | } |
diff --git a/src/burn/engine/search.h b/src/burn/engine/search.h index 6397d2a3..bc53f197 100644 --- a/src/burn/engine/search.h +++ b/src/burn/engine/search.h | |||
@@ -117,7 +117,8 @@ typedef struct _BURN_SEARCH | |||
117 | } ExtensionSearch; | 117 | } ExtensionSearch; |
118 | struct | 118 | struct |
119 | { | 119 | { |
120 | BURN_VARIANT value; | 120 | LPWSTR sczValue; |
121 | BURN_VARIANT_TYPE targetType; | ||
121 | } SetVariable; | 122 | } SetVariable; |
122 | }; | 123 | }; |
123 | } BURN_SEARCH; | 124 | } BURN_SEARCH; |
diff --git a/src/burn/test/BurnUnitTest/SearchTest.cpp b/src/burn/test/BurnUnitTest/SearchTest.cpp index de38f2d8..06ffd017 100644 --- a/src/burn/test/BurnUnitTest/SearchTest.cpp +++ b/src/burn/test/BurnUnitTest/SearchTest.cpp | |||
@@ -523,7 +523,7 @@ namespace Bootstrapper | |||
523 | L" <SetVariable Id='Search6' Type='string' Value='VAL6' Variable='PROP6' />" | 523 | L" <SetVariable Id='Search6' Type='string' Value='VAL6' Variable='PROP6' />" |
524 | L" <SetVariable Id='Search7' Type='string' Value='7' Variable='PROP7' />" | 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' />" | 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' />" | 527 | L" <SetVariable Id='Search10' Type='numeric' Value='42' Variable='OVERWRITTEN_STRING' />" |
528 | L" <SetVariable Id='Search11' Type='string' Value='NEW' Variable='OVERWRITTEN_NUMBER' />" | 528 | L" <SetVariable Id='Search11' Type='string' Value='NEW' Variable='OVERWRITTEN_NUMBER' />" |
529 | L" <SetVariable Id='Search12' Variable='REMOVED_NUMBER' />" | 529 | L" <SetVariable Id='Search12' Variable='REMOVED_NUMBER' />" |
@@ -549,7 +549,9 @@ namespace Bootstrapper | |||
549 | 549 | ||
550 | // check variable values | 550 | // check variable values |
551 | Assert::Equal<String^>(gcnew String(L"VAL1"), VariableGetStringHelper(&variables, L"PROP1")); | 551 | Assert::Equal<String^>(gcnew String(L"VAL1"), VariableGetStringHelper(&variables, L"PROP1")); |
552 | Assert::Equal((int)BURN_VARIANT_TYPE_STRING, VariableGetTypeHelper(&variables, L"PROP1")); | ||
552 | Assert::Equal(2ll, VariableGetNumericHelper(&variables, L"PROP2")); | 553 | Assert::Equal(2ll, VariableGetNumericHelper(&variables, L"PROP2")); |
554 | Assert::Equal((int)BURN_VARIANT_TYPE_NUMERIC, VariableGetTypeHelper(&variables, L"PROP2")); | ||
553 | Assert::Equal<String^>(gcnew String(L"2"), VariableGetStringHelper(&variables, L"PROP2")); | 555 | Assert::Equal<String^>(gcnew String(L"2"), VariableGetStringHelper(&variables, L"PROP2")); |
554 | Assert::Equal<String^>(gcnew String(L"VAL3"), VariableGetStringHelper(&variables, L"PROP3")); | 556 | Assert::Equal<String^>(gcnew String(L"VAL3"), VariableGetStringHelper(&variables, L"PROP3")); |
555 | Assert::Equal<String^>(gcnew String(L"VAL4"), VariableGetStringHelper(&variables, L"PROP4")); | 557 | Assert::Equal<String^>(gcnew String(L"VAL4"), VariableGetStringHelper(&variables, L"PROP4")); |
@@ -557,8 +559,10 @@ namespace Bootstrapper | |||
557 | Assert::Equal<String^>(gcnew String(L"VAL6"), VariableGetStringHelper(&variables, L"PROP6")); | 559 | Assert::Equal<String^>(gcnew String(L"VAL6"), VariableGetStringHelper(&variables, L"PROP6")); |
558 | Assert::Equal(7ll, VariableGetNumericHelper(&variables, L"PROP7")); | 560 | Assert::Equal(7ll, VariableGetNumericHelper(&variables, L"PROP7")); |
559 | Assert::Equal<String^>(gcnew String(L"1.1.0.0"), VariableGetVersionHelper(&variables, L"PROP8")); | 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")); | ||
560 | Assert::Equal<String^>(gcnew String(L"1.1.0.0"), VariableGetStringHelper(&variables, L"PROP8")); | 563 | Assert::Equal<String^>(gcnew String(L"1.1.0.0"), VariableGetStringHelper(&variables, L"PROP8")); |
561 | Assert::Equal<String^>(gcnew String(L"[VAL9]"), VariableGetStringHelper(&variables, L"PROP9")); | 564 | Assert::Equal<String^>(gcnew String(L"[VAL9]"), VariableGetStringHelper(&variables, L"PROP9")); |
565 | Assert::Equal((int)BURN_VARIANT_TYPE_FORMATTED, VariableGetTypeHelper(&variables, L"PROP9")); | ||
562 | 566 | ||
563 | Assert::Equal(42ll, VariableGetNumericHelper(&variables, L"OVERWRITTEN_STRING")); | 567 | Assert::Equal(42ll, VariableGetNumericHelper(&variables, L"OVERWRITTEN_STRING")); |
564 | Assert::Equal<String^>(gcnew String(L"NEW"), VariableGetStringHelper(&variables, L"OVERWRITTEN_NUMBER")); | 568 | Assert::Equal<String^>(gcnew String(L"NEW"), VariableGetStringHelper(&variables, L"OVERWRITTEN_NUMBER")); |