[ui] fix regression in conditional expression and use %c always

* This fixes the regression introduced in c28f9bc491.
* 'if ((a && !b) || (!a && b))' can not always be simplified as 'if (a != b)' when the types for 'a' and 'b' are not straight booleans.
* Closes #1862
* Also drop the use of '%C' in printf() expression, as it is intended to print wide characters and not turn a char to uppercase.
This commit is contained in:
Pete Batard 2022-01-31 16:55:42 +00:00
parent 891eb45549
commit 036f6260c5
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
6 changed files with 40 additions and 38 deletions

View File

@ -939,7 +939,7 @@ BOOL GetDevices(DWORD devnum)
}
// Make sure that we don't list any drive that should not be listed
if (remove_drive) {
uprintf("Removing %C: from the list: This is the %s!", drive_letters[--k],
uprintf("Removing %c: from the list: This is the %s!", toupper(drive_letters[--k]),
(remove_drive==1)?"disk from which " APPLICATION_NAME " is running":"system disk");
safe_free(devint_detail_data);
break;

View File

@ -1142,11 +1142,11 @@ static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT*
if ((_drive_type != DRIVE_REMOVABLE) && (_drive_type != DRIVE_FIXED))
continue;
static_sprintf(logical_drive, "\\\\.\\%c:", drive[0]);
static_sprintf(logical_drive, "\\\\.\\%c:", toupper(drive[0]));
hDrive = CreateFileA(logical_drive, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hDrive == INVALID_HANDLE_VALUE) {
// uprintf("Warning: could not open drive %c: %s", drive[0], WindowsErrorString());
// uprintf("Warning: could not open drive %c: %s", toupper(drive[0]), WindowsErrorString());
continue;
}
@ -1341,11 +1341,11 @@ BOOL GetDriveLabel(DWORD DriveIndex, char* letters, char** label)
if (DeviceIoControl(hPhysical, IOCTL_STORAGE_CHECK_VERIFY, NULL, 0, NULL, 0, &size, NULL))
AutorunLabel = get_token_data_file("label", AutorunPath);
else if (GetLastError() == ERROR_NOT_READY)
uprintf("Ignoring autorun.inf label for drive %c: %s", letters[0],
uprintf("Ignoring 'autorun.inf' label for drive %c: %s", toupper(letters[0]),
(HRESULT_CODE(GetLastError()) == ERROR_NOT_READY)?"No media":WindowsErrorString());
safe_closehandle(hPhysical);
if (AutorunLabel != NULL) {
uprintf("Using autorun.inf label for drive %c: '%s'", letters[0], AutorunLabel);
uprintf("Using 'autorun.inf' label for drive %c: '%s'", toupper(letters[0]), AutorunLabel);
static_strcpy(VolumeLabel, AutorunLabel);
safe_free(AutorunLabel);
*label = VolumeLabel;
@ -1832,12 +1832,12 @@ static BOOL FlushDrive(char drive_letter)
hDrive = CreateFileA(logical_drive, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hDrive == INVALID_HANDLE_VALUE) {
uprintf("Failed to open %c: for flushing: %s", drive_letter, WindowsErrorString());
uprintf("Failed to open %c: for flushing: %s", toupper(drive_letter), WindowsErrorString());
goto out;
}
r = FlushFileBuffers(hDrive);
if (r == FALSE)
uprintf("Failed to flush %c: %s", drive_letter, WindowsErrorString());
uprintf("Failed to flush %c: %s", toupper(drive_letter), WindowsErrorString());
out:
safe_closehandle(hDrive);
@ -1886,10 +1886,10 @@ BOOL MountVolume(char* drive_name, char *volume_name)
// about the level of thought and foresight that actually goes into the Windows APIs...
// [1] https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-definedosdevicew
if (!DefineDosDeviceA(DDD_RAW_TARGET_PATH | DDD_NO_BROADCAST_SYSTEM, dos_name, &volume_name[14])) {
uprintf("Could not mount %s as %C:", volume_name, drive_name[0]);
uprintf("Could not mount %s as %c:", volume_name, toupper(drive_name[0]));
return FALSE;
}
uprintf("%s was successfully mounted as %C:", volume_name, drive_name[0]);
uprintf("%s was successfully mounted as %c:", volume_name, toupper(drive_name[0]));
return TRUE;
}
@ -1902,8 +1902,8 @@ BOOL MountVolume(char* drive_name, char *volume_name)
// If that is the case, update drive_name to that letter.
if ( (GetVolumePathNamesForVolumeNameA(volume_name, mounted_letter, sizeof(mounted_letter), &size))
&& (size > 1) && (mounted_letter[0] != drive_name[0]) ) {
uprintf("%s is already mounted as %C: instead of %C: - Will now use this target instead...",
volume_name, mounted_letter[0], drive_name[0]);
uprintf("%s is already mounted as %c: instead of %c: - Will now use this target instead...",
volume_name, toupper(mounted_letter[0]), toupper(drive_name[0]));
drive_name[0] = mounted_letter[0];
return TRUE;
}
@ -1918,7 +1918,7 @@ BOOL MountVolume(char* drive_name, char *volume_name)
uprintf("%s is mounted, but volume GUID doesn't match:\r\n expected %s, got %s",
drive_name, volume_name, mounted_guid);
} else {
duprintf("%s is already mounted as %C:", volume_name, drive_name[0]);
duprintf("%s is already mounted as %c:", volume_name, toupper(drive_name[0]));
return TRUE;
}
uprintf("Retrying after dismount...");
@ -1929,7 +1929,7 @@ BOOL MountVolume(char* drive_name, char *volume_name)
if ((GetLastError() == ERROR_DIR_NOT_EMPTY) &&
GetVolumeNameForVolumeMountPointA(drive_name, mounted_guid, sizeof(mounted_guid)) &&
(safe_strcmp(volume_name, mounted_guid) == 0)) {
uprintf("%s was remounted as %C: (second time lucky!)", volume_name, drive_name[0]);
uprintf("%s was remounted as %c: (second time lucky!)", volume_name, toupper(drive_name[0]));
return TRUE;
}
}
@ -2002,9 +2002,9 @@ BOOL RemountVolume(char* drive_name, BOOL bSilent)
FlushDrive(drive_name[0]);
if (GetVolumeNameForVolumeMountPointA(drive_name, volume_name, sizeof(volume_name))) {
if (MountVolume(drive_name, volume_name)) {
suprintf("Successfully remounted %s as %C:", volume_name, drive_name[0]);
suprintf("Successfully remounted %s as %c:", volume_name, toupper(drive_name[0]));
} else {
suprintf("Could not remount %s as %C: %s", volume_name, drive_name[0], WindowsErrorString());
suprintf("Could not remount %s as %c: %s", volume_name, toupper(drive_name[0]), WindowsErrorString());
// This will leave the drive inaccessible and must be flagged as an error
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_REMOUNT_VOLUME);
return FALSE;

View File

@ -1105,13 +1105,13 @@ static BOOL SetupWinPE(char drive_letter)
static_sprintf(setupsrcdev, "SetupSourceDevice = \"\\device\\harddisk%d\\partition1\"",
ComboBox_GetCurSel(hDiskID));
// Copy of ntdetect.com in root
static_sprintf(src, "%c:\\%s\\ntdetect.com", drive_letter, basedir[2*(index/2)]);
static_sprintf(dst, "%c:\\ntdetect.com", drive_letter);
static_sprintf(src, "%c:\\%s\\ntdetect.com", toupper(drive_letter), basedir[2*(index/2)]);
static_sprintf(dst, "%c:\\ntdetect.com", toupper(drive_letter));
CopyFileA(src, dst, TRUE);
if (!img_report.uses_minint) {
// Create a copy of txtsetup.sif, as we want to keep the i386/amd64 files unmodified
static_sprintf(src, "%c:\\%s\\txtsetup.sif", drive_letter, basedir[index]);
static_sprintf(dst, "%c:\\txtsetup.sif", drive_letter);
static_sprintf(src, "%c:\\%s\\txtsetup.sif", toupper(drive_letter), basedir[index]);
static_sprintf(dst, "%c:\\txtsetup.sif", toupper(drive_letter));
if (!CopyFileA(src, dst, TRUE)) {
uprintf("Did not copy %s as %s: %s\n", src, dst, WindowsErrorString());
}
@ -1122,8 +1122,8 @@ static BOOL SetupWinPE(char drive_letter)
uprintf("Successfully added '%s' to %s\n", setupsrcdev, dst);
}
static_sprintf(src, "%c:\\%s\\setupldr.bin", drive_letter, basedir[2*(index/2)]);
static_sprintf(dst, "%c:\\BOOTMGR", drive_letter);
static_sprintf(src, "%c:\\%s\\setupldr.bin", toupper(drive_letter), basedir[2*(index/2)]);
static_sprintf(dst, "%c:\\BOOTMGR", toupper(drive_letter));
if (!CopyFileA(src, dst, TRUE)) {
uprintf("Did not copy %s as %s: %s\n", src, dst, WindowsErrorString());
}
@ -1922,7 +1922,7 @@ DWORD WINAPI FormatThread(void* param)
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_ASSIGN_LETTER);
goto out;
}
uprintf("Will use '%C:' as volume mountpoint", drive_name[0]);
uprintf("Will use '%c:' as volume mountpoint", toupper(drive_name[0]));
// It kind of blows, but we have to relinquish access to the physical drive
// for VDS to be able to delete the partitions that reside on it...
@ -2074,7 +2074,7 @@ DWORD WINAPI FormatThread(void* param)
if (GetDrivePartitionData(SelectedDrive.DeviceNumber, fs_name, sizeof(fs_name), TRUE)) {
volume_name = GetLogicalName(DriveIndex, 0, TRUE, TRUE);
if ((volume_name != NULL) && (MountVolume(drive_name, volume_name)))
uprintf("Remounted %s as %C:", volume_name, drive_name[0]);
uprintf("Remounted %s as %c:", volume_name, toupper(drive_name[0]));
}
}
goto out;
@ -2218,7 +2218,7 @@ DWORD WINAPI FormatThread(void* param)
// we forcibly removed them, so add yet another explicit call to RemoveDriveLetters()
RemoveDriveLetters(DriveIndex, FALSE, TRUE);
if (!MountVolume(drive_name, volume_name)) {
uprintf("Could not remount %s as %C: %s\n", volume_name, drive_name[0], WindowsErrorString());
uprintf("Could not remount %s as %c: %s\n", volume_name, toupper(drive_name[0]), WindowsErrorString());
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_MOUNT_VOLUME);
goto out;
}
@ -2398,7 +2398,7 @@ out:
volume_name = GetLogicalName(DriveIndex, partition_offset[PI_MAIN], TRUE, TRUE);
if (volume_name != NULL) {
if (MountVolume(drive_name, volume_name))
uprintf("Re-mounted volume as %C: after error", drive_name[0]);
uprintf("Re-mounted volume as %c: after error", toupper(drive_name[0]));
free(volume_name);
}
}

