From 5681c3ba41b85b598df881647b5727da41438bce Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Wed, 11 Mar 2020 13:21:32 +0000 Subject: [PATCH] [dos] fix assert when system locale is set to UTF-8 * Recent versions of Windows can set the deafult locale to codepage 65001 (UTF-8). * This produces an assert due to a missing entry in cp_hr_list[], so fix that. * However, this fix alone is not enough, as a GetOEMCP() that returns 65001 means that any systems set to UTF-8 will fall back to codepage 437 for DOS, which is definitely not what we want => Add an extra call to determine the actual OEM codepage when UTF-8 is detected. * Closes #1468 --- src/dos_locale.c | 14 +++++++++++--- src/rufus.rc | 10 +++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/dos_locale.c b/src/dos_locale.c index 2a38bef5..90f1dd34 100644 --- a/src/dos_locale.c +++ b/src/dos_locale.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * DOS keyboard locale setup - * Copyright © 2011-2013 Pete Batard + * Copyright © 2011-2020 Pete Batard * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -419,7 +419,8 @@ static cp_list cp_hr_list[] = { { 59829, "Georgian"}, { 60258, "Lat-Azeri"}, { 60853, "Georgian (Alt)"}, - { 62306, "Cyr-Uzbek"} + { 62306, "Cyr-Uzbek"}, + { 65001, "Unicode (UTF-8)" } }; static const char* cp_to_hr(ULONG cp) @@ -961,13 +962,13 @@ static ULONG fd_upgrade_cp(ULONG cp) } } - // Don't bother about setting up the country or multiple codepages BOOL SetDOSLocale(const char* path, BOOL bFreeDOS) { FILE* fd; char filename[MAX_PATH]; ULONG cp; + UINT actual_cp; const char *kb; int kbdrv; const char* egadrv; @@ -985,6 +986,13 @@ BOOL SetDOSLocale(const char* path, BOOL bFreeDOS) // Now get a codepage cp = GetOEMCP(); + if (cp == 65001) { + // GetOEMCP() may return UTF-8 for the codepage (65001), + // in which case we need to find the actual system OEM cp. + if (GetLocaleInfoA(GetUserDefaultUILanguage(), LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER, + (char*)&actual_cp, sizeof(actual_cp))) + cp = actual_cp; + } egadrv = bFreeDOS?fd_get_ega(cp):ms_get_ega(cp); if (egadrv == NULL) { // We need to use the fallback CP from the keyboard we got above, as 437 is not always available diff --git a/src/rufus.rc b/src/rufus.rc index 389012e2..1bd837d2 100644 --- a/src/rufus.rc +++ b/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 3.9.1625" +CAPTION "Rufus 3.9.1626" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -395,8 +395,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,9,1625,0 - PRODUCTVERSION 3,9,1625,0 + FILEVERSION 3,9,1626,0 + PRODUCTVERSION 3,9,1626,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -414,13 +414,13 @@ BEGIN VALUE "Comments", "https://rufus.ie" VALUE "CompanyName", "Akeo Consulting" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "3.9.1625" + VALUE "FileVersion", "3.9.1626" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "OriginalFilename", "rufus-3.9.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "3.9.1625" + VALUE "ProductVersion", "3.9.1626" END END BLOCK "VarFileInfo"