From ec978c49ebf347987abc76ed2a775dfc9fa88d03 Mon Sep 17 00:00:00 2001 From: George Stephanos Date: Sun, 25 Aug 2013 01:42:46 +0200 Subject: [PATCH 3/3] advapi32: HKCR merge: added hkcu --- dlls/advapi32/registry.c | 22 +++++++++++++++++----- dlls/advapi32/tests/registry.c | 20 +++++++++----------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c index 385d98c..5cabe5b 100644 --- a/dlls/advapi32/registry.c +++ b/dlls/advapi32/registry.c @@ -80,6 +80,7 @@ static HKEY special_root_keys[NB_SPECIAL_ROOT_KEYS]; static BOOL hkcu_cache_disabled; typedef struct { + HKEY hkcu; HKEY hklm; DWORD samDesired; WCHAR *path; @@ -315,8 +316,10 @@ static HKEY resolve_hkcr( HKEY hkey ) return NULL; } + if (!hkcr->hkcu) RegOpenKeyExW( HKEY_CURRENT_USER , hkcr->path, 0, hkcr->samDesired, &hkcr->hkcu ); if (!hkcr->hklm) RegOpenKeyExW( HKEY_LOCAL_MACHINE, hkcr->path, 0, hkcr->samDesired, &hkcr->hklm ); - ret = hkcr->hklm; + + ret = hkcr->hkcu ? hkcr->hkcu : hkcr->hklm; LeaveCriticalSection( &hkcr_handles_cs ); return ret; @@ -375,7 +378,7 @@ static LSTATUS WINAPI create_hkcr( HKEY hkey, CONST WCHAR *name, WCHAR *class, DWORD options, REGSAM samDesired, SECURITY_ATTRIBUTES *sa, HKEY *retkey, DWORD *dispos ) { - HKEY hklm; + HKEY hkcu, hklm; opened_hkcr_t *hkcr = NULL; LSTATUS res; WCHAR *buf = NULL; @@ -383,15 +386,19 @@ static LSTATUS WINAPI create_hkcr( HKEY hkey, CONST WCHAR *name, WCHAR *class, if ((res = get_hkcr_path( hkey, name, &buf ))) return res; - res = RegCreateKeyExW( HKEY_LOCAL_MACHINE, buf, 0, class, options, samDesired, sa, &hklm, dispos ); + res = RegOpenKeyExW( HKEY_CURRENT_USER, buf, 0, samDesired, &hkcu ); + if (res == ERROR_SUCCESS) RegOpenKeyExW( HKEY_LOCAL_MACHINE, buf, 0, samDesired, &hklm ); + else res = RegCreateKeyExW( HKEY_LOCAL_MACHINE, buf, 0, class, options, samDesired, sa, &hklm, dispos ); if (res) return res; if ((res = create_hkcr_struct(retkey, &hkcr))) { + RegCloseKey( hkcu ); RegCloseKey( hklm ); return res; } + hkcr->hkcu = hkcu; hkcr->hklm = hklm; hkcr->path = buf; hkcr->samDesired = samDesired; @@ -401,7 +408,7 @@ static LSTATUS WINAPI create_hkcr( HKEY hkey, CONST WCHAR *name, WCHAR *class, static LSTATUS WINAPI open_hkcr( HKEY hkey, CONST WCHAR *name, REGSAM samDesired, HKEY *retkey ) { - HKEY hklm; + HKEY hkcu, hklm; opened_hkcr_t *hkcr = NULL; LSTATUS res; WCHAR *buf = NULL; @@ -409,15 +416,19 @@ static LSTATUS WINAPI open_hkcr( HKEY hkey, CONST WCHAR *name, REGSAM samDesired if ((res = get_hkcr_path( hkey, name, &buf ))) return res; - res = RegOpenKeyExW( HKEY_LOCAL_MACHINE, buf, 0, samDesired, &hklm ); + res = RegOpenKeyExW( HKEY_CURRENT_USER, buf, 0, samDesired, &hkcu ); + if (res == ERROR_SUCCESS) RegOpenKeyExW( HKEY_LOCAL_MACHINE, buf, 0, samDesired, &hklm ); + else res = RegOpenKeyExW( HKEY_LOCAL_MACHINE, buf, 0, samDesired, &hklm ); if (res) return res; if ((res = create_hkcr_struct(retkey, &hkcr))) { + RegCloseKey( hkcu ); RegCloseKey( hklm ); return res; } + hkcr->hkcu = hkcu; hkcr->hklm = hklm; hkcr->path = buf; hkcr->samDesired = samDesired; @@ -498,6 +509,7 @@ static LSTATUS close_hkcr( HKEY hkey ) return ERROR_INVALID_HANDLE; } + RegCloseKey(hkcr->hkcu); RegCloseKey(hkcr->hklm); HeapFree( GetProcessHeap(), 0, hkcr->path ); HeapFree( GetProcessHeap(), 0, hkcr ); diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c index d94757f..b119005 100644 --- a/dlls/advapi32/tests/registry.c +++ b/dlls/advapi32/tests/registry.c @@ -2127,9 +2127,8 @@ static void test_classesroot(void) /* try to open that key in hkcr */ res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr ); - todo_wine ok(res == ERROR_SUCCESS || - broken(res == ERROR_FILE_NOT_FOUND /* WinNT */), - "test key not found in hkcr: %d\n", res); + ok(res == ERROR_SUCCESS || broken(res == ERROR_FILE_NOT_FOUND /* WinNT */), + "test key not found in hkcr: %d\n", res); if (res) { skip("HKCR key merging not supported\n"); @@ -2138,7 +2137,7 @@ static void test_classesroot(void) return; } - todo_wine ok(IS_HKCR(hkcr), "hkcr mask not set in %p\n", hkcr); + ok(IS_HKCR(hkcr), "hkcr mask not set in %p\n", hkcr); /* set a value in user's classes */ res = RegSetValueExA(hkey, "val1", 0, REG_SZ, (const BYTE *)"user", sizeof("user")); @@ -2423,9 +2422,8 @@ static void test_classesroot_enum(void) } res = RegOpenKeyA( HKEY_CLASSES_ROOT, "WineTestCls", &hkcr ); - todo_wine ok(res == ERROR_SUCCESS || - broken(res == ERROR_FILE_NOT_FOUND /* WinNT */), - "test key not found in hkcr: %d\n", res); + ok(res == ERROR_SUCCESS || broken(res == ERROR_FILE_NOT_FOUND /* WinNT */), + "test key not found in hkcr: %d\n", res); if (res) { skip("HKCR key merging not supported\n"); @@ -2506,8 +2504,8 @@ static void test_classesroot_enum(void) ok(!strcmp( buffer, "Y" ), "expected 'Y', got '%s'\n", buffer); size = sizeof(buffer); res = RegEnumValueA( hkcr, 2, buffer, &size, NULL, NULL, NULL, NULL ); - ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res ); - ok(!strcmp( buffer, "Z" ), "expected 'Z', got '%s'\n", buffer); + todo_wine ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res ); + todo_wine ok(!strcmp( buffer, "Z" ), "expected 'Z', got '%s'\n", buffer); size = sizeof(buffer); res = RegEnumValueA( hkcr, 3, buffer, &size, NULL, NULL, NULL, NULL ); ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res ); @@ -2519,8 +2517,8 @@ static void test_classesroot_enum(void) ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res ); ok(!strcmp( buffer, "B" ), "expected 'B', got '%s'\n", buffer); res = RegEnumKeyA( hkcr, 2, buffer, size ); - ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res ); - ok(!strcmp( buffer, "C" ), "expected 'C', got '%s'\n", buffer); + todo_wine ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res ); + todo_wine ok(!strcmp( buffer, "C" ), "expected 'C', got '%s'\n", buffer); res = RegEnumKeyA( hkcr, 3, buffer, size ); ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res ); -- 1.8.2.3