| 58 | } |
| 59 | |
| 60 | Util::null_terminated_wstring_view Localization::LoadLocalizedResourceString(uint16_t resource, HINSTANCE hInst, WORD lang) |
| 61 | { |
| 62 | const auto fail = [resource, hInst, lang]() -> Util::null_terminated_wstring_view |
| 63 | { |
| 64 | if (lang != MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)) |
| 65 | { |
| 66 | // try again in English |
| 67 | return LoadLocalizedResourceString(resource, hInst, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | return L"[error occurred while loading localized string]"; |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | const HRSRC src = FindResourceEx(hInst, RT_STRING, MAKEINTRESOURCE((resource >> 4) + 1), lang); |
| 76 | if (!src) |
| 77 | { |
| 78 | LastErrorHandle(spdlog::level::warn, L"Failed to find string resource."); |
| 79 | return fail(); |
| 80 | } |
| 81 | |
| 82 | const HGLOBAL res = LoadResource(hInst, src); |
| 83 | if (!res) |
| 84 | { |
| 85 | LastErrorHandle(spdlog::level::warn, L"Failed to load string resource."); |
| 86 | return fail(); |
| 87 | } |
| 88 | |
| 89 | auto str = static_cast<const wchar_t *>(LockResource(res)); |
| 90 | if (!str) |
| 91 | { |
| 92 | LastErrorHandle(spdlog::level::warn, L"Failed to lock string resource."); |
| 93 | return fail(); |
| 94 | } |
| 95 | |
| 96 | for (int i = 0; i < (resource & 0xF); i++) |
| 97 | { |
| 98 | str += 1 + static_cast<uint16_t>(*str); |
| 99 | } |
| 100 | |
| 101 | std::wstring_view resStr { str + 1, static_cast<uint16_t>(*str) }; |
| 102 | if (!resStr.empty() && resStr.back() == L'\0') |
| 103 | { |
| 104 | return Util::null_terminated_wstring_view::make_unsafe(resStr.data(), resStr.length() - 1); |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | return fail(); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | std::thread Localization::ShowLocalizedMessageBox(uint16_t resource, UINT type, HINSTANCE hInst, WORD lang) |
| 113 | { |
nothing calls this directly
no outgoing calls
no test coverage detected