mirror of
https://github.com/pbatard/rufus.git
synced 2025-05-19 09:25:12 -04:00
[misc] factorize SizeToHumanReadable() and ensure log sizes are in English
* Also use an allocated buffer for DD operations
This commit is contained in:
parent
5ad2ac0d47
commit
b83b087b52
7 changed files with 33 additions and 40 deletions
|
@ -147,19 +147,20 @@ char* GuidToString(const GUID* guid)
|
|||
}
|
||||
|
||||
// Convert a file size to human readable
|
||||
char* SizeToHumanReadable(LARGE_INTEGER size)
|
||||
char* SizeToHumanReadable(uint64_t size, BOOL log)
|
||||
{
|
||||
int suffix = 0;
|
||||
static char str_size[32];
|
||||
double hr_size = (double)size.QuadPart;
|
||||
double hr_size = (double)size;
|
||||
char **_msg_table = log?default_msg_table:msg_table;
|
||||
while ((suffix < MAX_SIZE_SUFFIXES) && (hr_size >= 1024.0)) {
|
||||
hr_size /= 1024.0;
|
||||
suffix++;
|
||||
}
|
||||
if (suffix == 0) {
|
||||
safe_sprintf(str_size, sizeof(str_size), "%d %s", (int)hr_size, lmprintf(MSG_020));
|
||||
safe_sprintf(str_size, sizeof(str_size), "%d %s", (int)hr_size, _msg_table[MSG_020-MSG_000]);
|
||||
} else {
|
||||
safe_sprintf(str_size, sizeof(str_size), "%0.1f %s", hr_size, lmprintf(MSG_020 + suffix));
|
||||
safe_sprintf(str_size, sizeof(str_size), "%0.1f %s", hr_size, _msg_table[MSG_020+suffix-MSG_000]);
|
||||
}
|
||||
return str_size;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue