Show full byte size of every file

This commit is contained in:
d0k3 2016-04-05 21:13:23 +02:00
parent e80f788a94
commit 03ad5205be
3 changed files with 23 additions and 2 deletions

View File

@ -62,11 +62,21 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, DirStruct* c
} else if (curr_entry->type == T_DOTDOT) {
snprintf(tempstr, 21, "%20s", "");
} else {
char numstr[32];
char bytestr[32];
FormatBytes(bytestr, curr_entry->size);
FormatNumber(numstr, curr_entry->size);
snprintf(bytestr, 31, "%s byte", numstr);
ResizeString(tempstr, bytestr, 20, 8, false);
}
DrawStringF(true, 4, info_start + 12 + 10, color_current, COLOR_STD_BG, tempstr);
if (((curr_entry->type == T_FILE) || (curr_entry->type == T_ROOT)) && (curr_entry->size >= 1024)) {
char bytestr[32];
FormatBytes(bytestr, curr_entry->size);
ResizeString(tempstr, bytestr, 20, 8, false);
} else {
snprintf(tempstr, 21, "%20s", "");
}
DrawStringF(true, 4, info_start + 12 + 20, color_current, COLOR_STD_BG, tempstr);
// right top - clipboard
DrawStringF(true, SCREEN_WIDTH_TOP - (20*8), info_start, COLOR_STD_FONT, COLOR_STD_BG, "%20s", (clipboard->n_entries) ? "[CLIPBOARD]" : "");

View File

@ -154,8 +154,18 @@ void TruncateString(char* dest, const char* orig, int nsize, int tpos) {
}
}
void FormatNumber(char* str, u64 number) { // str should be 32 byte in size
u64 mag1000 = 1;
*str = '\0';
for (; number / (mag1000 * 1000) > 0; mag1000 *= 1000);
for (; mag1000 > 0; mag1000 /= 1000) {
u32 pos = strnlen(str, 31);
snprintf(str + pos, 31 - pos, "%0*llu%c", (pos) ? 3 : 1, (number / mag1000) % 1000, (mag1000 > 1) ? ',' : '\0');
}
}
void FormatBytes(char* str, u64 bytes) { // str should be 32 byte in size, just to be safe
const char* units[] = {" byte", "kB", "MB", "GB"};
const char* units[] = {" byte", " kB", " MB", " GB"};
if (bytes == (u64) -1) snprintf(str, 32, "INVALID");
else if (bytes < 1024) snprintf(str, 32, "%llu%s", bytes, units[0]);

View File

@ -66,6 +66,7 @@ u32 GetDrawStringWidth(char* str);
void ResizeString(char* dest, const char* orig, int nsize, int tpos, bool align_right);
void TruncateString(char* dest, const char* orig, int nsize, int tpos);
void FormatNumber(char* str, u64 number);
void FormatBytes(char* str, u64 bytes);
bool ShowPrompt(bool ask, const char *format, ...);