Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=21023 Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/devinst.c | 45 +++++++++++++++-------------------- dlls/setupapi/tests/devinst.c | 39 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 26 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index e5d008fc83..1fc494617d 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -1426,6 +1426,7 @@ HKEY WINAPI SetupDiCreateDevRegKeyW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_da { struct device *device; HKEY key = INVALID_HANDLE_VALUE; + LONG l;
TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d, inf_handle %p, inf_section %s.\n", devinfo, device_data, Scope, HwProfile, KeyType, InfHandle, debugstr_w(InfSectionName)); @@ -1453,7 +1454,12 @@ HKEY WINAPI SetupDiCreateDevRegKeyW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_da switch (KeyType) { case DIREG_DEV: - key = SETUPDI_CreateDevKey(device); + if ((l = RegCreateKeyExW(device->key, DeviceParameters, 0, NULL, 0, + KEY_READ | KEY_WRITE, NULL, &key, NULL))) + { + key = INVALID_HANDLE_VALUE; + } + SetLastError(l); break; case DIREG_DRV: key = create_driver_key(device); @@ -3576,6 +3582,7 @@ HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, { struct device *device; HKEY key = INVALID_HANDLE_VALUE; + LONG l;
TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d, access %#x.\n", devinfo, device_data, Scope, HwProfile, KeyType, samDesired); @@ -3604,7 +3611,9 @@ HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, switch (KeyType) { case DIREG_DEV: - key = SETUPDI_OpenDevKey(device, samDesired); + if ((l = RegOpenKeyExW(device->key, DeviceParameters, 0, samDesired, &key))) + key = INVALID_HANDLE_VALUE; + SetLastError(l); break; case DIREG_DRV: key = open_driver_key(device, samDesired); @@ -3615,24 +3624,6 @@ HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, return key; }
-static BOOL SETUPDI_DeleteDevKey(struct device *device) -{ - HKEY enumKey; - BOOL ret = FALSE; - LONG l; - - l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS, - NULL, &enumKey, NULL); - if (!l) - { - ret = RegDeleteTreeW(enumKey, device->instanceId); - RegCloseKey(enumKey); - } - else - SetLastError(l); - return ret; -} - /*********************************************************************** * SetupDiDeleteDevRegKey (SETUPAPI.@) */ @@ -3641,6 +3632,7 @@ BOOL WINAPI SetupDiDeleteDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_dat { struct device *device; BOOL ret = FALSE; + LONG l;
TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d.\n", devinfo, device_data, Scope, HwProfile, KeyType); @@ -3668,16 +3660,17 @@ BOOL WINAPI SetupDiDeleteDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_dat FIXME("unimplemented for scope %d\n", Scope); switch (KeyType) { - case DIREG_DEV: - ret = SETUPDI_DeleteDevKey(device); - break; case DIREG_DRV: ret = delete_driver_key(device); break; case DIREG_BOTH: - ret = SETUPDI_DeleteDevKey(device); - if (ret) - ret = delete_driver_key(device); + if (!(ret = delete_driver_key(device))) + break; + /* fall through */ + case DIREG_DEV: + l = RegDeleteKeyW(device->key, DeviceParameters); + SetLastError(l); + ret = !l; break; default: WARN("unknown KeyType %d\n", KeyType); diff --git a/dlls/setupapi/tests/devinst.c b/dlls/setupapi/tests/devinst.c index d46aa9b120..2657252c03 100644 --- a/dlls/setupapi/tests/devinst.c +++ b/dlls/setupapi/tests/devinst.c @@ -1030,6 +1030,8 @@ static void test_device_iface_detail(void)
static void test_device_key(void) { + static const char params_key_path[] = "System\CurrentControlSet\Enum\Root" + "\LEGACY_BOGUS\0000\Device Parameters"; static const char class_key_path[] = "System\CurrentControlSet\Control\Class" "\{6a55b5a4-3f65-11db-b704-0011955c2bdb}"; static const WCHAR bogus[] = {'S','y','s','t','e','m','\', @@ -1159,6 +1161,43 @@ todo_wine { ok(key == INVALID_HANDLE_VALUE, "Expected failure.\n"); ok(GetLastError() == ERROR_KEY_DOES_NOT_EXIST, "Got unexpected error %#x.\n", GetLastError());
+ key = SetupDiOpenDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); + ok(key == INVALID_HANDLE_VALUE, "Expected failure.\n"); +todo_wine + ok(GetLastError() == ERROR_KEY_DOES_NOT_EXIST, "Got unexpected error %#x.\n", GetLastError()); + + res = RegOpenKeyA(HKEY_LOCAL_MACHINE, params_key_path, &key); + ok(res == ERROR_FILE_NOT_FOUND, "Key should not exist.\n"); + + key = SetupDiCreateDevRegKeyA(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, NULL, NULL); + ok(key != INVALID_HANDLE_VALUE, "Got unexpected error %#x.\n", GetLastError()); + RegCloseKey(key); + + res = RegOpenKeyA(HKEY_LOCAL_MACHINE, params_key_path, &key); + ok(!res, "Failed to open device key, error %u.\n", res); + res = RegSetValueExA(key, "foo", 0, REG_SZ, (BYTE *)"bar", sizeof("bar")); + ok(!res, "Failed to set value, error %u.\n", res); + RegCloseKey(key); + + key = SetupDiOpenDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); + ok(key != INVALID_HANDLE_VALUE, "Got unexpected error %#x.\n", GetLastError()); + size = sizeof(data); + res = RegQueryValueExA(key, "foo", NULL, NULL, (BYTE *)data, &size); + ok(!res, "Failed to get value, error %u.\n", res); + ok(!strcmp(data, "bar"), "Got wrong data %s.\n", data); + RegCloseKey(key); + + ret = SetupDiDeleteDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV); + ok(ret, "Got unexpected error %#x.\n", GetLastError()); + + key = SetupDiOpenDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); + ok(key == INVALID_HANDLE_VALUE, "Expected failure.\n"); +todo_wine + ok(GetLastError() == ERROR_KEY_DOES_NOT_EXIST, "Got unexpected error %#x.\n", GetLastError()); + + res = RegOpenKeyA(HKEY_LOCAL_MACHINE, params_key_path, &key); + ok(res == ERROR_FILE_NOT_FOUND, "Key should not exist.\n"); + key = SetupDiCreateDevRegKeyW(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DRV, NULL, NULL); ok(key != INVALID_HANDLE_VALUE, "Failed to create device key, error %#x.\n", GetLastError()); RegCloseKey(key);
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/devinst.c | 36 ++++++++++++++++------------------- dlls/setupapi/tests/devinst.c | 2 -- 2 files changed, 16 insertions(+), 22 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index 1fc494617d..a117d26158 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -514,9 +514,9 @@ static HKEY SETUPDI_CreateDevKey(struct device *device) return key; }
-static HKEY open_driver_key(struct device *device, REGSAM access) +static LONG open_driver_key(struct device *device, REGSAM access, HKEY *key) { - HKEY class_key, key; + HKEY class_key; WCHAR path[50]; DWORD size = sizeof(path); LONG l; @@ -525,23 +525,21 @@ static HKEY open_driver_key(struct device *device, REGSAM access) KEY_CREATE_SUB_KEY, NULL, &class_key, NULL))) { ERR("Failed to open driver class root key, error %u.\n", l); - SetLastError(l); - return INVALID_HANDLE_VALUE; + return l; }
if (!(l = RegGetValueW(device->key, NULL, Driver, RRF_RT_REG_SZ, NULL, path, &size))) { - if (!(l = RegOpenKeyExW(class_key, path, 0, access, &key))) + if (!(l = RegOpenKeyExW(class_key, path, 0, access, key))) { RegCloseKey(class_key); - return key; + return l; } ERR("Failed to open driver key, error %u.\n", l); }
RegCloseKey(class_key); - SetLastError(ERROR_KEY_DOES_NOT_EXIST); - return INVALID_HANDLE_VALUE; + return l; }
static HKEY create_driver_key(struct device *device) @@ -554,7 +552,7 @@ static HKEY create_driver_key(struct device *device) DWORD dispos; LONG l;
- if ((key = open_driver_key(device, KEY_READ | KEY_WRITE)) != INVALID_HANDLE_VALUE) + if (!open_driver_key(device, KEY_READ | KEY_WRITE, &key)) return key;
if ((l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ControlClass, 0, NULL, 0, @@ -593,16 +591,14 @@ static BOOL delete_driver_key(struct device *device) HKEY key; LONG l;
- if ((key = open_driver_key(device, KEY_READ | KEY_WRITE)) != INVALID_HANDLE_VALUE) + if (!(l = open_driver_key(device, KEY_READ | KEY_WRITE, &key))) { l = RegDeleteKeyW(key, emptyW); RegCloseKey(key); - - SetLastError(l); - return !l; }
- return FALSE; + SetLastError(l); + return !l; }
struct PropertyMapEntry @@ -3611,17 +3607,17 @@ HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, switch (KeyType) { case DIREG_DEV: - if ((l = RegOpenKeyExW(device->key, DeviceParameters, 0, samDesired, &key))) - key = INVALID_HANDLE_VALUE; - SetLastError(l); + l = RegOpenKeyExW(device->key, DeviceParameters, 0, samDesired, &key); break; case DIREG_DRV: - key = open_driver_key(device, samDesired); + l = open_driver_key(device, samDesired, &key); break; default: - WARN("unknown KeyType %d\n", KeyType); + FIXME("Unhandled type %#x.\n", KeyType); + l = ERROR_CALL_NOT_IMPLEMENTED; } - return key; + SetLastError(l == ERROR_FILE_NOT_FOUND ? ERROR_KEY_DOES_NOT_EXIST : l); + return l ? INVALID_HANDLE_VALUE : key; }
/*********************************************************************** diff --git a/dlls/setupapi/tests/devinst.c b/dlls/setupapi/tests/devinst.c index 2657252c03..85900b2612 100644 --- a/dlls/setupapi/tests/devinst.c +++ b/dlls/setupapi/tests/devinst.c @@ -1163,7 +1163,6 @@ todo_wine {
key = SetupDiOpenDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); ok(key == INVALID_HANDLE_VALUE, "Expected failure.\n"); -todo_wine ok(GetLastError() == ERROR_KEY_DOES_NOT_EXIST, "Got unexpected error %#x.\n", GetLastError());
res = RegOpenKeyA(HKEY_LOCAL_MACHINE, params_key_path, &key); @@ -1192,7 +1191,6 @@ todo_wine
key = SetupDiOpenDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); ok(key == INVALID_HANDLE_VALUE, "Expected failure.\n"); -todo_wine ok(GetLastError() == ERROR_KEY_DOES_NOT_EXIST, "Got unexpected error %#x.\n", GetLastError());
res = RegOpenKeyA(HKEY_LOCAL_MACHINE, params_key_path, &key);
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/devinst.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index a117d26158..a012eca2e6 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -586,7 +586,7 @@ static HKEY create_driver_key(struct device *device) return INVALID_HANDLE_VALUE; }
-static BOOL delete_driver_key(struct device *device) +static LONG delete_driver_key(struct device *device) { HKEY key; LONG l; @@ -597,8 +597,7 @@ static BOOL delete_driver_key(struct device *device) RegCloseKey(key); }
- SetLastError(l); - return !l; + return l; }
struct PropertyMapEntry @@ -3627,7 +3626,6 @@ BOOL WINAPI SetupDiDeleteDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_dat DWORD Scope, DWORD HwProfile, DWORD KeyType) { struct device *device; - BOOL ret = FALSE; LONG l;
TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d.\n", @@ -3657,21 +3655,21 @@ BOOL WINAPI SetupDiDeleteDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_dat switch (KeyType) { case DIREG_DRV: - ret = delete_driver_key(device); + l = delete_driver_key(device); break; case DIREG_BOTH: - if (!(ret = delete_driver_key(device))) + if ((l = delete_driver_key(device))) break; /* fall through */ case DIREG_DEV: l = RegDeleteKeyW(device->key, DeviceParameters); - SetLastError(l); - ret = !l; break; default: - WARN("unknown KeyType %d\n", KeyType); + FIXME("Unhandled type %#x.\n", KeyType); + l = ERROR_CALL_NOT_IMPLEMENTED; } - return ret; + SetLastError(l); + return !l; }
/***********************************************************************
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/devinst.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index a012eca2e6..110302b7ca 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -542,25 +542,24 @@ static LONG open_driver_key(struct device *device, REGSAM access, HKEY *key) return l; }
-static HKEY create_driver_key(struct device *device) +static LONG create_driver_key(struct device *device, HKEY *key) { static const WCHAR formatW[] = {'%','0','4','u',0}; static const WCHAR slash[] = { '\',0 }; - HKEY class_key, key; unsigned int i = 0; WCHAR path[50]; + HKEY class_key; DWORD dispos; LONG l;
- if (!open_driver_key(device, KEY_READ | KEY_WRITE, &key)) - return key; + if (!open_driver_key(device, KEY_READ | KEY_WRITE, key)) + return ERROR_SUCCESS;
if ((l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ControlClass, 0, NULL, 0, KEY_CREATE_SUB_KEY, NULL, &class_key, NULL))) { ERR("Failed to open driver class root key, error %u.\n", l); - SetLastError(l); - return INVALID_HANDLE_VALUE; + return l; }
SETUPDI_GuidToString(&device->class, path); @@ -570,20 +569,19 @@ static HKEY create_driver_key(struct device *device) for (;;) { sprintfW(path + 39, formatW, i++); - if ((l = RegCreateKeyExW(class_key, path, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &key, &dispos))) + if ((l = RegCreateKeyExW(class_key, path, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, key, &dispos))) break; else if (dispos == REG_CREATED_NEW_KEY) { RegSetValueExW(device->key, Driver, 0, REG_SZ, (BYTE *)path, strlenW(path) * sizeof(WCHAR)); RegCloseKey(class_key); - return key; + return ERROR_SUCCESS; } - RegCloseKey(key); + RegCloseKey(*key); } ERR("Failed to create driver key, error %u.\n", l); RegCloseKey(class_key); - SetLastError(l); - return INVALID_HANDLE_VALUE; + return l; }
static LONG delete_driver_key(struct device *device) @@ -1449,23 +1447,21 @@ HKEY WINAPI SetupDiCreateDevRegKeyW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_da switch (KeyType) { case DIREG_DEV: - if ((l = RegCreateKeyExW(device->key, DeviceParameters, 0, NULL, 0, - KEY_READ | KEY_WRITE, NULL, &key, NULL))) - { - key = INVALID_HANDLE_VALUE; - } - SetLastError(l); + l = RegCreateKeyExW(device->key, DeviceParameters, 0, NULL, 0, + KEY_READ | KEY_WRITE, NULL, &key, NULL); break; case DIREG_DRV: - key = create_driver_key(device); + l = create_driver_key(device, &key); break; default: - WARN("unknown KeyType %d\n", KeyType); + FIXME("Unhandled type %#x.\n", KeyType); + l = ERROR_CALL_NOT_IMPLEMENTED; } if (InfHandle) SetupInstallFromInfSectionW(NULL, InfHandle, InfSectionName, SPINST_ALL, NULL, NULL, SP_COPY_NEWER_ONLY, NULL, NULL, devinfo, device_data); - return key; + SetLastError(l); + return l ? INVALID_HANDLE_VALUE : key; }
/***********************************************************************