2024-04-03 14:27:35 +08:00
// CustomAction.cpp : Defines the entry point for the custom action.
#include "pch.h"
2024-04-06 16:30:33 +08:00
#include <strutil.h>
2024-04-03 14:27:35 +08:00
#include <shellapi.h>
UINT __stdcall CustomActionHello (
__in MSIHANDLE hInstall
)
{
HRESULT hr = S_OK ;
DWORD er = ERROR_SUCCESS ;
hr = WcaInitialize ( hInstall , "CustomActionHello" );
ExitOnFailure ( hr , "Failed to initialize" );
WcaLog ( LOGMSG_STANDARD , "Initialized." );
// TODO: Add your custom action code here.
WcaLog ( LOGMSG_STANDARD , "================= Example CustomAction Hello" );
LExit :
er = SUCCEEDED ( hr ) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE ;
return WcaFinalize ( er );
}
UINT __stdcall RemoveInstallFolder (
__in MSIHANDLE hInstall
)
{
HRESULT hr = S_OK ;
DWORD er = ERROR_SUCCESS ;
int nResult = 0 ;
2024-04-06 16:30:33 +08:00
LPWSTR installFolder = NULL ;
LPWSTR pwz = NULL ;
LPWSTR pwzData = NULL ;
2024-04-03 14:27:35 +08:00
hr = WcaInitialize ( hInstall , "RemoveInstallFolder" );
ExitOnFailure ( hr , "Failed to initialize" );
2024-04-06 16:30:33 +08:00
hr = WcaGetProperty ( L "CustomActionData" , & pwzData );
ExitOnFailure ( hr , "failed to get CustomActionData" );
pwz = pwzData ;
hr = WcaReadStringFromCaData ( & pwz , & installFolder );
ExitOnFailure ( hr , "failed to read database key from custom action data: %ls" , pwz );
2024-04-03 14:27:35 +08:00
SHFILEOPSTRUCTW fileOp ;
2024-04-06 16:30:33 +08:00
ZeroMemory ( & fileOp , sizeof ( SHFILEOPSTRUCT ));
2024-04-03 14:27:35 +08:00
fileOp . wFunc = FO_DELETE ;
2024-04-06 16:30:33 +08:00
fileOp . pFrom = installFolder ;
2024-04-03 14:27:35 +08:00
fileOp . fFlags = FOF_NOCONFIRMATION | FOF_SILENT ;
2024-04-06 16:30:33 +08:00
nResult = SHFileOperation ( & fileOp );
2024-04-03 14:27:35 +08:00
if ( nResult == 0 )
{
2024-04-06 16:30:33 +08:00
WcaLog ( LOGMSG_STANDARD , "The directory \" %ls \" has been deleted." , installFolder );
2024-04-03 14:27:35 +08:00
}
else
{
2024-04-06 16:30:33 +08:00
WcaLog ( LOGMSG_STANDARD , "The directory \" %ls \" has not been deleted, error code: 0X%02X. Please refer to https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shfileoperationa for the error codes." , installFolder , nResult );
2024-04-03 14:27:35 +08:00
}
LExit :
2024-04-06 16:30:33 +08:00
ReleaseStr ( installFolder );
2024-04-03 14:27:35 +08:00
er = SUCCEEDED ( hr ) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE ;
return WcaFinalize ( er );
}