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 --- .../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 ++ 8 files changed, 345 insertions(+) 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 (limited to 'src/test') 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