Jacek Caban : win32u: Factor out reg_open_hkcu_key.

Alexandre Julliard julliard at winehq.org
Thu Oct 14 15:09:34 CDT 2021


Module: wine
Branch: master
Commit: d841b31aeee36f40436feab4e606dca2f8474f16
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=d841b31aeee36f40436feab4e606dca2f8474f16

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Oct 14 15:21:54 2021 +0200

win32u: Factor out reg_open_hkcu_key.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/win32u/font.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/dlls/win32u/font.c b/dlls/win32u/font.c
index e35aeefe61f..1f9c2adc21c 100644
--- a/dlls/win32u/font.c
+++ b/dlls/win32u/font.c
@@ -49,6 +49,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(font);
 
 static HKEY wine_fonts_key;
 static HKEY wine_fonts_cache_key;
+static HKEY hkcu_key;
 
 struct font_physdev
 {
@@ -616,6 +617,12 @@ static HKEY reg_create_key( HKEY root, const WCHAR *name, ULONG name_len,
     return ret;
 }
 
+static HKEY reg_open_hkcu_key( const char *name )
+{
+    WCHAR nameW[128];
+    return reg_open_key( hkcu_key, nameW, asciiz_to_unicode( nameW, name ) - sizeof(WCHAR) );
+}
+
 static void set_reg_value( HKEY hkey, const WCHAR *name, UINT type, const void *value, DWORD count )
 {
     unsigned int name_size = name ? lstrlenW( name ) * sizeof(WCHAR) : 0;
@@ -643,8 +650,8 @@ static ULONG query_reg_value( HKEY hkey, const WCHAR *name,
     return size - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
 }
 
-static ULONG query_reg_ascii_value( HKEY hkey, const char *name,
-                                    KEY_VALUE_PARTIAL_INFORMATION *info, ULONG size )
+ULONG query_reg_ascii_value( HKEY hkey, const char *name,
+                             KEY_VALUE_PARTIAL_INFORMATION *info, ULONG size )
 {
     WCHAR nameW[64];
     asciiz_to_unicode( nameW, name );
@@ -4371,7 +4378,7 @@ static BOOL get_key_value( HKEY key, const char *name, DWORD *value )
     return !!count;
 }
 
-static UINT init_font_options( HKEY hkcu )
+static UINT init_font_options(void)
 {
     char value_buffer[FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[20 * sizeof(WCHAR)])];
     KEY_VALUE_PARTIAL_INFORMATION *info = (void *)value_buffer;
@@ -4379,9 +4386,6 @@ static UINT init_font_options( HKEY hkcu )
     DWORD i, val, gamma = 1400;
     UINT dpi = 0;
 
-    static const WCHAR desktop_keyW[] =
-        { 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p' };
-
     if (query_reg_ascii_value( wine_fonts_key, "AntialiasFakeBoldOrItalic",
                                info, sizeof(value_buffer) ) && info->Type == REG_SZ)
     {
@@ -4389,7 +4393,7 @@ static UINT init_font_options( HKEY hkcu )
         antialias_fakes = (wcschr( valsW, *(const WCHAR *)info->Data ) != NULL);
     }
 
-    if ((key = reg_open_key( hkcu, desktop_keyW, sizeof(desktop_keyW) )))
+    if ((key = reg_open_hkcu_key( "Control Panel\\Desktop" )))
     {
         /* FIXME: handle vertical orientations even though Windows doesn't */
         if (get_key_value( key, "FontSmoothingOrientation", &val ))
@@ -6355,7 +6359,7 @@ UINT font_init(void)
 {
     OBJECT_ATTRIBUTES attr = { sizeof(attr) };
     UNICODE_STRING name;
-    HANDLE mutex, hkcu;
+    HANDLE mutex;
     DWORD disposition;
     UINT dpi = 0;
 
@@ -6366,10 +6370,9 @@ UINT font_init(void)
         {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','F','o','n','t','s'};
     static const WCHAR cacheW[] = {'C','a','c','h','e'};
 
-    if (!(hkcu = open_hkcu())) return 0;
-    wine_fonts_key = reg_create_key( hkcu, wine_fonts_keyW, sizeof(wine_fonts_keyW), 0, NULL );
-    if (wine_fonts_key) dpi = init_font_options( hkcu );
-    NtClose( hkcu );
+    if (!(hkcu_key = open_hkcu())) return 0;
+    wine_fonts_key = reg_create_key( hkcu_key, wine_fonts_keyW, sizeof(wine_fonts_keyW), 0, NULL );
+    if (wine_fonts_key) dpi = init_font_options();
     if (!dpi) return 96;
     update_codepage( dpi );
 




More information about the wine-cvs mailing list