Module: wine Branch: master Commit: 880ef2bb3522aefe84faf34a00b09699c184a48d URL: http://source.winehq.org/git/wine.git/?a=commit;h=880ef2bb3522aefe84faf34a00...
Author: Hans Leidekker hans@codeweavers.com Date: Tue Jun 7 10:33:35 2011 +0200
msi: Factor out common code to execute custom action commands.
---
dlls/msi/custom.c | 201 +++++++++++++---------------------------------------- 1 files changed, 50 insertions(+), 151 deletions(-)
diff --git a/dlls/msi/custom.c b/dlls/msi/custom.c index 1a23175..1a1b052 100644 --- a/dlls/msi/custom.c +++ b/dlls/msi/custom.c @@ -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 )