diff --git a/source/godmode.c b/source/godmode.c index 6fdd9c5..8104df2 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -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]" : ""); diff --git a/source/ui.c b/source/ui.c index 68efb92..f317e96 100644 --- a/source/ui.c +++ b/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 - 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]); diff --git a/source/ui.h b/source/ui.h index 6903230..bc60079 100644 --- a/source/ui.h +++ b/source/ui.h @@ -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, ...);