📄 install.c
字号:
static void install_release(const ADVInfo *info)
{
SetupCloseInfFile(info->hinf);
HeapFree(GetProcessHeap(), 0, info->inf_path);
HeapFree(GetProcessHeap(), 0, info->inf_filename);
HeapFree(GetProcessHeap(), 0, info->install_sec);
HeapFree(GetProcessHeap(), 0, info->working_dir);
}
/* this structure very closely resembles parameters of RunSetupCommand() */
typedef struct
{
HWND hwnd;
LPCSTR title;
LPCSTR inf_name;
LPCSTR dir;
LPCSTR section_name;
} SETUPCOMMAND_PARAMS;
typedef struct
{
HWND hwnd;
LPCWSTR title;
LPCWSTR inf_name;
LPCWSTR dir;
LPCWSTR section_name;
} SETUPCOMMAND_PARAMSW;
/* internal: see DoInfInstall */
static HRESULT DoInfInstallW(const SETUPCOMMAND_PARAMSW *setup)
{
ADVInfo info;
HRESULT hr;
TRACE("(%p)\n", setup);
ZeroMemory(&info, sizeof(ADVInfo));
hr = install_init(setup->inf_name, setup->section_name, setup->dir, 0, &info);
if (hr != S_OK)
goto done;
hr = spapi_install(&info);
if (hr != S_OK)
goto done;
hr = adv_install(&info);
done:
install_release(&info);
return S_OK;
}
/***********************************************************************
* DoInfInstall (ADVPACK.@)
*
* Install an INF section.
*
* PARAMS
* setup [I] Structure containing install information.
*
* RETURNS
* S_OK Everything OK
* HRESULT_FROM_WIN32(GetLastError()) Some other error
*/
HRESULT WINAPI DoInfInstall(const SETUPCOMMAND_PARAMS *setup)
{
UNICODE_STRING title, inf, section, dir;
SETUPCOMMAND_PARAMSW params;
HRESULT hr;
if (!setup)
return E_INVALIDARG;
RtlCreateUnicodeStringFromAsciiz(&title, setup->title);
RtlCreateUnicodeStringFromAsciiz(&inf, setup->inf_name);
RtlCreateUnicodeStringFromAsciiz(§ion, setup->section_name);
RtlCreateUnicodeStringFromAsciiz(&dir, setup->dir);
params.title = title.Buffer;
params.inf_name = inf.Buffer;
params.section_name = section.Buffer;
params.dir = dir.Buffer;
params.hwnd = setup->hwnd;
hr = DoInfInstallW(¶ms);
RtlFreeUnicodeString(&title);
RtlFreeUnicodeString(&inf);
RtlFreeUnicodeString(§ion);
RtlFreeUnicodeString(&dir);
return hr;
}
/***********************************************************************
* ExecuteCabA (ADVPACK.@)
*
* See ExecuteCabW.
*/
HRESULT WINAPI ExecuteCabA(HWND hwnd, CABINFOA* pCab, LPVOID pReserved)
{
UNICODE_STRING cab, inf, section;
CABINFOW cabinfo;
HRESULT hr;
TRACE("(%p, %p, %p)\n", hwnd, pCab, pReserved);
if (!pCab)
return E_INVALIDARG;
if (pCab->pszCab)
{
RtlCreateUnicodeStringFromAsciiz(&cab, pCab->pszCab);
cabinfo.pszCab = cab.Buffer;
}
else
cabinfo.pszCab = NULL;
RtlCreateUnicodeStringFromAsciiz(&inf, pCab->pszInf);
RtlCreateUnicodeStringFromAsciiz(§ion, pCab->pszSection);
MultiByteToWideChar(CP_ACP, 0, pCab->szSrcPath, -1, cabinfo.szSrcPath,
sizeof(cabinfo.szSrcPath) / sizeof(WCHAR));
cabinfo.pszInf = inf.Buffer;
cabinfo.pszSection = section.Buffer;
cabinfo.dwFlags = pCab->dwFlags;
hr = ExecuteCabW(hwnd, &cabinfo, pReserved);
if (pCab->pszCab)
RtlFreeUnicodeString(&cab);
RtlFreeUnicodeString(&inf);
RtlFreeUnicodeString(§ion);
return hr;
}
/***********************************************************************
* ExecuteCabW (ADVPACK.@)
*
* Installs the INF file extracted from a specified cabinet file.
*
* PARAMS
* hwnd [I] Handle to the window used for the display.
* pCab [I] Information about the cabinet file.
* pReserved [I] Reserved. Must be NULL.
*
* RETURNS
* Success: S_OK.
* Failure: E_FAIL.
*/
HRESULT WINAPI ExecuteCabW(HWND hwnd, CABINFOW* pCab, LPVOID pReserved)
{
ADVInfo info;
HRESULT hr;
TRACE("(%p, %p, %p)\n", hwnd, pCab, pReserved);
ZeroMemory(&info, sizeof(ADVInfo));
if (pCab->pszCab && *pCab->pszCab)
FIXME("Cab archive not extracted!\n");
hr = install_init(pCab->pszInf, pCab->pszSection, pCab->szSrcPath, pCab->dwFlags, &info);
if (hr != S_OK)
goto done;
hr = spapi_install(&info);
if (hr != S_OK)
goto done;
hr = adv_install(&info);
done:
install_release(&info);
return hr;
}
/***********************************************************************
* LaunchINFSectionA (ADVPACK.@)
*
* See LaunchINFSectionW.
*/
INT WINAPI LaunchINFSectionA(HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show)
{
UNICODE_STRING cmd;
HRESULT hr;
TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_a(cmdline), show);
if (!cmdline)
return ADV_FAILURE;
RtlCreateUnicodeStringFromAsciiz(&cmd, cmdline);
hr = LaunchINFSectionW(hWnd, hInst, cmd.Buffer, show);
RtlFreeUnicodeString(&cmd);
return hr;
}
/***********************************************************************
* LaunchINFSectionW (ADVPACK.@)
*
* Installs an INF section without BACKUP/ROLLBACK capabilities.
*
* PARAMS
* hWnd [I] Handle to parent window, NULL for desktop.
* hInst [I] Instance of the process.
* cmdline [I] Contains parameters in the order INF,section,flags,reboot.
* show [I] How the window should be shown.
*
* RETURNS
* Success: ADV_SUCCESS.
* Failure: ADV_FAILURE.
*
* NOTES
* INF - Filename of the INF to launch.
* section - INF section to install.
* flags - see advpub.h.
* reboot - smart reboot behavior
* 'A' Always reboot.
* 'I' Reboot if needed (default).
* 'N' No reboot.
*/
INT WINAPI LaunchINFSectionW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT show)
{
ADVInfo info;
LPWSTR cmdline_copy, cmdline_ptr;
LPWSTR inf_filename, install_sec;
LPWSTR str_flags;
DWORD flags = 0;
HRESULT hr = S_OK;
TRACE("(%p, %p, %s, %d)\n", hWnd, hInst, debugstr_w(cmdline), show);
if (!cmdline)
return ADV_FAILURE;
cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
cmdline_ptr = cmdline_copy;
lstrcpyW(cmdline_copy, cmdline);
inf_filename = get_parameter(&cmdline_ptr, ',');
install_sec = get_parameter(&cmdline_ptr, ',');
str_flags = get_parameter(&cmdline_ptr, ',');
if (str_flags)
flags = atolW(str_flags);
ZeroMemory(&info, sizeof(ADVInfo));
hr = install_init(inf_filename, install_sec, NULL, flags, &info);
if (hr != S_OK)
goto done;
hr = spapi_install(&info);
if (hr != S_OK)
goto done;
hr = adv_install(&info);
done:
install_release(&info);
HeapFree(GetProcessHeap(), 0, cmdline_copy);
return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE;
}
/***********************************************************************
* LaunchINFSectionExA (ADVPACK.@)
*
* See LaunchINFSectionExW.
*/
HRESULT WINAPI LaunchINFSectionExA(HWND hWnd, HINSTANCE hInst, LPSTR cmdline, INT show)
{
UNICODE_STRING cmd;
HRESULT hr;
TRACE("(%p, %p, %s, %i)\n", hWnd, hInst, debugstr_a(cmdline), show);
if (!cmdline)
return ADV_FAILURE;
RtlCreateUnicodeStringFromAsciiz(&cmd, cmdline);
hr = LaunchINFSectionExW(hWnd, hInst, cmd.Buffer, show);
RtlFreeUnicodeString(&cmd);
return hr;
}
/***********************************************************************
* LaunchINFSectionExW (ADVPACK.@)
*
* Installs an INF section with BACKUP/ROLLBACK capabilities.
*
* PARAMS
* hWnd [I] Handle to parent window, NULL for desktop.
* hInst [I] Instance of the process.
* cmdline [I] Contains parameters in the order INF,section,CAB,flags,reboot.
* show [I] How the window should be shown.
*
* RETURNS
* Success: ADV_SUCCESS.
* Failure: ADV_FAILURE.
*
* NOTES
* INF - Filename of the INF to launch.
* section - INF section to install.
* flags - see advpub.h.
* reboot - smart reboot behavior
* 'A' Always reboot.
* 'I' Reboot if needed (default).
* 'N' No reboot.
*
* BUGS
* Doesn't handle the reboot flag.
*/
HRESULT WINAPI LaunchINFSectionExW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT show)
{
LPWSTR cmdline_copy, cmdline_ptr;
LPWSTR flags, ptr;
CABINFOW cabinfo;
HRESULT hr;
TRACE("(%p, %p, %s, %d)\n", hWnd, hInst, debugstr_w(cmdline), show);
if (!cmdline)
return ADV_FAILURE;
cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
cmdline_ptr = cmdline_copy;
lstrcpyW(cmdline_copy, cmdline);
cabinfo.pszInf = get_parameter(&cmdline_ptr, ',');
cabinfo.pszSection = get_parameter(&cmdline_ptr, ',');
cabinfo.pszCab = get_parameter(&cmdline_ptr, ',');
*cabinfo.szSrcPath = '\0';
flags = get_parameter(&cmdline_ptr, ',');
if (flags)
cabinfo.dwFlags = atolW(flags);
if (!is_full_path(cabinfo.pszCab) && !is_full_path(cabinfo.pszInf))
{
HeapFree(GetProcessHeap(), 0, cmdline_copy);
return E_INVALIDARG;
}
/* get the source path from the cab filename */
if (cabinfo.pszCab && *cabinfo.pszCab)
{
if (!is_full_path(cabinfo.pszCab))
lstrcpyW(cabinfo.szSrcPath, cabinfo.pszInf);
else
lstrcpyW(cabinfo.szSrcPath, cabinfo.pszCab);
ptr = strrchrW(cabinfo.szSrcPath, '\\');
*(++ptr) = '\0';
}
hr = ExecuteCabW(hWnd, &cabinfo, NULL);
HeapFree(GetProcessHeap(), 0, cmdline_copy);
return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE;
}
HRESULT launch_exe(LPCWSTR cmd, LPCWSTR dir, HANDLE *phEXE)
{
STARTUPINFOW si;
PROCESS_INFORMATION pi;
if (phEXE) *phEXE = NULL;
ZeroMemory(&pi, sizeof(pi));
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
if (!CreateProcessW(NULL, (LPWSTR)cmd, NULL, NULL, FALSE,
CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_PROCESS_GROUP,
NULL, dir, &si, &pi))
{
return HRESULT_FROM_WIN32(GetLastError());
}
CloseHandle(pi.hThread);
if (phEXE)
{
*phEXE = pi.hProcess;
return S_ASYNCHRONOUS;
}
/* wait for the child process to finish */
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
return S_OK;
}
/***********************************************************************
* 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;
}
/***********************************************************************
* RunSetupCommandW (ADVPACK.@)
*
* Executes an install section in an INF file or a program.
*
* PARAMS
* hWnd [I] Handle to parent window, NULL for quiet mode
* szCmdName [I] Inf or EXE filename to execute
* szInfSection [I] Inf section to install, NULL for DefaultInstall
* szDir [I] Path to extracted files
* szTitle [I] Title of all dialogs
* phEXE [O] Handle of EXE to wait for
* dwFlags [I] Flags; see include/advpub.h
* pvReserved [I] Reserved
*
* RETURNS
* S_OK Everything OK
* S_ASYNCHRONOUS OK, required to wait on phEXE
* ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
* E_INVALIDARG Invalid argument given
* HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
* Not supported on this Windows version
* E_UNEXPECTED Unexpected error
* HRESULT_FROM_WIN32(GetLastError()) Some other error
*/
HRESULT WINAPI RunSetupCommandW(HWND hWnd, LPCWSTR szCmdName,
LPCWSTR szInfSection, LPCWSTR szDir,
LPCWSTR lpszTitle, HANDLE *phEXE,
DWORD dwFlags, LPVOID pvReserved)
{
ADVInfo info;
HRESULT hr;
TRACE("(%p, %s, %s, %s, %s, %p, %d, %p)\n",
hWnd, debugstr_w(szCmdName), debugstr_w(szInfSection),
debugstr_w(szDir), debugstr_w(lpszTitle),
phEXE, dwFlags, pvReserved);
if (dwFlags & RSC_FLAG_UPDHLPDLLS)
FIXME("Unhandled flag: RSC_FLAG_UPDHLPDLLS\n");
if (!szCmdName || !szDir)
return E_INVALIDARG;
if (!(dwFlags & RSC_FLAG_INF))
return launch_exe(szCmdName, szDir, phEXE);
ZeroMemory(&info, sizeof(ADVInfo));
hr = install_init(szCmdName, szInfSection, szDir, dwFlags, &info);
if (hr != S_OK)
goto done;
hr = spapi_install(&info);
if (hr != S_OK)
goto done;
hr = adv_install(&info);
done:
install_release(&info);
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -