From ba7bab476501c16e437b0aee71c1be02c3dda176 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Mon, 3 May 2021 15:55:48 -0700 Subject: Move Bal.wixext into ext --- src/ext/Bal/Samples/bafunctions/Readme.txt | 85 +++++++++++++++++++ .../Samples/bafunctions/WixSampleBAFunctions.cpp | 95 ++++++++++++++++++++++ src/ext/Bal/Samples/bafunctions/bafunctions.cpp | 46 +++++++++++ src/ext/Bal/Samples/bafunctions/bafunctions.def | 6 ++ .../Bal/Samples/bafunctions/bafunctions.vcxproj | 81 ++++++++++++++++++ src/ext/Bal/Samples/bafunctions/packages.config | 7 ++ src/ext/Bal/Samples/bafunctions/precomp.h | 52 ++++++++++++ src/ext/Bal/Samples/bafunctions/resource.h | 15 ++++ 8 files changed, 387 insertions(+) create mode 100644 src/ext/Bal/Samples/bafunctions/Readme.txt create mode 100644 src/ext/Bal/Samples/bafunctions/WixSampleBAFunctions.cpp create mode 100644 src/ext/Bal/Samples/bafunctions/bafunctions.cpp create mode 100644 src/ext/Bal/Samples/bafunctions/bafunctions.def create mode 100644 src/ext/Bal/Samples/bafunctions/bafunctions.vcxproj create mode 100644 src/ext/Bal/Samples/bafunctions/packages.config create mode 100644 src/ext/Bal/Samples/bafunctions/precomp.h create mode 100644 src/ext/Bal/Samples/bafunctions/resource.h (limited to 'src/ext/Bal/Samples') diff --git a/src/ext/Bal/Samples/bafunctions/Readme.txt b/src/ext/Bal/Samples/bafunctions/Readme.txt new file mode 100644 index 00000000..517d0d4c --- /dev/null +++ b/src/ext/Bal/Samples/bafunctions/Readme.txt @@ -0,0 +1,85 @@ + +This is a sample project showing how to create a BA function assembly. + +The four interfaces are in the WixSampleBAFunctions.cpp file. + + +Example code: +~~~~~~~~~~~~~ + + + HRESULT hr = S_OK; + HKEY hkKey = NULL; + LPWSTR sczValue = NULL; + LPWSTR sczFormatedValue = NULL; + + + //--------------------------------------------------------------------------------------------- + // Example of BA function failure + hr = E_NOTIMPL; + BalExitOnFailure(hr, "Test failure."); + //--------------------------------------------------------------------------------------------- + + //--------------------------------------------------------------------------------------------- + // Example of setting a variables + hr = m_pEngine->SetVariableString(L"Variable1", L"String value"); + BalExitOnFailure(hr, "Failed to set variable."); + hr = m_pEngine->SetVariableNumeric(L"Variable2", 1234); + BalExitOnFailure(hr, "Failed to set variable."); + //--------------------------------------------------------------------------------------------- + + //--------------------------------------------------------------------------------------------- + // Example of reading burn variable. + BalGetStringVariable(L"WixBundleName", &sczValue); + BalExitOnFailure(hr, "Failed to get variable."); + + hr = m_pEngine->SetVariableString(L"Variable4", sczValue); + BalExitOnFailure(hr, "Failed to set variable."); + //--------------------------------------------------------------------------------------------- + + ReleaseNullStr(sczValue); // Release string so it can be re-used + + //--------------------------------------------------------------------------------------------- + // Examples of reading burn variable and formatting it. + BalGetStringVariable(L"InstallFolder", &sczValue); + BalExitOnFailure(hr, "Failed to get variable."); + + hr = m_pEngine->SetVariableString(L"Variable5", sczValue); + BalExitOnFailure(hr, "Failed to set variable."); + + BalFormatString(sczValue, &sczFormatedValue); + BalExitOnFailure(hr, "Failed to format variable."); + + hr = m_pEngine->SetVariableString(L"Variable6", sczFormatedValue); + BalExitOnFailure(hr, "Failed to set variable."); + //--------------------------------------------------------------------------------------------- + + ReleaseNullStr(sczValue); // Release string so it can be re-used + + //--------------------------------------------------------------------------------------------- + // Example of reading 64 bit registry and setting the InstallFolder variable to the value read. + hr = RegOpen(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5", KEY_READ | KEY_WOW64_64KEY, &hkKey); + BalExitOnFailure(hr, "Failed to open registry key."); + + hr = RegReadString(hkKey, L"InstallPath", &sczValue); + BalExitOnFailure(hr, "Failed to read registry value."); + + // Example of function call + PathBackslashTerminate(&sczValue); + + hr = m_pEngine->SetVariableString(L"InstallFolder", sczValue); + BalExitOnFailure(hr, "Failed to set variable."); + //--------------------------------------------------------------------------------------------- + + ReleaseNullStr(sczValue); // Release string so it can be re-used + + //--------------------------------------------------------------------------------------------- + // Example of calling a function that return HRESULT + hr = GetFileVersion(); + BalExitOnFailure(hr, "Failed to get version."); + //--------------------------------------------------------------------------------------------- + + LExit: + ReleaseRegKey(hkKey); + ReleaseStr(sczValue); + ReleaseStr(sczFormatedValue); diff --git a/src/ext/Bal/Samples/bafunctions/WixSampleBAFunctions.cpp b/src/ext/Bal/Samples/bafunctions/WixSampleBAFunctions.cpp new file mode 100644 index 00000000..531b86a3 --- /dev/null +++ b/src/ext/Bal/Samples/bafunctions/WixSampleBAFunctions.cpp @@ -0,0 +1,95 @@ +// 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" + +class CWixSampleBAFunctions : public CBalBaseBAFunctions +{ +public: // IBootstrapperApplication + virtual STDMETHODIMP OnDetectBegin( + __in BOOL fInstalled, + __in DWORD cPackages, + __inout BOOL* pfCancel + ) + { + HRESULT hr = S_OK; + + BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running detect begin BA function. fInstalled=%d, cPackages=%u, fCancel=%d", fInstalled, cPackages, *pfCancel); + + //------------------------------------------------------------------------------------------------- + // YOUR CODE GOES HERE + BalExitOnFailure(hr, "Change this message to represent real error handling."); + //------------------------------------------------------------------------------------------------- + + LExit: + return hr; + } + +public: // IBAFunctions + virtual STDMETHODIMP OnPlanBegin( + __in DWORD cPackages, + __inout BOOL* pfCancel + ) + { + HRESULT hr = S_OK; + + BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Running plan begin BA function. cPackages=%u, fCancel=%d", cPackages, *pfCancel); + + //------------------------------------------------------------------------------------------------- + // YOUR CODE GOES HERE + BalExitOnFailure(hr, "Change this message to represent real error handling."); + //------------------------------------------------------------------------------------------------- + + LExit: + return hr; + } + +public: + // + // Constructor - initialize member variables. + // + CWixSampleBAFunctions( + __in HMODULE hModule, + __in IBootstrapperEngine* pEngine, + __in const BA_FUNCTIONS_CREATE_ARGS* pArgs + ) : CBalBaseBAFunctions(hModule, pEngine, pArgs) + { + } + + // + // Destructor - release member variables. + // + ~CWixSampleBAFunctions() + { + } +}; + + +HRESULT WINAPI CreateBAFunctions( + __in HMODULE hModule, + __in const BA_FUNCTIONS_CREATE_ARGS* pArgs, + __inout BA_FUNCTIONS_CREATE_RESULTS* pResults + ) +{ + HRESULT hr = S_OK; + CWixSampleBAFunctions* pBAFunctions = NULL; + IBootstrapperEngine* pEngine = NULL; + + // This is required to enable logging functions. + hr = BalInitializeFromCreateArgs(pArgs->pBootstrapperCreateArgs, &pEngine); + ExitOnFailure(hr, "Failed to initialize Bal."); + + pBAFunctions = new CWixSampleBAFunctions(hModule, pEngine, pArgs); + ExitOnNull(pBAFunctions, hr, E_OUTOFMEMORY, "Failed to create new CWixSampleBAFunctions object."); + + pResults->pfnBAFunctionsProc = BalBaseBAFunctionsProc; + pResults->pvBAFunctionsProcContext = pBAFunctions; + pBAFunctions = NULL; + +LExit: + ReleaseObject(pBAFunctions); + ReleaseObject(pEngine); + + return hr; +} diff --git a/src/ext/Bal/Samples/bafunctions/bafunctions.cpp b/src/ext/Bal/Samples/bafunctions/bafunctions.cpp new file mode 100644 index 00000000..b20f4230 --- /dev/null +++ b/src/ext/Bal/Samples/bafunctions/bafunctions.cpp @@ -0,0 +1,46 @@ +// 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( + ) +{ + BalUninitialize(); +} diff --git a/src/ext/Bal/Samples/bafunctions/bafunctions.def b/src/ext/Bal/Samples/bafunctions/bafunctions.def new file mode 100644 index 00000000..6e016dad --- /dev/null +++ b/src/ext/Bal/Samples/bafunctions/bafunctions.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/ext/Bal/Samples/bafunctions/bafunctions.vcxproj b/src/ext/Bal/Samples/bafunctions/bafunctions.vcxproj new file mode 100644 index 00000000..640c812d --- /dev/null +++ b/src/ext/Bal/Samples/bafunctions/bafunctions.vcxproj @@ -0,0 +1,81 @@ + + + + + + + + + + + Debug + ARM64 + + + Release + ARM64 + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + {EB0A7D51-2133-4EE7-B6CA-87DBEAC67E02} + DynamicLibrary + v142 + Unicode + BAFunctions + bafunctions.def + + + + + + + comctl32.lib;gdiplus.lib;msimg32.lib;shlwapi.lib;wininet.lib + + + + + Create + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + diff --git a/src/ext/Bal/Samples/bafunctions/packages.config b/src/ext/Bal/Samples/bafunctions/packages.config new file mode 100644 index 00000000..548ddb48 --- /dev/null +++ b/src/ext/Bal/Samples/bafunctions/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/ext/Bal/Samples/bafunctions/precomp.h b/src/ext/Bal/Samples/bafunctions/precomp.h new file mode 100644 index 00000000..9d2fe726 --- /dev/null +++ b/src/ext/Bal/Samples/bafunctions/precomp.h @@ -0,0 +1,52 @@ +#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 + +// Standard WiX header files, include as required +#include "dutil.h" +//#include "memutil.h" +//#include "dictutil.h" +//#include "dirutil.h" +#include "fileutil.h" +#include "locutil.h" +//#include "logutil.h" +#include "pathutil.h" +//#include "resrutil.h" +//#include "shelutil.h" +#include "strutil.h" +#include "thmutil.h" +//#include "uriutil.h" +//#include "xmlutil.h" +#include "regutil.h" + +//#include "IBootstrapperEngine.h" +//#include "IBootstrapperApplication.h" + +#include "BalBaseBootstrapperApplication.h" +//#include "balinfo.h" +//#include "balcondition.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/ext/Bal/Samples/bafunctions/resource.h b/src/ext/Bal/Samples/bafunctions/resource.h new file mode 100644 index 00000000..149a8ff4 --- /dev/null +++ b/src/ext/Bal/Samples/bafunctions/resource.h @@ -0,0 +1,15 @@ +// 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. + +#define IDC_STATIC -1 + + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1003 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif -- cgit v1.2.3-55-g6feb