View File

@ -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.18.1865"
CAPTION "Rufus 3.18.1866"
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,18,1865,0
PRODUCTVERSION 3,18,1865,0
FILEVERSION 3,18,1866,0
PRODUCTVERSION 3,18,1866,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.18.1865"
VALUE "FileVersion", "3.18.1866"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2022 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.18.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.18.1865"
VALUE "ProductVersion", "3.18.1866"
END
END
BLOCK "VarFileInfo"

View File

@ -194,7 +194,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system)
}
/* Create ldlinux.sys file */
static_sprintf(path, "%c:\\%s.%s", drive_letter, ldlinux, ldlinux_ext[0]);
static_sprintf(path, "%c:\\%s.%s", toupper(drive_letter), ldlinux, ldlinux_ext[0]);
f_handle = CreateFileA(path, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS,
@ -236,7 +236,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system)
switch (file_system) {
case FS_NTFS:
static_sprintf(tmp, "%c:\\", drive_letter);
static_sprintf(tmp, "%c:\\", toupper(drive_letter));
vol_info.Handle = d_handle;
err = NtfsSectGetVolumeInfo(tmp, &vol_info);
if (err != ERROR_SUCCESS) {
@ -333,7 +333,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system)
IGNORE_RETVAL(_chdirU(app_data_dir));
static_sprintf(path, "%s\\%s-%s", FILES_DIR, syslinux, embedded_sl_version_str[1]);
IGNORE_RETVAL(_chdir(path));
static_sprintf(path, "%c:\\%s.%s", drive_letter, ldlinux, ldlinux_ext[2]);
static_sprintf(path, "%c:\\%s.%s", toupper(drive_letter), ldlinux, ldlinux_ext[2]);
fd = fopen(&path[3], "rb");
if (fd == NULL) {
uprintf("Caution: No '%s' was provided. The target will be missing a required Syslinux file!", &path[3]);
@ -354,7 +354,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system)
goto out;
}
/* Create mboot.c32 file */
static_sprintf(path, "%c:\\%s", drive_letter, mboot_c32);
static_sprintf(path, "%c:\\%s", toupper(drive_letter), mboot_c32);
f_handle = CreateFileA(path, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
@ -368,7 +368,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system)
goto out;
}
safe_closehandle(f_handle);
static_sprintf(path, "%c:\\syslinux.cfg", drive_letter);
static_sprintf(path, "%c:\\syslinux.cfg", toupper(drive_letter));
fd = fopen(path, "w");
if (fd == NULL) {
uprintf("Could not create ReactOS 'syslinux.cfg'");

View File

@ -1,7 +1,7 @@
/*
* Rufus: The Reliable USB Formatting Utility
* UI-related function calls
* Copyright © 2018-2021 Pete Batard <pete@akeo.ie>
* Copyright © 2018-2022 Pete Batard <pete@akeo.ie>
*
* 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
@ -789,7 +789,8 @@ void ToggleImageOptions(void)
if (image_option_txt[0] == 0)
GetWindowTextU(GetDlgItem(hMainDialog, IDS_IMAGE_OPTION_TXT), image_option_txt, sizeof(image_option_txt));
if ((has_wintogo) != (image_options & IMOP_WINTOGO)) {
if (((has_wintogo) && !(image_options & IMOP_WINTOGO)) ||
((!has_wintogo) && (image_options & IMOP_WINTOGO))) {
image_options ^= IMOP_WINTOGO;
if (image_options & IMOP_WINTOGO) {
// Set the Windows To Go selection in the dropdown
@ -797,7 +798,8 @@ void ToggleImageOptions(void)
}
}
if ((has_persistence) != (image_options & IMOP_PERSISTENCE)) {
if (((has_persistence) && !(image_options & IMOP_PERSISTENCE)) ||
((!has_persistence) && (image_options & IMOP_PERSISTENCE))) {
image_options ^= IMOP_PERSISTENCE;
if (image_options & IMOP_PERSISTENCE) {
SetWindowTextU(GetDlgItem(hMainDialog, IDS_IMAGE_OPTION_TXT), lmprintf(MSG_123));