From: Jon Turney Date: Thu, 10 Sep 2020 16:31:56 +0000 (+0100) Subject: Don't localize mbox strings written to log X-Git-Tag: release_2.911~9 X-Git-Url: https://cygwin.com/git/?a=commitdiff_plain;h=477a6ff52ec52e558188033d9f3128ac6ef7ef27;p=cygwin-apps%2Fsetup.git Don't localize mbox strings written to log Add LoadStringWEx to access string resource for a specifc locale. Use that in mbox when formatting string for log. --- diff --git a/msg.cc b/msg.cc index 5badcc3c..00eaf5aa 100644 --- a/msg.cc +++ b/msg.cc @@ -129,7 +129,7 @@ LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) { int mbox(HWND owner, unsigned int format_id, int mb_type, ...) { - std::wstring fmt = LoadStringW(format_id); + std::wstring fmt = LoadStringWEx(format_id, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); if (fmt.empty()) fmt = L"Internal error: format string resource not found"; @@ -138,12 +138,20 @@ mbox(HWND owner, unsigned int format_id, int mb_type, ...) std::wstring buf = vformat(fmt, args); va_end(args); - // write to log as UTF8 + // write unlocalized to log as UTF8 Log (LOG_PLAIN) << "mbox " << ": " << wstring_to_string(buf) << endLog; if (unattended_mode) return unattended_result(mb_type); + fmt = LoadStringW(format_id); + if (fmt.empty()) + fmt = L"Internal error: format string resource not found"; + + va_start(args, mb_type); + buf = vformat(fmt, args); + va_end(args); + bool retry_continue = (mb_type & MB_TYPEMASK) == MB_RETRYCONTINUE; if (retry_continue) { mb_type &= ~MB_TYPEMASK; diff --git a/win32.cc b/win32.cc index b6e7c947..be4a9acd 100644 --- a/win32.cc +++ b/win32.cc @@ -462,6 +462,38 @@ WowNativeMachine () #endif } +const std::wstring +LoadStringWEx(UINT uID, UINT langId) +{ + HINSTANCE hInstance = GetModuleHandle(NULL); + + // Convert the string ID into a bundle number + LPCSTR bundle = MAKEINTRESOURCE(uID / 16 + 1); + HRSRC hRes = ::FindResourceEx(hInstance, RT_STRING, bundle, langId); + if (hRes) + { + HGLOBAL h = ::LoadResource(hInstance, hRes); + if (h) + { + HGLOBAL hGlob = ::LockResource(h); + + // walk string bundle + wchar_t *buf = (wchar_t *)hGlob; + for (unsigned int i = 0; i < (uID & 15); i++) + { + buf += 1 + (UINT)*buf; + } + + int len = *buf; + return std::wstring(buf + 1, len); + } + } + // N.B.: Due to the way string bundles are encoded, there's no difference + // between an absent string resource whose bundle is present, and a string + // resource containing the null string. + return L""; +} + const std::wstring LoadStringW(unsigned int uID) { diff --git a/win32.h b/win32.h index 05f931c8..dcaa2511 100644 --- a/win32.h +++ b/win32.h @@ -195,6 +195,8 @@ SetDlgItemRect (HWND h, int item, LPRECT r) } const std::wstring LoadStringW(unsigned int uID); +const std::wstring LoadStringWEx(UINT uID, UINT langId); + bool is_developer_mode(void); #endif /* SETUP_WIN32_H */