mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 21:52:48 +00:00
Show full byte size of every file
This commit is contained in:
parent
e80f788a94
commit
03ad5205be
@ -62,11 +62,21 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, DirStruct* c
|
|||||||
} else if (curr_entry->type == T_DOTDOT) {
|
} else if (curr_entry->type == T_DOTDOT) {
|
||||||
snprintf(tempstr, 21, "%20s", "");
|
snprintf(tempstr, 21, "%20s", "");
|
||||||
} else {
|
} else {
|
||||||
|
char numstr[32];
|
||||||
char bytestr[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);
|
ResizeString(tempstr, bytestr, 20, 8, false);
|
||||||
}
|
}
|
||||||
DrawStringF(true, 4, info_start + 12 + 10, color_current, COLOR_STD_BG, tempstr);
|
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
|
// right top - clipboard
|
||||||
DrawStringF(true, SCREEN_WIDTH_TOP - (20*8), info_start, COLOR_STD_FONT, COLOR_STD_BG, "%20s", (clipboard->n_entries) ? "[CLIPBOARD]" : "");
|
DrawStringF(true, SCREEN_WIDTH_TOP - (20*8), info_start, COLOR_STD_FONT, COLOR_STD_BG, "%20s", (clipboard->n_entries) ? "[CLIPBOARD]" : "");
|
||||||
|
12
source/ui.c
12
source/ui.c
@ -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
|
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");
|
if (bytes == (u64) -1) snprintf(str, 32, "INVALID");
|
||||||
else if (bytes < 1024) snprintf(str, 32, "%llu%s", bytes, units[0]);
|
else if (bytes < 1024) snprintf(str, 32, "%llu%s", bytes, units[0]);
|
||||||
|
@ -66,6 +66,7 @@ u32 GetDrawStringWidth(char* str);
|
|||||||
|
|
||||||
void ResizeString(char* dest, const char* orig, int nsize, int tpos, bool align_right);
|
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 TruncateString(char* dest, const char* orig, int nsize, int tpos);
|
||||||
|
void FormatNumber(char* str, u64 number);
|
||||||
void FormatBytes(char* str, u64 bytes);
|
void FormatBytes(char* str, u64 bytes);
|
||||||
|
|
||||||
bool ShowPrompt(bool ask, const char *format, ...);
|
bool ShowPrompt(bool ask, const char *format, ...);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user