[PATCH v2 6/7] kernel32: Autoinitialize geographic values when launching any program.

João Diogo Ferreira devilj at outlook.pt
Tue Oct 29 23:30:58 CDT 2019


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'
    could cause real loss of functionality.

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

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46196
Signed-off-by: João Diogo Craveiro Ferreira <devilj at outlook.pt>
---
Supersedes: 171866
---
 dlls/kernel32/kernel_main.c    |  3 +++
 dlls/kernel32/kernel_private.h |  1 +
 dlls/kernel32/locale.c         | 47 ++++++++++++++++++++++++++++++++++
 3 files changed, 51 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 e9d46949d1..cc8ca45a05 100644
--- a/dlls/kernel32/locale.c
+++ b/dlls/kernel32/locale.c
@@ -877,6 +877,53 @@ 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
+        {
+            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("Initializing geographic data...\n");
+        if ((result = GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_SISO3166CTRYNAME,
+                                     name, ARRAY_SIZE(name))))
+            result = SetUserGeoName(name);
+
+        if (!result)
+            SetUserGeoName(fallback);
+        TRACE("Finished initializing geographic data.\n");
+    }
+    else
+        TRACE("Skipping: disabled by user.\n");
+}
 
 #ifdef __APPLE__
 /***********************************************************************
-- 
2.23.0



More information about the wine-devel mailing list