Commit 880ef2bb authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

msi: Factor out common code to execute custom action commands.

parent 219a8302
......@@ -972,55 +972,39 @@ static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
return r;
}
static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
LPCWSTR target, const INT type, LPCWSTR action)
static HANDLE execute_command( const WCHAR *exe, WCHAR *arg, const WCHAR *dir )
{
STARTUPINFOW si;
PROCESS_INFORMATION info;
BOOL rc;
INT len;
WCHAR *deformated = NULL;
WCHAR *cmd;
static const WCHAR spc[] = {' ',0};
MSIBINARY *binary;
UINT r;
memset(&si,0,sizeof(STARTUPINFOW));
if (!(binary = get_temp_binary( package, source, FALSE )))
return ERROR_FUNCTION_FAILED;
deformat_string(package,target,&deformated);
len = strlenW( binary->tmpfile ) + 2;
if (deformated)
len += strlenW(deformated);
BOOL ret;
cmd = msi_alloc(sizeof(WCHAR)*len);
strcpyW( cmd, binary->tmpfile );
if (deformated)
memset( &si, 0, sizeof(STARTUPINFOW) );
ret = CreateProcessW( exe, arg, NULL, NULL, FALSE, 0, NULL, dir, &si, &info );
if (!ret)
{
strcatW(cmd,spc);
strcatW(cmd,deformated);
msi_free(deformated);
WARN("unable to execute command %u\n", GetLastError());
return INVALID_HANDLE_VALUE;
}
CloseHandle( info.hThread );
return info.hProcess;
}
TRACE("executing exe %s\n", debugstr_w(cmd));
static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
LPCWSTR target, const INT type, LPCWSTR action)
{
MSIBINARY *binary;
HANDLE handle;
WCHAR *arg;
rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL, szCRoot, &si, &info);
msi_free(cmd);
if (!(binary = get_temp_binary( package, source, FALSE ))) return ERROR_FUNCTION_FAILED;
if ( !rc )
{
ERR("Unable to execute command %s\n", debugstr_w(cmd));
return ERROR_SUCCESS;
}
CloseHandle( info.hThread );
r = wait_process_handle(package, type, info.hProcess, action);
deformat_string( package, target, &arg );
TRACE("exe %s arg %s\n", debugstr_w(binary->tmpfile), debugstr_w(arg));
return r;
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,
......@@ -1049,53 +1033,19 @@ static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
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;
HANDLE handle;
WCHAR *arg;
memset(&si,0,sizeof(STARTUPINFOW));
file = msi_get_loaded_file(package, source);
if( !file )
return ERROR_FUNCTION_FAILED;
len = lstrlenW( file->TargetPath );
deformat_string(package,target,&deformated);
if (deformated)
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 (!(file = msi_get_loaded_file( package, source ))) return ERROR_FUNCTION_FAILED;
if ( !rc )
{
ERR("Unable to execute command %s\n", debugstr_w(cmd));
msi_free(cmd);
return ERROR_SUCCESS;
}
msi_free(cmd);
CloseHandle( info.hThread );
deformat_string( package, target, &arg );
TRACE("exe %s arg %s\n", debugstr_w(file->TargetPath), debugstr_w(arg));
return wait_process_handle(package, type, info.hProcess, action);
handle = execute_command( file->TargetPath, arg, szCRoot );
msi_free( arg );
if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
return wait_process_handle( package, type, handle, action );
}
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,
LPCWSTR target, const INT type, LPCWSTR action)
{
STARTUPINFOW si;
PROCESS_INFORMATION info;
WCHAR *prop;
BOOL rc;
WCHAR *deformated;
WCHAR *cmd;
INT len;
static const WCHAR spc[] = {' ',0};
memset(&si,0,sizeof(STARTUPINFOW));
memset(&info,0,sizeof(PROCESS_INFORMATION));
prop = msi_dup_property( package->db, source );
if (!prop)
return ERROR_SUCCESS;
deformat_string(package,target,&deformated);
len = strlenW(prop) + 2;
if (deformated)
len += strlenW(deformated);
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);
WCHAR *exe, *arg;
HANDLE handle;
if ( !rc )
{
ERR("Unable to execute command %s\n", debugstr_w(cmd));
msi_free(cmd);
return ERROR_SUCCESS;
}
msi_free(cmd);
if (!(exe = msi_dup_property( package->db, source ))) return ERROR_SUCCESS;
CloseHandle( info.hThread );
deformat_string( package, target, &arg );
TRACE("exe %s arg %s\n", debugstr_w(exe), debugstr_w(arg));
return wait_process_handle(package, type, info.hProcess, action);
handle = execute_command( exe, arg, szCRoot );
msi_free( arg );
if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
return wait_process_handle( package, type, handle, action );
}
static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
LPCWSTR target, const INT type, LPCWSTR action)
{
LPWSTR filename;
const WCHAR *workingdir;
STARTUPINFOW si;
PROCESS_INFORMATION info;
BOOL rc;
memset(&si, 0, sizeof(STARTUPINFOW));
HANDLE handle;
WCHAR *cmd;
workingdir = msi_get_target_folder( package, source );
if (!workingdir) return ERROR_FUNCTION_FAILED;
deformat_string(package, target, &filename);
if (!filename) return ERROR_FUNCTION_FAILED;
TRACE("executing exe %s with working directory %s\n",
debugstr_w(filename), debugstr_w(workingdir));
rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
workingdir, &si, &info);
deformat_string( package, target, &cmd );
if (!cmd) return ERROR_FUNCTION_FAILED;
if ( !rc )
{
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 );
TRACE("cmd %s dir %s\n", debugstr_w(cmd), debugstr_w(workingdir));
return wait_process_handle(package, type, info.hProcess, action);
handle = execute_command( NULL, cmd, workingdir );
msi_free( cmd );
if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
return wait_process_handle( package, type, handle, action );
}
static DWORD ACTION_CallScript( const GUID *guid )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment