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

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

View file

@ -669,12 +669,32 @@ void TogglePersistenceControls(BOOL display)
ShowWindow(hUnits, display ? SW_SHOW : SW_HIDE); ShowWindow(hUnits, display ? SW_SHOW : SW_HIDE);
} }
void SetPersistenceSize(uint64_t pos, uint64_t max) void SetPeristencePos(uint64_t pos)
{ {
char tmp[64]; char tmp[64];
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; int i, proposed_unit_selection = 0;
LONGLONG base_unit = MB; LONGLONG base_unit = MB;
HWND hCtrl; 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 // Reset the the Persistence Units dropdown
hCtrl = GetDlgItem(hMainDialog, IDC_PERSISTENCE_UNITS); hCtrl = GetDlgItem(hMainDialog, IDC_PERSISTENCE_UNITS);
@ -699,18 +719,16 @@ void SetPersistenceSize(uint64_t pos, uint64_t max)
pos /= 1024; pos /= 1024;
max /= 1024; max /= 1024;
} }
}
hCtrl = GetDlgItem(hMainDialog, IDC_PERSISTENCE_SLIDER); hCtrl = GetDlgItem(hMainDialog, IDC_PERSISTENCE_SLIDER);
SendMessage(hCtrl, TBM_SETRANGEMIN, (WPARAM)FALSE, (LPARAM)0); // Wow! Unless you set *all* these redraw WPARAMs to true, the one from
SendMessage(hCtrl, TBM_SETRANGEMAX, (WPARAM)FALSE, (LPARAM)max); // 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); SendMessage(hCtrl, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)pos);
if (pos != 0) {
static_sprintf(tmp, "%ld", (LONG)pos); SetPeristencePos(pos);
} else {
static_sprintf(tmp, "0 (%s)", lmprintf(MSG_124));
}
app_changed_size = TRUE;
SetWindowTextU(GetDlgItem(hMainDialog, IDC_PERSISTENCE_SIZE), tmp);
} }
// Toggle the Image Option dropdown (Windows To Go or persistence settings) // Toggle the Image Option dropdown (Windows To Go or persistence settings)
@ -770,7 +788,7 @@ void ToggleImageOptions(void)
} else if (image_options & IMOP_PERSISTENCE) { } else if (image_options & IMOP_PERSISTENCE) {
SetWindowTextU(GetDlgItem(hMainDialog, IDS_IMAGE_OPTION_TXT), lmprintf(MSG_123)); SetWindowTextU(GetDlgItem(hMainDialog, IDS_IMAGE_OPTION_TXT), lmprintf(MSG_123));
TogglePersistenceControls(persistence_size != 0); 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... // If you don't force a redraw here, all kind of bad UI artifacts happen...
InvalidateRect(hMainDialog, NULL, TRUE); InvalidateRect(hMainDialog, NULL, TRUE);

View file

@ -63,7 +63,8 @@ extern void GetFullWidth(HWND hDlg);
extern void PositionMainControls(HWND hDlg); extern void PositionMainControls(HWND hDlg);
extern void AdjustForLowDPI(HWND hDlg); extern void AdjustForLowDPI(HWND hDlg);
extern void SetSectionHeaders(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 TogglePersistenceControls(BOOL display);
extern void ToggleAdvancedDeviceOptions(BOOL enable); extern void ToggleAdvancedDeviceOptions(BOOL enable);
extern void ToggleAdvancedFormatOptions(BOOL enable); extern void ToggleAdvancedFormatOptions(BOOL enable);