[core] fix default listing of large SanDisk SSD devices

* Closes #2164
* Also add breakdown of score computation when device enumeration debug is active
* Also fix a minor Code Analysis warning in msapi_utf8.h
This commit is contained in:
Pete Batard 2023-02-13 13:31:40 +00:00
parent 3281f6b97e
commit b163b3dfe2
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
6 changed files with 51 additions and 25 deletions

View File

@ -418,9 +418,9 @@ BOOL GetOpticalMedia(IMG_SAVE* img_save)
/* For debugging user reports of HDDs vs UFDs */ /* For debugging user reports of HDDs vs UFDs */
//#define FORCED_DEVICE //#define FORCED_DEVICE
#ifdef FORCED_DEVICE #ifdef FORCED_DEVICE
#define FORCED_VID 0x048D #define FORCED_VID 0x0781
#define FORCED_PID 0x4030 #define FORCED_PID 0x55AE
#define FORCED_NAME "HP iLO Internal SD-CARD USB Device" #define FORCED_NAME "SanDisk Extreme 55AE SCSI Disk Device"
#endif #endif
void ClearDrives(void) void ClearDrives(void)

View File

@ -92,6 +92,8 @@ static str_score_t str_adjust[] = {
{ "Flash", -10 }, { "Flash", -10 },
{ "SD-CARD", -10 }, { "SD-CARD", -10 },
{ "HDD", +20 }, { "HDD", +20 },
{ "SATA", +20 },
{ "SCSI", +20 },
{ "SSD", +20 } { "SSD", +20 }
}; };

View File

@ -6,7 +6,7 @@
* *
* See also: https://utf8everywhere.org * See also: https://utf8everywhere.org
* *
* Copyright © 2010-2022 Pete Batard <pete@akeo.ie> * Copyright © 2010-2023 Pete Batard <pete@akeo.ie>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -359,7 +359,8 @@ static __inline int GetWindowTextU(HWND hWnd, char* lpString, int nMaxCount)
err = GetLastError(); err = GetLastError();
} }
wfree(lpString); wfree(lpString);
lpString[nMaxCount - 1] = 0; if (lpString != NULL)
lpString[nMaxCount - 1] = 0;
SetLastError(err); SetLastError(err);
return ret; return ret;
} }

View File

@ -3638,14 +3638,14 @@ skip_args_processing:
nWindowsVersion = forced_windows_version; nWindowsVersion = forced_windows_version;
// ...and nothing of value was lost // ...and nothing of value was lost
// TODO: Set to <= for 3.22 // TODO: Set to <= for 3.23
if (nWindowsVersion < WINDOWS_7) { if (nWindowsVersion < WINDOWS_7) {
// Load the translation before we print the error // Load the translation before we print the error
get_loc_data_file(loc_file, selected_locale); get_loc_data_file(loc_file, selected_locale);
right_to_left_mode = ((selected_locale->ctrl_id) & LOC_RIGHT_TO_LEFT); right_to_left_mode = ((selected_locale->ctrl_id) & LOC_RIGHT_TO_LEFT);
// Set MB_SYSTEMMODAL to prevent Far Manager from stealing focus... // Set MB_SYSTEMMODAL to prevent Far Manager from stealing focus...
MessageBoxExU(NULL, MessageBoxExU(NULL,
lmprintf(MSG_294, (nWindowsVersion == WINDOWS_7) ? 3 : 2, (nWindowsVersion == WINDOWS_7) ? 21 : 18), lmprintf(MSG_294, (nWindowsVersion == WINDOWS_7) ? 3 : 2, (nWindowsVersion == WINDOWS_7) ? 22 : 18),
lmprintf(MSG_293), MB_ICONSTOP | MB_IS_RTL | MB_SYSTEMMODAL, selected_langid); lmprintf(MSG_293), MB_ICONSTOP | MB_IS_RTL | MB_SYSTEMMODAL, selected_langid);
goto out; goto out;
} }

View File

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

View File

