diff --git a/src/net.c b/src/net.c index 683034a0..d6e2c048 100644 --- a/src/net.c +++ b/src/net.c @@ -641,7 +641,7 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param) do { for (i=0; (i<30) && (!force_update_check); i++) Sleep(500); - } while ((!force_update_check) && ((iso_op_in_progress || format_op_in_progress || (dialog_showing>0)))); + } while ((!force_update_check) && ((op_in_progress || (dialog_showing > 0)))); if (!force_update_check) { if ((ReadSetting32(SETTING_UPDATE_INTERVAL) == -1)) { vuprintf("Check for updates disabled, as per settings."); @@ -829,7 +829,7 @@ out: // Start the new download after cleanup if (found_new_version) { // User may have started an operation while we were checking - while ((!force_update_check) && (iso_op_in_progress || format_op_in_progress || (dialog_showing > 0))) { + while ((!force_update_check) && (op_in_progress || (dialog_showing > 0))) { Sleep(15000); } DownloadNewVersion(); @@ -994,7 +994,6 @@ static DWORD WINAPI DownloadISOThread(LPVOID param) // Download the ISO and report errors if any SendMessage(hMainDialog, UM_PROGRESS_INIT, 0, 0); FormatStatus = 0; - format_op_in_progress = TRUE; SendMessage(hMainDialog, UM_TIMER_START, 0, 0); if (DownloadToFileOrBuffer(url, img_save.ImagePath, NULL, hMainDialog, TRUE) == 0) { SendMessage(hMainDialog, UM_PROGRESS_EXIT, 0, 0); @@ -1011,7 +1010,6 @@ static DWORD WINAPI DownloadISOThread(LPVOID param) image_path = safe_strdup(img_save.ImagePath); PostMessage(hMainDialog, UM_SELECT_ISO, 0, 0); } - format_op_in_progress = FALSE; safe_free(img_save.ImagePath); } } diff --git a/src/rufus.c b/src/rufus.c index 724358cb..cbbf44b1 100755 --- a/src/rufus.c +++ b/src/rufus.c @@ -103,7 +103,7 @@ HWND hDeviceList, hPartitionScheme, hTargetSystem, hFileSystem, hClusterSize, hL HWND hLogDialog = NULL, hProgress = NULL, hDiskID; HANDLE dialog_handle = NULL; BOOL is_x86_32, use_own_c32[NB_OLD_C32] = { FALSE, FALSE }, mbr_selected_by_user = FALSE; -BOOL iso_op_in_progress = FALSE, format_op_in_progress = FALSE, right_to_left_mode = FALSE, has_uefi_csm; +BOOL op_in_progress = TRUE, right_to_left_mode = FALSE, has_uefi_csm; BOOL enable_HDDs = FALSE, enable_ntfs_compression = FALSE, no_confirmation_on_cancel = FALSE, lock_drive = TRUE; BOOL advanced_mode_device, advanced_mode_format, allow_dual_uefi_bios, detect_fakes, enable_vmdk, force_large_fat32, usb_debug; BOOL use_fake_units, preserve_timestamps = FALSE, fast_zeroing = FALSE, app_changed_size = FALSE; @@ -791,6 +791,8 @@ static void EnableBootOptions(BOOL enable, BOOL remove_checkboxes) // Toggle controls according to operation static void EnableControls(BOOL enable, BOOL remove_checkboxes) { + op_in_progress = !enable; + // The following only get disabled on format/checksum and otherwise remain enabled, // even if no device or image are selected EnableWindow(hDeviceList, enable); @@ -1074,7 +1076,6 @@ DWORD WINAPI ISOScanThread(LPVOID param) if (image_path == NULL) goto out; - format_op_in_progress = TRUE; PrintInfoDebug(0, MSG_202); user_notified = FALSE; EnableControls(FALSE, FALSE); @@ -1158,7 +1159,6 @@ DWORD WINAPI ISOScanThread(LPVOID param) out: dont_display_image_name = FALSE; - format_op_in_progress = FALSE; PrintInfo(0, MSG_210); ExitThread(0); } @@ -1727,51 +1727,48 @@ static void SaveVHD(void) EXT_DECL(img_ext, filename, __VA_GROUP__("*.vhd"), __VA_GROUP__(lmprintf(MSG_095))); ULARGE_INTEGER free_space; - if (DriveIndex >= 0) - static_sprintf(filename, "%s.vhd", DriveLabel.String[DriveIndex]); - if ((DriveIndex != CB_ERR) && (!format_op_in_progress) && (format_thid == NULL)) { - img_save.Type = IMG_SAVE_TYPE_VHD; - img_save.DeviceNum = (DWORD)ComboBox_GetItemData(hDeviceList, DriveIndex); - img_save.ImagePath = FileDialog(TRUE, NULL, &img_ext, 0); - img_save.BufSize = DD_BUFFER_SIZE; - img_save.DeviceSize = SelectedDrive.DiskSize; - if (img_save.ImagePath != NULL) { - // Reset all progress bars - SendMessage(hMainDialog, UM_PROGRESS_INIT, 0, 0); + if ((DriveIndex < 0) || (format_thid != NULL)) + return; + + static_sprintf(filename, "%s.vhd", DriveLabel.String[DriveIndex]); + img_save.Type = IMG_SAVE_TYPE_VHD; + img_save.DeviceNum = (DWORD)ComboBox_GetItemData(hDeviceList, DriveIndex); + img_save.ImagePath = FileDialog(TRUE, NULL, &img_ext, 0); + img_save.BufSize = DD_BUFFER_SIZE; + img_save.DeviceSize = SelectedDrive.DiskSize; + if (img_save.ImagePath != NULL) { + // Reset all progress bars + SendMessage(hMainDialog, UM_PROGRESS_INIT, 0, 0); + FormatStatus = 0; + free_space.QuadPart = 0; + if ((GetVolumePathNameA(img_save.ImagePath, path, sizeof(path))) + && (GetDiskFreeSpaceExA(path, &free_space, NULL, NULL)) + && ((LONGLONG)free_space.QuadPart > (SelectedDrive.DiskSize + 512))) { + // Disable all controls except cancel + EnableControls(FALSE, FALSE); FormatStatus = 0; - format_op_in_progress = TRUE; - free_space.QuadPart = 0; - if ((GetVolumePathNameA(img_save.ImagePath, path, sizeof(path))) - && (GetDiskFreeSpaceExA(path, &free_space, NULL, NULL)) - && ((LONGLONG)free_space.QuadPart > (SelectedDrive.DiskSize + 512))) { - // Disable all controls except cancel - EnableControls(FALSE, FALSE); - FormatStatus = 0; - InitProgress(TRUE); - format_thid = CreateThread(NULL, 0, SaveImageThread, &img_save, 0, NULL); - if (format_thid != NULL) { - uprintf("\r\nSave to VHD operation started"); - PrintInfo(0, -1); - SendMessage(hMainDialog, UM_TIMER_START, 0, 0); - } else { - uprintf("Unable to start VHD save thread"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); - safe_free(img_save.ImagePath); - PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); - format_op_in_progress = FALSE; - } + InitProgress(TRUE); + format_thid = CreateThread(NULL, 0, SaveImageThread, &img_save, 0, NULL); + if (format_thid != NULL) { + uprintf("\r\nSave to VHD operation started"); + PrintInfo(0, -1); + SendMessage(hMainDialog, UM_TIMER_START, 0, 0); } else { - if (free_space.QuadPart == 0) { - uprintf("Unable to isolate drive name for VHD save"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_PATH_NOT_FOUND; - } else { - uprintf("The VHD size is too large for the target drive"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_FILE_TOO_LARGE; - } + uprintf("Unable to start VHD save thread"); + FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); safe_free(img_save.ImagePath); PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); - format_op_in_progress = FALSE; } + } else { + if (free_space.QuadPart == 0) { + uprintf("Unable to isolate drive name for VHD save"); + FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_PATH_NOT_FOUND; + } else { + uprintf("The VHD size is too large for the target drive"); + FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_FILE_TOO_LARGE; + } + safe_free(img_save.ImagePath); + PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); } } } @@ -1782,7 +1779,7 @@ static void SaveISO(void) char filename[33] = "disc_image.iso"; EXT_DECL(img_ext, filename, __VA_GROUP__("*.iso"), __VA_GROUP__(lmprintf(MSG_036))); - if ((format_op_in_progress) || (format_thid != NULL)) + if (op_in_progress || (format_thid != NULL)) return; img_save.Type = IMG_SAVE_TYPE_ISO; @@ -1803,7 +1800,6 @@ static void SaveISO(void) return; SendMessage(hMainDialog, UM_PROGRESS_INIT, 0, 0); FormatStatus = 0; - format_op_in_progress = TRUE; // Disable all controls except cancel EnableControls(FALSE, FALSE); InitProgress(TRUE); @@ -1817,7 +1813,6 @@ static void SaveISO(void) FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); safe_free(img_save.ImagePath); PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); - format_op_in_progress = FALSE; } } @@ -1979,7 +1974,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA } no_confirmation_on_cancel = FALSE; return (INT_PTR)TRUE; - } else if (format_op_in_progress) { + } else if (op_in_progress) { // User might be trying to cancel during preliminary checks FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANCELLED; PrintInfo(0, MSG_201); @@ -2228,7 +2223,6 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA } } FormatStatus = 0; - format_op_in_progress = FALSE; if (CreateThread(NULL, 0, ISOScanThread, NULL, 0, NULL) == NULL) { uprintf("Unable to start ISO scanning thread"); FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); @@ -2261,7 +2255,6 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA FormatStatus = 0; LastWriteError = 0; StrArrayClear(&BlockingProcess); - format_op_in_progress = TRUE; no_confirmation_on_cancel = FALSE; SendMessage(hMainDialog, UM_PROGRESS_INIT, 0, 0); selection_default = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)); @@ -2286,7 +2279,6 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA case IDC_HASH: if ((format_thid == NULL) && (image_path != NULL)) { FormatStatus = 0; - format_op_in_progress = TRUE; no_confirmation_on_cancel = TRUE; SendMessage(hMainDialog, UM_PROGRESS_INIT, 0, 0); // Disable all controls except cancel @@ -2301,7 +2293,6 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA uprintf("Unable to start checksum thread"); FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); - format_op_in_progress = FALSE; } } break; @@ -2373,7 +2364,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA case DBT_CUSTOMEVENT: // Sent by our timer refresh function or for card reader media change LastRefresh = GetTickCount64(); KillTimer(hMainDialog, TID_REFRESH_TIMER); - if (!format_op_in_progress) { + if (!op_in_progress) { queued_hotplug_event = FALSE; GetDevices((DWORD)ComboBox_GetItemData(hDeviceList, ComboBox_GetCurSel(hDeviceList))); user_changed_label = FALSE; @@ -2564,7 +2555,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA case WM_CLIENTSHUTDOWN: case WM_QUERYENDSESSION: case WM_ENDSESSION: - if (format_op_in_progress) { + if (op_in_progress) { return (INT_PTR)TRUE; } if (message == WM_CLOSE) { @@ -2692,7 +2683,6 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA if (format_thid != NULL) break; aborted_start: - format_op_in_progress = FALSE; EnableControls(TRUE, FALSE); zero_drive = FALSE; if (queued_hotplug_event) @@ -2781,7 +2771,6 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA } FormatStatus = 0; LastWriteError = 0; - format_op_in_progress = FALSE; return (INT_PTR)TRUE; } @@ -3243,251 +3232,281 @@ relaunch: // Do our own event processing and process "magic" commands while(GetMessage(&msg, NULL, 0, 0)) { + static BOOL ctrl_without_focus = FALSE; + BOOL no_focus = (msg.message == WM_SYSKEYDOWN) && !(msg.lParam & 0x20000000); // ** ***** **** ** ********** // .,ABCDEFGHIJKLMNOPQRSTUVWXYZ // Sigh... The things one need to do to detect standalone use of the 'Alt' key. if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam != VK_MENU)) alt_command = TRUE; - else if (GetAsyncKeyState(VK_MENU)) + else if (GetKeyState(VK_MENU) & 0x8000) alt_pressed = TRUE; // Ctrl-A => Select the log data - if ( (IsWindowVisible(hLogDialog)) && (GetKeyState(VK_CONTROL) & 0x8000) && - (msg.message == WM_KEYDOWN) && (msg.wParam == 'A') ) { + if ((IsWindowVisible(hLogDialog)) && (GetKeyState(VK_CONTROL) & 0x8000) && + (msg.message == WM_KEYDOWN) && (msg.wParam == 'A')) { // Might also need ES_NOHIDESEL property if you want to select when not active Edit_SetSel(hLog, 0, -1); continue; } + + // Detecting Ctrl combination keypress while an operation is in progress is a super-mess + // because Windows considers that our dialog doesn't have keyboard focus (WHYYYYYY?!?!?) + // and therefore first sends a WM_SYSKEYDOWN (i.e. the message that is supposed to tell + // you that Alt is being pressed, because why not also use it for a COMPLETELY DIFFERENT + // FRIGGING KEY!!!) with bit 29 of msg.lParam cleared, along with the code for the Ctrl + // key and *THEN* a subsequent message (still using WM_SYSKEYDOWN without Alt) with the + // other key. So we need to detect both the messages in sequence... + if (no_focus && (msg.wParam == VK_CONTROL)) + ctrl_without_focus = op_in_progress; + // Ctrl-L => Open/Close the log - if ((GetKeyState(VK_CONTROL) & 0x8000) && (msg.message == WM_KEYDOWN) && (msg.wParam == 'L')) { + if ((ctrl_without_focus || ((GetKeyState(VK_CONTROL) & 0x8000) && (msg.message == WM_KEYDOWN))) + && (msg.wParam == 'L')) { + ctrl_without_focus = FALSE; SendMessage(hMainDialog, WM_COMMAND, IDC_LOG, 0); continue; } - // Alt-. => Enable USB enumeration debug - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == VK_OEM_PERIOD)) { - usb_debug = !usb_debug; - WriteSettingBool(SETTING_ENABLE_USB_DEBUG, usb_debug); - PrintStatusTimeout(lmprintf(MSG_270), usb_debug); - GetDevices(0); - continue; - } - // Alt-, => Disable physical drive locking - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == VK_OEM_COMMA)) { - lock_drive = !lock_drive; - PrintStatusTimeout(lmprintf(MSG_282), lock_drive); - continue; - } - // Alt-B => Toggle fake drive detection during bad blocks check - // By default, Rufus will check for fake USB flash drives that mistakenly present - // more capacity than they already have by looping over the flash. This check which - // is enabled by default is performed by writing the block number sequence and reading - // it back during the bad block check. - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'B')) { - detect_fakes = !detect_fakes; - WriteSettingBool(SETTING_DISABLE_FAKE_DRIVES_CHECK, !detect_fakes); - PrintStatusTimeout(lmprintf(MSG_256), detect_fakes); - continue; - } - // Alt-C => Cycle USB port for currently selected device - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'C')) { - int index = ComboBox_GetCurSel(hDeviceList); - if (index >= 0) - CyclePort(index); - continue; - } - // Alt-D => Delete the 'rufus_files' subdirectory - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'D')) { - static_sprintf(tmp_path, "%s\\%s", app_dir, FILES_DIR); - PrintStatus(2000, MSG_264, tmp_path); - SHDeleteDirectoryExU(NULL, tmp_path, FOF_SILENT | FOF_NOERRORUI | FOF_NOCONFIRMATION); - continue; - } - // Alt-E => Enhanced installation mode (allow dual UEFI/BIOS mode and FAT32 for Windows) - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'E')) { - allow_dual_uefi_bios = !allow_dual_uefi_bios; - WriteSettingBool(SETTING_ENABLE_WIN_DUAL_EFI_BIOS, allow_dual_uefi_bios); - PrintStatusTimeout(lmprintf(MSG_266), allow_dual_uefi_bios); - SetPartitionSchemeAndTargetSystem(FALSE); - continue; - } - // Alt-F => Toggle detection of USB HDDs - // By default Rufus does not list USB HDDs. This is a safety feature aimed at avoiding - // unintentional formatting of backup drives instead of USB keys. - // When enabled, Rufus will list and allow the formatting of USB HDDs. - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'F')) { - enable_HDDs = !enable_HDDs; - PrintStatusTimeout(lmprintf(MSG_253), enable_HDDs); - GetDevices(0); - CheckDlgButton(hMainDialog, IDC_LIST_USB_HDD, enable_HDDs?BST_CHECKED:BST_UNCHECKED); - continue; - } - // Alt-I => Toggle ISO support - // This is useful if you have an ISOHybrid image and you want to force Rufus to use - // DD-mode when writing the data. - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'I')) { - enable_iso = !enable_iso; - PrintStatusTimeout(lmprintf(MSG_262), enable_iso); - if (image_path != NULL) { - iso_provided = TRUE; - dont_display_image_name = TRUE; - SendMessage(hDlg, WM_COMMAND, IDC_SELECT, 0); - } - continue; - } - // Alt J => Toggle Joliet support for ISO9660 images - // Some ISOs (Ubuntu) have Joliet extensions but expect applications not to use them, - // due to their reliance on filenames that are > 64 chars (the Joliet max length for - // a file name). This option allows users to ignore Joliet when using such images. - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'J')) { - enable_joliet = !enable_joliet; - PrintStatusTimeout(lmprintf(MSG_257), enable_joliet); - continue; - } - // Alt K => Toggle Rock Ridge support for ISO9660 images - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'K')) { - enable_rockridge = !enable_rockridge; - PrintStatusTimeout(lmprintf(MSG_258), enable_rockridge); - continue; - } - // Alt-L => Force Large FAT32 format to be used on < 32 GB drives - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'L')) { - force_large_fat32 = !force_large_fat32; - WriteSettingBool(SETTING_FORCE_LARGE_FAT32_FORMAT, force_large_fat32); - PrintStatusTimeout(lmprintf(MSG_254), force_large_fat32); - GetDevices(0); - continue; - } - // Alt N => Enable NTFS compression - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'N')) { - enable_ntfs_compression = !enable_ntfs_compression; - PrintStatusTimeout(lmprintf(MSG_260), enable_ntfs_compression); - continue; - } - // Alt-O => Save from Optical drive to ISO - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'O')) { - SaveISO(); - continue; - } - // Alt-Q => Enable file indexing (for file systems that support it) - // For multiple reasons, file indexing is disabled by default - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'Q')) { - enable_file_indexing = !enable_file_indexing; - WriteSettingBool(SETTING_ENABLE_FILE_INDEXING, enable_file_indexing); - PrintStatusTimeout(lmprintf(MSG_290), !enable_file_indexing); - continue; - } - // Alt-R => Remove all the registry keys that may have been created by Rufus - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'R')) { - PrintStatus(2000, DeleteRegistryKey(REGKEY_HKCU, COMPANY_NAME "\\" APPLICATION_NAME)?MSG_248:MSG_249); - // Also try to delete the upper key (company name) if it's empty (don't care about the result) - DeleteRegistryKey(REGKEY_HKCU, COMPANY_NAME); - continue; - } - // Alt-S => Disable size limit for ISOs - // By default, Rufus will not copy ISOs that are larger than in size than - // the target USB drive. If this is enabled, the size check is disabled. - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'S')) { - size_check = !size_check; - PrintStatusTimeout(lmprintf(MSG_252), size_check); - GetDevices(0); - continue; - } - // Alt-T => Preserve timestamps when extracting ISO files - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'T')) { - preserve_timestamps = !preserve_timestamps; - WriteSettingBool(SETTING_PRESERVE_TIMESTAMPS, preserve_timestamps); - PrintStatusTimeout(lmprintf(MSG_269), preserve_timestamps); - continue; - } - // Alt-U => Use PROPER size units, instead of this whole Kibi/Gibi nonsense - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'U')) { - use_fake_units = !use_fake_units; - WriteSettingBool(SETTING_USE_PROPER_SIZE_UNITS, !use_fake_units); - PrintStatusTimeout(lmprintf(MSG_263), !use_fake_units); - GetDevices(0); - continue; - } - // Alt-V => Use VDS facilities for formatting - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'V')) { - use_vds = !use_vds; - WriteSettingBool(SETTING_USE_VDS, use_vds); - PrintStatusTimeout("VDS", use_vds); - continue; - } - // Alt-W => Enable VMWare disk detection - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'W')) { - enable_vmdk = !enable_vmdk; - WriteSettingBool(SETTING_ENABLE_VMDK_DETECTION, enable_vmdk); - PrintStatusTimeout(lmprintf(MSG_265), enable_vmdk); - GetDevices(0); - continue; - } - // Alt-X => Delete the NoDriveTypeAutorun key on exit (useful if the app crashed) - // This key is used to disable Windows popup messages when an USB drive is plugged in. - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'X')) { - PrintStatus(2000, MSG_255); - existing_key = FALSE; - continue; - } - // Alt Y => Force the update check to be successful - // This will set the reported current version of Rufus to 0.0.0.0 when performing an update - // check, so that it always succeeds. This is useful for translators. - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'Y')) { - force_update = (force_update > 0) ? 0 : 1; - PrintStatusTimeout(lmprintf(MSG_259), force_update); - continue; - } - // Alt-Z => Zero the drive - if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'Z')) { - zero_drive = TRUE; - fast_zeroing = FALSE; - // Simulate a button click for Start - PostMessage(hDlg, WM_COMMAND, (WPARAM)IDC_START, 0); - continue; - } - // Ctrl-Alt-Z => Zero the drive while trying to skip empty blocks - if ((msg.message == WM_KEYDOWN) && (msg.wParam == 'Z') && - (GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_MENU) & 0x8000)) { - zero_drive = TRUE; - fast_zeroing = TRUE; - // Simulate a button click for Start - PostMessage(hDlg, WM_COMMAND, (WPARAM)IDC_START, 0); - continue; - } - // Other hazardous cheat modes require Ctrl + Alt - // Ctrl-Alt-F => List non USB removable drives such as eSATA, etc - CAUTION!!! - if ((msg.message == WM_KEYDOWN) && (msg.wParam == 'F') && - (GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_MENU) & 0x8000)) { - list_non_usb_removable_drives = !list_non_usb_removable_drives; - if (list_non_usb_removable_drives) { - previous_enable_HDDs = enable_HDDs; - enable_HDDs = TRUE; - } else { - enable_HDDs = previous_enable_HDDs; - } - CheckDlgButton(hMainDialog, IDC_LIST_USB_HDD, enable_HDDs ? BST_CHECKED : BST_UNCHECKED); - PrintStatusTimeout(lmprintf(MSG_287), list_non_usb_removable_drives); - uprintf("%sListing of non-USB removable drives %s", - (list_non_usb_removable_drives)?"CAUTION: ":"", (list_non_usb_removable_drives)?"enabled":"disabled"); - if (list_non_usb_removable_drives) - uprintf("By using this unofficial cheat mode you forfeit ANY RIGHT to complain if you lose valuable data!"); - GetDevices(0); - continue; - } + if (no_focus && (msg.wParam != VK_CONTROL)) + ctrl_without_focus = FALSE; - // Ctrl-Alt-Y => Force update check to be successful and ignore timestamp errors - if ((msg.message == WM_KEYDOWN) && (msg.wParam == 'Y') && - (GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_MENU) & 0x8000)) { - force_update = (force_update > 0) ? 0 : 2; - PrintStatusTimeout(lmprintf(MSG_259), force_update); + if (no_focus) continue; + + // The following cheat modes should not be enacted when an operation is in progress + if (!op_in_progress) { + // Alt-. => Enable USB enumeration debug + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == VK_OEM_PERIOD)) { + usb_debug = !usb_debug; + WriteSettingBool(SETTING_ENABLE_USB_DEBUG, usb_debug); + PrintStatusTimeout(lmprintf(MSG_270), usb_debug); + GetDevices(0); + continue; + } + // Alt-, => Disable physical drive locking + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == VK_OEM_COMMA)) { + lock_drive = !lock_drive; + PrintStatusTimeout(lmprintf(MSG_282), lock_drive); + continue; + } + // Alt-B => Toggle fake drive detection during bad blocks check + // By default, Rufus will check for fake USB flash drives that mistakenly present + // more capacity than they already have by looping over the flash. This check which + // is enabled by default is performed by writing the block number sequence and reading + // it back during the bad block check. + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'B')) { + detect_fakes = !detect_fakes; + WriteSettingBool(SETTING_DISABLE_FAKE_DRIVES_CHECK, !detect_fakes); + PrintStatusTimeout(lmprintf(MSG_256), detect_fakes); + continue; + } + // Alt-C => Cycle USB port for currently selected device + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'C')) { + int index = ComboBox_GetCurSel(hDeviceList); + if (index >= 0) + CyclePort(index); + continue; + } + // Alt-D => Delete the 'rufus_files' subdirectory + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'D')) { + static_sprintf(tmp_path, "%s\\%s", app_dir, FILES_DIR); + PrintStatus(2000, MSG_264, tmp_path); + SHDeleteDirectoryExU(NULL, tmp_path, FOF_SILENT | FOF_NOERRORUI | FOF_NOCONFIRMATION); + continue; + } + // Alt-E => Enhanced installation mode (allow dual UEFI/BIOS mode and FAT32 for Windows) + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'E')) { + allow_dual_uefi_bios = !allow_dual_uefi_bios; + WriteSettingBool(SETTING_ENABLE_WIN_DUAL_EFI_BIOS, allow_dual_uefi_bios); + PrintStatusTimeout(lmprintf(MSG_266), allow_dual_uefi_bios); + SetPartitionSchemeAndTargetSystem(FALSE); + continue; + } + // Alt-F => Toggle detection of USB HDDs + // By default Rufus does not list USB HDDs. This is a safety feature aimed at avoiding + // unintentional formatting of backup drives instead of USB keys. + // When enabled, Rufus will list and allow the formatting of USB HDDs. + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'F')) { + enable_HDDs = !enable_HDDs; + PrintStatusTimeout(lmprintf(MSG_253), enable_HDDs); + GetDevices(0); + CheckDlgButton(hMainDialog, IDC_LIST_USB_HDD, enable_HDDs ? BST_CHECKED : BST_UNCHECKED); + continue; + } + // Alt-I => Toggle ISO support + // This is useful if you have an ISOHybrid image and you want to force Rufus to use + // DD-mode when writing the data. + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'I')) { + enable_iso = !enable_iso; + PrintStatusTimeout(lmprintf(MSG_262), enable_iso); + if (image_path != NULL) { + iso_provided = TRUE; + dont_display_image_name = TRUE; + SendMessage(hDlg, WM_COMMAND, IDC_SELECT, 0); + } + continue; + } + // Alt J => Toggle Joliet support for ISO9660 images + // Some ISOs (Ubuntu) have Joliet extensions but expect applications not to use them, + // due to their reliance on filenames that are > 64 chars (the Joliet max length for + // a file name). This option allows users to ignore Joliet when using such images. + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'J')) { + enable_joliet = !enable_joliet; + PrintStatusTimeout(lmprintf(MSG_257), enable_joliet); + continue; + } + // Alt K => Toggle Rock Ridge support for ISO9660 images + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'K')) { + enable_rockridge = !enable_rockridge; + PrintStatusTimeout(lmprintf(MSG_258), enable_rockridge); + continue; + } + // Alt-L => Force Large FAT32 format to be used on < 32 GB drives + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'L')) { + uprintf("DAFUQ!?!? LPARAM = 0x%08X", msg.lParam); + + if ((msg.message == WM_SYSKEYDOWN) && !(msg.lParam & 0x20000000)) { + uprintf("KIDDING ME?!?!."); + } + force_large_fat32 = !force_large_fat32; + WriteSettingBool(SETTING_FORCE_LARGE_FAT32_FORMAT, force_large_fat32); + PrintStatusTimeout(lmprintf(MSG_254), force_large_fat32); + GetDevices(0); + continue; + } + // Alt N => Enable NTFS compression + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'N')) { + enable_ntfs_compression = !enable_ntfs_compression; + PrintStatusTimeout(lmprintf(MSG_260), enable_ntfs_compression); + continue; + } + // Alt-O => Save from Optical drive to ISO + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'O')) { + SaveISO(); + continue; + } + // Alt-Q => Enable file indexing (for file systems that support it) + // For multiple reasons, file indexing is disabled by default + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'Q')) { + enable_file_indexing = !enable_file_indexing; + WriteSettingBool(SETTING_ENABLE_FILE_INDEXING, enable_file_indexing); + PrintStatusTimeout(lmprintf(MSG_290), !enable_file_indexing); + continue; + } + // Alt-R => Remove all the registry keys that may have been created by Rufus + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'R')) { + PrintStatus(2000, DeleteRegistryKey(REGKEY_HKCU, COMPANY_NAME "\\" APPLICATION_NAME) ? MSG_248 : MSG_249); + // Also try to delete the upper key (company name) if it's empty (don't care about the result) + DeleteRegistryKey(REGKEY_HKCU, COMPANY_NAME); + continue; + } + // Alt-S => Disable size limit for ISOs + // By default, Rufus will not copy ISOs that are larger than in size than + // the target USB drive. If this is enabled, the size check is disabled. + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'S')) { + size_check = !size_check; + PrintStatusTimeout(lmprintf(MSG_252), size_check); + GetDevices(0); + continue; + } + // Alt-T => Preserve timestamps when extracting ISO files + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'T')) { + preserve_timestamps = !preserve_timestamps; + WriteSettingBool(SETTING_PRESERVE_TIMESTAMPS, preserve_timestamps); + PrintStatusTimeout(lmprintf(MSG_269), preserve_timestamps); + continue; + } + // Alt-U => Use PROPER size units, instead of this whole Kibi/Gibi nonsense + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'U')) { + use_fake_units = !use_fake_units; + WriteSettingBool(SETTING_USE_PROPER_SIZE_UNITS, !use_fake_units); + PrintStatusTimeout(lmprintf(MSG_263), !use_fake_units); + GetDevices(0); + continue; + } + // Alt-V => Use VDS facilities for formatting + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'V')) { + use_vds = !use_vds; + WriteSettingBool(SETTING_USE_VDS, use_vds); + PrintStatusTimeout("VDS", use_vds); + continue; + } + // Alt-W => Enable VMWare disk detection + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'W')) { + enable_vmdk = !enable_vmdk; + WriteSettingBool(SETTING_ENABLE_VMDK_DETECTION, enable_vmdk); + PrintStatusTimeout(lmprintf(MSG_265), enable_vmdk); + GetDevices(0); + continue; + } + // Alt-X => Delete the NoDriveTypeAutorun key on exit (useful if the app crashed) + // This key is used to disable Windows popup messages when an USB drive is plugged in. + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'X')) { + PrintStatus(2000, MSG_255); + existing_key = FALSE; + continue; + } + // Alt Y => Force the update check to be successful + // This will set the reported current version of Rufus to 0.0.0.0 when performing an update + // check, so that it always succeeds. This is useful for translators. + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'Y')) { + force_update = (force_update > 0) ? 0 : 1; + PrintStatusTimeout(lmprintf(MSG_259), force_update); + continue; + } + // Alt-Z => Zero the drive + if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'Z')) { + zero_drive = TRUE; + fast_zeroing = FALSE; + // Simulate a button click for Start + PostMessage(hDlg, WM_COMMAND, (WPARAM)IDC_START, 0); + continue; + } + // Ctrl-Alt-Z => Zero the drive while trying to skip empty blocks + if ((msg.message == WM_KEYDOWN) && (msg.wParam == 'Z') && + (GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_MENU) & 0x8000)) { + zero_drive = TRUE; + fast_zeroing = TRUE; + // Simulate a button click for Start + PostMessage(hDlg, WM_COMMAND, (WPARAM)IDC_START, 0); + continue; + } + + // Other hazardous cheat modes require Ctrl + Alt + // Ctrl-Alt-F => List non USB removable drives such as eSATA, etc - CAUTION!!! + if ((msg.message == WM_KEYDOWN) && (msg.wParam == 'F') && + (GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_MENU) & 0x8000)) { + list_non_usb_removable_drives = !list_non_usb_removable_drives; + if (list_non_usb_removable_drives) { + previous_enable_HDDs = enable_HDDs; + enable_HDDs = TRUE; + } else { + enable_HDDs = previous_enable_HDDs; + } + CheckDlgButton(hMainDialog, IDC_LIST_USB_HDD, enable_HDDs ? BST_CHECKED : BST_UNCHECKED); + PrintStatusTimeout(lmprintf(MSG_287), list_non_usb_removable_drives); + uprintf("%sListing of non-USB removable drives %s", + (list_non_usb_removable_drives) ? "CAUTION: " : "", (list_non_usb_removable_drives) ? "enabled" : "disabled"); + if (list_non_usb_removable_drives) + uprintf("By using this unofficial cheat mode you forfeit ANY RIGHT to complain if you lose valuable data!"); + GetDevices(0); + continue; + } + + // Ctrl-Alt-Y => Force update check to be successful and ignore timestamp errors + if ((msg.message == WM_KEYDOWN) && (msg.wParam == 'Y') && + (GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_MENU) & 0x8000)) { + force_update = (force_update > 0) ? 0 : 2; + PrintStatusTimeout(lmprintf(MSG_259), force_update); + continue; + } } // Standalone 'Alt' key toggles progress report between percent, rate (if available) // and remaining time (if availabe) - if (alt_pressed && !GetAsyncKeyState(VK_MENU)) { + if (alt_pressed && !(GetKeyState(VK_MENU) & 0x8000)) { alt_pressed = FALSE; if (!alt_command) update_progress_type = (update_progress_type + 1) % UPT_MAX; diff --git a/src/rufus.h b/src/rufus.h index e80599fa..78dbbab0 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -444,7 +444,7 @@ extern HWND hPartitionScheme, hTargetSystem, hFileSystem, hClusterSize, hLabel, extern HWND hInfo, hProgress, hDiskID; extern WORD selected_langid; extern DWORD FormatStatus, DownloadStatus, MainThreadId, LastWriteError; -extern BOOL use_own_c32[NB_OLD_C32], detect_fakes, iso_op_in_progress, format_op_in_progress, right_to_left_mode; +extern BOOL use_own_c32[NB_OLD_C32], detect_fakes, op_in_progress, right_to_left_mode; extern BOOL allow_dual_uefi_bios, large_drive, usb_debug; extern int64_t iso_blocking_status; extern uint8_t image_options; @@ -481,7 +481,6 @@ extern const char* StrError(DWORD error_code, BOOL use_default_locale); extern char* GuidToString(const GUID* guid); extern char* SizeToHumanReadable(uint64_t size, BOOL copy_to_log, BOOL fake_units); extern char* TimestampToHumanReadable(uint64_t ts); -extern char* RateToHumanReadable(uint64_t transferred, uint64_t total); extern HWND MyCreateDialog(HINSTANCE hInstance, int Dialog_ID, HWND hWndParent, DLGPROC lpDialogFunc); extern INT_PTR MyDialogBox(HINSTANCE hInstance, int Dialog_ID, HWND hWndParent, DLGPROC lpDialogFunc); extern void CenterDialog(HWND hDlg, HWND hParent); diff --git a/src/rufus.rc b/src/rufus.rc index e9a00e82..7e2dc30f 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.7.1563" +CAPTION "Rufus 3.7.1564" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -394,8 +394,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,7,1563,0 - PRODUCTVERSION 3,7,1563,0 + FILEVERSION 3,7,1564,0 + PRODUCTVERSION 3,7,1564,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -413,13 +413,13 @@ BEGIN VALUE "Comments", "https://akeo.ie" VALUE "CompanyName", "Akeo Consulting" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "3.7.1563" + VALUE "FileVersion", "3.7.1564" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2019 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus-3.7.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "3.7.1563" + VALUE "ProductVersion", "3.7.1564" END END BLOCK "VarFileInfo" diff --git a/src/stdio.c b/src/stdio.c index 1c7a327f..954289e8 100644 --- a/src/stdio.c +++ b/src/stdio.c @@ -695,29 +695,6 @@ char* TimestampToHumanReadable(uint64_t ts) return str; } -// TODO: Add granularity -char* RateToHumanReadable(uint64_t transferred, uint64_t total) -{ - const uint64_t refresh_rate = 1000; - static uint64_t start_time, last_refresh = 0; - uint64_t current_time, rate; - if (total == 0) { - // init - start_time = GetTickCount64(); - last_refresh = start_time; - } else { - current_time = GetTickCount64(); - if (current_time <= start_time) - return NULL; - rate = (transferred * 1000) / (current_time - start_time); - if (current_time > last_refresh + refresh_rate) { - last_refresh = current_time; - uprintf("%s/s", SizeToHumanReadable(rate, FALSE, FALSE)); - } - } - return NULL; -} - // Convert custom error code to messages const char* _StrError(DWORD error_code) {