From fa393914f12f6d6bc88a73e4d5b009da765f6dd5 Mon Sep 17 00:00:00 2001 From: Jacob Hoover Date: Thu, 10 Nov 2022 10:48:23 -0600 Subject: WIXFEAT-3704 - Allow access to persisted variables from related bundles --- .../inc/BootstrapperEngine.h | 15 +++ .../inc/BundleExtensionEngine.h | 16 +++ src/api/burn/balutil/BalBootstrapperEngine.cpp | 28 +++++ src/api/burn/balutil/balutil.cpp | 51 ++++++++ src/api/burn/balutil/inc/IBootstrapperEngine.h | 8 ++ src/api/burn/balutil/inc/balutil.h | 24 ++++ .../burn/bextutil/BextBundleExtensionEngine.cpp | 29 +++++ src/api/burn/bextutil/inc/IBundleExtensionEngine.h | 7 ++ src/burn/engine/EngineForApplication.cpp | 19 +++ src/burn/engine/EngineForExtension.cpp | 19 +++ src/burn/engine/externalengine.cpp | 20 ++++ src/burn/engine/externalengine.h | 8 ++ src/burn/test/BurnUnitTest/VariantTest.cpp | 8 +- src/libs/dutil/WixToolset.DUtil/iniutil.cpp | 2 + src/libs/dutil/WixToolset.DUtil/path2utl.cpp | 11 +- .../BafRelatedBundleVariableTesting.cpp | 133 +++++++++++++++++++++ .../BafRelatedBundleVariableTesting.def | 6 + .../BafRelatedBundleVariableTesting.vcxproj | 66 ++++++++++ .../BafRelatedBundleVariableTesting/precomp.cpp | 48 ++++++++ .../BafRelatedBundleVariableTesting/precomp.h | 43 +++++++ .../burn/TestData/Manual/BundleD/BundleD.wixproj | 22 ++++ src/test/burn/TestData/Manual/BundleD/BundleD.wxs | 17 +++ .../burn/TestData/Manual/BundleD/ManualTests.txt | 10 ++ 23 files changed, 604 insertions(+), 6 deletions(-) create mode 100644 src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/BafRelatedBundleVariableTesting.cpp create mode 100644 src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/BafRelatedBundleVariableTesting.def create mode 100644 src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/BafRelatedBundleVariableTesting.vcxproj create mode 100644 src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/precomp.cpp create mode 100644 src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/precomp.h create mode 100644 src/test/burn/TestData/Manual/BundleD/BundleD.wixproj create mode 100644 src/test/burn/TestData/Manual/BundleD/BundleD.wxs create mode 100644 src/test/burn/TestData/Manual/BundleD/ManualTests.txt diff --git a/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperEngine.h b/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperEngine.h index 941e4241..96302bd1 100644 --- a/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperEngine.h +++ b/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BootstrapperEngine.h @@ -111,6 +111,7 @@ enum BOOTSTRAPPER_ENGINE_MESSAGE BOOTSTRAPPER_ENGINE_MESSAGE_LAUNCHAPPROVEDEXE, BOOTSTRAPPER_ENGINE_MESSAGE_SETUPDATESOURCE, BOOTSTRAPPER_ENGINE_MESSAGE_COMPAREVERSIONS, + BOOTSTRAPPER_ENGINE_MESSAGE_GETRELATEDBUNDLEVARIABLE, }; typedef struct _BAENGINE_APPLY_ARGS @@ -426,6 +427,20 @@ typedef struct _BAENGINE_SETVARIABLEVERSION_RESULTS DWORD cbSize; } BAENGINE_SETVARIABLEVERSION_RESULTS; +typedef struct _BAENGINE_GETRELATEDBUNDLEVARIABLE_ARGS +{ + DWORD cbSize; + LPCWSTR wzBundleId; + LPCWSTR wzVariable; +} BAENGINE_GETRELATEDBUNDLEVARIABLE_ARGS; + +typedef struct _BAENGINE_GETRELATEDBUNDLEVARIABLE_RESULTS +{ + DWORD cbSize; + LPWSTR wzValue; + // Should be initialized to the size of wzValue. + SIZE_T cchValue; +} BAENGINE_GETRELATEDBUNDLEVARIABLE_RESULTS; extern "C" typedef HRESULT(WINAPI *PFN_BOOTSTRAPPER_ENGINE_PROC)( __in BOOTSTRAPPER_ENGINE_MESSAGE message, diff --git a/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BundleExtensionEngine.h b/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BundleExtensionEngine.h index b397ec16..b585d1a2 100644 --- a/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BundleExtensionEngine.h +++ b/src/api/burn/WixToolset.BootstrapperCore.Native/inc/BundleExtensionEngine.h @@ -28,6 +28,7 @@ enum BUNDLE_EXTENSION_ENGINE_MESSAGE BUNDLE_EXTENSION_ENGINE_MESSAGE_SETVARIABLESTRING, BUNDLE_EXTENSION_ENGINE_MESSAGE_SETVARIABLEVERSION, BUNDLE_EXTENSION_ENGINE_MESSAGE_COMPAREVERSIONS, + BUNDLE_EXTENSION_ENGINE_MESSAGE_GETRELATEDBUNDLEVARIABLE, }; typedef struct _BUNDLE_EXTENSION_ENGINE_COMPAREVERSIONS_ARGS @@ -172,6 +173,21 @@ typedef struct _BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_RESULTS DWORD cbSize; } BUNDLE_EXTENSION_ENGINE_SETVARIABLEVERSION_RESULTS; +typedef struct _BUNDLE_EXTENSION_ENGINE_GETRELATEDBUNDLEVARIABLE_ARGS +{ + DWORD cbSize; + LPCWSTR wzBundleId; + LPCWSTR wzVariable; +} BUNDLE_EXTENSION_ENGINE_GETRELATEDBUNDLEVARIABLE_ARGS; + +typedef struct _BUNDLE_EXTENSION_ENGINE_GETRELATEDBUNDLEVARIABLE_RESULTS +{ + DWORD cbSize; + LPWSTR wzValue; + // Should be initialized to the size of wzValue. + SIZE_T cchValue; +} BUNDLE_EXTENSION_ENGINE_GETRELATEDBUNDLEVARIABLE_RESULTS; + extern "C" typedef HRESULT(WINAPI *PFN_BUNDLE_EXTENSION_ENGINE_PROC)( __in BUNDLE_EXTENSION_ENGINE_MESSAGE message, __in const LPVOID pvArgs, diff --git a/src/api/burn/balutil/BalBootstrapperEngine.cpp b/src/api/burn/balutil/BalBootstrapperEngine.cpp index 898a8a15..be53c6b9 100644 --- a/src/api/burn/balutil/BalBootstrapperEngine.cpp +++ b/src/api/burn/balutil/BalBootstrapperEngine.cpp @@ -158,6 +158,34 @@ public: // IBootstrapperEngine return hr; } + virtual STDMETHODIMP GetRelatedBundleVariable( + __in_z LPCWSTR wzBundleId, + __in_z LPCWSTR wzVariable, + __out_ecount_opt(*pcchValue) LPWSTR wzValue, + __inout SIZE_T* pcchValue + ) + { + HRESULT hr = S_OK; + BAENGINE_GETRELATEDBUNDLEVARIABLE_ARGS args = { }; + BAENGINE_GETRELATEDBUNDLEVARIABLE_RESULTS results = { }; + + ExitOnNull(pcchValue, hr, E_INVALIDARG, "pcchValue is required"); + + args.cbSize = sizeof(args); + args.wzBundleId = wzBundleId; + args.wzVariable = wzVariable; + + results.cbSize = sizeof(results); + results.wzValue = wzValue; + results.cchValue = *pcchValue; + + hr = m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_GETRELATEDBUNDLEVARIABLE, &args, &results, m_pvBAEngineProcContext); + + *pcchValue = results.cchValue; + LExit: + return hr; + } + virtual STDMETHODIMP FormatString( __in_z LPCWSTR wzIn, __out_ecount_opt(*pcchOut) LPWSTR wzOut, diff --git a/src/api/burn/balutil/balutil.cpp b/src/api/burn/balutil/balutil.cpp index 5671da4e..2d80878c 100644 --- a/src/api/burn/balutil/balutil.cpp +++ b/src/api/burn/balutil/balutil.cpp @@ -421,6 +421,57 @@ LExit: return hr; } +DAPI_(HRESULT) BalGetRelatedBundleVariable( + __in_z LPCWSTR wzBundleId, + __in_z LPCWSTR wzVariable, + __inout LPWSTR* psczValue +) +{ + HRESULT hr = S_OK; + + if (!vpEngine) + { + hr = E_POINTER; + ExitOnRootFailure(hr, "BalInitialize() must be called first."); + } + + hr = BalGetRelatedBundleVariableFromEngine(vpEngine, wzBundleId, wzVariable, psczValue); + +LExit: + return hr; +} + +DAPI_(HRESULT) BalGetRelatedBundleVariableFromEngine( + __in IBootstrapperEngine* pEngine, + __in_z LPCWSTR wzBundleId, + __in_z LPCWSTR wzVariable, + __inout LPWSTR* psczValue +) +{ + HRESULT hr = S_OK; + SIZE_T cch = 0; + + if (*psczValue) + { + hr = StrMaxLength(*psczValue, reinterpret_cast(&cch)); + ExitOnFailure(hr, "Failed to determine length of value."); + } + + hr = pEngine->GetRelatedBundleVariable(wzBundleId, wzVariable, *psczValue, &cch); + if (E_MOREDATA == hr) + { + ++cch; + + hr = StrAllocSecure(psczValue, cch); + ExitOnFailure(hr, "Failed to allocate value."); + + hr = pEngine->GetRelatedBundleVariable(wzBundleId, wzVariable, *psczValue, &cch); + } + +LExit: + return hr; +} + DAPI_(HRESULT) BalSetVersionVariable( __in_z LPCWSTR wzVariable, __in_z_opt LPCWSTR wzValue diff --git a/src/api/burn/balutil/inc/IBootstrapperEngine.h b/src/api/burn/balutil/inc/IBootstrapperEngine.h index 2a108223..bfa13997 100644 --- a/src/api/burn/balutil/inc/IBootstrapperEngine.h +++ b/src/api/burn/balutil/inc/IBootstrapperEngine.h @@ -136,4 +136,12 @@ DECLARE_INTERFACE_IID_(IBootstrapperEngine, IUnknown, "6480D616-27A0-44D7-905B-8 __in_z LPCWSTR wzVersion2, __out int* pnResult ) = 0; + + STDMETHOD(GetRelatedBundleVariable)( + __in_z LPCWSTR wzBundleId, + __in_z LPCWSTR wzVariable, + __out_ecount_opt(*pcchValue) LPWSTR wzValue, + __inout SIZE_T* pcchValue + ) = 0; + }; diff --git a/src/api/burn/balutil/inc/balutil.h b/src/api/burn/balutil/inc/balutil.h index 3040cfe8..36c165a3 100644 --- a/src/api/burn/balutil/inc/balutil.h +++ b/src/api/burn/balutil/inc/balutil.h @@ -139,6 +139,30 @@ DAPI_(HRESULT) BalGetNumericVariable( __out LONGLONG* pllValue ); +/******************************************************************* +BalGetRelatedBundleVariable - gets a string from a shared variable in the engine. + +Note: Use StrFree() to release psczValue. +********************************************************************/ +DAPI_(HRESULT) BalGetRelatedBundleVariable( + __in_z LPCWSTR wzBundleId, + __in_z LPCWSTR wzVariable, + __inout LPWSTR* psczValue +); + +/******************************************************************* +BalGetRelatedBundleVariableFromEngine - gets a string from a shared variable in the engine. + + Note: Use StrFree() to release psczValue. +********************************************************************/ +DAPI_(HRESULT) BalGetRelatedBundleVariableFromEngine( + __in IBootstrapperEngine* pEngine, + __in_z LPCWSTR wzBundleId, + __in_z LPCWSTR wzVariable, + __inout LPWSTR* psczValue +); + + /******************************************************************* BalSetNumericVariable - sets a numeric variable in the engine. diff --git a/src/api/burn/bextutil/BextBundleExtensionEngine.cpp b/src/api/burn/bextutil/BextBundleExtensionEngine.cpp index 6043e2db..2c854817 100644 --- a/src/api/burn/bextutil/BextBundleExtensionEngine.cpp +++ b/src/api/burn/bextutil/BextBundleExtensionEngine.cpp @@ -306,6 +306,35 @@ public: // IBundleExtensionEngine return hr; } + virtual STDMETHODIMP GetRelatedBundleVariable( + __in_z LPCWSTR wzBundleId, + __in_z LPCWSTR wzVariable, + __out_ecount_opt(*pcchValue) LPWSTR wzValue, + __inout SIZE_T* pcchValue + ) + { + HRESULT hr = S_OK; + BUNDLE_EXTENSION_ENGINE_GETRELATEDBUNDLEVARIABLE_ARGS args = { }; + BUNDLE_EXTENSION_ENGINE_GETRELATEDBUNDLEVARIABLE_RESULTS results = { }; + + ExitOnNull(pcchValue, hr, E_INVALIDARG, "pcchValue is required"); + + args.cbSize = sizeof(args); + args.wzBundleId = wzBundleId; + args.wzVariable = wzVariable; + + results.cbSize = sizeof(results); + results.wzValue = wzValue; + results.cchValue = *pcchValue; + + hr = m_pfnBundleExtensionEngineProc(BUNDLE_EXTENSION_ENGINE_MESSAGE_GETRELATEDBUNDLEVARIABLE, &args, &results, m_pvBundleExtensionEngineProcContext); + + *pcchValue = results.cchValue; + + LExit: + return hr; + } + public: CBextBundleExtensionEngine( __in PFN_BUNDLE_EXTENSION_ENGINE_PROC pfnBundleExtensionEngineProc, diff --git a/src/api/burn/bextutil/inc/IBundleExtensionEngine.h b/src/api/burn/bextutil/inc/IBundleExtensionEngine.h index 63dadb06..0053a71e 100644 --- a/src/api/burn/bextutil/inc/IBundleExtensionEngine.h +++ b/src/api/burn/bextutil/inc/IBundleExtensionEngine.h @@ -64,4 +64,11 @@ DECLARE_INTERFACE_IID_(IBundleExtensionEngine, IUnknown, "9D027A39-F6B6-42CC-973 __in_z LPCWSTR wzVersion2, __out int* pnResult ) = 0; + + STDMETHOD(GetRelatedBundleVariable)( + __in_z LPCWSTR wzBundleId, + __in_z LPCWSTR wzVariable, + __out_ecount_opt(*pcchValue) LPWSTR wzValue, + __inout SIZE_T * pcchValue + ) = 0; }; diff --git a/src/burn/engine/EngineForApplication.cpp b/src/burn/engine/EngineForApplication.cpp index 45bfaf83..eb77cc50 100644 --- a/src/burn/engine/EngineForApplication.cpp +++ b/src/burn/engine/EngineForApplication.cpp @@ -427,6 +427,22 @@ LExit: return hr; } +static HRESULT BAEngineGetRelatedBundleVariable( + __in BOOTSTRAPPER_ENGINE_CONTEXT* pContext, + __in const LPVOID pvArgs, + __inout LPVOID pvResults + ) +{ + HRESULT hr = S_OK; + ValidateMessageArgs(hr, pvArgs, BAENGINE_GETRELATEDBUNDLEVARIABLE_ARGS, pArgs); + ValidateMessageResults(hr, pvResults, BAENGINE_GETRELATEDBUNDLEVARIABLE_RESULTS, pResults); + + hr = ExternalEngineGetRelatedBundleVariable(pContext->pEngineState, pArgs->wzBundleId, pArgs->wzVariable, pResults->wzValue, &pResults->cchValue); + +LExit: + return hr; +} + HRESULT WINAPI EngineForApplicationProc( __in BOOTSTRAPPER_ENGINE_MESSAGE message, __in const LPVOID pvArgs, @@ -519,6 +535,9 @@ HRESULT WINAPI EngineForApplicationProc( case BOOTSTRAPPER_ENGINE_MESSAGE_COMPAREVERSIONS: hr = BAEngineCompareVersions(pContext, pvArgs, pvResults); break; + case BOOTSTRAPPER_ENGINE_MESSAGE_GETRELATEDBUNDLEVARIABLE: + hr = BAEngineGetRelatedBundleVariable(pContext, pvArgs, pvResults); + break; default: hr = E_NOTIMPL; break; diff --git a/src/burn/engine/EngineForExtension.cpp b/src/burn/engine/EngineForExtension.cpp index 2e1c98fd..bb134a61 100644 --- a/src/burn/engine/EngineForExtension.cpp +++ b/src/burn/engine/EngineForExtension.cpp @@ -203,6 +203,22 @@ LExit: return hr; } +static HRESULT BEEngineGetRelatedBundleVariable( + __in BURN_EXTENSION_ENGINE_CONTEXT* pContext, + __in const LPVOID pvArgs, + __inout LPVOID pvResults +) +{ + HRESULT hr = S_OK; + ValidateMessageArgs(hr, pvArgs, BUNDLE_EXTENSION_ENGINE_GETRELATEDBUNDLEVARIABLE_ARGS, pArgs); + ValidateMessageResults(hr, pvResults, BUNDLE_EXTENSION_ENGINE_GETRELATEDBUNDLEVARIABLE_RESULTS, pResults); + + hr = ExternalEngineGetRelatedBundleVariable(pContext->pEngineState, pArgs->wzBundleId, pArgs->wzVariable, pResults->wzValue, &pResults->cchValue); + +LExit: + return hr; +} + HRESULT WINAPI EngineForExtensionProc( __in BUNDLE_EXTENSION_ENGINE_MESSAGE message, __in const LPVOID pvArgs, @@ -253,6 +269,9 @@ HRESULT WINAPI EngineForExtensionProc( case BUNDLE_EXTENSION_ENGINE_MESSAGE_COMPAREVERSIONS: hr = BEEngineCompareVersions(pContext, pvArgs, pvResults); break; + case BUNDLE_EXTENSION_ENGINE_MESSAGE_GETRELATEDBUNDLEVARIABLE: + hr = BEEngineGetRelatedBundleVariable(pContext, pvArgs, pvResults); + break; default: hr = E_NOTIMPL; break; diff --git a/src/burn/engine/externalengine.cpp b/src/burn/engine/externalengine.cpp index 262bb1a9..c38d8fc3 100644 --- a/src/burn/engine/externalengine.cpp +++ b/src/burn/engine/externalengine.cpp @@ -801,6 +801,26 @@ LExit: return hr; } +HRESULT ExternalEngineGetRelatedBundleVariable( + __in BURN_ENGINE_STATE* /*pEngineState*/, + __in_z LPCWSTR wzBundleId, + __in_z LPCWSTR wzVariable, + __out_ecount_opt(*pcchValue) LPWSTR wzValue, + __inout SIZE_T* pcchValue + ) +{ + HRESULT hr = S_OK; + if (wzVariable && *wzVariable && pcchValue) + { + hr = BundleGetBundleVariableFixed(wzBundleId, wzVariable, wzValue, pcchValue); + } + else + { + hr = E_INVALIDARG; + } + return hr; +} + // TODO: callers need to provide the original size (at the time of first public release) of the struct instead of the current size. HRESULT WINAPI ExternalEngineValidateMessageParameter( __in_opt const LPVOID pv, diff --git a/src/burn/engine/externalengine.h b/src/burn/engine/externalengine.h index 9322234a..0c8a8cbb 100644 --- a/src/burn/engine/externalengine.h +++ b/src/burn/engine/externalengine.h @@ -129,6 +129,14 @@ HRESULT ExternalEngineCompareVersions( __out int* pnResult ); +HRESULT ExternalEngineGetRelatedBundleVariable( + __in BURN_ENGINE_STATE* pEngineState, + __in_z LPCWSTR wzBundleId, + __in_z LPCWSTR wzVariable, + __out_ecount_opt(*pcchValue) LPWSTR wzValue, + __inout SIZE_T* pcchValue +); + HRESULT ExternalEngineDetect( __in BOOTSTRAPPER_ENGINE_CONTEXT* pEngineContext, __in_opt const HWND hwndParent diff --git a/src/burn/test/BurnUnitTest/VariantTest.cpp b/src/burn/test/BurnUnitTest/VariantTest.cpp index 43899a2b..035864cf 100644 --- a/src/burn/test/BurnUnitTest/VariantTest.cpp +++ b/src/burn/test/BurnUnitTest/VariantTest.cpp @@ -27,11 +27,9 @@ namespace Bootstrapper { BURN_VARIANT expectedVariants[10]; BURN_VARIANT actualVariants[10]; - for (DWORD i = 0; i < 10; i++) - { - BVariantUninitialize(expectedVariants + i); - BVariantUninitialize(actualVariants + i); - } + + memset(expectedVariants, 0, sizeof(expectedVariants)); + memset(actualVariants, 0, sizeof(actualVariants)); try { diff --git a/src/libs/dutil/WixToolset.DUtil/iniutil.cpp b/src/libs/dutil/WixToolset.DUtil/iniutil.cpp index 70b62995..46f6e380 100644 --- a/src/libs/dutil/WixToolset.DUtil/iniutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/iniutil.cpp @@ -301,6 +301,8 @@ extern "C" HRESULT DAPI IniParse( wzOpenTagPostfix = wcsstr(pi->rgsczLines[i], pi->sczOpenTagPostfix); } + wzValueNameStart = NULL; + if (pi->sczValuePrefix) { wzValuePrefix = wcsstr(pi->rgsczLines[i], pi->sczValuePrefix); diff --git a/src/libs/dutil/WixToolset.DUtil/path2utl.cpp b/src/libs/dutil/WixToolset.DUtil/path2utl.cpp index 862a743d..d83a4578 100644 --- a/src/libs/dutil/WixToolset.DUtil/path2utl.cpp +++ b/src/libs/dutil/WixToolset.DUtil/path2utl.cpp @@ -327,6 +327,7 @@ DAPI_(HRESULT) PathDirectoryContainsPath( LPWSTR sczCanonicalizedPath = NULL; DWORD dwDefaultFlags = PATH_CANONICALIZE_APPEND_EXTENDED_PATH_PREFIX | PATH_CANONICALIZE_KEEP_UNC_ROOT; size_t cchDirectory = 0; + size_t cchPath = 0; if (!wzDirectory || !*wzDirectory) { @@ -355,12 +356,20 @@ DAPI_(HRESULT) PathDirectoryContainsPath( hr = ::StringCchLengthW(sczCanonicalizedDirectory, STRSAFE_MAX_CCH, &cchDirectory); PathExitOnFailure(hr, "Failed to get length of canonicalized directory."); + hr = ::StringCchLengthW(sczCanonicalizedPath, STRSAFE_MAX_CCH, &cchPath); + PathExitOnFailure(hr, "Failed to get length of canonicalized path."); + + if (cchPath <= cchDirectory) + { + ExitFunction1(hr = S_FALSE); + } + if (CSTR_EQUAL != ::CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, sczCanonicalizedDirectory, (DWORD)cchDirectory, sczCanonicalizedPath, (DWORD)cchDirectory)) { ExitFunction1(hr = S_FALSE); } - hr = sczCanonicalizedPath[cchDirectory] ? S_OK : S_FALSE; + hr = S_OK; LExit: ReleaseStr(sczCanonicalizedPath); diff --git a/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/BafRelatedBundleVariableTesting.cpp b/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/BafRelatedBundleVariableTesting.cpp new file mode 100644 index 00000000..5da7b170 --- /dev/null +++ b/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/BafRelatedBundleVariableTesting.cpp @@ -0,0 +1,133 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +#include "precomp.h" +#include "BalBaseBAFunctions.h" +#include "BalBaseBAFunctionsProc.h" + +const DWORD VARIABLE_GROW_FACTOR = 80; +const LPCWSTR STRING_VARIABLE = L"AString"; +const LPCWSTR NUMBER_VARIABLE = L"ANumber"; + +static void CALLBACK BafRelatedBundleVariableTestingTraceError( + __in_z LPCSTR szFile, + __in int iLine, + __in REPORT_LEVEL rl, + __in UINT source, + __in HRESULT hrError, + __in_z __format_string LPCSTR szFormat, + __in va_list args + ); + +class CBafRelatedBundleVariableTesting : public CBalBaseBAFunctions +{ +public: // IBAFunctions + + +public: //IBootstrapperApplication + virtual STDMETHODIMP OnDetectRelatedBundle( + __in_z LPCWSTR wzBundleId, + __in BOOTSTRAPPER_RELATION_TYPE relationType, + __in_z LPCWSTR wzBundleTag, + __in BOOL fPerMachine, + __in LPCWSTR wzVersion, + __in BOOL fMissingFromCache, + __inout BOOL* pfCancel + ) + { + + HRESULT hr = S_OK; + LPWSTR wzValue = NULL; + + hr = BalGetRelatedBundleVariable(wzBundleId, STRING_VARIABLE, &wzValue); + + ExitOnFailure(hr, "Failed to get related bundle string variable."); + + if (wzValue) + { + BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "AString = %ws", wzValue); + } + + hr = BalGetRelatedBundleVariable(wzBundleId, NUMBER_VARIABLE, &wzValue); + + if (wzValue) + { + BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "ANumber = %ws", wzValue); + } + + hr = __super::OnDetectRelatedBundle(wzBundleId, relationType, wzBundleTag, fPerMachine, wzVersion, fMissingFromCache, pfCancel); + LExit: + ReleaseStr(wzValue); + return hr; + } +private: + + +public: + // + // Constructor - initialize member variables. + // + CBafRelatedBundleVariableTesting( + __in HMODULE hModule, + __in IBootstrapperEngine* pEngine, + __in const BA_FUNCTIONS_CREATE_ARGS* pArgs + ) : CBalBaseBAFunctions(hModule, pEngine, pArgs) + { + } + + // + // Destructor - release member variables. + // + ~CBafRelatedBundleVariableTesting() + { + } + +private: +}; + + +HRESULT WINAPI CreateBAFunctions( + __in HMODULE hModule, + __in const BA_FUNCTIONS_CREATE_ARGS* pArgs, + __inout BA_FUNCTIONS_CREATE_RESULTS* pResults + ) +{ + HRESULT hr = S_OK; + CBafRelatedBundleVariableTesting* pBAFunctions = NULL; + IBootstrapperEngine* pEngine = NULL; + + DutilInitialize(&BafRelatedBundleVariableTestingTraceError); + + hr = BalInitializeFromCreateArgs(pArgs->pBootstrapperCreateArgs, &pEngine); + ExitOnFailure(hr, "Failed to initialize Bal."); + + pBAFunctions = new CBafRelatedBundleVariableTesting(hModule, pEngine, pArgs); + ExitOnNull(pBAFunctions, hr, E_OUTOFMEMORY, "Failed to create new CBafRelatedBundleVariableTesting object."); + + pResults->pfnBAFunctionsProc = BalBaseBAFunctionsProc; + pResults->pvBAFunctionsProcContext = pBAFunctions; + pBAFunctions = NULL; + +LExit: + ReleaseObject(pBAFunctions); + ReleaseObject(pEngine); + + return hr; +} + +static void CALLBACK BafRelatedBundleVariableTestingTraceError( + __in_z LPCSTR /*szFile*/, + __in int /*iLine*/, + __in REPORT_LEVEL /*rl*/, + __in UINT source, + __in HRESULT hrError, + __in_z __format_string LPCSTR szFormat, + __in va_list args + ) +{ + // BalLogError currently uses the Exit... macros, + // so if expanding the scope need to ensure this doesn't get called recursively. + if (DUTIL_SOURCE_THMUTIL == source) + { + BalLogErrorArgs(hrError, szFormat, args); + } +} diff --git a/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/BafRelatedBundleVariableTesting.def b/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/BafRelatedBundleVariableTesting.def new file mode 100644 index 00000000..6e016dad --- /dev/null +++ b/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/BafRelatedBundleVariableTesting.def @@ -0,0 +1,6 @@ +; Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + + +EXPORTS + BAFunctionsCreate + BAFunctionsDestroy diff --git a/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/BafRelatedBundleVariableTesting.vcxproj b/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/BafRelatedBundleVariableTesting.vcxproj new file mode 100644 index 00000000..94d44ac3 --- /dev/null +++ b/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/BafRelatedBundleVariableTesting.vcxproj @@ -0,0 +1,66 @@ + + + + + + + Debug + ARM64 + + + Release + ARM64 + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + {DDD02BDE-B44F-4F37-A359-CE802750CB45} + DynamicLibrary + Unicode + BafRelatedBundleVariableTesting + BafRelatedBundleVariableTesting.def + true + + + + + + + comctl32.lib;gdiplus.lib;msimg32.lib;shlwapi.lib;wininet.lib + + + + + + Create + + + + + + + + + + + + + + + diff --git a/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/precomp.cpp b/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/precomp.cpp new file mode 100644 index 00000000..fc9d1177 --- /dev/null +++ b/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/precomp.cpp @@ -0,0 +1,48 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +#include "precomp.h" + +static HINSTANCE vhInstance = NULL; + +extern "C" BOOL WINAPI DllMain( + IN HINSTANCE hInstance, + IN DWORD dwReason, + IN LPVOID /* pvReserved */ + ) +{ + switch (dwReason) + { + case DLL_PROCESS_ATTACH: + ::DisableThreadLibraryCalls(hInstance); + vhInstance = hInstance; + break; + + case DLL_PROCESS_DETACH: + vhInstance = NULL; + break; + } + + return TRUE; +} + +extern "C" HRESULT WINAPI BAFunctionsCreate( + __in const BA_FUNCTIONS_CREATE_ARGS* pArgs, + __inout BA_FUNCTIONS_CREATE_RESULTS* pResults + ) +{ + HRESULT hr = S_OK; + + hr = CreateBAFunctions(vhInstance, pArgs, pResults); + BalExitOnFailure(hr, "Failed to create BAFunctions interface."); + +LExit: + return hr; +} + +extern "C" void WINAPI BAFunctionsDestroy( + __in const BA_FUNCTIONS_DESTROY_ARGS* /*pArgs*/, + __inout BA_FUNCTIONS_DESTROY_RESULTS* /*pResults*/ + ) +{ + BalUninitialize(); +} diff --git a/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/precomp.h b/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/precomp.h new file mode 100644 index 00000000..2e14786a --- /dev/null +++ b/src/test/burn/TestData/Manual/BafRelatedBundleVariableTesting/precomp.h @@ -0,0 +1,43 @@ +#pragma once +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + + +#include + +#pragma warning(push) +#pragma warning(disable:4458) // declaration of 'xxx' hides class member +#include +#pragma warning(pop) + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dutil.h" +#include "dictutil.h" +#include "fileutil.h" +#include "locutil.h" +#include "memutil.h" +#include "pathutil.h" +#include "procutil.h" +#include "strutil.h" +#include "thmutil.h" +#include "regutil.h" +#include "xmlutil.h" + +#include "BalBaseBootstrapperApplication.h" +#include "balutil.h" + +#include "BAFunctions.h" +#include "IBAFunctions.h" + +HRESULT WINAPI CreateBAFunctions( + __in HMODULE hModule, + __in const BA_FUNCTIONS_CREATE_ARGS* pArgs, + __inout BA_FUNCTIONS_CREATE_RESULTS* pResults + ); diff --git a/src/test/burn/TestData/Manual/BundleD/BundleD.wixproj b/src/test/burn/TestData/Manual/BundleD/BundleD.wixproj new file mode 100644 index 00000000..1df1f895 --- /dev/null +++ b/src/test/burn/TestData/Manual/BundleD/BundleD.wixproj @@ -0,0 +1,22 @@ + + + + Bundle + customHyperlinkLicense + {98ACBCF6-B54A-46AF-8990-DFB8795B965B} + 1.0.0.0 + + + + + + + + + + + + + + + diff --git a/src/test/burn/TestData/Manual/BundleD/BundleD.wxs b/src/test/burn/TestData/Manual/BundleD/BundleD.wxs new file mode 100644 index 00000000..a877e214 --- /dev/null +++ b/src/test/burn/TestData/Manual/BundleD/BundleD.wxs @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/src/test/burn/TestData/Manual/BundleD/ManualTests.txt b/src/test/burn/TestData/Manual/BundleD/ManualTests.txt new file mode 100644 index 00000000..309338cc --- /dev/null +++ b/src/test/burn/TestData/Manual/BundleD/ManualTests.txt @@ -0,0 +1,10 @@ +BafRelatedBundleVariableTesting +# Building, Run initial build w/ no parameters, run a second (re)build w/ a /p:Version=1.1.0.0 (ensure it actually builds, as CLI params aren't accounted in the build optimization) +1. Run BundleD.exe (v1.0). +2. Click Install. +3. Verify that the Bundle installs successfully. +4. Run BundleD.exe (v1.1). +5. Check the log file in %TEMP% There should be lines reporting: +[0708:04B4]i000: AString = This is a test +[0708:04B4]i000: ANumber = 42 + -- cgit v1.2.3-55-g6feb