@ -440,21 +440,32 @@ BOOL SmartGetVersion(HANDLE hdevice)
*/ */
int IsHDD(DWORD DriveIndex, uint16_t vid, uint16_t pid, const char* strid) int IsHDD(DWORD DriveIndex, uint16_t vid, uint16_t pid, const char* strid)
{ {
int score = 0; int score = 0, score_list_size = 0;
size_t i, mlen, ilen; size_t i, mlen, ilen;
BOOL wc; BOOL wc;
uint64_t drive_size; uint64_t drive_size;
int8_t score_list[16];
char str[64] = { 0 };
// Boost the score if fixed, as these are *generally* HDDs // Boost the score if fixed, as these are *generally* HDDs
if (GetDriveTypeFromIndex(DriveIndex) == DRIVE_FIXED) if (GetDriveTypeFromIndex(DriveIndex) == DRIVE_FIXED) {
score += 3; score_list[score_list_size] = 3;
score += score_list[score_list_size++];
}
// Adjust the score depending on the size // Adjust the score depending on the size
drive_size = GetDriveSize(DriveIndex); drive_size = GetDriveSize(DriveIndex);
if (drive_size > 800 * GB) if (drive_size > 800 * GB) {
score += 10; score_list[score_list_size] = 15;
else if (drive_size < 32 * GB) score += score_list[score_list_size++];
score -= 10; if (drive_size > 1800 * GB) {
score_list[score_list_size] = 15;
score += score_list[score_list_size++];
}
} else if (drive_size < 32 * GB) {
score_list[score_list_size] = -15;
score += score_list[score_list_size++];
}
// Check the string against well known HDD identifiers // Check the string against well known HDD identifiers
if (strid != NULL) { if (strid != NULL) {
@ -466,7 +477,8 @@ int IsHDD(DWORD DriveIndex, uint16_t vid, uint16_t pid, const char* strid)
wc = (str_score[i].name[mlen-1] == '#'); wc = (str_score[i].name[mlen-1] == '#');
if ( (_strnicmp(strid, str_score[i].name, mlen-((wc)?1:0)) == 0) if ( (_strnicmp(strid, str_score[i].name, mlen-((wc)?1:0)) == 0)
&& ((!wc) || ((strid[mlen] >= '0') && (strid[mlen] <= '9'))) ) { && ((!wc) || ((strid[mlen] >= '0') && (strid[mlen] <= '9'))) ) {
score += str_score[i].score; score_list[score_list_size] = str_score[i].score;
score += score_list[score_list_size++];
break; break;
} }
} }
@ -475,14 +487,17 @@ int IsHDD(DWORD DriveIndex, uint16_t vid, uint16_t pid, const char* strid)
// Adjust for oddball devices // Adjust for oddball devices
if (strid != NULL) { if (strid != NULL) {
for (i = 0; i < ARRAYSIZE(str_adjust); i++) for (i = 0; i < ARRAYSIZE(str_adjust); i++)
if (StrStrIA(strid, str_adjust[i].name) != NULL) if (StrStrIA(strid, str_adjust[i].name) != NULL) {
score += str_adjust[i].score; score_list[score_list_size] = str_adjust[i].score;
score += score_list[score_list_size++];
}
} }
// Check against known VIDs // Check against known VIDs
for (i = 0; i < ARRAYSIZE(vid_score); i++) { for (i = 0; i < ARRAYSIZE(vid_score); i++) {
if (vid == vid_score[i].vid) { if (vid == vid_score[i].vid) {
score += vid_score[i].score; score_list[score_list_size] = vid_score[i].score;
score += score_list[score_list_size++];
break; break;
} }
} }
@ -490,11 +505,19 @@ int IsHDD(DWORD DriveIndex, uint16_t vid, uint16_t pid, const char* strid)
// Check against known VID:PIDs // Check against known VID:PIDs
for (i = 0; i < ARRAYSIZE(vidpid_score); i++) { for (i = 0; i < ARRAYSIZE(vidpid_score); i++) {
if ((vid == vidpid_score[i].vid) && (pid == vidpid_score[i].pid)) { if ((vid == vidpid_score[i].vid) && (pid == vidpid_score[i].pid)) {
score += vidpid_score[i].score; score_list[score_list_size] = vidpid_score[i].score;
score += score_list[score_list_size++];
break; break;
} }
} }
duprintf(" Score: %d\n", score); // Print a breakdown of the device score if requested
if (usb_debug) {
static_strcat(str, "Device score: ");
for (i = 0; i < score_list_size; i++)
static_sprintf(&str[strlen(str)], "%+d", score_list[i]);
uprintf("%s=%+d → Detected as %s", str, score, (score > 0) ? "HDD" : "UFD");
}
return score; return score;
} }