[PATCH v2 07/12] kernel32: Autoinitialize geographic values when launching any program.

João Diogo Ferreira devilj at outlook.pt
Tue Oct 22 21:13:57 CDT 2019


V2: Add more traces to make it obvious what is calling SetUserGeoName.

FIXES BUG: 46196
https://bugs.winehq.org/show_bug.cgi?id=46196

Autodetects the correct GeoName and GeoID based on Wine's current locale.
This should be more than satisfactory for almost everyone.

That being said, it may come in handy to bypass this in some scenarios:
  * When testing geo behaviour without wanting to change the languague;
  * Users who use a foreign language but want Wine and programs knows the
    actual country they live in;
  * Users in countries not represented by Linux or Wine locales.
The last case is, I think, particularly important, as that's where this patch
could cause real loss of functionality.

To opt-out:
  * Set HKCU\\Control Panel\\International\\Geo\\WineDisableAutoConfig to 1.
    * Type is REG_DWORD.
    * This key is created automatically if it doesn't exist yet.

Signed-off-by: João Diogo Craveiro Ferreira <devilj at outlook.pt>
---
 dlls/kernel32/kernel_main.c    |  3 +++
 dlls/kernel32/kernel_private.h |  1 +
 dlls/kernel32/locale.c         | 44 ++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+)

diff --git a/dlls/kernel32/kernel_main.c b/dlls/kernel32/kernel_main.c
index dfa66f0295..206972c210 100644
--- a/dlls/kernel32/kernel_main.c
+++ b/dlls/kernel32/kernel_main.c
@@ -88,6 +88,9 @@ static BOOL process_attach( HMODULE module )
     /* Setup registry locale information */
     LOCALE_InitRegistry();
 
+    /* Setup registry geographic information */
+    LOCALE_InitGeo();
+
     /* Setup registry timezone information */
     TIMEZONE_InitRegistry();
 
diff --git a/dlls/kernel32/kernel_private.h b/dlls/kernel32/kernel_private.h
index af85bee84d..6b93add056 100644
--- a/dlls/kernel32/kernel_private.h
+++ b/dlls/kernel32/kernel_private.h
@@ -76,6 +76,7 @@ extern void COMPUTERNAME_Init(void) DECLSPEC_HIDDEN;
 /* locale.c */
 extern void LOCALE_Init(void) DECLSPEC_HIDDEN;
 extern void LOCALE_InitRegistry(void) DECLSPEC_HIDDEN;
+extern void LOCALE_InitGeo(void) DECLSPEC_HIDDEN;
 
 /* time.c */
 extern void TIMEZONE_InitRegistry(void) DECLSPEC_HIDDEN;
diff --git a/dlls/kernel32/locale.c b/dlls/kernel32/locale.c
index eb8ad14bcd..2e785e0361 100644
--- a/dlls/kernel32/locale.c
+++ b/dlls/kernel32/locale.c
@@ -877,6 +877,50 @@ void LOCALE_InitRegistry(void)
     NtClose( hkey );
 }
 
+/* Initialize the geo values in the registry. */
+void LOCALE_InitGeo(void)
+{
+    int enabled = 1;
+    HANDLE hkey = create_geo_regkey();
+
+    if (hkey)
+    {
+        WCHAR value[] = {'W','i','n','e','D','i','s','a','b','l','e','A','u','t','o','C','o','n','f','i','g',0};
+        UNICODE_STRING uvalue;
+        KEY_VALUE_PARTIAL_INFORMATION kvi;
+        DWORD count;
+        NTSTATUS status;
+        RtlInitUnicodeString(&uvalue, value);
+
+        status = NtQueryValueKey(hkey, &uvalue, KeyValuePartialInformation, &kvi, sizeof(kvi), &count);
+        if (status == STATUS_SUCCESS)
+            enabled = !kvi.Data[0];
+        else if (status == STATUS_OBJECT_NAME_NOT_FOUND)
+        {
+            DWORD d = 0;
+            NtSetValueKey(hkey, &uvalue, 0, REG_DWORD, &d, sizeof(d));
+        }
+
+        NtClose(hkey);
+    }
+
+    if (enabled)
+    {
+        WCHAR name[4];
+        static WCHAR fallback[] = {'0','0','1',0}; /* World */
+        int result;
+
+        TRACE("Setting up geo values...\n");
+        if ((result = GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_SISO3166CTRYNAME, name, ARRAY_SIZE(name))))
+            result = SetUserGeoName(name);
+
+        if (!result)
+            SetUserGeoName(fallback);
+        TRACE("Finished setting geo values.\n");
+    }
+    else
+        TRACE("Skipping: disabled by user.\n");
+}
 
 #ifdef __APPLE__
 /***********************************************************************
-- 
2.23.0



More information about the wine-devel mailing list