From 30137de7cb4e9b0f0256ecbfc39e21a1ae45c3f3 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Mon, 1 May 2017 16:22:34 +0100 Subject: [PATCH] [iso] improve handling of image size * Don't use the projected size where the actual image size should be used * Also fix an issue with the projected size computation --- src/checksum.c | 4 ++-- src/format.c | 4 ++-- src/iso.c | 5 ++--- src/rufus.c | 6 ++++-- src/rufus.h | 1 + src/rufus.rc | 10 +++++----- src/vhd.c | 8 ++++---- 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/checksum.c b/src/checksum.c index f01abebb..bcb68693 100644 --- a/src/checksum.c +++ b/src/checksum.c @@ -931,10 +931,10 @@ DWORD WINAPI SumThread(void* param) // Update the progress and check for cancel if (_GetTickCount64() > LastRefresh + MAX_REFRESH) { LastRefresh = _GetTickCount64(); - format_percent = (100.0f*rb) / (1.0f*img_report.projected_size); + format_percent = (100.0f*rb) / (1.0f*img_report.image_size); PrintInfo(0, MSG_271, format_percent); SendMessage(hProgress, PBM_SETPOS, (WPARAM)((format_percent / 100.0f)*MAX_PROGRESS), 0); - SetTaskbarProgressValue(rb, img_report.projected_size); + SetTaskbarProgressValue(rb, img_report.image_size); } CHECK_FOR_USER_CANCEL; diff --git a/src/format.c b/src/format.c index d98533a0..81faed99 100644 --- a/src/format.c +++ b/src/format.c @@ -1505,7 +1505,7 @@ static void update_progress(const uint64_t processed_bytes) { if (_GetTickCount64() > LastRefresh + MAX_REFRESH) { LastRefresh = _GetTickCount64(); - format_percent = (100.0f*processed_bytes)/(1.0f*img_report.projected_size); + format_percent = (100.0f*processed_bytes)/(1.0f*img_report.image_size); PrintInfo(0, MSG_261, format_percent); UpdateProgress(OP_FORMAT, format_percent); } @@ -1517,7 +1517,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, HANDLE hSourceImage) BOOL s, ret = FALSE; LARGE_INTEGER li; DWORD rSize, wSize, BufSize; - uint64_t wb, target_size = hSourceImage?img_report.projected_size:SelectedDrive.DiskSize; + uint64_t wb, target_size = hSourceImage?img_report.image_size:SelectedDrive.DiskSize; uint8_t *buffer = NULL; int i; diff --git a/src/iso.c b/src/iso.c index 1665b432..d494fa79 100644 --- a/src/iso.c +++ b/src/iso.c @@ -242,9 +242,9 @@ static BOOL check_iso_props(const char* psz_dirname, int64_t i_file_length, cons if (i_file_length >= FOUR_GIGABYTES) img_report.has_4GB_file = TRUE; // Compute projected size needed - total_blocks += i_file_length/UDF_BLOCKSIZE; + total_blocks += i_file_length / ISO_BLOCKSIZE; // NB: ISO_BLOCKSIZE = UDF_BLOCKSIZE - if ((i_file_length != 0) && (i_file_length%ISO_BLOCKSIZE == 0)) + if ((i_file_length != 0) && (i_file_length % ISO_BLOCKSIZE != 0)) total_blocks++; return TRUE; } @@ -673,7 +673,6 @@ BOOL ExtractISO(const char* src_iso, const char* dest_dir, BOOL scan) uprintf("ISO analysis:"); SendMessage(hMainDialog, UM_PROGRESS_INIT, PBS_MARQUEE, 0); total_blocks = 0; - memset(&img_report, 0, sizeof(img_report)); has_ldlinux_c32 = FALSE; // String array of all isolinux/syslinux locations StrArrayCreate(&config_path, 8); diff --git a/src/rufus.c b/src/rufus.c index f5d8b752..393a1df9 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -972,7 +972,7 @@ static void DisplayISOProps(void) int i; uprintf("ISO label: '%s'", img_report.label); - uprintf(" Size: %s", SizeToHumanReadable( img_report.projected_size, FALSE, FALSE)); + uprintf(" Size: %s (Projected)", SizeToHumanReadable(img_report.projected_size, FALSE, FALSE)); PRINT_ISO_PROP(img_report.has_4GB_file, " Has a >4GB file"); PRINT_ISO_PROP(img_report.has_long_filename, " Has a >64 chars filename"); PRINT_ISO_PROP(HAS_SYSLINUX(img_report), " Uses: Syslinux/Isolinux v%s", img_report.sl_version_str); @@ -1015,9 +1015,11 @@ DWORD WINAPI ISOScanThread(LPVOID param) 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.is_iso && !img_report.is_bootable_img) { + + 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); diff --git a/src/rufus.h b/src/rufus.h index f4a7d08e..8b57e2b9 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -277,6 +277,7 @@ typedef struct { char cfg_path[128]; /* path to the ISO's isolinux.cfg */ char reactos_path[128]; /* path to the ISO's freeldr.sys or setupldr.sys */ char install_wim_path[64]; /* path to install.wim or install.swm */ + uint64_t image_size; uint64_t projected_size; uint32_t install_wim_version; BOOLEAN is_iso; diff --git a/src/rufus.rc b/src/rufus.rc index a87df814..884bdbe4 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 242, 376 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 2.15.1098" +CAPTION "Rufus 2.15.1099" FONT 8, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 @@ -334,8 +334,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,15,1098,0 - PRODUCTVERSION 2,15,1098,0 + FILEVERSION 2,15,1099,0 + PRODUCTVERSION 2,15,1099,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -352,13 +352,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "2.15.1098" + VALUE "FileVersion", "2.15.1099" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2017 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "2.15.1098" + VALUE "ProductVersion", "2.15.1099" END END BLOCK "VarFileInfo" diff --git a/src/vhd.c b/src/vhd.c index 0b9c6080..9ad47f20 100644 --- a/src/vhd.c +++ b/src/vhd.c @@ -293,19 +293,19 @@ BOOL IsBootableImage(const char* path) uprintf(" Could not get image size: %s", WindowsErrorString()); goto out; } - img_report.projected_size = (uint64_t)liImageSize.QuadPart; + img_report.image_size = (uint64_t)liImageSize.QuadPart; size = sizeof(vhd_footer); - if ((img_report.compression_type == BLED_COMPRESSION_NONE) && (img_report.projected_size >= (512 + size))) { + if ((img_report.compression_type == BLED_COMPRESSION_NONE) && (img_report.image_size >= (512 + size))) { footer = (vhd_footer*)malloc(size); - ptr.QuadPart = img_report.projected_size - size; + ptr.QuadPart = img_report.image_size - size; if ( (footer == NULL) || (!SetFilePointerEx(handle, ptr, NULL, FILE_BEGIN)) || (!ReadFile(handle, footer, size, &size, NULL)) || (size != sizeof(vhd_footer)) ) { uprintf(" Could not read VHD footer"); goto out; } if (memcmp(footer->cookie, conectix_str, sizeof(footer->cookie)) == 0) { - img_report.projected_size -= sizeof(vhd_footer); + img_report.image_size -= sizeof(vhd_footer); if ( (bswap_uint32(footer->file_format_version) != VHD_FOOTER_FILE_FORMAT_V1_0) || (bswap_uint32(footer->disk_type) != VHD_FOOTER_TYPE_FIXED_HARD_DISK)) { uprintf(" Unsupported type of VHD image");