diff --git a/mods/per-app-language-preferences.wh.cpp b/mods/per-app-language-preferences.wh.cpp index 150e8a08..c6497bf7 100644 --- a/mods/per-app-language-preferences.wh.cpp +++ b/mods/per-app-language-preferences.wh.cpp @@ -2,7 +2,7 @@ // @id per-app-language-preferences // @name Per-app Language Preferences // @description Override the preferred UI language for specific apps. -// @version 1.0 +// @version 1.1 // @author yezhiyi9670 // @github https://github.com/yezhiyi9670 // @include * @@ -23,7 +23,9 @@ This mod allow you to override the preferred language for specific apps using th Instructions on the settings: -- The filename pattern is parsed using [PathMatchSpecExW](https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-pathmatchspecexw). It supports wildcard `*` `?`. It also supports multiple semicolon-separated patterns. +- The file path pattern is parsed using [PathMatchSpecExW](https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-pathmatchspecexw). It supports wildcard `*` `?`. It also supports multiple semicolon-separated patterns. + Note that the full path (e.g. `C:\Program Files\MyApp\my-app.exe`), rather than the base filename (e.g. `my-app.exe`), is checked against the pattern. + To check the actual executable file path of your app, use the task manager or observe log output from this mod. - The language ID can be found in the [MS-LCID](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/70feba9f-294e-491e-b6eb-56532684c37f) specification. For example, the language ID for English (United States) is 1033. Use cases: @@ -49,9 +51,9 @@ Note that it changes the language only and does not affect the encoding used in - - glob: "*\\example-executable-file-114514.exe" $name: Filename pattern $description: "The pattern corresponding to the program filename." - - langId: 1033 + - langId: -1 $name: Language identifier - $description: "The language ID to apply." + $description: "The language ID to apply. Set -1 to use the system default value." $name: Overrides List $description: >- Assign a new language to these programs. @@ -65,16 +67,26 @@ Note that it changes the language only and does not affect the encoding used in // =========================================================== +int my_langid = -1; + using GetUserDefaultUILanguage_t = short(WINAPI*)(); GetUserDefaultUILanguage_t GetUserDefaultUILanguage_Original; short WINAPI GetUserDefaultUILanguage_Hook() { - wchar_t filename_buf[2049]; + // Wh_Log(L">GetUserDefaultUILanguage"); - Wh_Log(L">GetUserDefaultUILanguage"); + if(my_langid == -1) { + return GetUserDefaultUILanguage_Original(); + } else { + return my_langid; + } +} - GetModuleFileNameW(NULL, filename_buf, 2049); +void determine_my_langid() { + wchar_t *filename_buf = new wchar_t[2048]; + GetModuleFileNameW(NULL, filename_buf, 2048); Wh_Log(L">Process file: %ls", filename_buf); + int lang_id = -1; for(int index = 0; ; index++) { PCWSTR glob = Wh_GetStringSetting(L"programList[%d].glob", index); if(!*glob) { @@ -82,13 +94,14 @@ short WINAPI GetUserDefaultUILanguage_Hook() { break; } if(S_OK == PathMatchSpecExW(filename_buf, glob, PMSF_MULTIPLE)) { - int lang_id = Wh_GetIntSetting(L"programList[%d].langId", index); - return lang_id; + lang_id = Wh_GetIntSetting(L"programList[%d].langId", index); + Wh_FreeStringSetting(glob); + break; } Wh_FreeStringSetting(glob); } - - return GetUserDefaultUILanguage_Original(); + delete[] filename_buf; + my_langid = lang_id; } // =========================================================== @@ -133,9 +146,17 @@ BOOL ModInit() { BOOL Wh_ModInit() { Wh_Log(L">"); + determine_my_langid(); + return ModInit(); } +void Wh_ModSettingsChanged() { + Wh_Log(L">"); + + determine_my_langid(); +} + // The mod is being unloaded, free all allocated resources. void Wh_ModUninit() { Wh_Log(L">");