Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per-app Language Preferences 1.1 #1458

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions mods/per-app-language-preferences.wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -65,30 +65,42 @@ Note that it changes the language only and does not affect the encoding used in

// ===========================================================

bool langid_determined = false;
int my_langid = 0;

using GetUserDefaultUILanguage_t = short(WINAPI*)();
GetUserDefaultUILanguage_t GetUserDefaultUILanguage_Original;
short WINAPI GetUserDefaultUILanguage_Hook() {
wchar_t filename_buf[2049];

Wh_Log(L">GetUserDefaultUILanguage");

GetModuleFileNameW(NULL, filename_buf, 2049);
Wh_Log(L">Process file: %ls", filename_buf);

for(int index = 0; ; index++) {
PCWSTR glob = Wh_GetStringSetting(L"programList[%d].glob", index);
if(!*glob) {
// Wh_Log(L">GetUserDefaultUILanguage");

if(!langid_determined) {
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) {
Wh_FreeStringSetting(glob);
break;
}
if(S_OK == PathMatchSpecExW(filename_buf, glob, PMSF_MULTIPLE)) {
lang_id = Wh_GetIntSetting(L"programList[%d].langId", index);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string is not freed with Wh_FreeStringSetting in this case. Note that you can also use WindhawkUtils::StringSetting to have it freed automatically.

break;
}
Wh_FreeStringSetting(glob);
break;
}
if(S_OK == PathMatchSpecExW(filename_buf, glob, PMSF_MULTIPLE)) {
int lang_id = Wh_GetIntSetting(L"programList[%d].langId", index);
return lang_id;
}
Wh_FreeStringSetting(glob);
delete[] filename_buf;
my_langid = lang_id;
langid_determined = true;
}

return GetUserDefaultUILanguage_Original();
if(my_langid == -1) {
return GetUserDefaultUILanguage_Original();
} else {
return my_langid;
}
}

// ===========================================================
Expand Down
Loading