From 4f97cdfdc33081ed8e5d31b49be13da2c2202fcb Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Thu, 10 Jun 2021 17:18:40 +0100 Subject: [PATCH] [ui] increase projected size to prevent persistence overflow * If users set the persistent size to max, we may run into a situation where projected size (which is always a rough estimation) is too low. * When persistence is in use, we increase the projected size by 10%, to ensure that the above scenario cannot happen. * Also work around potential issues with Windows APIs when the application is launched from the root of a drive. --- res/appstore/Package.appxmanifest | 2 +- src/rufus.c | 14 +++++++++++--- src/rufus.h | 2 ++ src/rufus.rc | 10 +++++----- src/ui.c | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/res/appstore/Package.appxmanifest b/res/appstore/Package.appxmanifest index 8dc06d2f..80b25f24 100644 --- a/res/appstore/Package.appxmanifest +++ b/res/appstore/Package.appxmanifest @@ -11,7 +11,7 @@ + Version="3.14.1799.0" /> Rufus diff --git a/src/rufus.c b/src/rufus.c index 6beb02f8..e4cfd714 100755 --- a/src/rufus.c +++ b/src/rufus.c @@ -2342,14 +2342,14 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA persistence_size = lPos * MB; for (i = 0; i < persistence_unit_selection; i++) persistence_size *= 1024; - if (persistence_size > SelectedDrive.DiskSize - img_report.projected_size) - persistence_size = SelectedDrive.DiskSize - img_report.projected_size; + if (persistence_size > SelectedDrive.DiskSize - PERCENTAGE(PROJECTED_SIZE_RATIO, img_report.projected_size)) + persistence_size = SelectedDrive.DiskSize - PERCENTAGE(PROJECTED_SIZE_RATIO, img_report.projected_size); pos = persistence_size / MB; for (i = 0; i < persistence_unit_selection; i++) pos /= 1024; lPos = (LONG)pos; SendMessage(GetDlgItem(hMainDialog, IDC_PERSISTENCE_SLIDER), TBM_SETPOS, TRUE, lPos); - if (persistence_size >= (SelectedDrive.DiskSize - img_report.projected_size)) { + if (persistence_size >= (SelectedDrive.DiskSize - PERCENTAGE(PROJECTED_SIZE_RATIO, img_report.projected_size))) { static_sprintf(tmp, "%ld", lPos); app_changed_size = TRUE; SetWindowTextU(GetDlgItem(hMainDialog, IDC_PERSISTENCE_SIZE), tmp); @@ -3185,6 +3185,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine uprintf("Could not get current directory: %s", WindowsErrorString()); app_dir[0] = 0; } + // Microsoft has a bad habit of making some of its APIs (_chdir/_wchdir) break + // when app_dir is a drive letter that doesn't have a trailing backslash. For + // instance _chdir("F:") does not change the directory, whereas _chdir("F:\\") + // does. So make sure we add a trailing backslash if the app_dir is a drive. + if ((app_dir[1] == ':') && (app_dir[2] == 0)) { + app_dir[2] = '\\'; + app_dir[3] = 0; + } if (GetSystemDirectoryU(system_dir, sizeof(system_dir)) == 0) { uprintf("Could not get system directory: %s", WindowsErrorString()); static_strcpy(system_dir, "C:\\Windows\\System32"); diff --git a/src/rufus.h b/src/rufus.h index dce00e6e..3258c3ff 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -79,6 +79,7 @@ #define MAX_WININST 4 // Max number of install[.wim|.esd] we can handle on an image #define MBR_UEFI_MARKER 0x49464555 // 'U', 'E', 'F', 'I', as a 32 bit little endian longword #define MORE_INFO_URL 0xFFFF +#define PROJECTED_SIZE_RATIO 110 // Percentage by which we inflate projected_size to prevent persistence overflow #define STATUS_MSG_TIMEOUT 3500 // How long should cheat mode messages appear for on the status bar #define WRITE_RETRIES 4 #define WRITE_TIMEOUT 5000 // How long we should wait between write retries (in ms) @@ -129,6 +130,7 @@ #ifndef STRINGIFY #define STRINGIFY(x) #x #endif +#define PERCENTAGE(percent, value) ((1ULL * percent * value) / 100ULL) #define IsChecked(CheckBox_ID) (IsDlgButtonChecked(hMainDialog, CheckBox_ID) == BST_CHECKED) #define MB_IS_RTL (right_to_left_mode?MB_RTLREADING|MB_RIGHT:0) #define CHECK_FOR_USER_CANCEL if (IS_ERROR(FormatStatus) && (SCODE_CODE(FormatStatus) == ERROR_CANCELLED)) goto out diff --git a/src/rufus.rc b/src/rufus.rc index 9e64a037..35ef0422 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 232, 326 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 3.14.1798" +CAPTION "Rufus 3.14.1799" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -395,8 +395,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,14,1798,0 - PRODUCTVERSION 3,14,1798,0 + FILEVERSION 3,14,1799,0 + PRODUCTVERSION 3,14,1799,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -414,13 +414,13 @@ BEGIN VALUE "Comments", "https://rufus.ie" VALUE "CompanyName", "Akeo Consulting" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "3.14.1798" + VALUE "FileVersion", "3.14.1799" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2021 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "OriginalFilename", "rufus-3.14.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "3.14.1798" + VALUE "ProductVersion", "3.14.1799" END END BLOCK "VarFileInfo" diff --git a/src/ui.c b/src/ui.c index b860cca0..5f480a56 100644 --- a/src/ui.c +++ b/src/ui.c @@ -726,7 +726,7 @@ void SetPersistenceSize(void) uint64_t max = 0, pos = 0; if (ComboBox_GetCurSel(hDeviceList) >= 0) { - max = SelectedDrive.DiskSize - img_report.projected_size; + max = SelectedDrive.DiskSize - PERCENTAGE(PROJECTED_SIZE_RATIO, img_report.projected_size); persistence_size = min(persistence_size, max); pos = persistence_size;