*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include "winbase.h"
#include "winuser.h"
#include "winreg.h"
-#include "winver.h"
#include "winternl.h"
#include "winnls.h"
#include "setupapi.h"
#include "advpub.h"
+#include "ole2.h"
#include "wine/debug.h"
#include "wine/unicode.h"
#include "advpack_private.h"
#define SPAPI_ERROR 0xE0000000L
#define SPAPI_PREFIX 0x800F0000L
#define SPAPI_MASK 0xFFFFL
-#define HRESULT_FROM_SPAPI(x) ((x & SPAPI_MASK) | SPAPI_PREFIX)
+#define HRESULT_FROM_SPAPI(x) ((HRESULT)((x & SPAPI_MASK) | SPAPI_PREFIX))
#define ADV_HRESULT(x) ((x & SPAPI_ERROR) ? HRESULT_FROM_SPAPI(x) : HRESULT_FROM_WIN32(x))
+#define ADV_SUCCESS 0
+#define ADV_FAILURE 1
+
/* contains information about a specific install instance */
typedef struct _ADVInfo
{
HINF hinf;
+ LPWSTR inf_path;
LPWSTR inf_filename;
LPWSTR install_sec;
LPWSTR working_dir;
BOOL need_reboot;
} ADVInfo;
-typedef HRESULT (*iterate_fields_func)(HINF hinf, PCWSTR field, void *arg);
+typedef HRESULT (*iterate_fields_func)(HINF hinf, PCWSTR field, const void *arg);
/* Advanced INF commands */
+static const WCHAR CheckAdminRights[] = {
+ 'C','h','e','c','k','A','d','m','i','n','R','i','g','h','t','s',0
+};
+static const WCHAR DelDirs[] = {'D','e','l','D','i','r','s',0};
+static const WCHAR PerUserInstall[] = {'P','e','r','U','s','e','r','I','n','s','t','a','l','l',0};
static const WCHAR RegisterOCXs[] = {'R','e','g','i','s','t','e','r','O','C','X','s',0};
+static const WCHAR RunPreSetupCommands[] = {
+ 'R','u','n','P','r','e','S','e','t','u','p','C','o','m','m','a','n','d','s',0
+};
static const WCHAR RunPostSetupCommands[] = {
'R','u','n','P','o','s','t','S','e','t','u','p','C','o','m','m','a','n','d','s',0
};
/* Advanced INF callbacks */
-static HRESULT register_ocxs_callback(HINF hinf, PCWSTR field, void *arg)
+static HRESULT del_dirs_callback(HINF hinf, PCWSTR field, const void *arg)
+{
+ INFCONTEXT context;
+ HRESULT hr = S_OK;
+ DWORD size;
+
+ BOOL ok = SetupFindFirstLineW(hinf, field, NULL, &context);
+
+ for (; ok; ok = SetupFindNextLine(&context, &context))
+ {
+ WCHAR directory[MAX_INF_STRING_LENGTH];
+
+ if (!SetupGetLineTextW(&context, NULL, NULL, NULL, directory,
+ MAX_INF_STRING_LENGTH, &size))
+ continue;
+
+ if (DelNodeW(directory, ADN_DEL_IF_EMPTY) != S_OK)
+ hr = E_FAIL;
+ }
+
+ return hr;
+}
+
+static HRESULT per_user_install_callback(HINF hinf, PCWSTR field, const void *arg)
+{
+ PERUSERSECTIONW per_user;
+ INFCONTEXT context;
+ DWORD size;
+
+ static const WCHAR disp_name[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
+ static const WCHAR version[] = {'V','e','r','s','i','o','n',0};
+ static const WCHAR is_installed[] = {'I','s','I','n','s','t','a','l','l','e','d',0};
+ static const WCHAR comp_id[] = {'C','o','m','p','o','n','e','n','t','I','D',0};
+ static const WCHAR guid[] = {'G','U','I','D',0};
+ static const WCHAR locale[] = {'L','o','c','a','l','e',0};
+ static const WCHAR stub_path[] = {'S','t','u','b','P','a','t','h',0};
+
+ per_user.bRollback = FALSE;
+ per_user.dwIsInstalled = 0;
+
+ SetupGetLineTextW(NULL, hinf, field, disp_name, per_user.szDispName,
+ sizeof(per_user.szDispName) / sizeof(WCHAR), &size);
+
+ SetupGetLineTextW(NULL, hinf, field, version, per_user.szVersion,
+ sizeof(per_user.szVersion) / sizeof(WCHAR), &size);
+
+ if (SetupFindFirstLineW(hinf, field, is_installed, &context))
+ {
+ SetupGetIntField(&context, 1, (PINT)&per_user.dwIsInstalled);
+ }
+
+ SetupGetLineTextW(NULL, hinf, field, comp_id, per_user.szCompID,
+ sizeof(per_user.szCompID) / sizeof(WCHAR), &size);
+
+ SetupGetLineTextW(NULL, hinf, field, guid, per_user.szGUID,
+ sizeof(per_user.szGUID) / sizeof(WCHAR), &size);
+
+ SetupGetLineTextW(NULL, hinf, field, locale, per_user.szLocale,
+ sizeof(per_user.szLocale) / sizeof(WCHAR), &size);
+
+ SetupGetLineTextW(NULL, hinf, field, stub_path, per_user.szStub,
+ sizeof(per_user.szStub) / sizeof(WCHAR), &size);
+
+ return SetPerUserSecValuesW(&per_user);
+}
+
+static HRESULT register_ocxs_callback(HINF hinf, PCWSTR field, const void *arg)
{
HMODULE hm;
INFCONTEXT context;
continue;
hm = LoadLibraryExW(buffer, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
- if (!hm)
+ if (hm)
{
- hr = E_FAIL;
- continue;
- }
+ if (do_ocx_reg(hm, TRUE) != S_OK)
+ hr = E_FAIL;
- if (do_ocx_reg(hm, TRUE))
+ FreeLibrary(hm);
+ }
+ else
hr = E_FAIL;
- FreeLibrary(hm);
+ if (FAILED(hr))
+ {
+ /* FIXME: display a message box */
+ break;
+ }
}
return hr;
}
-static HRESULT run_post_setup_commands_callback(HINF hinf, PCWSTR field, void *arg)
+static HRESULT run_setup_commands_callback(HINF hinf, PCWSTR field, const void *arg)
{
- ADVInfo *info = (ADVInfo *)arg;
+ const ADVInfo *info = (const ADVInfo *)arg;
INFCONTEXT context;
HRESULT hr = S_OK;
DWORD size;
MAX_INF_STRING_LENGTH, &size))
continue;
- if (launch_exe(buffer, info->working_dir, NULL))
+ if (launch_exe(buffer, info->working_dir, NULL) != S_OK)
hr = E_FAIL;
}
return token;
}
-static BOOL is_full_path(LPWSTR path)
+static BOOL is_full_path(LPCWSTR path)
{
const int MIN_PATH_LEN = 3;
if (!path || lstrlenW(path) < MIN_PATH_LEN)
return FALSE;
- if (path[1] == ':' || (path[0] == '\\' && path[1] == '\\'))
+ if ((path[1] == ':' && path[2] == '\\') || (path[0] == '\\' && path[1] == '\\'))
return TRUE;
return FALSE;
/* retrieves the contents of a field, dynamically growing the buffer if necessary */
static WCHAR *get_field_string(INFCONTEXT *context, DWORD index, WCHAR *buffer,
- WCHAR *static_buffer, DWORD *size)
+ const WCHAR *static_buffer, DWORD *size)
{
DWORD required;
hr = S_OK;
done:
- if (buffer && buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
+ if (buffer != static_buffer) HeapFree(GetProcessHeap(), 0, buffer);
+ return hr;
+}
+
+static HRESULT check_admin_rights(const ADVInfo *info)
+{
+ INT check;
+ INFCONTEXT context;
+ HRESULT hr = S_OK;
+
+ if (!SetupFindFirstLineW(info->hinf, info->install_sec,
+ CheckAdminRights, &context))
+ return S_OK;
+
+ if (!SetupGetIntField(&context, 1, &check))
+ return S_OK;
+
+ if (check == 1)
+ hr = IsNTAdmin(0, NULL) ? S_OK : E_FAIL;
+
return hr;
}
/* performs a setupapi-level install of the INF file */
-static HRESULT spapi_install(ADVInfo *info)
+static HRESULT spapi_install(const ADVInfo *info)
{
BOOL ret;
HRESULT res;
SetupTermDefaultQueueCallback(context);
ret = SetupInstallFromInfSectionW(NULL, info->hinf, info->install_sec,
- SPINST_INIFILES | SPINST_REGISTRY,
+ SPINST_INIFILES | SPINST_REGISTRY | SPINST_REGSVR,
HKEY_LOCAL_MACHINE, NULL, 0,
NULL, NULL, NULL, NULL);
if (!ret)
{
HRESULT hr;
+ hr = check_admin_rights(info);
+ if (hr != S_OK)
+ return hr;
+
+ hr = iterate_section_fields(info->hinf, info->install_sec, RunPreSetupCommands,
+ run_setup_commands_callback, info);
+ if (hr != S_OK)
+ return hr;
+
+ OleInitialize(NULL);
hr = iterate_section_fields(info->hinf, info->install_sec,
RegisterOCXs, register_ocxs_callback, NULL);
+ OleUninitialize();
+ if (hr != S_OK)
+ return hr;
+
+ hr = iterate_section_fields(info->hinf, info->install_sec,
+ PerUserInstall, per_user_install_callback, info);
if (hr != S_OK)
return hr;
hr = iterate_section_fields(info->hinf, info->install_sec, RunPostSetupCommands,
- run_post_setup_commands_callback, info);
+ run_setup_commands_callback, info);
+ if (hr != S_OK)
+ return hr;
+
+ hr = iterate_section_fields(info->hinf, info->install_sec,
+ DelDirs, del_dirs_callback, info);
if (hr != S_OK)
return hr;
return hr;
}
+/* determines the proper working directory for the INF file */
+static HRESULT get_working_dir(ADVInfo *info, LPCWSTR inf_filename, LPCWSTR working_dir)
+{
+ WCHAR path[MAX_PATH];
+ LPCWSTR ptr;
+ DWORD len;
+
+ static const WCHAR backslash[] = {'\\',0};
+ static const WCHAR inf_dir[] = {'\\','I','N','F',0};
+
+ if ((ptr = strrchrW(inf_filename, '\\')))
+ {
+ len = ptr - inf_filename + 1;
+ ptr = inf_filename;
+ }
+ else if (working_dir && *working_dir)
+ {
+ len = lstrlenW(working_dir) + 1;
+ ptr = working_dir;
+ }
+ else
+ {
+ GetCurrentDirectoryW(MAX_PATH, path);
+ lstrcatW(path, backslash);
+ lstrcatW(path, inf_filename);
+
+ /* check if the INF file is in the current directory */
+ if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
+ {
+ GetCurrentDirectoryW(MAX_PATH, path);
+ }
+ else
+ {
+ /* default to the windows\inf directory if all else fails */
+ GetWindowsDirectoryW(path, MAX_PATH);
+ lstrcatW(path, inf_dir);
+ }
+
+ len = lstrlenW(path) + 1;
+ ptr = path;
+ }
+
+ info->working_dir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+ if (!info->working_dir)
+ return E_OUTOFMEMORY;
+
+ lstrcpynW(info->working_dir, ptr, len);
+
+ return S_OK;
+}
+
/* loads the INF file and performs checks on it */
-HRESULT install_init(LPCWSTR inf_filename, LPCWSTR install_sec,
- LPCWSTR working_dir, DWORD flags, ADVInfo *info)
+static HRESULT install_init(LPCWSTR inf_filename, LPCWSTR install_sec,
+ LPCWSTR working_dir, DWORD flags, ADVInfo *info)
{
DWORD len;
- LPCWSTR ptr;
+ HRESULT hr;
+ LPCWSTR ptr, path;
+ static const WCHAR backslash[] = {'\\',0};
static const WCHAR default_install[] = {
'D','e','f','a','u','l','t','I','n','s','t','a','l','l',0
};
- len = lstrlenW(inf_filename);
+ if (!(ptr = strrchrW(inf_filename, '\\')))
+ ptr = inf_filename;
+
+ len = lstrlenW(ptr);
info->inf_filename = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
if (!info->inf_filename)
return E_OUTOFMEMORY;
- lstrcpyW(info->inf_filename, inf_filename);
+ lstrcpyW(info->inf_filename, ptr);
/* FIXME: determine the proper platform to install (NTx86, etc) */
if (!install_sec || !*install_sec)
lstrcpyW(info->install_sec, ptr);
- /* FIXME: need to get the real working directory */
- if (!working_dir || !*working_dir)
- {
- ptr = strrchrW(info->inf_filename, '\\');
- len = ptr - info->inf_filename + 1;
- ptr = info->inf_filename;
- }
- else
- {
- len = lstrlenW(working_dir);
- ptr = working_dir;
- }
+ hr = get_working_dir(info, inf_filename, working_dir);
+ if (FAILED(hr))
+ return hr;
- info->working_dir = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
- if (!info->working_dir)
+ len = lstrlenW(info->working_dir) + lstrlenW(info->inf_filename) + 2;
+ info->inf_path = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+ if (!info->inf_path)
return E_OUTOFMEMORY;
- lstrcpynW(info->working_dir, ptr, len);
+ lstrcpyW(info->inf_path, info->working_dir);
+ lstrcatW(info->inf_path, backslash);
+ lstrcatW(info->inf_path, info->inf_filename);
- info->hinf = SetupOpenInfFileW(info->inf_filename, NULL, INF_STYLE_WIN4, NULL);
+ /* RunSetupCommand opens unmodifed filename parameter */
+ if (flags & RSC_FLAG_INF)
+ path = inf_filename;
+ else
+ path = info->inf_path;
+
+ info->hinf = SetupOpenInfFileW(path, NULL, INF_STYLE_WIN4, NULL);
if (info->hinf == INVALID_HANDLE_VALUE)
return ADV_HRESULT(GetLastError());
}
/* release the install instance information */
-void install_release(ADVInfo *info)
+static void install_release(const ADVInfo *info)
{
- if (info->hinf && info->hinf != INVALID_HANDLE_VALUE)
- SetupCloseInfFile(info->hinf);
+ 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);
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.@)
*
*/
HRESULT WINAPI DoInfInstall(const SETUPCOMMAND_PARAMS *setup)
{
- BOOL ret;
- HINF hinf;
- void *callback_context;
+ UNICODE_STRING title, inf, section, dir;
+ SETUPCOMMAND_PARAMSW params;
+ HRESULT hr;
- TRACE("(%p)\n", setup);
+ if (!setup)
+ return E_INVALIDARG;
+
+ RtlCreateUnicodeStringFromAsciiz(&title, setup->title);
+ RtlCreateUnicodeStringFromAsciiz(&inf, setup->inf_name);
+ RtlCreateUnicodeStringFromAsciiz(§ion, setup->section_name);
+ RtlCreateUnicodeStringFromAsciiz(&dir, setup->dir);
- hinf = SetupOpenInfFileA(setup->inf_name, NULL, INF_STYLE_WIN4, NULL);
- if (hinf == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError());
+ params.title = title.Buffer;
+ params.inf_name = inf.Buffer;
+ params.section_name = section.Buffer;
+ params.dir = dir.Buffer;
+ params.hwnd = setup->hwnd;
- callback_context = SetupInitDefaultQueueCallback(setup->hwnd);
+ hr = DoInfInstallW(¶ms);
- ret = SetupInstallFromInfSectionA(NULL, hinf, setup->section_name, SPINST_ALL,
- NULL, NULL, 0, SetupDefaultQueueCallbackA,
- callback_context, NULL, NULL);
- SetupTermDefaultQueueCallback(callback_context);
- SetupCloseInfFile(hinf);
+ RtlFreeUnicodeString(&title);
+ RtlFreeUnicodeString(&inf);
+ RtlFreeUnicodeString(§ion);
+ RtlFreeUnicodeString(&dir);
- return ret ? S_OK : HRESULT_FROM_WIN32(GetLastError());
+ return 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);
* show [I] How the window should be shown.
*
* RETURNS
- * Success: S_OK.
- * Failure: S_FALSE
+ * Success: ADV_SUCCESS.
+ * Failure: ADV_FAILURE.
*
* NOTES
* INF - Filename of the INF to launch.
TRACE("(%p, %p, %s, %d)\n", hWnd, hInst, debugstr_w(cmdline), show);
if (!cmdline)
- return E_INVALIDARG;
+ return ADV_FAILURE;
cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
cmdline_ptr = cmdline_copy;
install_release(&info);
HeapFree(GetProcessHeap(), 0, cmdline_copy);
- return hr;
+ return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE;
}
/***********************************************************************
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);
* show [I] How the window should be shown.
*
* RETURNS
- * Success: S_OK.
- * Failure: E_FAIL.
+ * Success: ADV_SUCCESS.
+ * Failure: ADV_FAILURE.
*
* NOTES
* INF - Filename of the INF to launch.
LPWSTR cmdline_copy, cmdline_ptr;
LPWSTR flags, ptr;
CABINFOW cabinfo;
- HRESULT hr = S_OK;
+ HRESULT hr;
TRACE("(%p, %p, %s, %d)\n", hWnd, hInst, debugstr_w(cmdline), show);
if (!cmdline)
- return E_INVALIDARG;
+ return ADV_FAILURE;
cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR));
cmdline_ptr = cmdline_copy;
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))
- goto done;
+ lstrcpyW(cabinfo.szSrcPath, cabinfo.pszInf);
+ else
+ lstrcpyW(cabinfo.szSrcPath, cabinfo.pszCab);
- lstrcpyW(cabinfo.szSrcPath, cabinfo.pszCab);
ptr = strrchrW(cabinfo.szSrcPath, '\\');
*(++ptr) = '\0';
}
hr = ExecuteCabW(hWnd, &cabinfo, NULL);
-
-done:
HeapFree(GetProcessHeap(), 0, cmdline_copy);
-
- return hr;
+ return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE;
}
HRESULT launch_exe(LPCWSTR cmd, LPCWSTR dir, HANDLE *phEXE)
UNICODE_STRING dir, title;
HRESULT hr;
- TRACE("(%p, %s, %s, %s, %s, %p, %ld, %p)\n",
+ 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);
* Not supported on this Windows version
* E_UNEXPECTED Unexpected error
* HRESULT_FROM_WIN32(GetLastError()) Some other error
- *
- * BUGS
- * INF install unimplemented.
*/
HRESULT WINAPI RunSetupCommandW(HWND hWnd, LPCWSTR szCmdName,
LPCWSTR szInfSection, LPCWSTR szDir,
ADVInfo info;
HRESULT hr;
- TRACE("(%p, %s, %s, %s, %s, %p, %ld, %p)\n",
+ 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)
- FIXME("Unhandled flags: 0x%08lx\n", dwFlags);
+ if (dwFlags & RSC_FLAG_UPDHLPDLLS)
+ FIXME("Unhandled flag: RSC_FLAG_UPDHLPDLLS\n");
if (!szCmdName || !szDir)
return E_INVALIDARG;