diff --git a/arm9/source/driveMenu.cpp b/arm9/source/driveMenu.cpp index 698162d..589fc28 100644 --- a/arm9/source/driveMenu.cpp +++ b/arm9/source/driveMenu.cpp @@ -170,19 +170,17 @@ void dm_drawBottomScreen(void) { if (sdLabel[0] != '\0') { iprintf (" (%s)", sdLabel); } - printf ("\n(SD FAT)"); - //printf ("\n(SD FAT, "); - //printBytes(sdSize); - //printf(")"); + printf ("\n(SD FAT, "); + printDriveBytes(sdSize); + printf(")"); } else if (dmAssignedOp[dmCursorPosition] == 1) { printf ("[fat:] FLASHCART"); if (fatLabel[0] != '\0') { iprintf (" (%s)", fatLabel); } - printf ("\n(Slot-1 SD FAT)"); - //printf ("\n(Slot-1 SD FAT, "); - //printBytes(fatSize); - //printf(")"); + printf ("\n(Slot-1 SD FAT, "); + printDriveBytes(fatSize); + printf(")"); } else if (dmAssignedOp[dmCursorPosition] == 2) { printf ("GBA GAMECART\n"); printf ("(GBA Game)"); @@ -194,10 +192,10 @@ void dm_drawBottomScreen(void) { printf ("(NDS Game)"); } else if (dmAssignedOp[dmCursorPosition] == 5) { printf ("[ram1:] RAMDRIVE\n"); - printf ("(RAMdrive FAT)"); + printf ("(RAMdrive FAT, 9 MB)"); } else if (dmAssignedOp[dmCursorPosition] == 6) { printf ("[ram2:] RAMDRIVE\n"); - printf ("(RAMdrive FAT)"); + printf ("(RAMdrive FAT, 16 MB)"); } } diff --git a/arm9/source/driveOperations.cpp b/arm9/source/driveOperations.cpp index 5bedb10..7a67155 100644 --- a/arm9/source/driveOperations.cpp +++ b/arm9/source/driveOperations.cpp @@ -31,8 +31,45 @@ int nitroCurrentDrive = 0; char sdLabel[12]; char fatLabel[12]; -int sdSize = 0; -int fatSize = 0; +u64 sdSize = 0; +u64 fatSize = 0; + +static int getGbNumber(u64 bytes) { + int gbNumber = 0; + for (u64 i = 0; i <= bytes; i += 0x40000000) { + gbNumber++; + } + return gbNumber; +} + +static int getTbNumber(u64 bytes) { + int tbNumber = 0; + for (u64 i = 0; i <= bytes; i += 0x10000000000) { + tbNumber++; + } + return tbNumber; +} + +void printDriveBytes(u64 bytes) +{ + if (bytes == 1) + iprintf("%d Byte", (int)bytes); + + else if (bytes >= 0 && bytes < 1024) + iprintf("%d Bytes", (int)bytes); + + else if (bytes >= 1024 && bytes < (1024 * 1024)) + printf("%d KB", (int)bytes / 1024); + + else if (bytes >= (1024 * 1024) && bytes < (1024 * 1024 * 1024)) + printf("%d MB", (int)bytes / 1024 / 1024); + + else if (bytes >= 0x40000000 && bytes < 0x10000000000) + printf("%d GB", getGbNumber(bytes)); + + else + printf("%d TB", getTbNumber(bytes)); +} const char* getDrivePath(void) { switch (currentDrive) { @@ -45,6 +82,7 @@ const char* getDrivePath(void) { case 3: return "ram2:/"; } + return ""; } void fixLabel(bool fat) { @@ -99,10 +137,10 @@ TWL_CODE bool sdMount(void) { sdMountedDone = true; fatGetVolumeLabel("sd", sdLabel); fixLabel(false); - /*struct statvfs st; + struct statvfs st; if (statvfs("sd:/", &st) == 0) { sdSize = st.f_bsize * st.f_blocks; - }*/ + } return true; } return false; @@ -238,10 +276,10 @@ TWL_CODE bool twl_flashcardMount(void) { if (flashcardFound()) { fatGetVolumeLabel("fat", fatLabel); fixLabel(true); - /*struct statvfs st; + struct statvfs st; if (statvfs("fat:/", &st) == 0) { fatSize = st.f_bsize * st.f_blocks; - }*/ + } return true; } } @@ -254,10 +292,10 @@ bool flashcardMount(void) { if (flashcardFound()) { fatGetVolumeLabel("fat", fatLabel); fixLabel(true); - /*struct statvfs st; + struct statvfs st; if (statvfs("fat:/", &st) == 0) { fatSize = st.f_bsize * st.f_blocks; - }*/ + } return true; } return false; diff --git a/arm9/source/driveOperations.h b/arm9/source/driveOperations.h index 1dd8a42..e92e609 100644 --- a/arm9/source/driveOperations.h +++ b/arm9/source/driveOperations.h @@ -16,8 +16,9 @@ extern int nitroCurrentDrive; extern char sdLabel[12]; extern char fatLabel[12]; -extern int sdSize; -extern int fatSize; +extern u64 sdSize; +extern u64 fatSize; +extern void printDriveBytes(u64 bytes); extern const char* getDrivePath(void); diff --git a/arm9/source/fileOperations.cpp b/arm9/source/fileOperations.cpp index fa0ea3a..fc9e45a 100644 --- a/arm9/source/fileOperations.cpp +++ b/arm9/source/fileOperations.cpp @@ -25,6 +25,24 @@ int clipboardDrive = false; // 0 == SD card, 1 == Flashcard, 2 == RAMdrive 1, 3 bool clipboardInNitro = false; void printBytes(int bytes) +{ + if (bytes == 1) + iprintf("%d Byte", bytes); + + else if (bytes < 1024) + iprintf("%d Bytes", bytes); + + else if (bytes < (1024 * 1024)) + printf("%d KB", bytes / 1024); + + else if (bytes < (1024 * 1024 * 1024)) + printf("%d MB", bytes / 1024 / 1024); + + else + printf("%d GB", bytes / 1024 / 1024 / 1024); +} + +void printBytesAlign(int bytes) { if (bytes == 1) iprintf("%4d Byte", bytes); @@ -32,10 +50,10 @@ void printBytes(int bytes) else if (bytes < 1024) iprintf("%3d Bytes", bytes); - else if (bytes < 1024 * 1024) + else if (bytes < (1024 * 1024)) printf("%6d KB", bytes / 1024); - else if (bytes < 1024 * 1024 * 1024) + else if (bytes < (1024 * 1024 * 1024)) printf("%6d MB", bytes / 1024 / 1024); else diff --git a/arm9/source/fileOperations.h b/arm9/source/fileOperations.h index 4d4c370..63d9055 100644 --- a/arm9/source/fileOperations.h +++ b/arm9/source/fileOperations.h @@ -14,6 +14,7 @@ extern int clipboardDrive; // 0 == SD card, 1 == Flashcard, 2 == RAMdrive 1, 3 = extern bool clipboardInNitro; extern void printBytes(int bytes); +extern void printBytesAlign(int bytes); extern off_t getFileSize(const char *fileName); extern int fcopy(const char *sourcePath, const char *destinationPath); diff --git a/arm9/source/file_browse.cpp b/arm9/source/file_browse.cpp index 9b50332..ab0d484 100644 --- a/arm9/source/file_browse.cpp +++ b/arm9/source/file_browse.cpp @@ -181,7 +181,7 @@ void showDirectoryContents (const vector& dirContents, int fileOffset, printf ("(dir)"); } else { printf ("\x1b[%d;23H", i + ENTRIES_START_ROW); - printBytes((int)entry->size); + printBytesAlign((int)entry->size); } } diff --git a/arm9/source/file_browse.h b/arm9/source/file_browse.h index f8bd661..f189950 100644 --- a/arm9/source/file_browse.h +++ b/arm9/source/file_browse.h @@ -29,7 +29,7 @@ using namespace std; struct DirEntry { string name; - off_t size; + size_t size; bool isDirectory; bool isApp; } ;