msi: Factor out common code to execute custom action commands.
This commit is contained in:
parent
219a830273
commit
880ef2bb35
@ -972,55 +972,39 @@ static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
|
static HANDLE execute_command( const WCHAR *exe, WCHAR *arg, const WCHAR *dir )
|
||||||
LPCWSTR target, const INT type, LPCWSTR action)
|
|
||||||
{
|
{
|
||||||
STARTUPINFOW si;
|
STARTUPINFOW si;
|
||||||
PROCESS_INFORMATION info;
|
PROCESS_INFORMATION info;
|
||||||
BOOL rc;
|
BOOL ret;
|
||||||
INT len;
|
|
||||||
WCHAR *deformated = NULL;
|
|
||||||
WCHAR *cmd;
|
|
||||||
static const WCHAR spc[] = {' ',0};
|
|
||||||
MSIBINARY *binary;
|
|
||||||
UINT r;
|
|
||||||
|
|
||||||
memset( &si, 0, sizeof(STARTUPINFOW) );
|
memset( &si, 0, sizeof(STARTUPINFOW) );
|
||||||
|
ret = CreateProcessW( exe, arg, NULL, NULL, FALSE, 0, NULL, dir, &si, &info );
|
||||||
if (!(binary = get_temp_binary( package, source, FALSE )))
|
if (!ret)
|
||||||
return ERROR_FUNCTION_FAILED;
|
|
||||||
|
|
||||||
deformat_string(package,target,&deformated);
|
|
||||||
|
|
||||||
len = strlenW( binary->tmpfile ) + 2;
|
|
||||||
if (deformated)
|
|
||||||
len += strlenW(deformated);
|
|
||||||
|
|
||||||
cmd = msi_alloc(sizeof(WCHAR)*len);
|
|
||||||
|
|
||||||
strcpyW( cmd, binary->tmpfile );
|
|
||||||
if (deformated)
|
|
||||||
{
|
{
|
||||||
strcatW(cmd,spc);
|
WARN("unable to execute command %u\n", GetLastError());
|
||||||
strcatW(cmd,deformated);
|
return INVALID_HANDLE_VALUE;
|
||||||
msi_free(deformated);
|
|
||||||
}
|
|
||||||
|
|
||||||
TRACE("executing exe %s\n", debugstr_w(cmd));
|
|
||||||
|
|
||||||
rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL, szCRoot, &si, &info);
|
|
||||||
msi_free(cmd);
|
|
||||||
|
|
||||||
if ( !rc )
|
|
||||||
{
|
|
||||||
ERR("Unable to execute command %s\n", debugstr_w(cmd));
|
|
||||||
return ERROR_SUCCESS;
|
|
||||||
}
|
}
|
||||||
CloseHandle( info.hThread );
|
CloseHandle( info.hThread );
|
||||||
|
return info.hProcess;
|
||||||
|
}
|
||||||
|
|
||||||
r = wait_process_handle(package, type, info.hProcess, action);
|
static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
|
||||||
|
LPCWSTR target, const INT type, LPCWSTR action)
|
||||||
|
{
|
||||||
|
MSIBINARY *binary;
|
||||||
|
HANDLE handle;
|
||||||
|
WCHAR *arg;
|
||||||
|
|
||||||
return r;
|
if (!(binary = get_temp_binary( package, source, FALSE ))) return ERROR_FUNCTION_FAILED;
|
||||||
|
|
||||||
|
deformat_string( package, target, &arg );
|
||||||
|
TRACE("exe %s arg %s\n", debugstr_w(binary->tmpfile), debugstr_w(arg));
|
||||||
|
|
||||||
|
handle = execute_command( binary->tmpfile, arg, szCRoot );
|
||||||
|
msi_free( arg );
|
||||||
|
if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
|
||||||
|
return wait_process_handle( package, type, handle, action );
|
||||||
}
|
}
|
||||||
|
|
||||||
static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
|
static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
|
||||||
@ -1049,53 +1033,19 @@ static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
|
|||||||
static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
|
static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
|
||||||
LPCWSTR target, const INT type, LPCWSTR action)
|
LPCWSTR target, const INT type, LPCWSTR action)
|
||||||
{
|
{
|
||||||
STARTUPINFOW si;
|
|
||||||
PROCESS_INFORMATION info;
|
|
||||||
BOOL rc;
|
|
||||||
WCHAR *deformated;
|
|
||||||
WCHAR *cmd;
|
|
||||||
INT len;
|
|
||||||
static const WCHAR spc[] = {' ',0};
|
|
||||||
MSIFILE *file;
|
MSIFILE *file;
|
||||||
|
HANDLE handle;
|
||||||
|
WCHAR *arg;
|
||||||
|
|
||||||
memset(&si,0,sizeof(STARTUPINFOW));
|
if (!(file = msi_get_loaded_file( package, source ))) return ERROR_FUNCTION_FAILED;
|
||||||
|
|
||||||
file = msi_get_loaded_file(package, source);
|
deformat_string( package, target, &arg );
|
||||||
if( !file )
|
TRACE("exe %s arg %s\n", debugstr_w(file->TargetPath), debugstr_w(arg));
|
||||||
return ERROR_FUNCTION_FAILED;
|
|
||||||
|
|
||||||
len = lstrlenW( file->TargetPath );
|
handle = execute_command( file->TargetPath, arg, szCRoot );
|
||||||
|
msi_free( arg );
|
||||||
deformat_string(package,target,&deformated);
|
if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
|
||||||
if (deformated)
|
return wait_process_handle( package, type, handle, action );
|
||||||
len += strlenW(deformated);
|
|
||||||
len += 2;
|
|
||||||
|
|
||||||
cmd = msi_alloc(len * sizeof(WCHAR));
|
|
||||||
|
|
||||||
lstrcpyW( cmd, file->TargetPath);
|
|
||||||
if (deformated)
|
|
||||||
{
|
|
||||||
strcatW(cmd, spc);
|
|
||||||
strcatW(cmd, deformated);
|
|
||||||
|
|
||||||
msi_free(deformated);
|
|
||||||
}
|
|
||||||
|
|
||||||
TRACE("executing exe %s\n", debugstr_w(cmd));
|
|
||||||
|
|
||||||
rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL, szCRoot, &si, &info);
|
|
||||||
|
|
||||||
if ( !rc )
|
|
||||||
{
|
|
||||||
ERR("Unable to execute command %s\n", debugstr_w(cmd));
|
|
||||||
msi_free(cmd);
|
|
||||||
return ERROR_SUCCESS;
|
|
||||||
}
|
|
||||||
msi_free(cmd);
|
|
||||||
CloseHandle( info.hThread );
|
|
||||||
|
|
||||||
return wait_process_handle(package, type, info.hProcess, action);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
|
static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
|
||||||
@ -1132,90 +1082,39 @@ static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
|
|||||||
static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
|
static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
|
||||||
LPCWSTR target, const INT type, LPCWSTR action)
|
LPCWSTR target, const INT type, LPCWSTR action)
|
||||||
{
|
{
|
||||||
STARTUPINFOW si;
|
WCHAR *exe, *arg;
|
||||||
PROCESS_INFORMATION info;
|
HANDLE handle;
|
||||||
WCHAR *prop;
|
|
||||||
BOOL rc;
|
|
||||||
WCHAR *deformated;
|
|
||||||
WCHAR *cmd;
|
|
||||||
INT len;
|
|
||||||
static const WCHAR spc[] = {' ',0};
|
|
||||||
|
|
||||||
memset(&si,0,sizeof(STARTUPINFOW));
|
if (!(exe = msi_dup_property( package->db, source ))) return ERROR_SUCCESS;
|
||||||
memset(&info,0,sizeof(PROCESS_INFORMATION));
|
|
||||||
|
|
||||||
prop = msi_dup_property( package->db, source );
|
deformat_string( package, target, &arg );
|
||||||
if (!prop)
|
TRACE("exe %s arg %s\n", debugstr_w(exe), debugstr_w(arg));
|
||||||
return ERROR_SUCCESS;
|
|
||||||
|
|
||||||
deformat_string(package,target,&deformated);
|
handle = execute_command( exe, arg, szCRoot );
|
||||||
len = strlenW(prop) + 2;
|
msi_free( arg );
|
||||||
if (deformated)
|
if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
|
||||||
len += strlenW(deformated);
|
return wait_process_handle( package, type, handle, action );
|
||||||
|
|
||||||
cmd = msi_alloc(sizeof(WCHAR)*len);
|
|
||||||
|
|
||||||
strcpyW(cmd,prop);
|
|
||||||
if (deformated)
|
|
||||||
{
|
|
||||||
strcatW(cmd,spc);
|
|
||||||
strcatW(cmd,deformated);
|
|
||||||
|
|
||||||
msi_free(deformated);
|
|
||||||
}
|
|
||||||
msi_free(prop);
|
|
||||||
|
|
||||||
TRACE("executing exe %s\n", debugstr_w(cmd));
|
|
||||||
|
|
||||||
rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL, szCRoot, &si, &info);
|
|
||||||
|
|
||||||
if ( !rc )
|
|
||||||
{
|
|
||||||
ERR("Unable to execute command %s\n", debugstr_w(cmd));
|
|
||||||
msi_free(cmd);
|
|
||||||
return ERROR_SUCCESS;
|
|
||||||
}
|
|
||||||
msi_free(cmd);
|
|
||||||
|
|
||||||
CloseHandle( info.hThread );
|
|
||||||
|
|
||||||
return wait_process_handle(package, type, info.hProcess, action);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
|
static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
|
||||||
LPCWSTR target, const INT type, LPCWSTR action)
|
LPCWSTR target, const INT type, LPCWSTR action)
|
||||||
{
|
{
|
||||||
LPWSTR filename;
|
|
||||||
const WCHAR *workingdir;
|
const WCHAR *workingdir;
|
||||||
STARTUPINFOW si;
|
HANDLE handle;
|
||||||
PROCESS_INFORMATION info;
|
WCHAR *cmd;
|
||||||
BOOL rc;
|
|
||||||
|
|
||||||
memset(&si, 0, sizeof(STARTUPINFOW));
|
|
||||||
|
|
||||||
workingdir = msi_get_target_folder( package, source );
|
workingdir = msi_get_target_folder( package, source );
|
||||||
if (!workingdir) return ERROR_FUNCTION_FAILED;
|
if (!workingdir) return ERROR_FUNCTION_FAILED;
|
||||||
|
|
||||||
deformat_string(package, target, &filename);
|
deformat_string( package, target, &cmd );
|
||||||
if (!filename) return ERROR_FUNCTION_FAILED;
|
if (!cmd) return ERROR_FUNCTION_FAILED;
|
||||||
|
|
||||||
TRACE("executing exe %s with working directory %s\n",
|
TRACE("cmd %s dir %s\n", debugstr_w(cmd), debugstr_w(workingdir));
|
||||||
debugstr_w(filename), debugstr_w(workingdir));
|
|
||||||
|
|
||||||
rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
|
handle = execute_command( NULL, cmd, workingdir );
|
||||||
workingdir, &si, &info);
|
msi_free( cmd );
|
||||||
|
if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
|
||||||
if ( !rc )
|
return wait_process_handle( package, type, handle, action );
|
||||||
{
|
|
||||||
ERR("Unable to execute command %s with working directory %s\n",
|
|
||||||
debugstr_w(filename), debugstr_w(workingdir));
|
|
||||||
msi_free(filename);
|
|
||||||
return ERROR_SUCCESS;
|
|
||||||
}
|
|
||||||
msi_free(filename);
|
|
||||||
CloseHandle( info.hThread );
|
|
||||||
|
|
||||||
return wait_process_handle(package, type, info.hProcess, action);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static DWORD ACTION_CallScript( const GUID *guid )
|
static DWORD ACTION_CallScript( const GUID *guid )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user