setupapi: Handle error translation in SetupDiOpenDevRegKey().

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2019-02-24 22:08:18 -06:00 committed by Alexandre Julliard
parent 486fffa45c
commit f703c7f22d
2 changed files with 16 additions and 22 deletions

View File

@ -514,9 +514,9 @@ static HKEY SETUPDI_CreateDevKey(struct device *device)
return key; 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]; WCHAR path[50];
DWORD size = sizeof(path); DWORD size = sizeof(path);
LONG l; LONG l;
@ -525,23 +525,21 @@ static HKEY open_driver_key(struct device *device, REGSAM access)
KEY_CREATE_SUB_KEY, NULL, &class_key, NULL))) KEY_CREATE_SUB_KEY, NULL, &class_key, NULL)))
{ {
ERR("Failed to open driver class root key, error %u.\n", l); ERR("Failed to open driver class root key, error %u.\n", l);
SetLastError(l); return l;
return INVALID_HANDLE_VALUE;
} }
if (!(l = RegGetValueW(device->key, NULL, Driver, RRF_RT_REG_SZ, NULL, path, &size))) 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); RegCloseKey(class_key);
return key; return l;
} }
ERR("Failed to open driver key, error %u.\n", l); ERR("Failed to open driver key, error %u.\n", l);
} }
RegCloseKey(class_key); RegCloseKey(class_key);
SetLastError(ERROR_KEY_DOES_NOT_EXIST); return l;
return INVALID_HANDLE_VALUE;
} }
static HKEY create_driver_key(struct device *device) static HKEY create_driver_key(struct device *device)
@ -554,7 +552,7 @@ static HKEY create_driver_key(struct device *device)
DWORD dispos; DWORD dispos;
LONG l; 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; return key;
if ((l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ControlClass, 0, NULL, 0, if ((l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ControlClass, 0, NULL, 0,
@ -593,16 +591,14 @@ static BOOL delete_driver_key(struct device *device)
HKEY key; HKEY key;
LONG l; 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); l = RegDeleteKeyW(key, emptyW);
RegCloseKey(key); RegCloseKey(key);
SetLastError(l);
return !l;
} }
return FALSE; SetLastError(l);
return !l;
} }
struct PropertyMapEntry struct PropertyMapEntry
@ -3555,17 +3551,17 @@ HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data,
switch (KeyType) switch (KeyType)
{ {
case DIREG_DEV: case DIREG_DEV:
if ((l = RegOpenKeyExW(device->key, DeviceParameters, 0, samDesired, &key))) l = RegOpenKeyExW(device->key, DeviceParameters, 0, samDesired, &key);
key = INVALID_HANDLE_VALUE;
SetLastError(l);
break; break;
case DIREG_DRV: case DIREG_DRV:
key = open_driver_key(device, samDesired); l = open_driver_key(device, samDesired, &key);
break; break;
default: 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;
} }
/*********************************************************************** /***********************************************************************

View File

@ -1163,7 +1163,6 @@ todo_wine {
key = SetupDiOpenDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); key = SetupDiOpenDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ);
ok(key == INVALID_HANDLE_VALUE, "Expected failure.\n"); ok(key == INVALID_HANDLE_VALUE, "Expected failure.\n");
todo_wine
ok(GetLastError() == ERROR_KEY_DOES_NOT_EXIST, "Got unexpected error %#x.\n", GetLastError()); ok(GetLastError() == ERROR_KEY_DOES_NOT_EXIST, "Got unexpected error %#x.\n", GetLastError());
res = RegOpenKeyA(HKEY_LOCAL_MACHINE, params_key_path, &key); 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); key = SetupDiOpenDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ);
ok(key == INVALID_HANDLE_VALUE, "Expected failure.\n"); ok(key == INVALID_HANDLE_VALUE, "Expected failure.\n");
todo_wine
ok(GetLastError() == ERROR_KEY_DOES_NOT_EXIST, "Got unexpected error %#x.\n", GetLastError()); ok(GetLastError() == ERROR_KEY_DOES_NOT_EXIST, "Got unexpected error %#x.\n", GetLastError());
res = RegOpenKeyA(HKEY_LOCAL_MACHINE, params_key_path, &key); res = RegOpenKeyA(HKEY_LOCAL_MACHINE, params_key_path, &key);