[PATCH 4/4] setupapi: Delete all empty parent keys of a removed device key.
Zebediah Figura
z.figura12 at gmail.com
Fri Nov 30 16:42:13 CST 2018
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
dlls/setupapi/devinst.c | 17 +++++++++++++++++
dlls/setupapi/tests/devinst.c | 31 -------------------------------
2 files changed, 17 insertions(+), 31 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c
index 7c551aab6f..72e7876356 100644
--- a/dlls/setupapi/devinst.c
+++ b/dlls/setupapi/devinst.c
@@ -578,7 +578,9 @@ static void remove_device_iface(struct device_iface *iface)
static void remove_device(struct device *device)
{
+ WCHAR id[MAX_DEVICE_ID_LEN], *p;
struct device_iface *iface;
+ HKEY enum_key;
LIST_FOR_EACH_ENTRY(iface, &device->interfaces, struct device_iface, entry)
{
@@ -587,6 +589,21 @@ static void remove_device(struct device *device)
RegDeleteTreeW(device->key, NULL);
RegDeleteKeyW(device->key, emptyW);
+
+ /* delete all empty parents of the key */
+ if (!RegOpenKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, 0, &enum_key))
+ {
+ strcpyW(id, device->instanceId);
+
+ while ((p = strrchrW(id, '\\')))
+ {
+ *p = 0;
+ RegDeleteKeyW(enum_key, id);
+ }
+
+ RegCloseKey(enum_key);
+ }
+
RegCloseKey(device->key);
device->key = NULL;
device->removed = TRUE;
diff --git a/dlls/setupapi/tests/devinst.c b/dlls/setupapi/tests/devinst.c
index 07e082b2e1..29f12c3f53 100644
--- a/dlls/setupapi/tests/devinst.c
+++ b/dlls/setupapi/tests/devinst.c
@@ -466,9 +466,6 @@ static void test_get_device_instance_id(void)
static void test_register_device_info(void)
{
- static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
- 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
- 'E','n','u','m','\\','R','o','o','t','\\','L','E','G','A','C','Y','_','B','O','G','U','S',0};
SP_DEVINFO_DATA device = {0};
BOOL ret;
HDEVINFO set;
@@ -526,9 +523,6 @@ static void test_register_device_info(void)
ok(GetLastError() == ERROR_NO_MORE_ITEMS, "Got unexpected error %#x.\n", GetLastError());
SetupDiDestroyDeviceInfoList(set);
-
- /* remove once Wine is fixed */
- devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
}
static void check_device_iface_(int line, HDEVINFO set, SP_DEVINFO_DATA *device,
@@ -662,10 +656,6 @@ static void test_device_iface(void)
static void test_device_iface_detail(void)
{
- static const WCHAR bogus[] = {'S','y','s','t','e','m','\\',
- 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
- 'E','n','u','m','\\','R','o','o','t','\\',
- 'L','E','G','A','C','Y','_','B','O','G','U','S',0};
static const char path[] = "\\\\?\\root#legacy_bogus#0000#{6a55b5a4-3f65-11db-b704-0011955c2bdb}";
SP_DEVICE_INTERFACE_DETAIL_DATA_A *detail;
SP_DEVICE_INTERFACE_DATA iface = {sizeof(iface)};
@@ -737,9 +727,6 @@ static void test_device_iface_detail(void)
heap_free(detail);
SetupDiDestroyDeviceInfoList(set);
-
- /* remove once Wine is fixed */
- devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
}
static void test_device_key(void)
@@ -849,7 +836,6 @@ todo_wine {
SetupDiDestroyDeviceInfoList(set);
/* remove once Wine is fixed */
- devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, classKey);
}
@@ -890,9 +876,6 @@ static void test_register_device_iface(void)
SetupDiDestroyDeviceInfoList(set);
SetupDiDestroyDeviceInfoList(set2);
-
- /* remove once Wine is fixed */
- devinst_RegDeleteTreeW(HKEY_LOCAL_MACHINE, bogus);
}
static void test_registry_property_a(void)
@@ -992,14 +975,7 @@ todo_wine {
SetupDiDestroyDeviceInfoList(set);
res = RegOpenKeyA(HKEY_LOCAL_MACHINE, bogus, &key);
-todo_wine
ok(res == ERROR_FILE_NOT_FOUND, "Key should not exist.\n");
- /* FIXME: Remove when Wine is fixed */
- if (res == ERROR_SUCCESS)
- {
- /* Wine doesn't delete the information currently */
- RegDeleteKeyA(HKEY_LOCAL_MACHINE, bogus);
- }
}
static void test_registry_property_w(void)
@@ -1103,14 +1079,7 @@ todo_wine {
SetupDiDestroyDeviceInfoList(set);
res = RegOpenKeyW(HKEY_LOCAL_MACHINE, bogus, &key);
-todo_wine
ok(res == ERROR_FILE_NOT_FOUND, "Key should not exist.\n");
- /* FIXME: Remove when Wine is fixed */
- if (res == ERROR_SUCCESS)
- {
- /* Wine doesn't delete the information currently */
- RegDeleteKeyW(HKEY_LOCAL_MACHINE, bogus);
- }
}
static void test_get_inf_class(void)
--
2.14.1
More information about the wine-devel
mailing list