diff --git a/res/localization/rufus.loc b/res/localization/rufus.loc index dc4478d0..24fcceb8 100644 --- a/res/localization/rufus.loc +++ b/res/localization/rufus.loc @@ -98,20 +98,17 @@ v 1.0.22 # Main dialog g IDD_DIALOG t IDS_DEVICE_TXT "Device" +# TODO: use MSG_278 for translations +t IDS_BOOT_TYPE_TXT "Boot type" t IDS_PARTITION_TYPE_TXT "Partition scheme" -t IDS_TARGET_SYSTEM_TXT "Target system type" +t IDS_TARGET_SYSTEM_TXT "Target system" t IDS_FILESYSTEM_TXT "File system" t IDS_CLUSTERSIZE_TXT "Cluster size" -t IDS_LABEL_TXT "New volume label" +t IDS_LABEL_TXT "Volume label" t IDS_FORMAT_OPTIONS_GRP "Format Options" # Note: The button (IDC_ADVANCED) that appears next to "Format Options" is repositioned automatically. t IDC_BADBLOCKS "Check device for bad blocks" t IDC_QUICKFORMAT "Quick format" -t IDC_BOOT "Create a bootable disk using" -t IDC_WINDOWS_INSTALL "Standard Windows installation" -# Only translate if Microsoft has a specific name for http://en.wikipedia.org/wiki/Windows_To_Go in your language -# Otherwise, you can add a parenthesis eg. "Windows To Go (hint at what it does)" and/or use the tooltip (MSG_200) -t IDC_WINDOWS_TO_GO "Windows To Go" t IDC_SET_ICON "Create extended label and icon files" t IDC_ABOUT "About..." t IDC_LOG "Log" @@ -180,8 +177,8 @@ t MSG_003 "WARNING: ALL DATA ON DEVICE '%s' WILL BE DESTROYED.\n" t MSG_004 "Rufus update policy" t MSG_005 "Do you want to allow Rufus to check for application updates online?" # Must be the same as IDD_DIALOG:IDCANCEL (i.e. "Close" - I know it's confusing) -t MSG_006 "Close" -t MSG_007 "Cancel" +t MSG_006 "CLOSE" +t MSG_007 "CANCEL" t MSG_008 "Yes" t MSG_009 "No" t MSG_010 "Bad blocks found" @@ -210,13 +207,13 @@ t MSG_028 "megabytes" t MSG_029 "Default" # The following gets appended to the file system, cluster size, etc. t MSG_030 "%s (Default)" -t MSG_031 "%s partition scheme for BIOS or %s" -t MSG_032 "%s partition scheme for BIOS" -t MSG_033 "%s partition scheme for UEFI" +t MSG_031 "BIOS (or UEFI-CSM)" +t MSG_032 "UEFI (non CSM)" +t MSG_033 "BIOS or UEFI" # Number of bad block check passes (singular for 1 pass, plural for 2 or more passes) -t MSG_034 "%d mass" -t MSG_035 "%d masses" -t MSG_036 "ISO Image" +t MSG_034 "%d pass" +t MSG_035 "%d passes" +t MSG_036 "Disk or ISO Image" t MSG_037 "Application" t MSG_038 "Abort" t MSG_039 "Launch" @@ -298,7 +295,7 @@ t MSG_093 "IMPORTANT: THIS DRIVE CONTAINS MULTIPLE PARTITIONS!!\n\n" "This may include partitions/volumes that aren't listed or even visible from Windows. " "Should you wish to proceed, you are responsible for any data loss on these partitions." t MSG_094 "Multiple partitions detected" -t MSG_095 "DD Image" +###### t MSG_095 "DD Image" t MSG_096 "The file system currently selected can not be used with this type of ISO. " "Please select a different file system or use a different ISO." t MSG_097 "'%s' can only be applied if the file system is NTFS." @@ -379,7 +376,7 @@ t MSG_159 "Use this field to set the drive label\nInternational characters are a t MSG_160 "Toggle advanced options" t MSG_161 "Check the device for bad blocks using a test pattern" t MSG_162 "Uncheck this box to use the \"slow\" format method" -t MSG_163 "Check this box to make the USB drive bootable" +### t MSG_163 ###FREE TO USE### t MSG_164 "Method that will be used to make the drive bootable" t MSG_165 "Click to select an image..." t MSG_166 "Check this box to allow the display of international labels " @@ -570,6 +567,11 @@ t MSG_299 "Timestamp validation error" t MSG_300 "Rufus could not validate that the timestamp of the downloaded update is more recent than the one for the " "current executable.\n\nIn order to prevent potential attack scenarios, the update process has been aborted and " "the download will be deleted. Please check the log for more details." +t MSG_301 "Standard Windows installation" +# Only translate if Microsoft has a specific name for http://en.wikipedia.org/wiki/Windows_To_Go in your language +# Otherwise, you can add a parenthesis eg. "Windows To Go (hint at what it does)" and/or use the tooltip (MSG_200) +t MSG_302 "Windows To Go" + ################################################################################ ############################# TRANSLATOR END COPY ############################## diff --git a/src/checksum.c b/src/checksum.c index 40352a61..37898c35 100644 --- a/src/checksum.c +++ b/src/checksum.c @@ -69,6 +69,7 @@ uint32_t bufnum, sum_count[CHECKSUM_MAX] = { 16, 20, 32 }; HANDLE data_ready[CHECKSUM_MAX] = { 0 }, thread_ready[CHECKSUM_MAX] = { 0 }; DWORD read_size[2]; unsigned char ALIGNED(64) buffer[2][BUFFER_SIZE]; +extern progress_in_use; /* * Rotate 32 bit integers by n bytes. @@ -927,6 +928,7 @@ DWORD WINAPI SumThread(void* param) bufnum = 0; _bufnum = 0; read_size[0] = 1; // Don't trigger the first loop break + progress_in_use = TRUE; for (rb = 0; ;rb += read_size[_bufnum]) { // Update the progress and check for cancel if (GetTickCount64() > LastRefresh + MAX_REFRESH) { @@ -982,6 +984,7 @@ DWORD WINAPI SumThread(void* param) r = 0; out: + progress_in_use = FALSE; for (i = 0; i < CHECKSUM_MAX; i++) { if (sum_thread[i] != NULL) TerminateThread(sum_thread[i], 1); diff --git a/src/dev.c b/src/dev.c index b2e61281..07da6762 100644 --- a/src/dev.c +++ b/src/dev.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * Device detection and enumeration - * Copyright © 2014-2017 Pete Batard + * Copyright © 2014-2018 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 diff --git a/src/drive.c b/src/drive.c index d3eac0fd..bdf39ffc 100644 --- a/src/drive.c +++ b/src/drive.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * Drive access function calls - * Copyright © 2011-2016 Pete Batard + * Copyright © 2011-2018 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 @@ -1164,7 +1164,7 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m } DriveLayoutEx.PartitionEntry[pn].PartitionLength.QuadPart = main_part_size_in_sectors * SelectedDrive.SectorSize; if (partition_style == PARTITION_STYLE_MBR) { - DriveLayoutEx.PartitionEntry[pn].Mbr.BootIndicator = IsChecked(IDC_BOOT); + DriveLayoutEx.PartitionEntry[pn].Mbr.BootIndicator = (bt != BT_NON_BOOTABLE); switch (file_system) { case FS_FAT16: DriveLayoutEx.PartitionEntry[pn].Mbr.PartitionType = 0x0e; // FAT16 LBA diff --git a/src/format.c b/src/format.c index adf1a276..ba35f4b8 100644 --- a/src/format.c +++ b/src/format.c @@ -2,7 +2,7 @@ * Rufus: The Reliable USB Formatting Utility * Formatting function calls * Copyright © 2007-2009 Tom Thornhill/Ridgecrop - * Copyright © 2011-2017 Pete Batard + * Copyright © 2011-2018 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 @@ -683,7 +683,6 @@ static BOOL FormatDrive(DWORD DriveIndex) WCHAR wLabel[64]; ULONG ulClusterSize; size_t i; - int fs; GetWindowTextU(hFileSystem, FSType, ARRAYSIZE(FSType)); // Might have a (Default) suffix => remove it @@ -693,7 +692,6 @@ static BOOL FormatDrive(DWORD DriveIndex) break; } } - fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem)); if ((fs == FS_UDF) && !((dur_mins == 0) && (dur_secs == 0))) { PrintInfoDebug(0, MSG_220, FSType, dur_mins, dur_secs); } else { @@ -864,9 +862,6 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive) FAKE_FD fake_fd = { 0 }; FILE* fp = (FILE*)&fake_fd; const char* using_msg = "Using %s MBR\n"; - int fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem)); - int bt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)); - int tt = GETTARGETTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme))); AnalyzeMBR(hPhysicalDrive, "Drive"); @@ -906,7 +901,7 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive) buffer[0x1c2] = 0x0c; break; } - if ((IsChecked(IDC_BOOT)) && (tt == TT_BIOS)) { + if ((bt != BT_NON_BOOTABLE) && (tt == TT_BIOS)) { // Set first partition bootable - masquerade as per the DiskID selected buffer[0x1be] = IsChecked(IDC_RUFUS_MBR) ? (BYTE)ComboBox_GetItemData(hDiskID, ComboBox_GetCurSel(hDiskID)):0x80; @@ -936,21 +931,21 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive) // Syslinux if ( (bt == BT_SYSLINUX_V4) || (bt == BT_SYSLINUX_V6) || - ((bt == BT_ISO) && HAS_SYSLINUX(img_report)) ) { + ((bt == BT_IMAGE) && HAS_SYSLINUX(img_report)) ) { uprintf(using_msg, "Syslinux"); r = write_syslinux_mbr(fp); goto notify; } // Grub 2.0 - if ( ((bt == BT_ISO) && (img_report.has_grub2)) || (bt == BT_GRUB2) ) { + if ( ((bt == BT_IMAGE) && (img_report.has_grub2)) || (bt == BT_GRUB2) ) { uprintf(using_msg, "Grub 2.0"); r = write_grub2_mbr(fp); goto notify; } // Grub4DOS - if ( ((bt == BT_ISO) && (img_report.has_grub4dos)) || (bt == BT_GRUB4DOS) ) { + if ( ((bt == BT_IMAGE) && (img_report.has_grub4dos)) || (bt == BT_GRUB4DOS) ) { uprintf(using_msg, "Grub4DOS"); r = write_grub4dos_mbr(fp); goto notify; @@ -964,7 +959,7 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive) } // KolibriOS - if ( (bt == BT_ISO) && HAS_KOLIBRIOS(img_report) && (IS_FAT(fs))) { + if ( (bt == BT_IMAGE) && HAS_KOLIBRIOS(img_report) && (IS_FAT(fs))) { uprintf(using_msg, "KolibriOS"); r = write_kolibrios_mbr(fp); goto notify; @@ -997,7 +992,7 @@ static BOOL WriteSBR(HANDLE hPhysicalDrive) { // TODO: Do we need anything special for 4K sectors? DWORD size, max_size, mbr_size = 0x200; - int r, bt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)); + int r; unsigned char* buf = NULL; FAKE_FD fake_fd = { 0 }; FILE* fp = (FILE*)&fake_fd; @@ -1009,7 +1004,7 @@ static BOOL WriteSBR(HANDLE hPhysicalDrive) (DWORD)(SelectedDrive.SectorsPerTrack * SelectedDrive.SectorSize) : 1*MB; max_size -= mbr_size; // Syslinux has precedence over Grub - if ((bt == BT_ISO) && (!HAS_SYSLINUX(img_report))) { + if ((bt == BT_IMAGE) && (!HAS_SYSLINUX(img_report))) { if (img_report.has_grub4dos) bt = BT_GRUB4DOS; if (img_report.has_grub2) @@ -1059,12 +1054,12 @@ static BOOL WriteSBR(HANDLE hPhysicalDrive) /* * Process the Partition Boot Record */ -static __inline const char* bt_to_name(int bt) { +static __inline const char* bt_to_name(void) { switch (bt) { case BT_FREEDOS: return "FreeDOS"; case BT_REACTOS: return "ReactOS"; default: - return ((bt==BT_ISO) && HAS_KOLIBRIOS(img_report)) ? "KolibriOS" : "Standard"; + return ((bt==BT_IMAGE) && HAS_KOLIBRIOS(img_report)) ? "KolibriOS" : "Standard"; } } static BOOL WritePBR(HANDLE hLogicalVolume) @@ -1072,7 +1067,6 @@ static BOOL WritePBR(HANDLE hLogicalVolume) int i; FAKE_FD fake_fd = { 0 }; FILE* fp = (FILE*)&fake_fd; - int bt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)); const char* using_msg = "Using %s %s partition boot record\n"; fake_fd._handle = (char*)hLogicalVolume; @@ -1080,7 +1074,7 @@ static BOOL WritePBR(HANDLE hLogicalVolume) switch (ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem))) { case FS_FAT16: - uprintf(using_msg, bt_to_name(bt), "FAT16"); + uprintf(using_msg, bt_to_name(), "FAT16"); if (!is_fat_16_fs(fp)) { uprintf("New volume does not have a FAT16 boot sector - aborting\n"); break; @@ -1090,7 +1084,7 @@ static BOOL WritePBR(HANDLE hLogicalVolume) if (!write_fat_16_fd_br(fp, 0)) break; } else if (bt == BT_REACTOS) { if (!write_fat_16_ros_br(fp, 0)) break; - } else if ((bt == BT_ISO) && HAS_KOLIBRIOS(img_report)) { + } else if ((bt == BT_IMAGE) && HAS_KOLIBRIOS(img_report)) { uprintf("FAT16 is not supported for KolibriOS\n"); break; } else { if (!write_fat_16_br(fp, 0)) break; @@ -1100,7 +1094,7 @@ static BOOL WritePBR(HANDLE hLogicalVolume) break; return TRUE; case FS_FAT32: - uprintf(using_msg, bt_to_name(bt), "FAT32"); + uprintf(using_msg, bt_to_name(), "FAT32"); for (i=0; i<2; i++) { if (!is_fat_32_fs(fp)) { uprintf("New volume does not have a %s FAT32 boot sector - aborting\n", i?"secondary":"primary"); @@ -1112,11 +1106,11 @@ static BOOL WritePBR(HANDLE hLogicalVolume) if (!write_fat_32_fd_br(fp, 0)) break; } else if (bt == BT_REACTOS) { if (!write_fat_32_ros_br(fp, 0)) break; - } else if ((bt == BT_ISO) && HAS_KOLIBRIOS(img_report)) { + } else if ((bt == BT_IMAGE) && HAS_KOLIBRIOS(img_report)) { if (!write_fat_32_kos_br(fp, 0)) break; - } else if ((bt == BT_ISO) && HAS_BOOTMGR(img_report)) { + } else if ((bt == BT_IMAGE) && HAS_BOOTMGR(img_report)) { if (!write_fat_32_pe_br(fp, 0)) break; - } else if ((bt == BT_ISO) && HAS_WINPE(img_report)) { + } else if ((bt == BT_IMAGE) && HAS_WINPE(img_report)) { if (!write_fat_32_nt_br(fp, 0)) break; } else { if (!write_fat_32_br(fp, 0)) break; @@ -1128,7 +1122,7 @@ static BOOL WritePBR(HANDLE hLogicalVolume) } return TRUE; case FS_NTFS: - uprintf(using_msg, bt_to_name(bt), "NTFS"); + uprintf(using_msg, bt_to_name(), "NTFS"); if (!is_ntfs_fs(fp)) { uprintf("New volume does not have an NTFS boot sector - aborting\n"); break; @@ -1644,7 +1638,7 @@ out: */ DWORD WINAPI FormatThread(void* param) { - int i, r, pt, tt, fs, bt; + int i, r; BOOL ret, use_large_fat32, windows_to_go; DWORD DriveIndex = (DWORD)(uintptr_t)param; HANDLE hPhysicalDrive = INVALID_HANDLE_VALUE; @@ -1660,11 +1654,9 @@ DWORD WINAPI FormatThread(void* param) char efi_dst[] = "?:\\efi\\boot\\bootx64.efi"; char kolibri_dst[] = "?:\\MTLD_F32"; char grub4dos_dst[] = "?:\\grldr"; + // TODO: Have a boolean to indicate DD writing + BOOL write_as_image = FALSE; - fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem)); - bt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)); - pt = GETPARTTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme))); - tt = GETTARGETTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme))); use_large_fat32 = (fs == FS_FAT32) && ((SelectedDrive.DiskSize > LARGE_FAT32_SIZE) || (force_large_fat32)); windows_to_go = (togo_mode) && HAS_WINTOGO(img_report) && (Button_GetCheck(GetDlgItem(hMainDialog, IDC_WINDOWS_TO_GO)) == BST_CHECKED); large_drive = (SelectedDrive.DiskSize > (1*TB)); @@ -1676,7 +1668,7 @@ DWORD WINAPI FormatThread(void* param) // http://msdn.microsoft.com/en-us/library/windows/hardware/dn640535.aspx#gpt_faq_what_disk_require_msr extra_partitions = XP_MSR | XP_EFI; else if ( (fs == FS_NTFS) && ((bt == BT_UEFI_NTFS) || - ((bt == BT_ISO) && IS_EFI_BOOTABLE(img_report) && ((tt == TT_UEFI) || (windows_to_go) || (allow_dual_uefi_bios)))) ) + ((bt == BT_IMAGE) && IS_EFI_BOOTABLE(img_report) && ((tt == TT_UEFI) || (windows_to_go) || (allow_dual_uefi_bios)))) ) extra_partitions = XP_UEFI_NTFS; else if (IsChecked(IDC_EXTRA_PARTITION)) extra_partitions = XP_COMPAT; @@ -1707,7 +1699,7 @@ DWORD WINAPI FormatThread(void* param) // Do it in reverse so that we always end on the first volume letter for (i=(int)safe_strlen(drive_letters); i>0; i--) { drive_name[0] = drive_letters[i-1]; - if (IsChecked(IDC_BOOT) && ((bt == BT_ISO) || (bt == BT_IMG))) { + if (bt == BT_IMAGE) { // If we are using an image, check that it isn't located on the drive we are trying to format if ((PathGetDriveNumberU(image_path) + 'A') == drive_letters[i-1]) { uprintf("ABORTED: Cannot use an image that is located on the target drive!\n"); @@ -1755,7 +1747,7 @@ DWORD WINAPI FormatThread(void* param) // Note, Microsoft's way of cleaning partitions (IOCTL_DISK_CREATE_DISK, which is what we apply // in InitializeDisk) is *NOT ENOUGH* to reset a disk and can render it inoperable for partitioning // or formatting under Windows. See https://github.com/pbatard/rufus/issues/759 for details. - if ((!IsChecked(IDC_BOOT)) || (bt != BT_IMG)) { + if ((bt != BT_IMAGE) || (img_report.is_iso)) { if ((!ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, SelectedDrive.SectorSize, use_large_fat32)) || (!InitializeDisk(hPhysicalDrive))) { uprintf("Could not reset partitions\n"); @@ -1830,7 +1822,7 @@ DWORD WINAPI FormatThread(void* param) } // Write an image file - if (IsChecked(IDC_BOOT) && (bt == BT_IMG)) { + if ((bt == BT_IMAGE) && write_as_image) { hSourceImage = CreateFileU(image_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (hSourceImage == INVALID_HANDLE_VALUE) { @@ -1935,18 +1927,18 @@ DWORD WINAPI FormatThread(void* param) uprintf("Warning: Failed to refresh label: %s", WindowsErrorString()); } - if (IsChecked(IDC_BOOT)) { + if (bt != BT_NON_BOOTABLE) { if (bt == BT_UEFI_NTFS) { // All good } else if (tt == TT_UEFI) { // For once, no need to do anything - just check our sanity - if ( (bt != BT_ISO) || !IS_EFI_BOOTABLE(img_report) || (fs > FS_NTFS) ) { + if ( (bt != BT_IMAGE) || !IS_EFI_BOOTABLE(img_report) || (fs > FS_NTFS) ) { uprintf("Spock gone crazy error in %s:%d", __FILE__, __LINE__); FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INSTALL_FAILURE; goto out; } } else if ( (bt == BT_SYSLINUX_V4) || (bt == BT_SYSLINUX_V6) || - ((bt == BT_ISO) && (HAS_SYSLINUX(img_report) || HAS_REACTOS(img_report)) && + ((bt == BT_IMAGE) && (HAS_SYSLINUX(img_report) || HAS_REACTOS(img_report)) && (!HAS_WINDOWS(img_report) || !allow_dual_uefi_bios)) ) { if (!InstallSyslinux(DriveIndex, drive_name[0], fs)) { FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INSTALL_FAILURE; @@ -1985,7 +1977,7 @@ DWORD WINAPI FormatThread(void* param) goto out; CHECK_FOR_USER_CANCEL; - if (IsChecked(IDC_BOOT)) { + if (bt != BT_NON_BOOTABLE) { if ((bt == BT_MSDOS) || (bt == BT_FREEDOS)) { UpdateProgress(OP_DOS, -1.0f); PrintInfoDebug(0, MSG_230); @@ -2001,7 +1993,7 @@ DWORD WINAPI FormatThread(void* param) IsFileInDB(FILES_DIR "\\grub4dos-" GRUB4DOS_VERSION "\\grldr")?"✓":"✗"); if (!CopyFileU(FILES_DIR "\\grub4dos-" GRUB4DOS_VERSION "\\grldr", grub4dos_dst, FALSE)) uprintf("Failed to copy file: %s", WindowsErrorString()); - } else if ((bt == BT_ISO) && (image_path != NULL)) { + } else if ((bt == BT_IMAGE) && (image_path != NULL) && (img_report.is_iso)) { UpdateProgress(OP_DOS, 0.0f); drive_name[2] = 0; // Ensure our drive is something like 'D:' if (windows_to_go) { @@ -2057,7 +2049,7 @@ DWORD WINAPI FormatThread(void* param) // Issue another complete remount before we exit, to ensure we're clean RemountVolume(drive_name); // NTFS fixup (WinPE/AIK images don't seem to boot without an extra checkdisk) - if ((bt == BT_ISO) && (fs == FS_NTFS)) { + if ((bt == BT_IMAGE) && (img_report.is_iso) && (fs == FS_NTFS)) { // Try to ensure that all messages from Checkdisk will be in English if (PRIMARYLANGID(GetThreadUILanguage()) != LANG_ENGLISH) { SetThreadUILanguage(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); diff --git a/src/format.h b/src/format.h index bc32557c..3c5ef25e 100644 --- a/src/format.h +++ b/src/format.h @@ -2,7 +2,7 @@ * Rufus: The Reliable USB Formatting Utility * Formatting function calls * Copyright © 2007-2009 Tom Thornhill/Ridgecrop - * Copyright © 2011-2014 Pete Batard + * Copyright © 2011-2018 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 diff --git a/src/iso.c b/src/iso.c index 76f28ad2..27a6612d 100644 --- a/src/iso.c +++ b/src/iso.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * ISO file extraction - * Copyright © 2011-2016 Pete Batard + * Copyright © 2011-2018 Pete Batard * Based on libcdio's iso & udf samples: * Copyright © 2003-2014 Rocky Bernstein * @@ -1170,7 +1170,7 @@ BOOL ExtractEfiImgFiles(const char* dir) iso9660_readfat_private* p_private = NULL; libfat_sector_t s; int32_t dc, c; - struct libfat_filesystem *fs = NULL; + struct libfat_filesystem *lf_fs = NULL; struct libfat_direntry direntry; char name[12] = { 0 }; char path[64]; @@ -1201,17 +1201,17 @@ BOOL ExtractEfiImgFiles(const char* dir) uprintf("Error reading ISO-9660 file %s at LSN %lu\n", img_report.efi_img_path, (long unsigned int)p_private->lsn); goto out; } - fs = libfat_open(iso9660_readfat, (intptr_t)p_private); - if (fs == NULL) { + lf_fs = libfat_open(iso9660_readfat, (intptr_t)p_private); + if (lf_fs == NULL) { uprintf("FAT access error"); goto out; } // Navigate to /EFI/BOOT - if (libfat_searchdir(fs, 0, "EFI ", &direntry) < 0) + if (libfat_searchdir(lf_fs, 0, "EFI ", &direntry) < 0) goto out; dc = direntry.entry[26] + (direntry.entry[27] << 8); - if (libfat_searchdir(fs, dc, "BOOT ", &direntry) < 0) + if (libfat_searchdir(lf_fs, dc, "BOOT ", &direntry) < 0) goto out; dc = direntry.entry[26] + (direntry.entry[27] << 8); @@ -1228,7 +1228,7 @@ BOOL ExtractEfiImgFiles(const char* dir) } else name[k++] = toupper(efi_bootname[i][j]); } - c = libfat_searchdir(fs, dc, name, &direntry); + c = libfat_searchdir(lf_fs, dc, name, &direntry); if (c > 0) { if (dir == NULL) { if (!ret) @@ -1265,9 +1265,9 @@ BOOL ExtractEfiImgFiles(const char* dir) } written = 0; - s = libfat_clustertosector(fs, c); + s = libfat_clustertosector(lf_fs, c); while ((s != 0) && (s < 0xFFFFFFFFULL) && (written < file_size)) { - buf = libfat_get_sector(fs, s); + buf = libfat_get_sector(lf_fs, s); size = MIN(LIBFAT_SECTOR_SIZE, file_size - written); if (!WriteFileWithRetry(handle, buf, size, &size, WRITE_RETRIES) || (size != MIN(LIBFAT_SECTOR_SIZE, file_size - written))) { @@ -1276,7 +1276,7 @@ BOOL ExtractEfiImgFiles(const char* dir) continue; } written += size; - s = libfat_nextsector(fs, s); + s = libfat_nextsector(lf_fs, s); } CloseHandle(handle); ret = TRUE; @@ -1285,8 +1285,8 @@ BOOL ExtractEfiImgFiles(const char* dir) } out: - if (fs != NULL) - libfat_close(fs); + if (lf_fs != NULL) + libfat_close(lf_fs); if (p_statbuf != NULL) safe_free(p_statbuf->rr.psz_symlink); safe_free(p_statbuf); diff --git a/src/license.h b/src/license.h index a1fe2087..931607a8 100644 --- a/src/license.h +++ b/src/license.h @@ -34,7 +34,7 @@ RUFUS_URL "\\line\n" const char* additional_copyrights = "{\\rtf1\\ansi\n" -"Based on a GUI redesign concept by Fahad Al-Riyami\\line\n" +"Rufus 3.0 GUI redesign concept by Fahad Al-Riyami\\line\n" "Used with kind authorization\\line\n" "\\line\n" "Icon by PC Unleashed:\\line\n" diff --git a/src/localization.c b/src/localization.c index fb25b6b5..937c0d28 100644 --- a/src/localization.c +++ b/src/localization.c @@ -80,6 +80,8 @@ char* default_msg_table[MSG_MAX-MSG_000] = {"%s", 0}; char* current_msg_table[MSG_MAX-MSG_000] = {"%s", 0}; char** msg_table = NULL; +extern progress_in_use; + static void mtab_destroy(BOOL reinit) { size_t j; @@ -428,7 +430,15 @@ static uint64_t last_msg_time[2] = { 0, 0 }; static void PrintInfoMessage(char* msg) { SetWindowTextU(hProgress, msg); // Make sure our field gets redrawn - SendMessage(hProgress, WM_PAINT, 0, 0); + // If the progress bar is not active, it looks like WM_PAINT is + // ignored. But InvalidateRect is causing refresh tearing so we + // don't want to use that while active. + // Refresh still sucks though and marquee no longer works... :( + // TODO: Create our own progress bar control with text overlay and inverted text + if (!progress_in_use) + InvalidateRect(hProgress, NULL, TRUE); + else + SendMessage(hProgress, WM_PAINT, 0, 0); } static void PrintStatusMessage(char* msg) { SendMessageLU(hStatus, SB_SETTEXTW, SBT_OWNERDRAW | SB_SECTION_LEFT, msg); @@ -446,6 +456,7 @@ static void CALLBACK OutputMessageTimeout(HWND hWnd, UINT uMsg, UINT_PTR idEvent KillTimer(hMainDialog, idEvent); bOutputTimerArmed[i] = FALSE; + PrintMessage[i](output_msg[i]); last_msg_time[i] = GetTickCount64(); } diff --git a/src/localization_data.h b/src/localization_data.h index 4575ac62..520b77bf 100644 --- a/src/localization_data.h +++ b/src/localization_data.h @@ -46,13 +46,12 @@ const loc_control_id control_id[] = { LOC_CTRL(IDC_ABOUT), LOC_CTRL(IDC_LABEL), LOC_CTRL(IDC_QUICKFORMAT), - LOC_CTRL(IDC_BOOT), LOC_CTRL(IDC_BADBLOCKS), LOC_CTRL(IDC_PROGRESS), LOC_CTRL(IDC_BOOTTYPE), LOC_CTRL(IDC_NBPASSES), LOC_CTRL(IDC_TEST), - LOC_CTRL(IDC_SELECT_ISO), + LOC_CTRL(IDC_SELECT_IMAGE), LOC_CTRL(IDC_SET_ICON), LOC_CTRL(IDC_RUFUS_MBR), LOC_CTRL(IDC_TARGET_SYSTEM), @@ -65,7 +64,7 @@ const loc_control_id control_id[] = { LOC_CTRL(IDC_HASH), LOC_CTRL(IDC_SAVE), LOC_CTRL(IDC_SELECTED_IMAGE), - LOC_CTRL(IDC_BOOT_OPTION), + LOC_CTRL(IDC_IMAGE_OPTION), LOC_CTRL(IDC_ABOUT_LICENSE), LOC_CTRL(IDC_ABOUT_ICON), LOC_CTRL(IDC_ABOUT_UPDATES), @@ -150,13 +149,13 @@ const loc_control_id control_id[] = { LOC_CTRL(IDS_CHECK_NOW_GRP), LOC_CTRL(IDS_TARGET_SYSTEM_TXT), LOC_CTRL(IDS_SELETED_IMAGE_TXT), - LOC_CTRL(IDS_BOOT_OPTION_TXT), + LOC_CTRL(IDS_IMAGE_OPTION_TXT), LOC_CTRL(IDS_SELECTED_IMAGE_TXT), LOC_CTRL(IDS_BOOT_TYPE_TXT), - LOC_CTRL(IDS_DEVICE_OPTIONS_TXT), + LOC_CTRL(IDS_DEVICE_SETTINGS_TXT), + LOC_CTRL(IDS_IMAGE_SETTINGS_TXT), LOC_CTRL(IDS_FORMAT_OPTIONS_TXT), LOC_CTRL(IDS_ADVANCED_OPTIONS_TXT), - LOC_CTRL(IDS_FORMAT_OPTIONS_TXT2), LOC_CTRL(IDS_STATUS_TXT), LOC_CTRL(MSG_000), LOC_CTRL(MSG_001), @@ -459,6 +458,16 @@ const loc_control_id control_id[] = { LOC_CTRL(MSG_298), LOC_CTRL(MSG_299), LOC_CTRL(MSG_300), + LOC_CTRL(MSG_301), + LOC_CTRL(MSG_302), + LOC_CTRL(MSG_303), + LOC_CTRL(MSG_304), + LOC_CTRL(MSG_305), + LOC_CTRL(MSG_306), + LOC_CTRL(MSG_307), + LOC_CTRL(MSG_308), + LOC_CTRL(MSG_309), + LOC_CTRL(MSG_310), LOC_CTRL(MSG_MAX), LOC_CTRL(IDOK), LOC_CTRL(IDCANCEL), diff --git a/src/resource.h b/src/resource.h index 13548dfa..7d00874b 100644 --- a/src/resource.h +++ b/src/resource.h @@ -82,13 +82,12 @@ #define IDC_ABOUT 1007 #define IDC_LABEL 1008 #define IDC_QUICKFORMAT 1009 -#define IDC_BOOT 1010 #define IDC_BADBLOCKS 1011 #define IDC_PROGRESS 1012 #define IDC_BOOTTYPE 1013 #define IDC_NBPASSES 1014 #define IDC_TEST 1015 -#define IDC_SELECT_ISO 1016 +#define IDC_SELECT_IMAGE 1016 #define IDC_SET_ICON 1017 #define IDC_RUFUS_MBR 1018 #define IDC_TARGET_SYSTEM 1019 @@ -101,7 +100,7 @@ #define IDC_HASH 1026 #define IDC_SAVE 1027 #define IDC_SELECTED_IMAGE 1028 -#define IDC_BOOT_OPTION 1029 +#define IDC_IMAGE_OPTION 1029 #define IDC_ABOUT_LICENSE 1030 #define IDC_ABOUT_ICON 1031 #define IDC_ABOUT_UPDATES 1032 @@ -186,14 +185,14 @@ #define IDS_CHECK_NOW_GRP 2012 #define IDS_TARGET_SYSTEM_TXT 2013 #define IDS_SELETED_IMAGE_TXT 2014 -#define IDS_BOOT_OPTION_TXT 2015 +#define IDS_IMAGE_OPTION_TXT 2015 #define IDS_SELECTED_IMAGE_TXT 2016 #define IDS_BOOT_TYPE_TXT 2017 -#define IDS_DEVICE_OPTIONS_TXT 2018 -#define IDS_FORMAT_OPTIONS_TXT 2019 -#define IDS_ADVANCED_OPTIONS_TXT 2020 -#define IDS_FORMAT_OPTIONS_TXT2 2020 -#define IDS_STATUS_TXT 2021 +#define IDS_DEVICE_SETTINGS_TXT 2018 +#define IDS_IMAGE_SETTINGS_TXT 2019 +#define IDS_FORMAT_OPTIONS_TXT 2020 +#define IDS_ADVANCED_OPTIONS_TXT 2021 +#define IDS_STATUS_TXT 2022 #define MSG_000 3000 #define MSG_001 3001 #define MSG_002 3002 @@ -495,7 +494,17 @@ #define MSG_298 3298 #define MSG_299 3299 #define MSG_300 3300 -#define MSG_MAX 3301 +#define MSG_301 3301 +#define MSG_302 3302 +#define MSG_303 3303 +#define MSG_304 3304 +#define MSG_305 3305 +#define MSG_306 3306 +#define MSG_307 3307 +#define MSG_308 3308 +#define MSG_309 3309 +#define MSG_310 3310 +#define MSG_MAX 3311 // Next default values for new objects // diff --git a/src/rufus.c b/src/rufus.c index 62e5e159..0d392cd4 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -47,11 +47,45 @@ #include "../res/grub/grub_version.h" #include "../res/grub2/grub2_version.h" -static int togo_move_ids[] = { - IDS_PARTITION_TYPE_TXT, - IDC_PARTITION_TYPE, - IDS_TARGET_SYSTEM_TXT, - IDC_TARGET_SYSTEM, +// TODO: move this somewhere else (ui.h?) +static int image_option_move_ids[] = { + IDS_FORMAT_OPTIONS_TXT, + IDS_LABEL_TXT, + IDC_LABEL, + IDS_FILESYSTEM_TXT, + IDC_FILESYSTEM, + IDS_CLUSTERSIZE_TXT, + IDC_CLUSTERSIZE, + IDC_ADVANCED, + IDC_BADBLOCKS, + IDC_NBPASSES, + IDC_SET_ICON, + IDS_ADVANCED_OPTIONS_TXT, + IDC_ENABLE_FIXED_DISKS, + IDC_QUICKFORMAT, + IDC_EXTRA_PARTITION, + IDC_RUFUS_MBR, + IDC_DISK_ID, + IDS_STATUS_TXT, + IDC_PROGRESS, + IDC_INFO, + IDC_ABOUT, + IDC_LOG, + IDC_TEST, + IDC_START, + IDCANCEL, + IDC_STATUS, + IDC_STATUS_TOOLBAR, +}; + +static int image_option_toggle_ids[] = { + IDS_IMAGE_OPTION_TXT, + IDC_IMAGE_OPTION, +}; + +static int image_settings_move_ids[] = { + IDS_IMAGE_OPTION_TXT, + IDC_IMAGE_OPTION, IDS_FORMAT_OPTIONS_TXT, IDS_FILESYSTEM_TXT, IDC_FILESYSTEM, @@ -81,48 +115,14 @@ static int togo_move_ids[] = { IDC_STATUS_TOOLBAR, }; -static int togo_toggle_ids[] = { - IDS_BOOT_OPTION_TXT, - IDC_BOOT_OPTION, +static int image_settings_toggle_ids[] = { + IDS_IMAGE_SETTINGS_TXT, + IDS_SELECTED_IMAGE_TXT, + IDC_SELECTED_IMAGE, + IDC_HASH }; -static int advanced_move1_ids[] = { - IDS_BOOT_OPTION_TXT, - IDC_BOOT_OPTION, - IDS_PARTITION_TYPE_TXT, - IDC_PARTITION_TYPE, - IDS_TARGET_SYSTEM_TXT, - IDC_TARGET_SYSTEM, - IDS_FORMAT_OPTIONS_TXT, - IDS_FILESYSTEM_TXT, - IDC_FILESYSTEM, - IDS_CLUSTERSIZE_TXT, - IDC_CLUSTERSIZE, - IDS_LABEL_TXT, - IDC_LABEL, - IDC_ADVANCED, - IDC_BADBLOCKS, - IDC_NBPASSES, - IDC_SET_ICON, - IDS_ADVANCED_OPTIONS_TXT, - IDC_ENABLE_FIXED_DISKS, - IDC_QUICKFORMAT, - IDC_EXTRA_PARTITION, - IDC_RUFUS_MBR, - IDC_DISK_ID, - IDS_STATUS_TXT, - IDC_PROGRESS, - IDC_INFO, - IDC_ABOUT, - IDC_LOG, - IDC_TEST, - IDC_START, - IDCANCEL, - IDC_STATUS, - IDC_STATUS_TOOLBAR -}; - -static int advanced_move2_ids[] = { +static int advanced_move_ids[] = { IDS_ADVANCED_OPTIONS_TXT, IDC_ENABLE_FIXED_DISKS, IDC_QUICKFORMAT, @@ -143,9 +143,6 @@ static int advanced_move2_ids[] = { static int advanced_toggle_ids[] = { IDC_SAVE, - IDS_SELECTED_IMAGE_TXT, - IDC_SELECTED_IMAGE, - IDC_HASH, IDC_ENABLE_FIXED_DISKS, IDC_QUICKFORMAT, IDC_EXTRA_PARTITION, @@ -160,7 +157,6 @@ static const char* ep_reg = "Software\\Microsoft\\Windows\\CurrentVersion\\Polic static const char* vs_reg = "Software\\Microsoft\\VisualStudio"; // Number of steps for each FS for FCC_STRUCTURE_PROGRESS const int nb_steps[FS_MAX] = { 5, 5, 12, 1, 10 }; -static const char* PartitionTypeLabel[2] = { "MBR", "GPT" }; static BOOL existing_key = FALSE; // For LGP set/restore static BOOL size_check = TRUE; static BOOL log_displayed = FALSE; @@ -170,18 +166,20 @@ static BOOL relaunch = FALSE; static BOOL dont_display_image_name = FALSE; static BOOL user_changed_label = FALSE; static BOOL app_changed_label = FALSE; +static BOOL allowed_filesystem[FS_MAX] = { 0 }; static int64_t last_iso_blocking_status; -static int selection_default, row_height, advanced_section_height; -static int device_vpos, format_vpos, advanced_vpos, status_vpos; +// TODO: rename 'selection_default' to something more explicit +static int selection_default, row_height, advanced_section_height, image_settings_height, image_index; +static int device_vpos, image_vpos, format_vpos, advanced_vpos, status_vpos; static UINT_PTR UM_LANGUAGE_MENU_MAX = UM_LANGUAGE_MENU; static RECT relaunch_rc = { -65536, -65536, 0, 0}; -static UINT uBootChecked = BST_CHECKED, uQFChecked = BST_CHECKED, uMBRChecked = BST_UNCHECKED; +static UINT uQFChecked = BST_CHECKED, uMBRChecked = BST_UNCHECKED; static HFONT hInfoFont; static HBRUSH hInfoBrush; -static WNDPROC info_original_proc = NULL, progress_original_proc = NULL; +static WNDPROC progress_original_proc = NULL; static HANDLE format_thid = NULL, dialog_handle = NULL; -static HWND hBoot = NULL, hSelectISO = NULL, hStart = NULL; -static HICON hIconDisc, hIconSave, hIconDown, hIconUp, hIconLang; +static HWND hSelectImage = NULL, hStart = NULL; +static HICON hIconSave, hIconDown, hIconUp, hIconLang; static char szTimer[12] = "00:00:00"; static unsigned int timer; @@ -202,15 +200,15 @@ BUTTON_IMAGELIST bi_iso = { 0 }, bi_up = { 0 }, bi_down = { 0 }, bi_save = { 0 } char szFolderPath[MAX_PATH], app_dir[MAX_PATH], system_dir[MAX_PATH], temp_dir[MAX_PATH], sysnative_dir[MAX_PATH]; char* image_path = NULL; float fScale = 1.0f; -int default_fs; +int default_fs, fs, bt, pt, tt; uint32_t dur_mins, dur_secs; loc_cmd* selected_locale = NULL; WORD selected_langid = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT); DWORD MainThreadId; -HWND hDeviceList, hPartitionScheme, hFileSystem, hClusterSize, hLabel, hBootType, hNBPasses, hLog = NULL; +HWND hDeviceList, hPartitionScheme, hTargetSystem, hFileSystem, hClusterSize, hLabel, hBootType, hNBPasses, hLog = NULL; HWND hLogDlg = NULL, hProgress = NULL, hDiskID, hStatusToolbar; -BOOL use_own_c32[NB_OLD_C32] = {FALSE, FALSE}, mbr_selected_by_user = FALSE, togo_mode; -BOOL iso_op_in_progress = FALSE, format_op_in_progress = FALSE, right_to_left_mode = FALSE; +BOOL use_own_c32[NB_OLD_C32] = {FALSE, FALSE}, mbr_selected_by_user = FALSE, togo_mode = FALSE, display_image_settings = FALSE; +BOOL iso_op_in_progress = FALSE, format_op_in_progress = FALSE, right_to_left_mode = FALSE, progress_in_use = FALSE; BOOL enable_HDDs = FALSE, force_update = FALSE, enable_ntfs_compression = FALSE, no_confirmation_on_cancel = FALSE, lock_drive = TRUE; BOOL advanced_mode, allow_dual_uefi_bios, detect_fakes, enable_vmdk, force_large_fat32, usb_debug, use_fake_units, preserve_timestamps; BOOL zero_drive = FALSE, list_non_usb_removable_drives = FALSE, disable_file_indexing, large_drive = FALSE, prefer_gpt = FALSE; @@ -221,10 +219,10 @@ char embedded_sl_version_ext[2][32]; char ClusterSizeLabel[MAX_CLUSTER_SIZES][64]; char msgbox[1024], msgbox_title[32], *ini_file = NULL; RUFUS_UPDATE update = { {0,0,0}, {0,0}, NULL, NULL}; -StrArray DriveID, DriveLabel, DriveHub, BlockingProcess; +StrArray DriveID, DriveLabel, DriveHub, BlockingProcess, ImageList; uint32_t DrivePort[MAX_DRIVES]; -static void ToggleToGo(void); +static void ToggleImageOption(void); /* * The following is used to allocate slots within the progress bar @@ -242,12 +240,16 @@ static float previous_end; // localization_data.sh and the .rc when the year changes! // Set the combo selection according to the data -static __inline void SetComboEntry(HWND hDlg, int data) { +static void SetComboEntry(HWND hDlg, int data) { int i; for (i = 0; i < ComboBox_GetCount(hDlg); i++) { - if (ComboBox_GetItemData(hDlg, i) == data) + if (ComboBox_GetItemData(hDlg, i) == data) { IGNORE_RETVAL(ComboBox_SetCurSel(hDlg, i)); + break; + } } + if (i == ComboBox_GetCount(hDlg)) + IGNORE_RETVAL(ComboBox_SetCurSel(hDlg, 0)); } /* @@ -266,21 +268,233 @@ static void SetClusterSizeLabels(void) } } -/* - * Set cluster size values according to http://support.microsoft.com/kb/140365 - * this call will return FALSE if we can't find a supportable FS for the drive - */ -static BOOL DefineClusterSizes(void) +static void SetAllowedFileSystems(void) { + int i; + + memset(allowed_filesystem, 0, sizeof(allowed_filesystem)); + switch (selection_default) { + case BT_NON_BOOTABLE: + // TODO: Disable target system control, add "Super Floppy" to the list + for (i = 0; i < FS_MAX; i++) + allowed_filesystem[i] = TRUE; + break; + case BT_MSDOS: + case BT_FREEDOS: + allowed_filesystem[FS_FAT16] = TRUE; + allowed_filesystem[FS_FAT32] = TRUE; + break; + case BT_IMAGE: + // TODO: only do this if ISO we can service + allowed_filesystem[FS_FAT16] = TRUE; + allowed_filesystem[FS_FAT32] = TRUE; + allowed_filesystem[FS_NTFS] = TRUE; + break; + case BT_SYSLINUX_V6: + allowed_filesystem[FS_NTFS] = TRUE; + // Fall through + case BT_SYSLINUX_V4: + case BT_REACTOS: + case BT_GRUB4DOS: + case BT_GRUB2: + allowed_filesystem[FS_FAT16] = TRUE; + allowed_filesystem[FS_FAT32] = TRUE; + break; + case BT_UEFI_NTFS: + allowed_filesystem[FS_NTFS] = TRUE; + break; + } + + // Reset disk ID to 0x80 if Rufus MBR is used + if (selection_default != BT_IMAGE) { + IGNORE_RETVAL(ComboBox_SetCurSel(hDiskID, 0)); + } +} + +// Populate the Boot Type dropdown +static void SetBootOptions(void) +{ + char tmp[32]; + + IGNORE_RETVAL(ComboBox_ResetContent(hBootType)); + IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, lmprintf(MSG_279)), BT_NON_BOOTABLE)); + if (nWindowsVersion < WINDOWS_10) // The diskcopy.dll along with its MS-DOS floppy image was removed in Windows 10 + IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "MS-DOS"), BT_MSDOS)); + IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "FreeDOS"), BT_FREEDOS)); + // TODO: Merge DD and ISO images + image_index = (nWindowsVersion < WINDOWS_10) ? 3 : 2; + IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, lmprintf(MSG_036)), BT_IMAGE)); + + if (advanced_mode) { + static_sprintf(tmp, "Syslinux %s", embedded_sl_version_str[0]); + IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, tmp), BT_SYSLINUX_V4)); + static_sprintf(tmp, "Syslinux %s", embedded_sl_version_str[1]); + IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, tmp), BT_SYSLINUX_V6)); + IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "ReactOS"), BT_REACTOS)); + IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, + "Grub " GRUB2_PACKAGE_VERSION), BT_GRUB2)); + IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, + "Grub4DOS " GRUB4DOS_VERSION), BT_GRUB4DOS)); + IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "UEFI:NTFS"), BT_UEFI_NTFS)); + } + // TODO: re-select last image instead of FreeDOS + if ((!advanced_mode) && (selection_default >= BT_SYSLINUX_V4)) { + selection_default = BT_FREEDOS; + CheckDlgButton(hMainDialog, IDC_DISK_ID, BST_UNCHECKED); + } + SetComboEntry(hBootType, selection_default); +// EnableWindow(hSelectImage, FALSE); + + //if ((pt != PARTITION_STYLE_SFD) && !IsWindowEnabled(hBoot)) { + // EnableWindow(hBoot, TRUE); + // EnableWindow(hBootType, TRUE); + // EnableWindow(hSelectImage, TRUE); + // EnableWindow(GetDlgItem(hMainDialog, IDC_WINDOWS_INSTALL), TRUE); + // EnableWindow(GetDlgItem(hMainDialog, IDC_WINDOWS_TO_GO), TRUE); + //} +} + +static void SetPartitionSchemeAndTargetSystem(BOOL only_target) +{ + BOOL allowed_partition_scheme[3] = { TRUE, TRUE, FALSE }; + BOOL allowed_target_system[3] = { TRUE, TRUE, FALSE }; + BOOL dual_boot = FALSE; +// BOOL prefer_gpt = FALSE; + // TODO: Windows To Go selected + BOOL is_windows_to_go_selected = FALSE; + + if (!only_target) + IGNORE_RETVAL(ComboBox_ResetContent(hPartitionScheme)); + IGNORE_RETVAL(ComboBox_ResetContent(hTargetSystem)); + + bt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)); + switch (bt) { + case BT_NON_BOOTABLE: + allowed_partition_scheme[PARTITION_STYLE_SFD] = TRUE; + allowed_target_system[0] = FALSE; + allowed_target_system[1] = FALSE; + allowed_target_system[2] = TRUE; + // TODO: Grey out target system + break; + case BT_IMAGE: + if (pt == PARTITION_STYLE_GPT) + allowed_target_system[0] = FALSE; + if (image_path == NULL) + break; +// if HAS_BOOTMGR(img_report) +// prefer_gpt = TRUE; + // Check if image is EFI bootable + if (!IS_EFI_BOOTABLE(img_report)) { + allowed_partition_scheme[PARTITION_STYLE_GPT] = FALSE; + allowed_target_system[1] = FALSE; + break; + } + // Image is EFI bootable => set dual BIOS + UEFI and so on... + if (IS_BIOS_BOOTABLE(img_report)) { + if (!HAS_WINDOWS(img_report) || allow_dual_uefi_bios || is_windows_to_go_selected) { + allowed_target_system[0] = FALSE; + allowed_target_system[1] = FALSE; + allowed_target_system[2] = TRUE; + } else { + // If GPT is selected, only enable UEFI as target + if (prefer_gpt) + allowed_target_system[0] = FALSE; + } + } else { + allowed_target_system[0] = FALSE; + } + break; + case BT_MSDOS: + case BT_FREEDOS: + case BT_SYSLINUX_V4: + case BT_SYSLINUX_V6: + case BT_REACTOS: + case BT_GRUB4DOS: + case BT_GRUB2: + allowed_partition_scheme[PARTITION_STYLE_GPT] = FALSE; + allowed_target_system[1] = FALSE; + break; + case BT_UEFI_NTFS: + allowed_target_system[0] = FALSE; + break; + } + + if (!only_target) { + if (allowed_partition_scheme[PARTITION_STYLE_MBR]) + IGNORE_RETVAL(ComboBox_SetItemData(hPartitionScheme, + ComboBox_AddStringU(hPartitionScheme, "MBR"), PARTITION_STYLE_MBR)); + if (allowed_partition_scheme[PARTITION_STYLE_GPT]) + IGNORE_RETVAL(ComboBox_SetItemData(hPartitionScheme, + ComboBox_AddStringU(hPartitionScheme, "GPT"), PARTITION_STYLE_GPT)); + if (allowed_partition_scheme[PARTITION_STYLE_SFD]) + IGNORE_RETVAL(ComboBox_SetItemData(hPartitionScheme, + ComboBox_AddStringU(hPartitionScheme, "Super Floppy Disk"), PARTITION_STYLE_SFD)); + SetComboEntry(hPartitionScheme, prefer_gpt ? PARTITION_STYLE_GPT : PARTITION_STYLE_MBR); + } + + if (allowed_target_system[0]) + IGNORE_RETVAL(ComboBox_SetItemData(hTargetSystem, + ComboBox_AddStringU(hTargetSystem, lmprintf(MSG_031)), TT_BIOS)); + if (allowed_target_system[1]) + IGNORE_RETVAL(ComboBox_SetItemData(hTargetSystem, + ComboBox_AddStringU(hTargetSystem, lmprintf(MSG_032)), TT_UEFI)); + if (allowed_target_system[2]) + IGNORE_RETVAL(ComboBox_SetItemData(hTargetSystem, + ComboBox_AddStringU(hTargetSystem, lmprintf(MSG_033)), TT_BIOS)); + // TODO: use SetComboEntry to be more explicit + IGNORE_RETVAL(ComboBox_SetCurSel(hTargetSystem, 0)); +} + +// Populate the Allocation unit size field +static BOOL SetClusterSizes(int FSType) +{ + char* szClustSize; + int i, k, default_index = 0; + ULONG j; + + IGNORE_RETVAL(ComboBox_ResetContent(hClusterSize)); + + if ((FSType < 0) || (FSType >= FS_MAX)) { + return FALSE; + } + + if ((SelectedDrive.ClusterSize[FSType].Allowed == 0) + || (SelectedDrive.ClusterSize[FSType].Default == 0)) { + uprintf("The drive is incompatible with FS type #%d\n", FSType); + return FALSE; + } + + for (i = 0, j = 0x100, k = 0; j<0x10000000; i++, j <<= 1) { + if (j & SelectedDrive.ClusterSize[FSType].Allowed) { + if (j == SelectedDrive.ClusterSize[FSType].Default) { + szClustSize = lmprintf(MSG_030, ClusterSizeLabel[i]); + default_index = k; + } else { + szClustSize = ClusterSizeLabel[i]; + } + IGNORE_RETVAL(ComboBox_SetItemData(hClusterSize, ComboBox_AddStringU(hClusterSize, szClustSize), j)); + k++; + } + } + + IGNORE_RETVAL(ComboBox_SetCurSel(hClusterSize, default_index)); + return TRUE; +} + +// Populate the File System and Cluster Size dropdowns +static BOOL SetFileSystemAndClusterSize(char* fs_type) +{ + int fs_index; LONGLONG i; - int fs; - BOOL r = FALSE; char tmp[128] = "", *entry; + IGNORE_RETVAL(ComboBox_ResetContent(hFileSystem)); + IGNORE_RETVAL(ComboBox_ResetContent(hClusterSize)); default_fs = FS_UNKNOWN; memset(&SelectedDrive.ClusterSize, 0, sizeof(SelectedDrive.ClusterSize)); /* + * See https://support.microsoft.com/en-gb/help/140365/default-cluster-size-for-ntfs--fat--and-exfat * The following are MS's allowed cluster sizes for FAT16 and FAT32: * * FAT16 @@ -388,133 +602,43 @@ static BOOL DefineClusterSizes(void) } // Only add the filesystems we can service - for (fs=0; fs Use rightmost bit to select the new one - SelectedDrive.ClusterSize[fs].Default = - SelectedDrive.ClusterSize[fs].Allowed & (-(LONG)SelectedDrive.ClusterSize[fs].Allowed); + SelectedDrive.ClusterSize[fs_index].Default = + SelectedDrive.ClusterSize[fs_index].Allowed & (-(LONG)SelectedDrive.ClusterSize[fs_index].Allowed); } - if (SelectedDrive.ClusterSize[fs].Allowed != 0) { + if (SelectedDrive.ClusterSize[fs_index].Allowed != 0) { tmp[0] = 0; // Tell the user if we're going to use Large FAT32 or regular - if ((fs == FS_FAT32) && ((SelectedDrive.DiskSize > LARGE_FAT32_SIZE) || (force_large_fat32))) + if ((fs_index == FS_FAT32) && ((SelectedDrive.DiskSize > LARGE_FAT32_SIZE) || (force_large_fat32))) static_strcat(tmp, "Large "); - static_strcat(tmp, FileSystemLabel[fs]); + static_strcat(tmp, FileSystemLabel[fs_index]); if (default_fs == FS_UNKNOWN) { entry = lmprintf(MSG_030, tmp); - default_fs = fs; + default_fs = fs_index; } else { entry = tmp; } - IGNORE_RETVAL(ComboBox_SetItemData(hFileSystem, - ComboBox_AddStringU(hFileSystem, entry), fs)); - r = TRUE; - } - } - - return r; -} - -/* - * Populate the Allocation unit size field - */ -static BOOL SetClusterSizes(int FSType) -{ - char* szClustSize; - int i, k, default_index = 0; - ULONG j; - - IGNORE_RETVAL(ComboBox_ResetContent(hClusterSize)); - - if ((FSType < 0) || (FSType >= FS_MAX)) { - return FALSE; - } - - if ( (SelectedDrive.ClusterSize[FSType].Allowed == 0) - || (SelectedDrive.ClusterSize[FSType].Default == 0) ) { - uprintf("The drive is incompatible with FS type #%d\n", FSType); - return FALSE; - } - - for(i=0,j=0x100,k=0;j<0x10000000;i++,j<<=1) { - if (j & SelectedDrive.ClusterSize[FSType].Allowed) { - if (j == SelectedDrive.ClusterSize[FSType].Default) { - szClustSize = lmprintf(MSG_030, ClusterSizeLabel[i]); - default_index = k; - } else { - szClustSize = ClusterSizeLabel[i]; + if (allowed_filesystem[fs_index]) { + IGNORE_RETVAL(ComboBox_SetItemData(hFileSystem, + ComboBox_AddStringU(hFileSystem, entry), fs_index)); } - IGNORE_RETVAL(ComboBox_SetItemData(hClusterSize, ComboBox_AddStringU(hClusterSize, szClustSize), j)); - k++; } } - IGNORE_RETVAL(ComboBox_SetCurSel(hClusterSize, default_index)); - return TRUE; -} - -// This call sets the first option for the "partition type and target system" field -// according to whether we will be running in UEFI/CSM mode or standard UEFI -// Return value is -1 if the image is pure EFI (non BIOS bootable), 0 otherwise. -static int SetMBRForUEFI(BOOL replace) -{ - static BOOL pure_efi = FALSE; - BOOL useCSM = FALSE; - - if (ComboBox_GetCurSel(hDeviceList) < 0) - return 0; - - if (image_path != NULL) { - if ( !IS_EFI_BOOTABLE(img_report) || (HAS_BOOTMGR(img_report) && (!allow_dual_uefi_bios) && - (Button_GetCheck(GetDlgItem(hMainDialog, IDC_WINDOWS_TO_GO)) != BST_CHECKED)) ) - useCSM = TRUE; - } - - // If we weren't already dealing with pure EFI, we need to remove the first option - if (replace && !pure_efi) - ComboBox_DeleteString(hPartitionScheme, 0); - - if ((image_path != NULL) && IS_EFI_BOOTABLE(img_report) && !IS_BIOS_BOOTABLE(img_report)) { - pure_efi = TRUE; - // Pure EFI -> no need to add the BIOS option - return -1; - } - - pure_efi = FALSE; - IGNORE_RETVAL(ComboBox_SetItemData(hPartitionScheme, ComboBox_InsertStringU(hPartitionScheme, 0, - lmprintf(MSG_031, PartitionTypeLabel[PARTITION_STYLE_MBR], useCSM?"UEFI-CSM":"UEFI")), (TT_BIOS<<16)|PARTITION_STYLE_MBR)); - if (replace) - IGNORE_RETVAL(ComboBox_SetCurSel(hPartitionScheme, max(ComboBox_GetCurSel(hPartitionScheme), 0))); - return 0; -} - -/* - * Fill the drive properties (size, FS, etc) - */ -static BOOL SetDriveInfo(int ComboIndex) -{ - DWORD i; - int pt; - char fs_type[32]; - - memset(&SelectedDrive, 0, sizeof(SelectedDrive)); - SelectedDrive.DeviceNumber = (DWORD)ComboBox_GetItemData(hDeviceList, ComboIndex); - - GetDrivePartitionData(SelectedDrive.DeviceNumber, fs_type, sizeof(fs_type), FALSE); - - if (!DefineClusterSizes()) { - uprintf("No file system is selectable for this drive\n"); - return FALSE; - } - + // TODO: get fs_type from // re-select existing FS if it's one we know SelectedDrive.FSType = FS_UNKNOWN; if (safe_strlen(fs_type) != 0) { - for (SelectedDrive.FSType=FS_MAX-1; SelectedDrive.FSType>=0; SelectedDrive.FSType--) { + for (SelectedDrive.FSType = FS_MAX - 1; SelectedDrive.FSType >= 0; SelectedDrive.FSType--) { if (safe_strcmp(fs_type, FileSystemLabel[SelectedDrive.FSType]) == 0) { break; } @@ -523,7 +647,7 @@ static BOOL SetDriveInfo(int ComboIndex) SelectedDrive.FSType = FS_UNKNOWN; } - for (i=0; i pick default - for (i=0; i enable formatting - EnableWindow(hStart, TRUE); + // EnableWindow(hStart, TRUE); return SetClusterSizes((int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem))); } + +// This call sets the options for "Partition Scheme" and "Target System" +// according to whether we will be running in UEFI/CSM mode or standard UEFI +// Return value is -1 if the image is pure EFI (non BIOS bootable), 0 otherwise. +//static int SetMBRForUEFI(void) +//{ +// static BOOL pure_efi = FALSE; +// BOOL useCSM = FALSE; +// +// if (ComboBox_GetCurSel(hDeviceList) < 0) +// return 0; +// +// if (image_path != NULL) { +// if ( !IS_EFI_BOOTABLE(img_report) || (HAS_BOOTMGR(img_report) && (!allow_dual_uefi_bios) && +// (Button_GetCheck(GetDlgItem(hMainDialog, IDC_WINDOWS_TO_GO)) != BST_CHECKED)) ) +// useCSM = TRUE; +// } +// +// if ((image_path != NULL) && IS_EFI_BOOTABLE(img_report) && !IS_BIOS_BOOTABLE(img_report)) { +// pure_efi = TRUE; +// // Pure EFI -> no need to add the BIOS option +// return -1; +// } +// +// pure_efi = FALSE; +// IGNORE_RETVAL(ComboBox_SetItemData(hTargetSystem, ComboBox_InsertStringU(hTargetSystem, 0, +// "BIOS (or UEFI-CSM)"), TT_BIOS)); +// IGNORE_RETVAL(ComboBox_SetItemData(hTargetSystem, ComboBox_InsertStringU(hTargetSystem, 1, +// "UEFI (non CSM)"), TT_UEFI)); +// IGNORE_RETVAL(ComboBox_SetItemData(hTargetSystem, ComboBox_InsertStringU(hTargetSystem, 2, +// "BIOS or UEFI"), TT_UEFI)); +// // IGNORE_RETVAL(ComboBox_SetItemData(hTargetSystem, ComboBox_InsertStringU(hTargetSystem, 0, +//// useCSM?"BIOS or UEFI-CSM":"BIOS (or CSM emulation"), TT_BIOS)); +// if (replace) +// IGNORE_RETVAL(ComboBox_SetCurSel(hTargetSystem, max(ComboBox_GetCurSel(hTargetSystem), 0))); +// return 0; +//} + static void SetFSFromISO(void) { - int i, fs, selected_fs = FS_UNKNOWN; + int i, fs_tmp, selected_fs = FS_UNKNOWN; uint32_t fs_mask = 0; - int tt = GETTARGETTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme))); BOOL windows_to_go = (togo_mode) && HAS_WINTOGO(img_report) && (Button_GetCheck(GetDlgItem(hMainDialog, IDC_WINDOWS_TO_GO)) == BST_CHECKED); @@ -574,8 +716,8 @@ static void SetFSFromISO(void) // Create a mask of all the FS's available for (i=0; i=BT_IMG)||!IsChecked(IDC_BOOT))?FALSE:enable; - BOOL actual_enable_fix = ((tt==TT_UEFI)||(selection_default==BT_IMG)||!IsChecked(IDC_BOOT))?FALSE:enable; + BOOL actual_enable_mbr = ((tt==TT_UEFI)||(selection_default>=BT_IMAGE)||(bt == BT_NON_BOOTABLE))?FALSE:enable; + BOOL actual_enable_fix = ((tt==TT_UEFI)||(selection_default==BT_IMAGE)||(bt == BT_NON_BOOTABLE))?FALSE:enable; static UINT uXPartChecked = BST_UNCHECKED; - if ((selection_default == BT_ISO) && IS_BIOS_BOOTABLE(img_report) && !HAS_WINPE(img_report) && !HAS_BOOTMGR(img_report)) { + if ((selection_default == BT_IMAGE) && IS_BIOS_BOOTABLE(img_report) && !HAS_WINPE(img_report) && !HAS_BOOTMGR(img_report)) { actual_enable_mbr = FALSE; mbr_selected_by_user = FALSE; } @@ -665,21 +804,18 @@ static void EnableAdvancedBootOptions(BOOL enable, BOOL remove_checkboxes) static void EnableBootOptions(BOOL enable, BOOL remove_checkboxes) { - int fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem)); - BOOL actual_enable = ((!IS_FAT(fs)) && (fs != FS_NTFS) && (selection_default == BT_IMG))?FALSE:enable; + BOOL actual_enable = ((!IS_FAT(fs)) && (fs != FS_NTFS) && (selection_default == BT_IMAGE) && (img_report.is_bootable_img))?FALSE:enable; - EnableWindow(hBoot, actual_enable); EnableWindow(hBootType, actual_enable); - EnableWindow(hSelectISO, actual_enable); + EnableWindow(hSelectImage, actual_enable); EnableWindow(GetDlgItem(hMainDialog, IDC_WINDOWS_INSTALL), actual_enable); EnableWindow(GetDlgItem(hMainDialog, IDC_WINDOWS_TO_GO), actual_enable); EnableAdvancedBootOptions(actual_enable, remove_checkboxes); } +// TODO: Set target type tooltips static void SetPartitionSchemeTooltip(void) { - int tt = GETTARGETTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme))); - int pt = GETPARTTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme))); if (tt == TT_BIOS) { if (pt != PARTITION_STYLE_SFD) CreateTooltip(hPartitionScheme, lmprintf(MSG_150), 15000); @@ -695,31 +831,30 @@ static void SetPartitionSchemeTooltip(void) } } -static void SetTargetSystem(void) -{ - int ts = SetMBRForUEFI(TRUE); // Will be set to -1 for pure UEFI, 0 otherwise - if ((prefer_gpt && IS_EFI_BOOTABLE(img_report)) || SelectedDrive.PartitionType == PARTITION_STYLE_GPT) { - ts += 2; // GPT/UEFI - } else if (SelectedDrive.has_protective_mbr || SelectedDrive.has_mbr_uefi_marker || - (IS_EFI_BOOTABLE(img_report) && !IS_BIOS_BOOTABLE(img_report)) ) { - ts += 1; // MBR/UEFI - } else { - ts += 0; // MBR/BIOS|UEFI - } - IGNORE_RETVAL(ComboBox_SetCurSel(hPartitionScheme, ts)); - // Can't call SetPartitionSchemeTooltip() directly, as we may be on a different thread - SendMessage(hMainDialog, UM_SET_PARTITION_SCHEME_TOOLTIP, 0, 0); -} +//static void SetTargetSystem(void) +//{ +// int ts = SetMBRForUEFI(TRUE); // Will be set to -1 for pure UEFI, 0 otherwise +// if ((prefer_gpt && IS_EFI_BOOTABLE(img_report)) || SelectedDrive.PartitionType == PARTITION_STYLE_GPT) { +// ts += 2; // GPT/UEFI +// } else if (SelectedDrive.has_protective_mbr || SelectedDrive.has_mbr_uefi_marker || +// (IS_EFI_BOOTABLE(img_report) && !IS_BIOS_BOOTABLE(img_report)) ) { +// ts += 1; // MBR/UEFI +// } else { +// ts += 0; // MBR/BIOS|UEFI +// } +// IGNORE_RETVAL(ComboBox_SetCurSel(hPartitionScheme, ts)); +// // Can't call SetPartitionSchemeTooltip() directly, as we may be on a different thread +// SendMessage(hMainDialog, UM_SET_PARTITION_SCHEME_TOOLTIP, 0, 0); +//} static void SetProposedLabel(int ComboIndex) { const char no_label[] = STR_NO_LABEL, empty[] = ""; - int bt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)); app_changed_label = TRUE; // If bootable ISO creation is selected, and we have an ISO selected with a valid name, use that // Also some distros (eg. Arch) require the USB to have the same label as the ISO - if (IsChecked(IDC_BOOT) && (bt == BT_ISO) && (image_path != NULL) && (img_report.label[0] != 0)) { + if ((bt == BT_IMAGE) && (image_path != NULL) && (img_report.label[0] != 0)) { SetWindowTextU(hLabel, img_report.label); // If we force the ISO label, we need to reset the user_changed_label flag user_changed_label = FALSE; @@ -747,28 +882,30 @@ static void SetProposedLabel(int ComboIndex) } } -/* - * Populate the UI properties - */ -static BOOL PopulateProperties(int ComboIndex) +// Populate the UI main dropdown properties. +// This should be called on device or boot type change. +static BOOL PopulateProperties(int device_index) { char* device_tooltip; + char fs_type[32]; - IGNORE_RETVAL(ComboBox_ResetContent(hPartitionScheme)); - IGNORE_RETVAL(ComboBox_ResetContent(hFileSystem)); - IGNORE_RETVAL(ComboBox_ResetContent(hClusterSize)); - EnableWindow(hStart, FALSE); memset(&SelectedDrive, 0, sizeof(SelectedDrive)); + EnableWindow(hStart, FALSE); - if (ComboIndex < 0) + if (device_index < 0) goto out; - if (!SetDriveInfo(ComboIndex)) { // This also populates FS + // Get data from the currently selected drive + SelectedDrive.DeviceNumber = (DWORD)ComboBox_GetItemData(hDeviceList, device_index); + GetDrivePartitionData(SelectedDrive.DeviceNumber, fs_type, sizeof(fs_type), FALSE); + + SetPartitionSchemeAndTargetSystem(FALSE); + if (!SetFileSystemAndClusterSize(fs_type)) { SetProposedLabel(-1); + uprintf("No file system is selectable for this drive\n"); return FALSE; } - SetTargetSystem(); - SetFSFromISO(); + EnableBootOptions(TRUE, TRUE); // Set a proposed label according to the size (eg: "256MB", "8GB") @@ -776,16 +913,21 @@ static BOOL PopulateProperties(int ComboIndex) SizeToHumanReadable(SelectedDrive.DiskSize, FALSE, use_fake_units)); // Add a tooltip (with the size of the device in parenthesis) - device_tooltip = (char*) malloc(safe_strlen(DriveID.String[ComboIndex]) + 16); + device_tooltip = (char*) malloc(safe_strlen(DriveID.String[device_index]) + 16); if (device_tooltip != NULL) { - safe_sprintf(device_tooltip, safe_strlen(DriveID.String[ComboIndex]) + 16, "%s (%s)", - DriveID.String[ComboIndex], SizeToHumanReadable(SelectedDrive.DiskSize, FALSE, FALSE)); + safe_sprintf(device_tooltip, safe_strlen(DriveID.String[device_index]) + 16, "%s (%s)", + DriveID.String[device_index], SizeToHumanReadable(SelectedDrive.DiskSize, FALSE, FALSE)); CreateTooltip(hDeviceList, device_tooltip, -1); free(device_tooltip); } + + // TODO: should only be enabled when we are in a position to start + // i.e. not if Image is selected and no image + EnableWindow(hStart, TRUE); + out: - SetProposedLabel(ComboIndex); + SetProposedLabel(device_index); return TRUE; } @@ -794,11 +936,9 @@ out: */ static void InitProgress(BOOL bOnlyFormat) { - int i, fs; + int i; float last_end = 0.0f, slots_discrete = 0.0f, slots_analog = 0.0f; - fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem)); - memset(nb_slots, 0, sizeof(nb_slots)); memset(slot_end, 0, sizeof(slot_end)); previous_end = 0.0f; @@ -810,7 +950,7 @@ static void InitProgress(BOOL bOnlyFormat) if (IsChecked(IDC_BADBLOCKS)) { nb_slots[OP_BADBLOCKS] = -1; } - if (IsChecked(IDC_BOOT)) { + if (bt != BT_NON_BOOTABLE) { // 1 extra slot for PBR writing switch (selection_default) { case BT_MSDOS: @@ -819,18 +959,15 @@ static void InitProgress(BOOL bOnlyFormat) case BT_FREEDOS: nb_slots[OP_DOS] = 5+1; break; - case BT_IMG: - nb_slots[OP_DOS] = 0; - break; - case BT_ISO: - nb_slots[OP_DOS] = -1; + case BT_IMAGE: + nb_slots[OP_DOS] = img_report.is_iso ? -1 : 0; break; default: nb_slots[OP_DOS] = 2+1; break; } } - if (selection_default == BT_IMG) { + if (selection_default == BT_IMAGE && !img_report.is_iso) { nb_slots[OP_FORMAT] = -1; } else { nb_slots[OP_ZERO_MBR] = 1; @@ -842,7 +979,7 @@ static void InitProgress(BOOL bOnlyFormat) || ((fs == FS_FAT32) && ((SelectedDrive.DiskSize >= LARGE_FAT32_SIZE) || (force_large_fat32))) ) { nb_slots[OP_FORMAT] = -1; } - nb_slots[OP_FINALIZE] = ((selection_default == BT_ISO) && (fs == FS_NTFS))?3:2; + nb_slots[OP_FINALIZE] = ((selection_default == BT_IMAGE) && (fs == FS_NTFS))?3:2; } } @@ -931,16 +1068,19 @@ static void EnableControls(BOOL bEnable) EnableWindow(GetDlgItem(hMainDialog, IDC_ABOUT), bEnable); EnableWindow(GetDlgItem(hMainDialog, IDC_BADBLOCKS), bEnable); EnableBootOptions(bEnable, FALSE); - EnableWindow(hSelectISO, bEnable); + EnableWindow(hSelectImage, bEnable); EnableWindow(hNBPasses, bEnable); EnableWindow(GetDlgItem(hMainDialog, IDC_ADVANCED), bEnable); EnableWindow(hLangToolbar, bEnable); EnableWindow(hStatusToolbar, bEnable); EnableWindow(GetDlgItem(hMainDialog, IDC_ENABLE_FIXED_DISKS), bEnable); SetDlgItemTextU(hMainDialog, IDCANCEL, lmprintf(bEnable?MSG_006:MSG_007)); - if (selection_default == BT_IMG) + if ((selection_default == BT_IMAGE) && (!img_report.is_iso)) return; EnableWindow(GetDlgItem(hMainDialog, IDC_PARTITION_TYPE), bEnable); + EnableWindow(GetDlgItem(hMainDialog, IDC_TARGET_SYSTEM), bEnable); + EnableWindow(GetDlgItem(hMainDialog, IDC_SELECTED_IMAGE), bEnable); + EnableWindow(GetDlgItem(hMainDialog, IDC_IMAGE_OPTION), bEnable); EnableWindow(GetDlgItem(hMainDialog, IDC_FILESYSTEM), bEnable); EnableWindow(GetDlgItem(hMainDialog, IDC_CLUSTERSIZE), bEnable); EnableWindow(GetDlgItem(hMainDialog, IDC_LABEL), bEnable); @@ -953,7 +1093,7 @@ static void EnableControls(BOOL bEnable) /* Callback for the log window */ BOOL CALLBACK LogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - HDC hdc; + HDC hDC; HFONT hf; long lfHeight, style; DWORD log_size; @@ -967,10 +1107,9 @@ BOOL CALLBACK LogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) // Increase the size of our log textbox to MAX_LOG_SIZE (unsigned word) PostMessage(hLog, EM_LIMITTEXT, MAX_LOG_SIZE , 0); // Set the font to Unicode so that we can display anything - hdc = GetDC(NULL); - lfHeight = -MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72); - if (hdc != NULL) - ReleaseDC(NULL, hdc); + hDC = GetDC(NULL); + lfHeight = -MulDiv(8, GetDeviceCaps(hDC, LOGPIXELSY), 72); + safe_release_dc(NULL, hDC); hf = CreateFontA(lfHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0, PROOF_QUALITY, 0, "Arial Unicode MS"); SendDlgItemMessageA(hDlg, IDC_LOG_EDIT, WM_SETFONT, (WPARAM)hf, TRUE); @@ -1119,95 +1258,7 @@ static void DisplayISOProps(void) // We don't support ToGo on Windows 7 or earlier, for lack of native ISO mounting capabilities if (nWindowsVersion >= WINDOWS_8) if ( ((!togo_mode) && (HAS_WINTOGO(img_report))) || ((togo_mode) && (!HAS_WINTOGO(img_report))) ) - ToggleToGo(); -} - -// The scanning process can be blocking for message processing => use a thread -DWORD WINAPI ISOScanThread(LPVOID param) -{ - int i; - - if (image_path == NULL) - goto out; - PrintInfoDebug(0, MSG_202); - user_notified = FALSE; - EnableControls(FALSE); - memset(&img_report, 0, sizeof(img_report)); - img_report.is_iso = (BOOLEAN)ExtractISO(image_path, "", TRUE); - img_report.is_bootable_img = (BOOLEAN)IsBootableImage(image_path); - - if ((img_report.image_size == 0) || (!img_report.is_iso && !img_report.is_bootable_img)) { - // Failed to scan image - SendMessage(hMainDialog, UM_PROGRESS_EXIT, 0, 0); - PrintInfoDebug(0, MSG_203); - safe_free(image_path); - EnableControls(TRUE); - EnableWindow(hStatusToolbar, FALSE); - PrintStatus(0, MSG_086); - SetMBRProps(); - goto out; - } - - if (img_report.is_bootable_img) { - uprintf(" Image is a %sbootable %s image", - (img_report.compression_type != BLED_COMPRESSION_NONE) ? "compressed " : "", img_report.is_vhd ? "VHD" : "disk"); - selection_default = BT_IMG; - } - - if (img_report.is_iso) { - DisplayISOProps(); - // If we have an ISOHybrid, but without an ISO method we support, disable ISO support altogether - if (IS_DD_BOOTABLE(img_report) && !IS_BIOS_BOOTABLE(img_report) && !IS_EFI_BOOTABLE(img_report)) { - uprintf("This ISOHybrid is not compatible with any of the ISO boot methods we support"); - img_report.is_iso = FALSE; - } else { - // Will override BT_IMG above for ISOHybrid - selection_default = BT_ISO; - } - } - // Only enable AFTER we have determined the image type - EnableControls(TRUE); - if (!IS_DD_BOOTABLE(img_report) && !IS_BIOS_BOOTABLE(img_report) && !IS_EFI_BOOTABLE(img_report)) { - // No boot method that we support - PrintInfo(0, MSG_081); - safe_free(image_path); - EnableWindow(hStatusToolbar, FALSE); - MessageBoxExU(hMainDialog, lmprintf(MSG_082), lmprintf(MSG_081), MB_OK|MB_ICONINFORMATION|MB_IS_RTL, selected_langid); - PrintStatus(0, MSG_086); - SetMBRProps(); - } else { - // Enable bootable and set Target System and FS accordingly - CheckDlgButton(hMainDialog, IDC_BOOT, BST_CHECKED); - if (img_report.is_iso) { - SetTargetSystem(); - SetFSFromISO(); - SetMBRProps(); - SetProposedLabel(ComboBox_GetCurSel(hDeviceList)); - } else { - SendMessage(hMainDialog, WM_COMMAND, (CBN_SELCHANGE<<16) | IDC_FILESYSTEM, - ComboBox_GetCurSel(hFileSystem)); - } - if (!dont_display_image_name) { - for (i = (int)safe_strlen(image_path); (i > 0) && (image_path[i] != '\\'); i--); - PrintStatus(0, MSG_205, &image_path[i + 1]); - uprintf("Using image: %s (%s)", &image_path[i + 1], SizeToHumanReadable(img_report.image_size, FALSE, FALSE)); - } - // Lose the focus on the select ISO (but place it on Close) - SendMessage(hMainDialog, WM_NEXTDLGCTL, (WPARAM)FALSE, 0); - // Lose the focus from Close and set it back to Start - SendMessage(hMainDialog, WM_NEXTDLGCTL, (WPARAM)hStart, TRUE); - } - - // Need to invalidate as we may have changed the UI and may get artifacts if we don't - // Oh and we need to invoke BOTH RedrawWindow() and InvalidateRect() because UI refresh - // in the Microsoft worlds SUCKS!!!! (we may lose the disabled "Start" button otherwise) - RedrawWindow(hMainDialog, NULL, NULL, RDW_ALLCHILDREN | RDW_UPDATENOW); - InvalidateRect(hMainDialog, NULL, TRUE); - -out: - dont_display_image_name = FALSE; - PrintInfo(0, MSG_210); - ExitThread(0); + ToggleImageOption(); } // Move a control along the Y axis @@ -1252,43 +1303,22 @@ static void ResizeDialogs(int shift) // Toggle "advanced" mode static void ToggleAdvanced(BOOL enable) { - int i, shift1 = row_height, shift2 = advanced_section_height; - BOOL needs_resel = FALSE; + int i, shift = advanced_section_height; - if (!enable) { - shift2 = -shift2; - shift1 = -shift1; - } - status_vpos += shift1 + shift2; - format_vpos += shift1; + if (!enable) + shift = -shift; + status_vpos += shift; // Move the controls up or down - for (i = 0; i 0) && (image_path[i] != '\\'); i--); + hCtrl = GetDlgItem(hMainDialog, IDC_SELECTED_IMAGE); + // TODO: Populate the dropdown + IGNORE_RETVAL(ComboBox_SetItemData(hCtrl, ComboBox_AddStringU(hCtrl, &image_name[i + 1]), image_index)); + IGNORE_RETVAL(ComboBox_SetCurSel(hCtrl, image_index)); + } + display_image_settings = (bt == BT_IMAGE) && (ImageList.Index != 0); + if ((displaying && display_image_settings) || (!displaying && !display_image_settings)) + return; + if (displaying) + shift = -shift; + + displaying = !displaying; + format_vpos += shift; + advanced_vpos += shift; + status_vpos += shift; + + // Move the controls up or down + for (i = 0; i use a thread +DWORD WINAPI ISOScanThread(LPVOID param) +{ + int i; + + if (image_path == NULL) + goto out; + PrintInfoDebug(0, MSG_202); + user_notified = FALSE; + EnableControls(FALSE); + memset(&img_report, 0, sizeof(img_report)); + img_report.is_iso = (BOOLEAN)ExtractISO(image_path, "", TRUE); + img_report.is_bootable_img = (BOOLEAN)IsBootableImage(image_path); + + if ((img_report.image_size == 0) || (!img_report.is_iso && !img_report.is_bootable_img)) { + // Failed to scan image + SendMessage(hMainDialog, UM_PROGRESS_EXIT, 0, 0); + PrintInfoDebug(0, MSG_203); + safe_free(image_path); + EnableControls(TRUE); + EnableWindow(hStatusToolbar, FALSE); + PrintStatus(0, MSG_086); + SetMBRProps(); + goto out; + } + + if (img_report.is_bootable_img) { + uprintf(" Image is a %sbootable %s image", + (img_report.compression_type != BLED_COMPRESSION_NONE) ? "compressed " : "", img_report.is_vhd ? "VHD" : "disk"); + selection_default = BT_IMAGE; + } + + if (img_report.is_iso) { + DisplayISOProps(); + // If we have an ISOHybrid, but without an ISO method we support, disable ISO support altogether + if (IS_DD_BOOTABLE(img_report) && !IS_BIOS_BOOTABLE(img_report) && !IS_EFI_BOOTABLE(img_report)) { + uprintf("This ISOHybrid is not compatible with any of the ISO boot methods we support"); + img_report.is_iso = FALSE; + } + selection_default = BT_IMAGE; + } + // Only enable AFTER we have determined the image type + EnableControls(TRUE); + if (!IS_DD_BOOTABLE(img_report) && !IS_BIOS_BOOTABLE(img_report) && !IS_EFI_BOOTABLE(img_report)) { + // No boot method that we support + PrintInfo(0, MSG_081); + safe_free(image_path); + EnableWindow(hStatusToolbar, FALSE); + MessageBoxExU(hMainDialog, lmprintf(MSG_082), lmprintf(MSG_081), MB_OK | MB_ICONINFORMATION | MB_IS_RTL, selected_langid); + PrintStatus(0, MSG_086); + SetMBRProps(); + } else { + // Set Target and FS accordingly + // TODO + if (img_report.is_iso) { + IGNORE_RETVAL(ComboBox_SetCurSel(hBootType, image_index)); + SetPartitionSchemeAndTargetSystem(FALSE); + SetFSFromISO(); + SetMBRProps(); + SetProposedLabel(ComboBox_GetCurSel(hDeviceList)); + } else { + SendMessage(hMainDialog, WM_COMMAND, (CBN_SELCHANGE << 16) | IDC_FILESYSTEM, + ComboBox_GetCurSel(hFileSystem)); + } + if (!dont_display_image_name) { + for (i = (int)safe_strlen(image_path); (i > 0) && (image_path[i] != '\\'); i--); + PrintStatus(0, MSG_205, &image_path[i + 1]); + ShowImageSettings(image_path); + uprintf("Using image: %s (%s)", &image_path[i + 1], SizeToHumanReadable(img_report.image_size, FALSE, FALSE)); + } + // Lose the focus on the select ISO (but place it on Close) + SendMessage(hMainDialog, WM_NEXTDLGCTL, (WPARAM)FALSE, 0); + // Lose the focus from Close and set it back to Start + SendMessage(hMainDialog, WM_NEXTDLGCTL, (WPARAM)hStart, TRUE); + } + + // Need to invalidate as we may have changed the UI and may get artifacts if we don't + // Oh and we need to invoke BOTH RedrawWindow() and InvalidateRect() because UI refresh + // in the Microsoft worlds SUCKS!!!! (we may lose the disabled "Start" button otherwise) + RedrawWindow(hMainDialog, NULL, NULL, RDW_ALLCHILDREN | RDW_UPDATENOW); + InvalidateRect(hMainDialog, NULL, TRUE); + +out: + dont_display_image_name = FALSE; + PrintInfo(0, MSG_210); + ExitThread(0); +} + static BOOL BootCheck(void) { - int i, fs, tt, bt, pt, r; + int i, r; FILE *fd; DWORD len; BOOL in_files_dir = FALSE; @@ -1363,9 +1526,7 @@ static BOOL BootCheck(void) syslinux_ldlinux_len[0] = 0; syslinux_ldlinux_len[1] = 0; safe_free(grub2_buf); - bt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)); - pt = GETPARTTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme))); - if ((bt == BT_ISO) || (bt == BT_IMG)) { + if (bt == BT_IMAGE) { if (image_path == NULL) { // Please click on the disc button to select a bootable ISO MessageBoxExU(hMainDialog, lmprintf(MSG_087), lmprintf(MSG_086), MB_OK|MB_ICONERROR|MB_IS_RTL, selected_langid); @@ -1376,14 +1537,12 @@ static BOOL BootCheck(void) MessageBoxExU(hMainDialog, lmprintf(MSG_089), lmprintf(MSG_088), MB_OK|MB_ICONERROR|MB_IS_RTL, selected_langid); return FALSE; } - if (bt == BT_IMG) { - if (!IS_DD_BOOTABLE(img_report)) - // The selected image doesn't match the boot option selected. - MessageBoxExU(hMainDialog, lmprintf(MSG_188), lmprintf(MSG_187), MB_OK|MB_ICONERROR|MB_IS_RTL, selected_langid); - return IS_DD_BOOTABLE(img_report); - } - fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem)); - tt = GETTARGETTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme))); + //if (bt == BT_IMG) { + // if (!IS_DD_BOOTABLE(img_report)) + // // The selected image doesn't match the boot option selected. + // MessageBoxExU(hMainDialog, lmprintf(MSG_188), lmprintf(MSG_187), MB_OK|MB_ICONERROR|MB_IS_RTL, selected_langid); + // return IS_DD_BOOTABLE(img_report); + //} if ((togo_mode) && (Button_GetCheck(GetDlgItem(hMainDialog, IDC_WINDOWS_TO_GO)) == BST_CHECKED)) { if (fs != FS_NTFS) { // Windows To Go only works for NTFS @@ -1746,7 +1905,6 @@ static void CreateAdditionalControls(HWND hDlg) // Load system icons (NB: Use the excellent http://www.nirsoft.net/utils/iconsext.html to find icon IDs) hShell32DllInst = GetLibraryHandle("Shell32"); - hIconDisc = (HICON)LoadImage(hShell32DllInst, MAKEINTRESOURCE(12), IMAGE_ICON, s16, s16, LR_DEFAULTCOLOR | LR_SHARED); hIconSave = (HICON)LoadImage(hShell32DllInst, MAKEINTRESOURCE(16761), IMAGE_ICON, s16, s16, LR_DEFAULTCOLOR | LR_SHARED); if (nWindowsVersion >= WINDOWS_8) { @@ -1782,10 +1940,6 @@ static void CreateAdditionalControls(HWND hDlg) SetWindowTextW(hCtrl, wtmp); // Set the icons on the the buttons - //bi_iso.himl = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_MASK, 1, 0); - //ImageList_ReplaceIcon(bi_iso.himl, -1, hIconDisc); - //SetRect(&bi_iso.margin, 0, 1, 0, 0); - //bi_iso.uAlign = BUTTON_IMAGELIST_ALIGN_CENTER; bi_save.himl = ImageList_Create(i16, i16, ILC_COLOR32 | ILC_MASK, 1, 0); ImageList_ReplaceIcon(bi_save.himl, -1, hIconSave); SetRect(&bi_save.margin, 0, 1, 0, 0); @@ -1799,7 +1953,7 @@ static void CreateAdditionalControls(HWND hDlg) SetRect(&bi_up.margin, 0, 0, 0, 0); bi_up.uAlign = BUTTON_IMAGELIST_ALIGN_CENTER; - //SendMessage(hSelectISO, BCM_SETIMAGELIST, 0, (LPARAM)&bi_iso); + //SendMessage(hSelectImage, BCM_SETIMAGELIST, 0, (LPARAM)&bi_iso); hCtrl = GetDlgItem(hDlg, IDC_SAVE); SendMessage(hCtrl, BCM_SETIMAGELIST, 0, (LPARAM)&bi_save); SendMessage(GetDlgItem(hDlg, IDC_ADVANCED), BCM_SETIMAGELIST, 0, @@ -1832,7 +1986,7 @@ static int GetMaxTextWidth(HWND hDlg) bu.cy = rc.bottom; uprintf("bu.cx = %d, bu.cy = %d", bu.cx, bu.cy); - GetWindowRect(hSelectISO, &rc); + GetWindowRect(hSelectImage, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); ib_width = rc.right - rc.left; uprintf("button.width = %d", ib_width); @@ -1876,12 +2030,19 @@ static void PositionControls(HWND hDlg) int max_text_width = GetMaxTextWidth(hDlg); // TODO: dynamicize this int dialog_width = 770; + int dropdown_height, button_fudge = 2; // Set the section header fonts and resize the static controls accordingly hf = CreateFontA(48, 0, 0, 0, FW_SEMIBOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0, PROOF_QUALITY, 0, "Segoe UI"); - SendDlgItemMessageA(hDlg, IDS_DEVICE_OPTIONS_TXT, WM_SETFONT, (WPARAM)hf, TRUE); - hCtrl = GetDlgItem(hDlg, IDS_DEVICE_OPTIONS_TXT); + SendDlgItemMessageA(hDlg, IDS_DEVICE_SETTINGS_TXT, WM_SETFONT, (WPARAM)hf, TRUE); + hCtrl = GetDlgItem(hDlg, IDS_DEVICE_SETTINGS_TXT); + GetWindowRect(hCtrl, &rc); + MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); + sz = GetTextSize(hCtrl); + SetWindowPos(hCtrl, NULL, rc.left, rc.top, sz.cx, sz.cy, SWP_NOZORDER); + SendDlgItemMessageA(hDlg, IDS_IMAGE_SETTINGS_TXT, WM_SETFONT, (WPARAM)hf, TRUE); + hCtrl = GetDlgItem(hDlg, IDS_IMAGE_SETTINGS_TXT); GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); sz = GetTextSize(hCtrl); @@ -1905,18 +2066,38 @@ static void PositionControls(HWND hDlg) sz = GetTextSize(hCtrl); SetWindowPos(hCtrl, NULL, rc.left, rc.top, sz.cx, sz.cy, SWP_NOZORDER); - // Get the height of the Boot Options (Windows To Go) - hCtrl = GetDlgItem(hDlg, IDS_PARTITION_TYPE_TXT); + // Resize the height of the label and progress bar to the height of standard dropdowns + hCtrl = GetDlgItem(hDlg, IDC_DEVICE); + GetWindowRect(hCtrl, &rc); + MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); + dropdown_height = rc.bottom - rc.top; + hCtrl = GetDlgItem(hDlg, IDC_LABEL); + GetWindowRect(hCtrl, &rc); + MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); + SetWindowPos(hCtrl, NULL, rc.left, rc.top, rc.right - rc.left, dropdown_height, SWP_NOZORDER); + GetWindowRect(hProgress, &rc); + MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); + SetWindowPos(hProgress, NULL, rc.left, rc.top, rc.right - rc.left, dropdown_height, SWP_NOZORDER); + + // Get the height of a typical row + hCtrl = GetDlgItem(hDlg, IDS_BOOT_TYPE_TXT); GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); row_height = rc.top; - hCtrl = GetDlgItem(hDlg, IDS_BOOT_OPTION_TXT); + hCtrl = GetDlgItem(hDlg, IDS_DEVICE_TXT); GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); row_height -= rc.top; - uprintf("row height = %d", row_height); - // Get the height of the advanced section + // Get the height of the image settings and advanced sections + hCtrl = GetDlgItem(hDlg, IDS_IMAGE_SETTINGS_TXT); + GetWindowRect(hCtrl, &rc); + MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); + image_settings_height = rc.top; + hCtrl = GetDlgItem(hDlg, IDS_IMAGE_OPTION_TXT); + GetWindowRect(hCtrl, &rc); + MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); + image_settings_height = rc.top - image_settings_height; hCtrl = GetDlgItem(hDlg, IDS_ADVANCED_OPTIONS_TXT); GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); @@ -1927,11 +2108,16 @@ static void PositionControls(HWND hDlg) advanced_section_height = rc.top - advanced_section_height; // Get the vertical position of the sections text - hCtrl = GetDlgItem(hDlg, IDS_DEVICE_OPTIONS_TXT); + hCtrl = GetDlgItem(hDlg, IDS_DEVICE_SETTINGS_TXT); GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); sz = GetTextSize(hCtrl); device_vpos = rc.top + 2 * sz.cy / 3; + hCtrl = GetDlgItem(hDlg, IDS_IMAGE_SETTINGS_TXT); + GetWindowRect(hCtrl, &rc); + MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); + sz = GetTextSize(hCtrl); + image_vpos = rc.top + 2 * sz.cy / 3; hCtrl = GetDlgItem(hDlg, IDS_FORMAT_OPTIONS_TXT); GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); @@ -1953,12 +2139,12 @@ static void PositionControls(HWND hDlg) SendMessage(hLangToolbar, TB_GETRECT, IDC_LANG, (LPARAM)&rc); GetWindowRect(hDeviceList, &rcDeviceList); MapWindowPoints(NULL, hDlg, (POINT*)&rcDeviceList, 2); - // TODO: use + // TODO: SetWindowPos(hLangToolbar, HWND_TOP, dialog_width - rc.right, (int)(4.0f * fScale), rc.right, rc.bottom, 0); ShowWindow(hLangToolbar, SW_SHOWNORMAL); - // TEST TEST TEST + // TODO: TEST TEST TEST hCtrl = GetDlgItem(hDlg, IDC_DISK_ID); GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); @@ -1972,19 +2158,48 @@ static void PositionControls(HWND hDlg) SetWindowPos(GetDlgItem(hDlg, IDC_ADVANCED), hCtrl, dialog_width - 40, rc.top, i16 + (int)(4.0f * fScale), i16 / 2 + (int)(8.0f * fScale), 0); - // Reposition and resize the Select Image and Hash button + // Reposition and resize the SELECT and # buttons GetWindowRect(hBootType, &rcBootType); MapWindowPoints(NULL, hDlg, (POINT*)&rcBootType, 2); - GetWindowRect(hSelectISO, &rc); + GetWindowRect(hSelectImage, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); - SetWindowPos(hSelectISO, NULL, rc.left, rcBootType.top - 1, - rc.right - rc.left, rcBootType.bottom - rcBootType.top + 2, SWP_NOZORDER); + SetWindowPos(hSelectImage, NULL, rc.left, rcBootType.top - 1, + rc.right - rc.left, dropdown_height + button_fudge, SWP_NOZORDER); + // Resize the START and CANCEL/CLOSE buttons + GetWindowRect(hStart, &rc); + MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); + SetWindowPos(hStart, NULL, rc.left, rc.top, + rc.right - rc.left, dropdown_height + button_fudge, SWP_NOZORDER); + hCtrl = GetDlgItem(hDlg, IDCANCEL); + GetWindowRect(hCtrl, &rc); + MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); + SetWindowPos(hCtrl, NULL, rc.left, rc.top, + rc.right - rc.left, dropdown_height + button_fudge, SWP_NOZORDER); + + // TODO: remove this once we use icons + hCtrl = GetDlgItem(hDlg, IDC_ABOUT); + GetWindowRect(hCtrl, &rc); + MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); + SetWindowPos(hCtrl, NULL, rc.left, rc.top, + rc.right - rc.left, dropdown_height + button_fudge, SWP_NOZORDER); + hCtrl = GetDlgItem(hDlg, IDC_LOG); + GetWindowRect(hCtrl, &rc); + MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); + SetWindowPos(hCtrl, NULL, rc.left, rc.top, + rc.right - rc.left, dropdown_height + button_fudge, SWP_NOZORDER); + hCtrl = GetDlgItem(hDlg, IDC_TEST); + GetWindowRect(hCtrl, &rc); + MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); + SetWindowPos(hCtrl, NULL, rc.left, rc.top, + rc.right - rc.left, dropdown_height + button_fudge, SWP_NOZORDER); + + // TODO: Use a SAVE label and resize hCtrl = GetDlgItem(hDlg, IDC_SAVE); GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); SetWindowPos(hCtrl, NULL, rc.left, rcDeviceList.top - 1, - rc.right - rc.left, rcDeviceList.bottom - rcDeviceList.top + 2, SWP_NOZORDER); + rc.right - rc.left, dropdown_height + button_fudge, SWP_NOZORDER); hCtrl = GetDlgItem(hDlg, IDC_SELECTED_IMAGE); GetWindowRect(hCtrl, &rcSelectedImage); @@ -1993,7 +2208,7 @@ static void PositionControls(HWND hDlg) GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2); SetWindowPos(hCtrl, NULL, rc.left, rcSelectedImage.top - 1, - rc.right - rc.left, rcSelectedImage.bottom - rcSelectedImage.top + 2, SWP_NOZORDER); + rc.right - rc.left, dropdown_height + button_fudge, SWP_NOZORDER); // The things one needs to do to keep things looking good... if (fScale > 1.4f) { @@ -2008,6 +2223,10 @@ void OnPaint(HDC hdc) SelectObject(hdc, hp); MoveToEx(hdc, 50, device_vpos, NULL); LineTo(hdc, 700, device_vpos); + if (display_image_settings) { + MoveToEx(hdc, 50, image_vpos, NULL); + LineTo(hdc, 700, image_vpos); + } MoveToEx(hdc, 50, format_vpos, NULL); LineTo(hdc, 700, format_vpos); if (advanced_mode) { @@ -2021,7 +2240,7 @@ void OnPaint(HDC hdc) static void InitDialog(HWND hDlg) { DWORD len; - HDC hdc; + HDC hDC; int i, lfHeight; char tmp[128], *token, *buf, *ext; static char* resource[2] = { MAKEINTRESOURCEA(IDR_SL_LDLINUX_V4_SYS), MAKEINTRESOURCEA(IDR_SL_LDLINUX_V6_SYS) }; @@ -2030,23 +2249,22 @@ static void InitDialog(HWND hDlg) ShowWindow(GetDlgItem(hDlg, IDC_TEST), SW_SHOW); #endif - hdc = GetDC(hDlg); - lfHeight = -MulDiv(9, GetDeviceCaps(hdc, LOGPIXELSY), 72); - if (hdc != NULL) - ReleaseDC(hDlg, hdc); + hDC = GetDC(hDlg); + lfHeight = -MulDiv(9, GetDeviceCaps(hDC, LOGPIXELSY), 72); + safe_release_dc(hDlg, hDC); // Quite a burden to carry around as parameters hMainDialog = hDlg; MainThreadId = GetCurrentThreadId(); hDeviceList = GetDlgItem(hDlg, IDC_DEVICE); hPartitionScheme = GetDlgItem(hDlg, IDC_PARTITION_TYPE); + hTargetSystem = GetDlgItem(hDlg, IDC_TARGET_SYSTEM); hFileSystem = GetDlgItem(hDlg, IDC_FILESYSTEM); hClusterSize = GetDlgItem(hDlg, IDC_CLUSTERSIZE); hLabel = GetDlgItem(hDlg, IDC_LABEL); hProgress = GetDlgItem(hDlg, IDC_PROGRESS); - hBoot = GetDlgItem(hDlg, IDC_BOOT); hBootType = GetDlgItem(hDlg, IDC_BOOTTYPE); - hSelectISO = GetDlgItem(hDlg, IDC_SELECT_ISO); + hSelectImage = GetDlgItem(hDlg, IDC_SELECT_IMAGE); hNBPasses = GetDlgItem(hDlg, IDC_NBPASSES); hDiskID = GetDlgItem(hDlg, IDC_DISK_ID); hStart = GetDlgItem(hDlg, IDC_START); @@ -2102,8 +2320,6 @@ static void InitDialog(HWND hDlg) uprintf("If you think you can help update this translation, please e-mail the author of this application"); } - SetClusterSizeLabels(); - // Prefer FreeDOS to MS-DOS selection_default = BT_FREEDOS; // Create the status line and initialize the taskbar icon for progress overlay @@ -2113,19 +2329,19 @@ static void InitDialog(HWND hDlg) // Use maximum granularity for the progress bar SendMessage(hProgress, PBM_SETRANGE, 0, (MAX_PROGRESS<<16) & 0xFFFF0000); + // Fill up the passes for (i=0; i<4; i++) { IGNORE_RETVAL(ComboBox_AddStringU(hNBPasses, lmprintf((i==0)?MSG_034:MSG_035, i+1))); } IGNORE_RETVAL(ComboBox_SetCurSel(hNBPasses, 0)); SetPassesTooltip(); - // Fill up the boot type dropdown - if (nWindowsVersion < WINDOWS_10) // The diskcopy.dll with the MS-DOS floppy image was removed in Windows 10 - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "MS-DOS (MBR only)"), BT_MSDOS)); - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "FreeDOS (MBR only)"), BT_FREEDOS)); - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, lmprintf(MSG_036)), BT_ISO)); - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, lmprintf(MSG_095)), BT_IMG)); + + // Fill up the boot options dropdown + SetBootOptions(); SetComboEntry(hBootType, selection_default); + + // SetOptionsAccordingToBootEntry(); // Fill up the MBR masqueraded disk IDs ("8 disks should be enough for anybody") IGNORE_RETVAL(ComboBox_SetItemData(hDiskID, ComboBox_AddStringU(hDiskID, lmprintf(MSG_030, LEFT_TO_RIGHT_EMBEDDING "0x80" POP_DIRECTIONAL_FORMATTING)), 0x80)); for (i=1; i<=7; i++) { @@ -2138,9 +2354,9 @@ static void InitDialog(HWND hDlg) StrArrayCreate(&DriveLabel, MAX_DRIVES); StrArrayCreate(&DriveHub, MAX_DRIVES); StrArrayCreate(&BlockingProcess, 16); + StrArrayCreate(&ImageList, 16); // Set various checkboxes CheckDlgButton(hDlg, IDC_QUICKFORMAT, BST_CHECKED); - CheckDlgButton(hDlg, IDC_BOOT, BST_CHECKED); CheckDlgButton(hDlg, IDC_SET_ICON, BST_CHECKED); CreateAdditionalControls(hDlg); @@ -2156,9 +2372,8 @@ static void InitDialog(HWND hDlg) CreateTooltip(GetDlgItem(hDlg, IDC_ADVANCED), lmprintf(MSG_160), -1); CreateTooltip(GetDlgItem(hDlg, IDC_BADBLOCKS), lmprintf(MSG_161), -1); CreateTooltip(GetDlgItem(hDlg, IDC_QUICKFORMAT), lmprintf(MSG_162), -1); - CreateTooltip(hBoot, lmprintf(MSG_163), -1); CreateTooltip(hBootType, lmprintf(MSG_164), -1); - CreateTooltip(hSelectISO, lmprintf(MSG_165), -1); + CreateTooltip(hSelectImage, lmprintf(MSG_165), -1); CreateTooltip(GetDlgItem(hDlg, IDC_SET_ICON), lmprintf(MSG_166), 10000); CreateTooltip(GetDlgItem(hDlg, IDC_RUFUS_MBR), lmprintf(MSG_167), 10000); CreateTooltip(hDiskID, lmprintf(MSG_168), 10000); @@ -2176,12 +2391,13 @@ static void InitDialog(HWND hDlg) if (!advanced_mode) // Hide as needed, since we display the advanced controls by default ToggleAdvanced(FALSE); - ToggleToGo(); + ShowImageSettings(NULL); + ToggleImageOption(); // Process commandline parameters if (iso_provided) { - // Simulate a button click for ISO selection - PostMessage(hDlg, WM_COMMAND, IDC_SELECT_ISO, 0); + // Simulate a button click for image selection + PostMessage(hDlg, WM_COMMAND, IDC_SELECT_IMAGE, 0); } PrintInfo(0, MSG_210); @@ -2227,56 +2443,6 @@ static void ShowLanguageMenu(RECT rcExclude) DestroyMenu(menu); } -static void SetBoot(int fs, int tt, int pt) -{ - int i; - char tmp[32]; - - IGNORE_RETVAL(ComboBox_ResetContent(hBootType)); - if ((tt == TT_BIOS) && (IS_FAT(fs))) { - if (nWindowsVersion < WINDOWS_10) // The diskcopy.dll with the MS-DOS floppy image was removed in Windows 10 - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "MS-DOS (MBR only)"), BT_MSDOS)); - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "FreeDOS (MBR only)"), BT_FREEDOS)); - } - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, lmprintf(MSG_036)), BT_ISO)); - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, lmprintf(MSG_095)), BT_IMG)); - // If needed (advanced mode) also append "bare" Syslinux and other options - if ( (tt == TT_BIOS) && ((IS_FAT(fs) || (fs == FS_NTFS)) && (advanced_mode)) ) { - static_sprintf(tmp, "Syslinux %s (MBR only)", embedded_sl_version_str[0]); - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, tmp), BT_SYSLINUX_V4)); - static_sprintf(tmp, "Syslinux %s (MBR only)", embedded_sl_version_str[1]); - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, tmp), BT_SYSLINUX_V6)); - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "ReactOS (MBR only)"), BT_REACTOS)); - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, - "Grub " GRUB2_PACKAGE_VERSION " (MBR only)"), BT_GRUB2)); - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, - "Grub4DOS " GRUB4DOS_VERSION " (MBR only)"), BT_GRUB4DOS)); - } - if (advanced_mode) - IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "UEFI:NTFS"), BT_UEFI_NTFS)); - if ((!advanced_mode) && (selection_default >= BT_SYSLINUX_V4)) { - selection_default = BT_FREEDOS; - CheckDlgButton(hMainDialog, IDC_DISK_ID, BST_UNCHECKED); - } - for (i=0; i don't bother - IGNORE_RETVAL(ComboBox_SetCurSel(hBootType, 0)); - uBootChecked = IsChecked(IDC_BOOT); - CheckDlgButton(hDlg, IDC_BOOT, BST_UNCHECKED); - EnableBootOptions(FALSE, TRUE); - } else if (IsChecked(IDC_BOOT)) { - uBootChecked = TRUE; - CheckDlgButton(hDlg, IDC_BOOT, BST_UNCHECKED); - } - SetMBRProps(); - break; - } + //if ((fs == FS_EXFAT) || (fs == FS_UDF) || (fs == FS_REFS) || (pt == PARTITION_STYLE_SFD)) { + // // unlikely to be supported by BIOSes => don't bother + // IGNORE_RETVAL(ComboBox_SetCurSel(hBootType, 0)); + // uBootChecked = IsChecked(IDC_BOOT); + // CheckDlgButton(hDlg, IDC_BOOT, BST_UNCHECKED); + // EnableBootOptions(FALSE, TRUE); + // } else if (IsChecked(IDC_BOOT)) { + // uBootChecked = TRUE; + // CheckDlgButton(hDlg, IDC_BOOT, BST_UNCHECKED); + // } + // SetMBRProps(); + // break; + //} EnableAdvancedBootOptions(TRUE, TRUE); - SetBoot(fs, tt, pt); +// SetAllowedFileSystems(fs, tt, pt); SetMBRProps(); - SetToGo(); - break; - case IDC_BOOT: - EnableAdvancedBootOptions(TRUE, TRUE); - if (selection_default == BT_IMG) - ToggleImage(!IsChecked(IDC_BOOT)); - SetProposedLabel(ComboBox_GetCurSel(hDeviceList)); +// SetToGo(); break; case IDC_BOOTTYPE: - if (HIWORD(wParam) != CBN_SELCHANGE) + bt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)); + if ((HIWORD(wParam) != CBN_SELCHANGE) || (bt == selection_default)) break; - selection_default = (int) ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)); + // TODO: do we really need both bt and selection_default? + selection_default = bt; + SetPartitionSchemeAndTargetSystem(FALSE); EnableAdvancedBootOptions(TRUE, TRUE); - ToggleImage(!IsChecked(IDC_BOOT) || (selection_default != BT_IMG)); + ShowImageSettings(NULL); + // TODO: SetToGo() would be better invoked from ShowImageSettings() SetToGo(); SetProposedLabel(ComboBox_GetCurSel(hDeviceList)); - if (selection_default == BT_UEFI_NTFS) { - // Try to select NTFS as default - for (i=0; i 1) && (MessageBoxExU(hMainDialog, lmprintf(MSG_093), lmprintf(MSG_094), MB_OKCANCEL|MB_ICONWARNING|MB_IS_RTL, selected_langid) == IDCANCEL)) goto aborted_start; - if ((!zero_drive) && (IsChecked(IDC_BOOT)) && (SelectedDrive.SectorSize != 512) && + if ((!zero_drive) && (bt != BT_NON_BOOTABLE) && (SelectedDrive.SectorSize != 512) && (MessageBoxExU(hMainDialog, lmprintf(MSG_196, SelectedDrive.SectorSize), lmprintf(MSG_197), MB_OKCANCEL|MB_ICONWARNING|MB_IS_RTL, selected_langid) == IDCANCEL)) goto aborted_start; @@ -2946,19 +3104,19 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA case WM_INITDIALOG: // Make sure fScale is set before the first call to apply localization, so that move/resize scale appropriately - hdc = GetDC(hDlg); - fScale = GetDeviceCaps(hdc, LOGPIXELSX) / 96.0f; - if (hdc != NULL) - ReleaseDC(hDlg, hdc); + hDC = GetDC(hDlg); + fScale = GetDeviceCaps(hDC, LOGPIXELSX) / 96.0f; + safe_release_dc(hDlg, hDC); apply_localization(IDD_DIALOG, hDlg); SetUpdateCheck(); togo_mode = TRUE; // We display the ToGo controls by default and need to hide them - // Create the log window (hidden) + display_image_settings = TRUE; first_log_display = TRUE; log_displayed = FALSE; hLogDlg = MyCreateDialog(hMainInstance, IDD_LOG, hDlg, (DLGPROC)LogProc); InitDialog(hDlg); GetDevices(0); + PopulateProperties(ComboBox_GetCurSel(hDeviceList)); CheckForUpdates(FALSE); // Register MEDIA_INSERTED/MEDIA_REMOVED notifications for card readers if (SUCCEEDED(SHGetSpecialFolderLocation(0, CSIDL_DESKTOP, &pidlDesktop))) { @@ -2974,8 +3132,8 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA SetWindowPos(hMainDialog, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); SetWindowPos(hMainDialog, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); - // Set 'Start' as the selected button if it's enabled, otherwise use 'Select ISO', instead - SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)(IsWindowEnabled(hStart) ? hStart : hSelectISO), TRUE); + // Set 'START' as the selected button if it's enabled, otherwise use 'SELECT', instead + SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)(IsWindowEnabled(hStart) ? hStart : hSelectImage), TRUE); #if defined(ALPHA) // Add a VERY ANNOYING popup for Alpha releases, so that people don't start redistributing them @@ -3010,8 +3168,8 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA break; case WM_PAINT: - hdc = BeginPaint(hDlg, &ps); - OnPaint(hdc); + hDC = BeginPaint(hDlg, &ps); + OnPaint(hDC); EndPaint(hDlg, &ps); break; @@ -3050,8 +3208,8 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA if (image_path != NULL) { iso_provided = TRUE; - // Simulate ISO selection click - SendMessage(hDlg, WM_COMMAND, IDC_SELECT_ISO, 0); + // Simulate image selection click + SendMessage(hDlg, WM_COMMAND, IDC_SELECT_IMAGE, 0); } break; @@ -3088,7 +3246,8 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA } SetTaskbarProgressState(TASKBAR_NORMAL); SetTaskbarProgressValue(0, MAX_PROGRESS); - + progress_in_use = TRUE; + uprintf("PROGRESS IN USE = TRUE"); break; case UM_PROGRESS_EXIT: @@ -3107,6 +3266,8 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA } SendMessage(hProgress, PBM_SETSTATE, (WPARAM)PBST_NORMAL, 0); SetTaskbarProgressState(TASKBAR_NORMAL); + progress_in_use = FALSE; + uprintf("PROGRESS IN USE = FALSE"); break; case UM_NO_UPDATE: @@ -3411,8 +3572,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine // Initialize the global scaling, in case we need it before we initialize the dialog hDC = GetDC(NULL); fScale = GetDeviceCaps(hDC, LOGPIXELSX) / 96.0f; - if (hDC != NULL) - ReleaseDC(NULL, hDC); + safe_release_dc(NULL, hDC); // Init localization init_localization(); @@ -3619,7 +3779,8 @@ relaunch: 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); - SetMBRForUEFI(TRUE); + SetPartitionSchemeAndTargetSystem(FALSE); +// SetMBRForUEFI(TRUE); continue; } // Alt-F => Toggle detection of USB HDDs @@ -3642,7 +3803,7 @@ relaunch: if (image_path != NULL) { iso_provided = TRUE; dont_display_image_name = TRUE; - SendMessage(hDlg, WM_COMMAND, IDC_SELECT_ISO, 0); + SendMessage(hDlg, WM_COMMAND, IDC_SELECT_IMAGE, 0); } continue; } diff --git a/src/rufus.h b/src/rufus.h index ebb6c435..084b3069 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -218,14 +218,14 @@ enum fs_type { enum boot_type { BT_MSDOS = 0, BT_FREEDOS, - BT_ISO, - BT_IMG, + BT_IMAGE, BT_SYSLINUX_V4, // Start of indexes that only display in advanced mode BT_SYSLINUX_V6, BT_REACTOS, BT_GRUB4DOS, BT_GRUB2, BT_UEFI_NTFS, + BT_NON_BOOTABLE, BT_MAX }; @@ -236,8 +236,6 @@ enum target_type { }; // For the partition types we'll use Microsoft's PARTITION_STYLE_### constants #define PARTITION_STYLE_SFD PARTITION_STYLE_RAW -#define GETTARGETTYPE(x) (((x)>0)?(((x) >> 16) & 0xFFFF):0) -#define GETPARTTYPE(x) (((x)>0)?((x) & 0xFFFF):0); enum checksum_type { CHECKSUM_MD5 = 0, @@ -385,7 +383,7 @@ enum WindowsVersion { */ extern HINSTANCE hMainInstance; extern HWND hMainDialog, hLogDlg, hStatus, hDeviceList, hCapacity; -extern HWND hPartitionScheme, hFileSystem, hClusterSize, hLabel, hBootType, hNBPasses, hLog; +extern HWND hPartitionScheme, hTargetSystem, hFileSystem, hClusterSize, hLabel, hBootType, hNBPasses, hLog; extern HWND hInfo, hProgress, hDiskID, hStatusToolbar; extern float fScale; extern char szFolderPath[MAX_PATH], app_dir[MAX_PATH], temp_dir[MAX_PATH], system_dir[MAX_PATH], sysnative_dir[MAX_PATH]; @@ -401,6 +399,7 @@ extern int64_t iso_blocking_status; extern uint16_t rufus_version[3], embedded_sl_version[2]; extern int nWindowsVersion; extern int nWindowsBuildNumber; +extern int fs, bt, pt, tt; extern char WindowsVersionStr[128]; extern size_t ubuffer_pos; extern char ubuffer[UBUFFER_SIZE]; @@ -541,6 +540,7 @@ typedef struct { } StrArray; extern void StrArrayCreate(StrArray* arr, uint32_t initial_size); extern int32_t StrArrayAdd(StrArray* arr, const char* str, BOOL ); +extern int32_t StrArrayFind(StrArray* arr, const char* str); extern void StrArrayClear(StrArray* arr); extern void StrArrayDestroy(StrArray* arr); #define IsStrArrayEmpty(arr) (arr.Index == 0) diff --git a/src/rufus.rc b/src/rufus.rc index 1211428a..043a8748 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -36,48 +36,49 @@ EXSTYLE WS_EX_ACCEPTFILES CAPTION "Rufus 3.0.1220" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN - LTEXT "Device",IDS_DEVICE_TXT,9,19,101,8 + LTEXT "Device Settings ",IDS_DEVICE_SETTINGS_TXT,8,3,53,11,NOT WS_GROUP + LTEXT "Device",IDS_DEVICE_TXT,8,19,101,8 COMBOBOX IDC_DEVICE,8,30,200,33,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Boot Type",IDS_BOOT_TYPE_TXT,9,45,35,8 - COMBOBOX IDC_BOOTTYPE,8,55,175,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Boot Option",IDS_BOOT_OPTION_TXT,8,92,201,8 - COMBOBOX IDC_BOOT_OPTION,7,102,175,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Partition scheme",IDS_PARTITION_TYPE_TXT,9,116,108,8 - COMBOBOX IDC_PARTITION_TYPE,8,129,109,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Target system type",IDS_TARGET_SYSTEM_TXT,130,116,71,10 - COMBOBOX IDC_TARGET_SYSTEM,132,129,96,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "File system",IDS_FILESYSTEM_TXT,9,162,110,10 - COMBOBOX IDC_FILESYSTEM,8,173,108,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Cluster size",IDS_CLUSTERSIZE_TXT,130,161,71,10 - COMBOBOX IDC_CLUSTERSIZE,132,173,96,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "New volume label",IDS_LABEL_TXT,9,188,222,10 - EDITTEXT IDC_LABEL,8,198,226,12,ES_AUTOHSCROLL - PUSHBUTTON "",IDC_ADVANCED,217,146,14,10,BS_ICON - CONTROL "Check device for bad blocks",IDC_BADBLOCKS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,9,218,112,10 - COMBOBOX IDC_NBPASSES,124,216,16,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - CONTROL "Quick format",IDC_QUICKFORMAT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,276,121,10 - PUSHBUTTON "SELECT",IDC_SELECT_ISO,191,51,44,14,BS_ICON - CONTROL "Create extended label and icon files",IDC_SET_ICON, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,9,231,216,10 - CONTROL "List USB Hard Drives",IDC_ENABLE_FIXED_DISKS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,263,216,10 - CONTROL "Add fixes for old BIOSes (extra partition, align, etc.)",IDC_EXTRA_PARTITION, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,290,216,10 - CONTROL "Use Rufus MBR with BIOS ID",IDC_RUFUS_MBR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,304,110,10 - COMBOBOX IDC_DISK_ID,128,305,100,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - CONTROL "",IDC_PROGRESS,"msctls_progress32",PBS_SMOOTH | WS_BORDER,8,341,225,9 - PUSHBUTTON "About...",IDC_ABOUT,8,359,50,14 - PUSHBUTTON "Log",IDC_LOG,63,359,21,14 - PUSHBUTTON "T",IDC_TEST,90,359,12,14,NOT WS_VISIBLE - DEFPUSHBUTTON "START",IDC_START,127,359,50,14 - PUSHBUTTON "CLOSE",IDCANCEL,183,359,50,14 - PUSHBUTTON "#",IDC_HASH,215,77,21,14,BS_ICON PUSHBUTTON "...",IDC_SAVE,215,28,21,14,BS_ICON - LTEXT "Selected Image",IDS_SELECTED_IMAGE_TXT,8,69,204,8 - COMBOBOX IDC_SELECTED_IMAGE,7,79,199,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Device Settings ",IDS_DEVICE_OPTIONS_TXT,9,3,53,11,NOT WS_GROUP - LTEXT "Status ",IDS_STATUS_TXT,11,325,23,9,NOT WS_GROUP - LTEXT "Format Options ",IDS_FORMAT_OPTIONS_TXT,9,147,57,9,NOT WS_GROUP - LTEXT "Advanced Options ",IDS_ADVANCED_OPTIONS_TXT,7,250,67,9,NOT WS_GROUP + LTEXT "Boot Type",IDS_BOOT_TYPE_TXT,8,45,35,8 + COMBOBOX IDC_BOOTTYPE,8,55,175,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Selected Image",IDS_SELECTED_IMAGE_TXT,8,110,204,8 + COMBOBOX IDC_SELECTED_IMAGE,8,119,199,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "#",IDC_HASH,215,118,21,14,BS_ICON + LTEXT "Image Option",IDS_IMAGE_OPTION_TXT,8,130,201,8 + COMBOBOX IDC_IMAGE_OPTION,8,141,175,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Partition scheme",IDS_PARTITION_TYPE_TXT,8,70,108,8 + COMBOBOX IDC_PARTITION_TYPE,8,81,109,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Target system",IDS_TARGET_SYSTEM_TXT,130,70,71,10 + COMBOBOX IDC_TARGET_SYSTEM,132,81,96,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Format Options ",IDS_FORMAT_OPTIONS_TXT,8,156,57,9,NOT WS_GROUP + LTEXT "File system",IDS_FILESYSTEM_TXT,8,194,110,10 + COMBOBOX IDC_FILESYSTEM,8,208,108,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Cluster size",IDS_CLUSTERSIZE_TXT,130,193,71,10 + COMBOBOX IDC_CLUSTERSIZE,132,208,96,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Volume label",IDS_LABEL_TXT,8,171,222,10 + EDITTEXT IDC_LABEL,8,181,226,12,ES_AUTOHSCROLL + PUSHBUTTON "",IDC_ADVANCED,217,155,14,10,BS_ICON + CONTROL "Check device for bad blocks",IDC_BADBLOCKS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,227,112,10 + COMBOBOX IDC_NBPASSES,124,225,16,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Quick format",IDC_QUICKFORMAT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,285,121,10 + PUSHBUTTON "SELECT",IDC_SELECT_IMAGE,191,51,44,14 + CONTROL "Create extended label and icon files",IDC_SET_ICON, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,240,216,10 + LTEXT "Advanced Options ",IDS_ADVANCED_OPTIONS_TXT,8,259,67,9,NOT WS_GROUP + CONTROL "List USB Hard Drives",IDC_ENABLE_FIXED_DISKS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,272,216,10 + CONTROL "Add fixes for old BIOSes (extra partition, align, etc.)",IDC_EXTRA_PARTITION, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,299,216,10 + CONTROL "Use Rufus MBR with BIOS ID",IDC_RUFUS_MBR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,313,110,10 + COMBOBOX IDC_DISK_ID,124,314,100,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Status ",IDS_STATUS_TXT,8,327,23,9,NOT WS_GROUP + CONTROL "",IDC_PROGRESS,"msctls_progress32",PBS_SMOOTH | WS_BORDER,8,342,225,9 + PUSHBUTTON "About...",IDC_ABOUT,8,362,50,14 + PUSHBUTTON "Log",IDC_LOG,63,362,21,14 + PUSHBUTTON "T",IDC_TEST,90,362,12,14,NOT WS_VISIBLE + DEFPUSHBUTTON "START",IDC_START,127,362,50,14 + PUSHBUTTON "CLOSE",IDCANCEL,183,362,50,14 + LTEXT "Image Settings ",IDS_IMAGE_SETTINGS_TXT,8,96,57,9,NOT WS_GROUP END IDD_ABOUTBOX DIALOGEX 0, 0, 319, 237 diff --git a/src/smart.c b/src/smart.c index 7b32e328..3715792d 100644 --- a/src/smart.c +++ b/src/smart.c @@ -312,7 +312,7 @@ static int UsbCypressAtaPassthrough(HANDLE hPhysical, ATA_PASSTHROUGH_CMD* Comma } /* The various bridges we will try, in order */ -AtaPassThroughType pt[] = { +AtaPassThroughType ata_pt[] = { { SatAtaPassthrough, "SAT" }, { UsbJmicronAtaPassthrough, "JMicron" }, { UsbProlificAtaPassthrough, "Prolific" }, @@ -335,10 +335,10 @@ BOOL Identify(HANDLE hPhysical) if (idd == NULL) return FALSE; - for (i=0; iCommandSetSupport.SmartCommands) { DumpBufferHex(idd, sizeof(IDENTIFY_DEVICE_DATA)); uprintf("SMART support detected!\n"); @@ -347,9 +347,9 @@ BOOL Identify(HANDLE hPhysical) } break; } - uprintf("No joy with: %s (%s)\n", pt[i].type, SptStrerr(r)); + uprintf("No joy with: %s (%s)\n", ata_pt[i].type, SptStrerr(r)); } - if (i >= ARRAYSIZE(pt)) + if (i >= ARRAYSIZE(ata_pt)) uprintf("NO ATA FOR YOU!\n"); _mm_free(idd); diff --git a/src/stdfn.c b/src/stdfn.c index 779184dd..0dfa3ab8 100644 --- a/src/stdfn.c +++ b/src/stdfn.c @@ -370,6 +370,18 @@ int32_t StrArrayAdd(StrArray* arr, const char* str, BOOL duplicate) return arr->Index++; } +int32_t StrArrayFind(StrArray* arr, const char* str) +{ + size_t i; + if ((str == NULL) || (arr == NULL) || (arr->String == NULL)) + return -1; + for (i = 0; iIndex; i++) { + if (strcmp(arr->String[i], str) == 0) + return i; + } + return -1; +} + void StrArrayClear(StrArray* arr) { size_t i; @@ -628,19 +640,23 @@ static BOOL CALLBACK EnumFontFamExProc(const LOGFONTA *lpelfe, return TRUE; } -BOOL IsFontAvailable(const char* font_name) { +BOOL IsFontAvailable(const char* font_name) +{ + BOOL r; LOGFONTA lf = { 0 }; HDC hDC = GetDC(hMainDialog); if (font_name == NULL) { - ReleaseDC(hMainDialog, hDC); + safe_release_dc(hMainDialog, hDC); return FALSE; } lf.lfCharSet = DEFAULT_CHARSET; safe_strcpy(lf.lfFaceName, LF_FACESIZE, font_name); - return EnumFontFamiliesExA(hDC, &lf, EnumFontFamExProc, 0, 0); + r = EnumFontFamiliesExA(hDC, &lf, EnumFontFamExProc, 0, 0); + safe_release_dc(hMainDialog, hDC); + return r; } /* diff --git a/src/stdlg.c b/src/stdlg.c index a698abab..2dfc33c0 100644 --- a/src/stdlg.c +++ b/src/stdlg.c @@ -409,16 +409,15 @@ void CreateStatusBar(void) height = rect.bottom; // Set the font we'll use to display the '#' sign in the toolbar button - hFont = CreateFontA(-MulDiv(10, GetDeviceCaps(GetDC(hMainDialog), LOGPIXELSY), 72), + hDC = GetDC(hMainDialog); + hFont = CreateFontA(-MulDiv(10, GetDeviceCaps(hDC, LOGPIXELSY), 72), 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0, PROOF_QUALITY, 0, "Segoe UI"); // Find the width of our hash sign - hDC = GetDC(hMainDialog); SelectObject(hDC, hFont); GetTextExtentPoint32W(hDC, L"#", 1, &sz); - if (hDC != NULL) - ReleaseDC(hMainDialog, hDC); + safe_release_dc(hMainDialog, hDC); // Create 3 status areas GetClientRect(hMainDialog, &rect); @@ -879,8 +878,7 @@ INT_PTR CALLBACK SelectionCallback(HWND hDlg, UINT message, WPARAM wParam, LPARA dh = rect.bottom - rect.top; DrawTextU(hDC, szMessageText, -1, &rect, DT_CALCRECT | DT_WORDBREAK); dh = rect.bottom - rect.top - dh; - if (hDC != NULL) - ReleaseDC(hCtrl, hDC); + safe_release_dc(hCtrl, hDC); ResizeMoveCtrl(hDlg, hCtrl, 0, 0, 0, dh, 1.0f); for (i = 0; i < nDialogItems; i++) ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDC_SELECTION_CHOICE1 + i), 0, dh, 0, 0, 1.0f); @@ -1012,8 +1010,7 @@ INT_PTR CALLBACK ListCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa dh = rect.bottom - rect.top; DrawTextU(hDC, szMessageText, -1, &rect, DT_CALCRECT | DT_WORDBREAK); dh = rect.bottom - rect.top - dh; - if (hDC != NULL) - ReleaseDC(hCtrl, hDC); + safe_release_dc(hCtrl, hDC); ResizeMoveCtrl(hDlg, hCtrl, 0, 0, 0, dh, 1.0f); for (i = 0; i < nDialogItems; i++) ResizeMoveCtrl(hDlg, GetDlgItem(hDlg, IDC_LIST_ITEM1 + i), 0, dh, 0, 0, 1.0f); @@ -1237,8 +1234,7 @@ LONG GetEntryWidth(HWND hDropDown, const char *entry) if (hFont != NULL) SelectObject(hDC, hDefFont); - if (hDC != NULL) - ReleaseDC(hDropDown, hDC); + safe_release_dc(hDropDown, hDC); return size.cx; } @@ -1669,8 +1665,7 @@ SIZE GetTextSize(HWND hCtrl) GetTextExtentPoint32W(hDC, wstr, len, &sz); out: safe_free(wstr); - if (hDC != NULL) - ReleaseDC(hCtrl, hDC); + safe_release_dc(hCtrl, hDC); return sz; } diff --git a/src/syslinux.c b/src/syslinux.c index 8cdcb598..47c8bd34 100644 --- a/src/syslinux.c +++ b/src/syslinux.c @@ -2,7 +2,7 @@ * * Copyright 2003 Lars Munch Christensen - All Rights Reserved * Copyright 1998-2008 H. Peter Anvin - All Rights Reserved - * Copyright 2012-2016 Pete Batard + * Copyright 2012-2018 Pete Batard * * Based on the Linux installer program for SYSLINUX by H. Peter Anvin * @@ -106,16 +106,15 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) const char* mboot_c32 = "mboot.c32"; char path[MAX_PATH], tmp[64]; const char *errmsg; - struct libfat_filesystem *fs; + struct libfat_filesystem *lf_fs; libfat_sector_t s, *secp; libfat_sector_t *sectors = NULL; int ldlinux_sectors; uint32_t ldlinux_cluster; int i, nsectors, sl_fs_stype; - int bt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType)); - BOOL use_v5 = (bt == BT_SYSLINUX_V6) || ((bt == BT_ISO) && (SL_MAJOR(img_report.sl_version) >= 5)); + BOOL use_v5 = (bt == BT_SYSLINUX_V6) || ((bt == BT_IMAGE) && (SL_MAJOR(img_report.sl_version) >= 5)); - PrintInfoDebug(0, MSG_234, (bt == BT_ISO)?img_report.sl_version_str:embedded_sl_version_str[use_v5?1:0]); + PrintInfoDebug(0, MSG_234, (bt == BT_IMAGE)?img_report.sl_version_str:embedded_sl_version_str[use_v5?1:0]); /* 4K sector size workaround */ SECTOR_SHIFT = 0; @@ -219,7 +218,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) } uprintf("Successfully wrote '%s'", &path[3]); - if (bt != BT_ISO) + if (bt != BT_IMAGE) UpdateProgress(OP_DOS, -1.0f); /* Now flush the media */ @@ -266,21 +265,21 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) case FS_FAT16: case FS_FAT32: case FS_EXFAT: - fs = libfat_open(libfat_readfile, (intptr_t) d_handle); - if (fs == NULL) { + lf_fs = libfat_open(libfat_readfile, (intptr_t) d_handle); + if (lf_fs == NULL) { uprintf("Syslinux FAT access error"); goto out; } - ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL); + ldlinux_cluster = libfat_searchdir(lf_fs, 0, "LDLINUX SYS", NULL); secp = sectors; nsectors = 0; - s = libfat_clustertosector(fs, ldlinux_cluster); + s = libfat_clustertosector(lf_fs, ldlinux_cluster); while (s && nsectors < ldlinux_sectors) { *secp++ = s; nsectors++; - s = libfat_nextsector(fs, s); + s = libfat_nextsector(lf_fs, s); } - libfat_close(fs); + libfat_close(lf_fs); break; default: uprintf("Unsupported Syslinux filesystem"); @@ -380,7 +379,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int fs_type) fclose(fd); } - if (bt != BT_ISO) + if (bt != BT_IMAGE) UpdateProgress(OP_DOS, -1.0f); r = TRUE;