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

[ui] smarter proposed default label

This commit is contained in:
Pete Batard 2011-11-24 20:02:14 +00:00
parent 53f236dffe
commit b41687ec92
2 changed files with 13 additions and 4 deletions

16
rufus.c
View file

@ -205,7 +205,7 @@ static const char* GetPartitionType(BYTE Type)
}
/*
* Open a drive - return a drive HANDLE and the drive letter
* Open a drive with optional write access - return a drive HANDLE and the drive letter
* This call is quite risky (left unchecked, inadvertently passing 0 as index would
* return a handle to C:, which we might then proceed to unknowingly repartition!),
* so we apply the following mitigation factors:
@ -413,12 +413,20 @@ static BOOL PopulateProperties(int ComboIndex)
IGNORE_RETVAL(ComboBox_AddStringU(hFileSystem, SelectedDrive.FSType));
IGNORE_RETVAL(ComboBox_SetCurSel(hFileSystem, 0));
hDeviceToolTip = CreateTooltip(hDeviceList, DriveID.Table[ComboIndex], -1);
// If no existing label is available, propose one according to the size (eg: "256MB", "8GB")
if (safe_strcmp(no_label, DriveLabel.Table[ComboIndex]) == 0) {
if (fabs(floor(HumanReadableSize + 0.5) - HumanReadableSize) < 0.15) {
safe_sprintf(proposed_label, sizeof(proposed_label), "%0.0f%s", floor(HumanReadableSize + 0.5), suffix[i]);
SetWindowTextA(hLabel, proposed_label);
if (HumanReadableSize < 1.0) {
HumanReadableSize *= 1024.0;
i--;
}
// If we're beneath the tolerance, round proposed label to an integer, if not, show one decimal point
if (fabs(HumanReadableSize / ceil(HumanReadableSize) - 1.0) < PROPOSEDLABEL_TOLERANCE) {
safe_sprintf(proposed_label, sizeof(proposed_label), "%0.0f%s", ceil(HumanReadableSize), suffix[i]);
} else {
safe_sprintf(proposed_label, sizeof(proposed_label), "%0.1f%s", HumanReadableSize, suffix[i]);
}
SetWindowTextA(hLabel, proposed_label);
} else {
SetWindowTextA(hLabel, DriveLabel.Table[ComboIndex]);
}

View file

@ -26,6 +26,7 @@
#define DRIVE_INDEX_MAX 0xC0
#define MAX_DRIVES 16
#define MAX_TOOLTIPS 16
#define PROPOSEDLABEL_TOLERANCE 0.10
#define WHITE RGB(255,255,255)
#define SEPARATOR_GREY RGB(223,223,223)
#define RUFUS_URL "https://github.com/pbatard/rufus/wiki/Rufus"