From 2c568de11510b453f499827919964badef22304e Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 31 Dec 2018 23:52:58 -0600 Subject: Import code from old v4 repo --- src/Samples/bafunctions/Readme.txt | 85 ++++++++++++++++ src/Samples/bafunctions/WixSampleBAFunctions.cpp | 95 ++++++++++++++++++ src/Samples/bafunctions/bafunctions.cpp | 46 +++++++++ src/Samples/bafunctions/bafunctions.def | 6 ++ src/Samples/bafunctions/bafunctions.rc | 118 +++++++++++++++++++++++ src/Samples/bafunctions/bafunctions.vcxproj | 54 +++++++++++ src/Samples/bafunctions/bafunctionsver.h | 13 +++ src/Samples/bafunctions/precomp.h | 47 +++++++++ src/Samples/bafunctions/resource.h | 15 +++ 9 files changed, 479 insertions(+) create mode 100644 src/Samples/bafunctions/Readme.txt create mode 100644 src/Samples/bafunctions/WixSampleBAFunctions.cpp create mode 100644 src/Samples/bafunctions/bafunctions.cpp create mode 100644 src/Samples/bafunctions/bafunctions.def create mode 100644 src/Samples/bafunctions/bafunctions.rc create mode 100644 src/Samples/bafunctions/bafunctions.vcxproj create mode 100644 src/Samples/bafunctions/bafunctionsver.h create mode 100644 src/Samples/bafunctions/precomp.h create mode 100644 src/Samples/bafunctions/resource.h (limited to 'src/Samples') diff --git a/src/Samples/bafunctions/Readme.txt b/src/Samples/bafunctions/Readme.txt new file mode 100644 index 00000000..517d0d4c --- /dev/null +++ b/src/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/Samples/bafunctions/WixSampleBAFunctions.cpp b/src/Samples/bafunctions/WixSampleBAFunctions.cpp new file mode 100644 index 00000000..531b86a3 --- /dev/null +++ b/src/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/Samples/bafunctions/bafunctions.cpp b/src/Samples/bafunctions/bafunctions.cpp new file mode 100644 index 00000000..b20f4230 --- /dev/null +++ b/src/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/Samples/bafunctions/bafunctions.def b/src/Samples/bafunctions/bafunctions.def new file mode 100644 index 00000000..6e016dad --- /dev/null +++ b/src/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/Samples/bafunctions/bafunctions.rc b/src/Samples/bafunctions/bafunctions.rc new file mode 100644 index 00000000..9643d240 --- /dev/null +++ b/src/Samples/bafunctions/bafunctions.rc @@ -0,0 +1,118 @@ +// 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 +#include +#include "bafunctionsver.h" + +#define VER_APP +#define VER_ORIGINAL_FILENAME "bafunctions.dll" +#define VER_INTERNAL_NAME "bafunctions" +#define VER_PRODUCT_NAME "WiX Sample BAFunctions" +#define VER_FILE_DESCRIPTION "WiX Sample BAFunctions" + +#ifdef DEBUG + #define VER_DEBUG VS_FF_DEBUG + #define VER_PRIVATE_BUILD VS_FF_PRIVATEBUILD + #define VER_PRE_RELEASE (VS_FF_PRERELEASE | VS_FF_SPECIALBUILD) +#else + #define VER_DEBUG 0 + #define VER_PRIVATE_BUILD 0 + #define VER_PRE_RELEASE 0 +#endif + +#if defined(VER_APP) + #define VER_FILE_TYPE VFT_APP +#elif defined(VER_DLL) + #define VER_FILE_TYPE VFT_DLL +#elif defined(VER_TYPELIB) + #define VER_FILE_TYPE VFT_UNKNOWN +#else + #define VER_FILE_TYPE VFT_UNKNOWN +#endif + +#if defined(VER_LANG_NEUTRAL) + #ifndef VER_LANG + #define VER_LANG 0x0000 + #endif + #ifndef VER_CP + #define VER_CP 0x04E4 + #endif + #ifndef VER_BLOCK + #define VER_BLOCK "000004E4" + #endif +#else + #ifndef VER_LANG + #define VER_LANG 0x0409 + #endif + #ifndef VER_CP + #define VER_CP 0x04E4 + #endif + #ifndef VER_BLOCK + #define VER_BLOCK "040904E4" + #endif +#endif + +#define VER_FILE_VERSION rmj, rmm, rbd, rev +#define VER_PRODUCT_VERSION rmj, rmm, rbd, rev +#define VER_FILE_VERSION_STRING szVerMajorMinorBuildRev +#define VER_PRODUCT_VERSION_STRING VER_FILE_VERSION_STRING +#define VER_FILE_FLAGS_MASK VS_FFI_FILEFLAGSMASK +#define VER_FILE_FLAGS (VER_DEBUG | VER_PRIVATE_BUILD | VER_PRE_RELEASE) + +#define VER_FILE_OS VOS__WINDOWS32 + +#define VER_COMPANY_NAME ".NET Foundation" +#ifndef VER_PRODUCT_NAME + #define VER_PRODUCT_NAME "Windows Installer XML (WiX)" +#endif +#ifndef VER_FILE_DESCRIPTION + #define VER_FILE_DESCRIPTION "Windows Installer XML (WiX) component" +#endif + +#if defined(VER_LEGAL_COPYRIGHT) + #error +#endif +#define VER_LEGAL_COPYRIGHT "Copyright (c) .NET Foundation and contributors.\240 All rights reserved." + +#if !defined(VER_FILE_SUBTYPE) + #define VER_FILE_SUBTYPE 0 +#endif + +#ifdef RC_INVOKED + +VS_VERSION_INFO VERSIONINFO +FILEVERSION VER_FILE_VERSION +PRODUCTVERSION VER_PRODUCT_VERSION +FILEFLAGSMASK VER_FILE_FLAGS_MASK +FILEFLAGS VER_FILE_FLAGS +FILEOS VER_FILE_OS +FILETYPE VER_FILE_TYPE +FILESUBTYPE VER_FILE_SUBTYPE +BEGIN +BLOCK "StringFileInfo" + BEGIN + BLOCK VER_BLOCK + BEGIN + VALUE "CompanyName", VER_COMPANY_NAME + VALUE "FileDescription", VER_FILE_DESCRIPTION + VALUE "FileVersion", VER_FILE_VERSION_STRING + VALUE "InternalName", VER_INTERNAL_NAME + + VALUE "LegalCopyright", VER_LEGAL_COPYRIGHT + + VALUE "OriginalFilename", VER_ORIGINAL_FILENAME + VALUE "ProductName", VER_PRODUCT_NAME + VALUE "ProductVersion", VER_FILE_VERSION_STRING +#if defined(DEBUG) + VALUE "WiX Common Resource Format", "Debug Only" +#endif + END + END + +BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", VER_LANG, VER_CP + END +END + +#endif diff --git a/src/Samples/bafunctions/bafunctions.vcxproj b/src/Samples/bafunctions/bafunctions.vcxproj new file mode 100644 index 00000000..71b27bca --- /dev/null +++ b/src/Samples/bafunctions/bafunctions.vcxproj @@ -0,0 +1,54 @@ + + + + + + + + Debug + Win32 + + + Release + Win32 + + + + + Debug + ARM + + + Release + ARM + + + + {EB0A7D51-2133-4EE7-B6CA-87DBEAC67E02} + DynamicLibrary + Unicode + BAFunctions + bafunctions.def + + + + $(WixRoot)src\libs\dutil\inc;$(WixRoot)src\burn\inc;$(WixRoot)src\libs\balutil\inc + comctl32.lib;gdiplus.lib;msimg32.lib;shlwapi.lib;wininet.lib;dutil.lib;balutil.lib;version.lib + + + + + + + + + + + + + + + + + + diff --git a/src/Samples/bafunctions/bafunctionsver.h b/src/Samples/bafunctions/bafunctionsver.h new file mode 100644 index 00000000..e6e22f4e --- /dev/null +++ b/src/Samples/bafunctions/bafunctionsver.h @@ -0,0 +1,13 @@ +// 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. + +#ifndef _VERSION_FILE_H_ +#define _VERSION_FILE_H_ + +#define szVerMajorMinor "1.0" +#define szVerMajorMinorBuildRev "1.0.0.0" +#define rmj 1 +#define rmm 0 +#define rbd 0 +#define rev 0 + +#endif diff --git a/src/Samples/bafunctions/precomp.h b/src/Samples/bafunctions/precomp.h new file mode 100644 index 00000000..82ce2dae --- /dev/null +++ b/src/Samples/bafunctions/precomp.h @@ -0,0 +1,47 @@ +#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 +#include +#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/Samples/bafunctions/resource.h b/src/Samples/bafunctions/resource.h new file mode 100644 index 00000000..149a8ff4 --- /dev/null +++ b/src/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