Browse Source

[misc] fall back to user/system default locale when getting error description

* Some Windows localisations do not contain English MUI files for specific error codes, so show *something* instead of an error.
* Closes #2687.
pull/2704/head
Rairii 6 months ago
committed by Pete Batard
parent
commit
50801a47ff
No known key found for this signature in database GPG Key ID: 38E0CF5E69EDD671
  1. 10
      src/rufus.rc
  2. 17
      src/stdio.c

10
src/rufus.rc

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 4.7.2220"
CAPTION "Rufus 4.7.2221"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -399,8 +399,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,7,2220,0
PRODUCTVERSION 4,7,2220,0
FILEVERSION 4,7,2221,0
PRODUCTVERSION 4,7,2221,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -418,13 +418,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "4.7.2220"
VALUE "FileVersion", "4.7.2221"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2025 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-4.7.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "4.7.2220"
VALUE "ProductVersion", "4.7.2221"
END
END
BLOCK "VarFileInfo"

17
src/stdio.c

@ -234,10 +234,22 @@ const char *WindowsErrorString(void)
DWORD size, presize;
DWORD error_code, _error_code, format_error;
LCID locale;
HANDLE hModule = NULL;
error_code = GetLastError();
_error_code = error_code;
// Set thread locale to en-US when in this function.
// This is because kernel32!FormatMessage is documented to try the following order when dwLanguageId==0:
// - Language neutral
// - Thread locale
// - User default locale
// - System default locale
// - English US
// Some Windows localisations do not provide English MUI resources for specific error codes.
// So with thread locale set to en-US, FormatMessage will try neutral, then en-US, then fall back to localised string.
locale = GetThreadLocale();
SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
retry:
// Check for specific facility error codes
switch (HRESULT_FACILITY(_error_code)) {
@ -262,7 +274,7 @@ retry:
// coverity[var_deref_model]
size = FormatMessageU(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
((hModule != NULL) ? FORMAT_MESSAGE_FROM_HMODULE : 0), hModule,
_error_code, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
_error_code, 0,
&err_string[presize], (DWORD)(sizeof(err_string) - strlen(err_string)), NULL);
if (size == 0) {
format_error = GetLastError();
@ -278,7 +290,7 @@ retry:
_error_code = HRESULT_CODE(_error_code);
goto retry;
}
static_sprintf(err_string, "[0x%08lX] (NB: This system was unable to provide an English error message)", error_code);
static_sprintf(err_string, "[0x%08lX] (NB: This system was unable to provide a descriptive error message)", error_code);
break;
default:
static_sprintf(err_string, "[0x%08lX] (FormatMessage error code 0x%08lX)", error_code, format_error);
@ -293,6 +305,7 @@ retry:
err_string[size--] = 0;
}
SetThreadLocale(locale); // Set the original thread locale on exit
SetLastError(error_code); // Make sure we don't change the errorcode on exit
return err_string;
}

Loading…
Cancel
Save