[PATCH] wineconsole: When loading settings for an application, respect a 0 in FontSize

Fabian Maurer dark.shadow4 at web.de
Mon Apr 16 17:09:44 CDT 2018


Fixes bug 44976.

Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
---
 dlls/kernel32/tests/console.c   | 72 +++++++++++++++++++++++++++++----
 programs/wineconsole/registry.c | 13 +++++-
 2 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c
index 926c052686..38ffec868d 100644
--- a/dlls/kernel32/tests/console.c
+++ b/dlls/kernel32/tests/console.c
@@ -3019,6 +3019,66 @@ static void test_GetConsoleScreenBufferInfoEx(HANDLE std_output)
     ok(GetLastError() == 0xdeadbeef, "got %u, expected 0xdeadbeef\n", GetLastError());
 }
 
+static void reset_console(HANDLE *hConIn, HANDLE *hConOut)
+{
+    CloseHandle(*hConIn);
+    CloseHandle(*hConOut);
+    FreeConsole();
+    ok(AllocConsole(), "Couldn't alloc console\n");
+    *hConIn = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
+    *hConOut = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
+    ok(*hConIn != INVALID_HANDLE_VALUE, "Opening ConIn\n");
+    ok(*hConOut != INVALID_HANDLE_VALUE, "Opening ConOut\n");
+}
+
+static void set_redirected_console_settings(DWORD font_size)
+{
+    char path_exe[MAX_PATH];
+    HKEY key_console, key_setting;
+    int i;
+
+    GetModuleFileNameA(NULL, path_exe, MAX_PATH);
+    for (i = 0; path_exe[i]; i++)
+    {
+        if (path_exe[i] == '\\')
+            path_exe[i] = '_';
+    }
+
+    if (!RegOpenKeyA(HKEY_CURRENT_USER, "Console", &key_console))
+    {
+        if (!RegCreateKeyExA(key_console, path_exe, 0, 0, 0, KEY_ALL_ACCESS, 0, &key_setting, 0))
+        {
+            RegSetValueExA(key_setting, "FontSize", 0, REG_DWORD, (BYTE *)&font_size, sizeof(DWORD));
+            RegCloseKey(key_setting);
+        }
+        RegCloseKey(key_console);
+    }
+}
+
+static void test_Redirected(HANDLE std_output)
+{
+    HANDLE std_input_dummy;
+    CONSOLE_FONT_INFO cfi;
+    COORD coord;
+    BOOL ret;
+
+    memset(&cfi, 0, sizeof(CONSOLE_FONT_INFO));
+    ret = GetCurrentConsoleFont(std_output, FALSE, &cfi);
+    ok(ret, "got %d, expected non-zero\n", ret);
+
+    set_redirected_console_settings(MAKELONG(42, 43));
+    reset_console(&std_input_dummy, &std_output);
+    coord = GetConsoleFontSize(std_output, cfi.nFont);
+    ok(coord.X == 42, "Expected 42, got %d\n", coord.X);
+    ok(coord.Y == 43, "Expected 43, got %d\n", coord.Y);
+
+    set_redirected_console_settings(MAKELONG(0, 0));
+    reset_console(&std_input_dummy, &std_output);
+    coord = GetConsoleFontSize(std_output, cfi.nFont);
+    ok(coord.X == 8, "Expected 8, got %d\n", coord.X);
+    ok(coord.Y == 16, "Expected 16, got %d\n", coord.Y);
+}
+
 START_TEST(console)
 {
     static const char font_name[] = "Lucida Console";
@@ -3129,14 +3189,7 @@ START_TEST(console)
     testWaitForConsoleInput(hConIn);
 
     /* clear duplicated console font table */
-    CloseHandle(hConIn);
-    CloseHandle(hConOut);
-    FreeConsole();
-    ok(AllocConsole(), "Couldn't alloc console\n");
-    hConIn = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
-    hConOut = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
-    ok(hConIn != INVALID_HANDLE_VALUE, "Opening ConIn\n");
-    ok(hConOut != INVALID_HANDLE_VALUE, "Opening ConOut\n");
+    reset_console(&hConIn, &hConOut);
 
     testCtrlHandler();
     /* still to be done: access rights & access on objects */
@@ -3170,4 +3223,7 @@ START_TEST(console)
     test_GetConsoleFontInfo(hConOut);
     test_SetConsoleFont(hConOut);
     test_GetConsoleScreenBufferInfoEx(hConOut);
+
+    test_Redirected(hConOut);
+    reset_console(&hConIn, &hConOut);
 }
diff --git a/programs/wineconsole/registry.c b/programs/wineconsole/registry.c
index 080431a5ff..92c53a7ca4 100644
--- a/programs/wineconsole/registry.c
+++ b/programs/wineconsole/registry.c
@@ -126,8 +126,17 @@ static void WINECON_RegLoadHelper(HKEY hConKey, struct config_data* cfg)
     count = sizeof(val);
     if (!RegQueryValueExW(hConKey, wszFontSize, 0, &type, (LPBYTE)&val, &count))
     {
-        cfg->cell_height = HIWORD(val);
-        cfg->cell_width  = LOWORD(val);
+        int height = HIWORD(val);
+        int width = LOWORD(val);
+        /* A value of zero reflects the default settings */
+        if (height != 0)
+        {
+            cfg->cell_height = height;
+        }
+        if (width != 0)
+        {
+            cfg->cell_width = width;
+        }
     }
 
     count = sizeof(val);
-- 
2.17.0




More information about the wine-devel mailing list