1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[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.
This commit is contained in:
Pete Batard 2021-06-10 17:18:40 +01:00
parent 9d7e96e293
commit 4f97cdfdc3
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
5 changed files with 20 additions and 10 deletions

View file

@ -11,7 +11,7 @@
<Identity <Identity
Name="19453.net.Rufus" Name="19453.net.Rufus"
Publisher="CN=7AC86D13-3E5A-491A-ADD5-80095C212740" Publisher="CN=7AC86D13-3E5A-491A-ADD5-80095C212740"
Version="3.14.1798.0" /> Version="3.14.1799.0" />
<Properties> <Properties>
<DisplayName>Rufus</DisplayName> <DisplayName>Rufus</DisplayName>

View file

@ -2342,14 +2342,14 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
persistence_size = lPos * MB; persistence_size = lPos * MB;
for (i = 0; i < persistence_unit_selection; i++) for (i = 0; i < persistence_unit_selection; i++)
persistence_size *= 1024; persistence_size *= 1024;
if (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 - img_report.projected_size; persistence_size = SelectedDrive.DiskSize - PERCENTAGE(PROJECTED_SIZE_RATIO, img_report.projected_size);
pos = persistence_size / MB; pos = persistence_size / MB;
for (i = 0; i < persistence_unit_selection; i++) for (i = 0; i < persistence_unit_selection; i++)
pos /= 1024; pos /= 1024;
lPos = (LONG)pos; lPos = (LONG)pos;
SendMessage(GetDlgItem(hMainDialog, IDC_PERSISTENCE_SLIDER), TBM_SETPOS, TRUE, lPos); 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); static_sprintf(tmp, "%ld", lPos);
app_changed_size = TRUE; app_changed_size = TRUE;
SetWindowTextU(GetDlgItem(hMainDialog, IDC_PERSISTENCE_SIZE), tmp); 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()); uprintf("Could not get current directory: %s", WindowsErrorString());
app_dir[0] = 0; 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) { if (GetSystemDirectoryU(system_dir, sizeof(system_dir)) == 0) {
uprintf("Could not get system directory: %s", WindowsErrorString()); uprintf("Could not get system directory: %s", WindowsErrorString());
static_strcpy(system_dir, "C:\\Windows\\System32"); static_strcpy(system_dir, "C:\\Windows\\System32");

View file

@ -79,6 +79,7 @@
#define MAX_WININST 4 // Max number of install[.wim|.esd] we can handle on an image #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 MBR_UEFI_MARKER 0x49464555 // 'U', 'E', 'F', 'I', as a 32 bit little endian longword
#define MORE_INFO_URL 0xFFFF #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 STATUS_MSG_TIMEOUT 3500 // How long should cheat mode messages appear for on the status bar
#define WRITE_RETRIES 4 #define WRITE_RETRIES 4
#define WRITE_TIMEOUT 5000 // How long we should wait between write retries (in ms) #define WRITE_TIMEOUT 5000 // How long we should wait between write retries (in ms)
@ -129,6 +130,7 @@
#ifndef STRINGIFY #ifndef STRINGIFY
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#endif #endif
#define PERCENTAGE(percent, value) ((1ULL * percent * value) / 100ULL)
#define IsChecked(CheckBox_ID) (IsDlgButtonChecked(hMainDialog, CheckBox_ID) == BST_CHECKED) #define IsChecked(CheckBox_ID) (IsDlgButtonChecked(hMainDialog, CheckBox_ID) == BST_CHECKED)
#define MB_IS_RTL (right_to_left_mode?MB_RTLREADING|MB_RIGHT:0) #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 #define CHECK_FOR_USER_CANCEL if (IS_ERROR(FormatStatus) && (SCODE_CODE(FormatStatus) == ERROR_CANCELLED)) goto out

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326 IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.14.1798" CAPTION "Rufus 3.14.1799"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0 FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -395,8 +395,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,14,1798,0 FILEVERSION 3,14,1799,0
PRODUCTVERSION 3,14,1798,0 PRODUCTVERSION 3,14,1799,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -414,13 +414,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie" VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting" VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.14.1798" VALUE "FileVersion", "3.14.1799"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2021 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2021 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.14.exe" VALUE "OriginalFilename", "rufus-3.14.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.14.1798" VALUE "ProductVersion", "3.14.1799"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View file

@ -726,7 +726,7 @@ void SetPersistenceSize(void)
uint64_t max = 0, pos = 0; uint64_t max = 0, pos = 0;
if (ComboBox_GetCurSel(hDeviceList) >= 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); persistence_size = min(persistence_size, max);
pos = persistence_size; pos = persistence_size;