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

[ui] fix multiple persistence slider issues

* Range not being set when plugging a drive
* Set position to zero when no drive is selected
* Make sure the restored position can not be greater than the max
This commit is contained in:
Pete Batard 2018-08-14 23:05:52 +01:00
parent e591868555
commit e8745339e4
4 changed files with 65 additions and 50 deletions

View file

@ -714,6 +714,9 @@ static void EnableBootOptions(BOOL enable, BOOL remove_checkboxes)
EnableWindow(GetDlgItem(hMainDialog, IDC_IMAGE_OPTION), actual_enable);
EnableWindow(GetDlgItem(hMainDialog, IDC_PERSISTENCE_SLIDER), actual_enable);
// Make sure we set the range if we have persistence
if ((image_path != NULL) && HAS_PERSISTENCE(img_report))
SetPersistenceSize();
EnableWindow(GetDlgItem(hMainDialog, IDC_PERSISTENCE_SIZE), (persistence_size != 0) && actual_enable);
EnableWindow(GetDlgItem(hMainDialog, IDC_PERSISTENCE_UNITS), (persistence_size != 0) && actual_enable);
EnableMBRBootOptions(actual_enable, remove_checkboxes);
@ -779,6 +782,7 @@ static BOOL PopulateProperties(void)
if (device_index < 0)
goto out;
persistence_unit_selection = -1;
// Get data from the currently selected drive
SelectedDrive.DeviceNumber = (DWORD)ComboBox_GetItemData(hDeviceList, device_index);
// This fills the SelectedDrive properties
@ -2074,7 +2078,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
for (i = 0; i < persistence_unit_selection; i++)
persistence_size *= 1024;
persistence_unit_selection = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PERSISTENCE_UNITS));
SetPersistenceSize(persistence_size, SelectedDrive.DiskSize - img_report.projected_size);
SetPersistenceSize();
break;
case IDC_NB_PASSES:
if (HIWORD(wParam) != CBN_SELCHANGE)
@ -2291,6 +2295,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
SetPartitionSchemeAndTargetSystem(FALSE);
SetFileSystemAndClusterSize(NULL);
ShowWindow(GetDlgItem(hDlg, IDS_CSM_HELP_TXT), SW_HIDE);
persistence_unit_selection = -1;
}
} else {
queued_hotplug_event = TRUE;
@ -2418,19 +2423,10 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
case WM_HSCROLL:
lPos = (LONG)SendMessage(GetDlgItem(hMainDialog, IDC_PERSISTENCE_SLIDER), TBM_GETPOS, 0, 0);
if (lPos != 0) {
if (persistence_size == 0)
TogglePersistenceControls(TRUE);
static_sprintf(tmp, "%ld", lPos);
} else {
TogglePersistenceControls(FALSE);
static_sprintf(tmp, "0 (%s)", lmprintf(MSG_124));
}
SetPeristencePos(lPos);
persistence_size = lPos * MB;
for (i = 0; i < persistence_unit_selection; i++)
persistence_size *= 1024;
app_changed_size = TRUE;
SetWindowTextU(GetDlgItem(hMainDialog, IDC_PERSISTENCE_SIZE), tmp);
break;
case WM_DROPFILES:

View file

@ -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.2.1369"
CAPTION "Rufus 3.2.1370"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -392,8 +392,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,2,1369,0
PRODUCTVERSION 3,2,1369,0
FILEVERSION 3,2,1370,0
PRODUCTVERSION 3,2,1370,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -411,13 +411,13 @@ BEGIN
VALUE "Comments", "https://akeo.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.2.1369"
VALUE "FileVersion", "3.2.1370"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus-3.2.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.2.1369"
VALUE "ProductVersion", "3.2.1370"
END
END
BLOCK "VarFileInfo"

View file

@ -669,50 +669,68 @@ void TogglePersistenceControls(BOOL display)
ShowWindow(hUnits, display ? SW_SHOW : SW_HIDE);
}
void SetPersistenceSize(uint64_t pos, uint64_t max)
void SetPeristencePos(uint64_t pos)
{
char tmp[64];
int i, proposed_unit_selection = 0;
LONGLONG base_unit = MB;
HWND hCtrl;
// Reset the the Persistence Units dropdown
hCtrl = GetDlgItem(hMainDialog, IDC_PERSISTENCE_UNITS);
IGNORE_RETVAL(ComboBox_ResetContent(hCtrl));
for (i = 0; i < 3; i++) {
IGNORE_RETVAL(ComboBox_SetItemData(hCtrl, ComboBox_AddStringU(hCtrl, lmprintf(MSG_022 + i)), i));
// If we have more than 7 discrete positions, set this unit as our base
if (SelectedDrive.DiskSize > 7 * base_unit)
proposed_unit_selection = i;
base_unit *= 1024;
// Don't allow a base unit unless the drive is at least twice the size of that unit
if (SelectedDrive.DiskSize < 2 * base_unit)
break;
}
if (persistence_unit_selection < 0)
persistence_unit_selection = proposed_unit_selection;
IGNORE_RETVAL(ComboBox_SetCurSel(hCtrl, persistence_unit_selection));
pos /= MB;
max /= MB;
for (i = 0; i < persistence_unit_selection; i++) {
pos /= 1024;
max /= 1024;
}
hCtrl = GetDlgItem(hMainDialog, IDC_PERSISTENCE_SLIDER);
SendMessage(hCtrl, TBM_SETRANGEMIN, (WPARAM)FALSE, (LPARAM)0);
SendMessage(hCtrl, TBM_SETRANGEMAX, (WPARAM)FALSE, (LPARAM)max);
SendMessage(hCtrl, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)pos);
if (pos != 0) {
TogglePersistenceControls(TRUE);
static_sprintf(tmp, "%ld", (LONG)pos);
} else {
TogglePersistenceControls(FALSE);
static_sprintf(tmp, "0 (%s)", lmprintf(MSG_124));
}
app_changed_size = TRUE;
SetWindowTextU(GetDlgItem(hMainDialog, IDC_PERSISTENCE_SIZE), tmp);
}
void SetPersistenceSize(void)
{
int i, proposed_unit_selection = 0;
LONGLONG base_unit = MB;
HWND hCtrl;
uint64_t max = 0, pos = 0;
if (ComboBox_GetCurSel(hDeviceList) >= 0) {
max = SelectedDrive.DiskSize - img_report.projected_size;
persistence_size = min(persistence_size, max);
pos = persistence_size;
// Reset the the Persistence Units dropdown
hCtrl = GetDlgItem(hMainDialog, IDC_PERSISTENCE_UNITS);
IGNORE_RETVAL(ComboBox_ResetContent(hCtrl));
for (i = 0; i < 3; i++) {
IGNORE_RETVAL(ComboBox_SetItemData(hCtrl, ComboBox_AddStringU(hCtrl, lmprintf(MSG_022 + i)), i));
// If we have more than 7 discrete positions, set this unit as our base
if (SelectedDrive.DiskSize > 7 * base_unit)
proposed_unit_selection = i;
base_unit *= 1024;
// Don't allow a base unit unless the drive is at least twice the size of that unit
if (SelectedDrive.DiskSize < 2 * base_unit)
break;
}
if (persistence_unit_selection < 0)
persistence_unit_selection = proposed_unit_selection;
IGNORE_RETVAL(ComboBox_SetCurSel(hCtrl, persistence_unit_selection));
pos /= MB;
max /= MB;
for (i = 0; i < persistence_unit_selection; i++) {
pos /= 1024;
max /= 1024;
}
}
hCtrl = GetDlgItem(hMainDialog, IDC_PERSISTENCE_SLIDER);
// Wow! Unless you set *all* these redraw WPARAMs to true, the one from
// TBM_SETPOS gets completely ignored if the value is zero!
SendMessage(hCtrl, TBM_SETRANGEMIN, (WPARAM)TRUE, (LPARAM)0);
SendMessage(hCtrl, TBM_SETRANGEMAX, (WPARAM)TRUE, (LPARAM)max);
SendMessage(hCtrl, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)pos);
SetPeristencePos(pos);
}
// Toggle the Image Option dropdown (Windows To Go or persistence settings)
void ToggleImageOptions(void)
{
@ -770,7 +788,7 @@ void ToggleImageOptions(void)
} else if (image_options & IMOP_PERSISTENCE) {
SetWindowTextU(GetDlgItem(hMainDialog, IDS_IMAGE_OPTION_TXT), lmprintf(MSG_123));
TogglePersistenceControls(persistence_size != 0);
SetPersistenceSize(persistence_size, SelectedDrive.DiskSize - img_report.projected_size);
SetPersistenceSize();
}
// If you don't force a redraw here, all kind of bad UI artifacts happen...
InvalidateRect(hMainDialog, NULL, TRUE);

View file

@ -63,7 +63,8 @@ extern void GetFullWidth(HWND hDlg);
extern void PositionMainControls(HWND hDlg);
extern void AdjustForLowDPI(HWND hDlg);
extern void SetSectionHeaders(HWND hDlg);
extern void SetPersistenceSize(uint64_t pos, uint64_t max);
extern void SetPeristencePos(uint64_t pos);
extern void SetPersistenceSize(void);
extern void TogglePersistenceControls(BOOL display);
extern void ToggleAdvancedDeviceOptions(BOOL enable);
extern void ToggleAdvancedFormatOptions(BOOL enable);