[PATCH 4/6] conhost: Save console configuration directly to default or app-specific key

Hugh McMaster hugh.mcmaster at outlook.com
Mon Apr 11 07:35:53 CDT 2022


Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
 programs/conhost/window.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/programs/conhost/window.c b/programs/conhost/window.c
index 6cccba69d57..cb93ad257a4 100644
--- a/programs/conhost/window.c
+++ b/programs/conhost/window.c
@@ -346,31 +346,29 @@ static void save_registry_key( HKEY key, const struct console_config *config )
 
 static void save_config( const WCHAR *key_name, const struct console_config *config )
 {
-    HKEY key, app_key;
-
-    TRACE( "%s %s\n", debugstr_w( key_name ), debugstr_config( config ));
+    WCHAR *key_path = NULL;
+    HKEY hkey;
 
-    if (RegCreateKeyW( HKEY_CURRENT_USER, L"Console", &key ))
+    if (key_name)
     {
-        ERR("Can't open registry for saving\n");
-        return;
+        int len = lstrlenW( key_name ) + 9;
+        key_path = malloc( len * sizeof(WCHAR) );
+        wsprintfW( key_path, L"%s\\%s", L"Console", key_name );
     }
 
-    if (key_name)
+    if (!RegCreateKeyExW( HKEY_CURRENT_USER, key_name ? key_path : L"Console", 0, NULL,
+                          REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL ))
     {
-        if (RegCreateKeyW( key, key_name, &app_key ))
-        {
-            ERR("Can't open registry for saving\n");
-        }
-        else
-        {
-            /* FIXME: maybe only save the values different from the default value ? */
-            save_registry_key( app_key, config );
-            RegCloseKey( app_key );
-        }
+        TRACE( "Saving %s console settings\n", key_name ? debugstr_w( key_name ) : "default" );
+
+        save_registry_key( hkey, config );
+        RegCloseKey( hkey );
+    }
+    else
+    {
+        ERR( "Error saving %s console settings (%lu)\n",
+             key_name ? debugstr_w( key_name ) : "default", GetLastError() );
     }
-    else save_registry_key( key, config );
-    RegCloseKey(key);
 }
 
 /* fill memory DC with current cells values */
-- 
2.35.1




More information about the wine-devel mailing list