From ab3daf1863af104523eadd3af143b835a81c2248 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 23 Feb 2022 15:14:46 -0600 Subject: Change SetVariable to format the value and convert it at search time. Fixes #6724 --- src/burn/engine/search.cpp | 45 +++++++++++++++++++++---------- src/burn/engine/search.h | 3 ++- src/burn/test/BurnUnitTest/SearchTest.cpp | 6 ++++- 3 files changed, 38 insertions(+), 16 deletions(-) (limited to 'src/burn') 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( BSTR bstrNodeName = NULL; BOOL fXmlFound = FALSE; LPWSTR scz = NULL; - BURN_VARIANT_TYPE valueType = BURN_VARIANT_TYPE_NONE; // select search nodes hr = XmlSelectNodes(pixnBundle, L"DirectorySearch|FileSearch|RegistrySearch|MsiComponentSearch|MsiProductSearch|MsiFeatureSearch|ExtensionSearch|SetVariable", &pixnNodes); @@ -357,8 +356,8 @@ extern "C" HRESULT SearchesParseFromXml( if (fXmlFound) { - hr = BVariantSetString(&pSearch->SetVariable.value, scz, 0, FALSE); - ExitOnFailure(hr, "Failed to set variant value."); + pSearch->SetVariable.sczValue = scz; + scz = NULL; // @Type hr = XmlGetAttributeEx(pixnNode, L"Type", &scz); @@ -366,19 +365,19 @@ extern "C" HRESULT SearchesParseFromXml( if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"formatted", -1)) { - valueType = BURN_VARIANT_TYPE_FORMATTED; + pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_FORMATTED; } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"numeric", -1)) { - valueType = BURN_VARIANT_TYPE_NUMERIC; + pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_NUMERIC; } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"string", -1)) { - valueType = BURN_VARIANT_TYPE_STRING; + pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_STRING; } else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"version", -1)) { - valueType = BURN_VARIANT_TYPE_VERSION; + pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_VERSION; } else { @@ -387,12 +386,8 @@ extern "C" HRESULT SearchesParseFromXml( } else { - valueType = BURN_VARIANT_TYPE_NONE; + pSearch->SetVariable.targetType = BURN_VARIANT_TYPE_NONE; } - - // change value variant to correct type - hr = BVariantChangeType(&pSearch->SetVariable.value, valueType); - ExitOnFailure(hr, "Failed to change variant type."); } else { @@ -551,7 +546,7 @@ extern "C" void SearchesUninitialize( ReleaseStr(pSearch->MsiProductSearch.sczGuid); break; case BURN_SEARCH_TYPE_SET_VARIABLE: - BVariantUninitialize(&pSearch->SetVariable.value); + ReleaseStr(pSearch->SetVariable.sczValue); break; } } @@ -1207,10 +1202,32 @@ static HRESULT PerformSetVariable( ) { HRESULT hr = S_OK; + BURN_VARIANT newValue = { }; + LPWSTR sczFormattedValue = NULL; + SIZE_T cchOut = 0; + + if (BURN_VARIANT_TYPE_NONE == pSearch->SetVariable.targetType) + { + BVariantUninitialize(&newValue); + } + else + { + hr = VariableFormatString(pVariables, pSearch->SetVariable.sczValue, &sczFormattedValue, &cchOut); + ExitOnFailure(hr, "Failed to format search value."); + + hr = BVariantSetString(&newValue, sczFormattedValue, 0, FALSE); + ExitOnFailure(hr, "Failed to set variant value."); - hr = VariableSetVariant(pVariables, pSearch->sczVariable, &pSearch->SetVariable.value); + // change value variant to correct type + hr = BVariantChangeType(&newValue, pSearch->SetVariable.targetType); + ExitOnFailure(hr, "Failed to change variant type."); + } + + hr = VariableSetVariant(pVariables, pSearch->sczVariable, &newValue); ExitOnFailure(hr, "Failed to set variable: %ls", pSearch->sczVariable); LExit: + BVariantUninitialize(&newValue); + return hr; } 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 } ExtensionSearch; struct { - BURN_VARIANT value; + LPWSTR sczValue; + BURN_VARIANT_TYPE targetType; } SetVariable; }; } 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 L" " L" " L" " - L" " + L" " L" " L" " L" " @@ -549,7 +549,9 @@ namespace Bootstrapper // check variable values Assert::Equal(gcnew String(L"VAL1"), VariableGetStringHelper(&variables, L"PROP1")); + Assert::Equal((int)BURN_VARIANT_TYPE_STRING, VariableGetTypeHelper(&variables, L"PROP1")); Assert::Equal(2ll, VariableGetNumericHelper(&variables, L"PROP2")); + Assert::Equal((int)BURN_VARIANT_TYPE_NUMERIC, VariableGetTypeHelper(&variables, L"PROP2")); Assert::Equal(gcnew String(L"2"), VariableGetStringHelper(&variables, L"PROP2")); Assert::Equal(gcnew String(L"VAL3"), VariableGetStringHelper(&variables, L"PROP3")); Assert::Equal(gcnew String(L"VAL4"), VariableGetStringHelper(&variables, L"PROP4")); @@ -557,8 +559,10 @@ namespace Bootstrapper Assert::Equal(gcnew String(L"VAL6"), VariableGetStringHelper(&variables, L"PROP6")); Assert::Equal(7ll, VariableGetNumericHelper(&variables, L"PROP7")); Assert::Equal(gcnew String(L"1.1.0.0"), VariableGetVersionHelper(&variables, L"PROP8")); + Assert::Equal((int)BURN_VARIANT_TYPE_VERSION, VariableGetTypeHelper(&variables, L"PROP8")); Assert::Equal(gcnew String(L"1.1.0.0"), VariableGetStringHelper(&variables, L"PROP8")); Assert::Equal(gcnew String(L"[VAL9]"), VariableGetStringHelper(&variables, L"PROP9")); + Assert::Equal((int)BURN_VARIANT_TYPE_FORMATTED, VariableGetTypeHelper(&variables, L"PROP9")); Assert::Equal(42ll, VariableGetNumericHelper(&variables, L"OVERWRITTEN_STRING")); Assert::Equal(gcnew String(L"NEW"), VariableGetStringHelper(&variables, L"OVERWRITTEN_NUMBER")); -- cgit v1.2.3-55-g6feb