/*********************************************************************** * RunSetupCommandA (ADVPACK.@) * * See RunSetupCommandW. */ HRESULT WINAPI RunSetupCommandA(HWND hWnd, LPCSTR szCmdName, LPCSTR szInfSection, LPCSTR szDir, LPCSTR lpszTitle, HANDLE *phEXE, DWORD dwFlags, LPVOID pvReserved) { UNICODE_STRING cmdname, infsec; UNICODE_STRING dir, title; HRESULT hr; TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n", hWnd, debugstr_a(szCmdName), debugstr_a(szInfSection), debugstr_a(szDir), debugstr_a(lpszTitle), phEXE, dwFlags, pvReserved); if (!szCmdName || !szDir) return E_INVALIDARG; RtlCreateUnicodeStringFromAsciiz(&cmdname, szCmdName); RtlCreateUnicodeStringFromAsciiz(&infsec, szInfSection); RtlCreateUnicodeStringFromAsciiz(&dir, szDir); RtlCreateUnicodeStringFromAsciiz(&title, lpszTitle); hr = RunSetupCommandW(hWnd, cmdname.Buffer, infsec.Buffer, dir.Buffer, title.Buffer, phEXE, dwFlags, pvReserved); RtlFreeUnicodeString(&cmdname); RtlFreeUnicodeString(&infsec); RtlFreeUnicodeString(&dir); RtlFreeUnicodeString(&title); return hr; }
static HRESULT install_inf_file(install_ctx_t *ctx) { WCHAR buf[2048], sect_name[128]; BOOL default_install = TRUE; const WCHAR *key; DWORD len; HRESULT hres; static const WCHAR setup_hooksW[] = {'S','e','t','u','p',' ','H','o','o','k','s',0}; static const WCHAR add_codeW[] = {'A','d','d','.','C','o','d','e',0}; len = GetPrivateProfileStringW(setup_hooksW, NULL, NULL, buf, sizeof(buf)/sizeof(*buf), ctx->install_file); if(len) { default_install = FALSE; for(key = buf; *key; key += strlenW(key)+1) { TRACE("[Setup Hooks] key: %s\n", debugstr_w(key)); len = GetPrivateProfileStringW(setup_hooksW, key, NULL, sect_name, sizeof(sect_name)/sizeof(*sect_name), ctx->install_file); if(!len) { WARN("Could not get key value\n"); return E_FAIL; } hres = process_hook_section(ctx, sect_name); if(FAILED(hres)) return hres; } } len = GetPrivateProfileStringW(add_codeW, NULL, NULL, buf, sizeof(buf)/sizeof(*buf), ctx->install_file); if(len) { FIXME("[Add.Code] section not supported\n"); /* Don't throw an error if we successfully ran setup hooks; installation is likely to be complete enough */ if(default_install) return E_NOTIMPL; } if(default_install) { hres = RunSetupCommandW(ctx->hwnd, ctx->install_file, NULL, ctx->tmp_dir, NULL, NULL, RSC_FLAG_INF, NULL); if(FAILED(hres)) { WARN("RunSetupCommandW failed: %08x\n", hres); return hres; } } return S_OK; }
static HRESULT install_cab_file(install_ctx_t *ctx) { WCHAR tmp_path[MAX_PATH], tmp_dir[MAX_PATH]; BOOL res = FALSE, leave_temp = FALSE; DWORD i; HRESULT hres; GetTempPathW(sizeof(tmp_path)/sizeof(WCHAR), tmp_path); for(i=0; !res && i < 100; i++) { GetTempFileNameW(tmp_path, NULL, GetTickCount() + i*17037, tmp_dir); res = CreateDirectoryW(tmp_dir, NULL); } if(!res) return E_FAIL; ctx->tmp_dir = tmp_dir; TRACE("Using temporary directory %s\n", debugstr_w(tmp_dir)); hres = extract_cab_file(ctx); if(SUCCEEDED(hres)) { if(ctx->callback) IBindStatusCallback_OnProgress(ctx->callback, 0, 0, BINDSTATUS_INSTALLINGCOMPONENTS, ctx->install_file); switch(ctx->install_type) { case INSTALL_INF: hres = RunSetupCommandW(ctx->hwnd, ctx->install_file, NULL, ctx->tmp_dir, NULL, NULL, RSC_FLAG_INF, NULL); if(FAILED(hres)) WARN("RunSetupCommandW failed: %08x\n", hres); break; case INSTALL_DLL: FIXME("Installing DLL, registering in temporary location\n"); hres = setup_dll(ctx); if(SUCCEEDED(hres)) leave_temp = TRUE; break; default: assert(0); } } if(!leave_temp) RemoveDirectoryW(ctx->tmp_dir); return hres; }
static HRESULT process_hook_section(install_ctx_t *ctx, const WCHAR *sect_name) { WCHAR buf[2048], val[2*MAX_PATH]; const WCHAR *key; DWORD len; HRESULT hres; static const WCHAR runW[] = {'r','u','n',0}; len = GetPrivateProfileStringW(sect_name, NULL, NULL, buf, sizeof(buf)/sizeof(*buf), ctx->install_file); if(!len) return S_OK; for(key = buf; *key; key += strlenW(key)+1) { if(!strcmpiW(key, runW)) { WCHAR *cmd; size_t size; len = GetPrivateProfileStringW(sect_name, runW, NULL, val, sizeof(val)/sizeof(*val), ctx->install_file); TRACE("Run %s\n", debugstr_w(val)); expand_command(ctx, val, NULL, &size); cmd = heap_alloc(size*sizeof(WCHAR)); if(!cmd) heap_free(cmd); expand_command(ctx, val, cmd, &size); hres = RunSetupCommandW(ctx->hwnd, cmd, NULL, ctx->tmp_dir, NULL, NULL, 0, NULL); heap_free(cmd); if(FAILED(hres)) return hres; }else { FIXME("Unsupported hook %s\n", debugstr_w(key)); return E_NOTIMPL; } } return S_OK; }