Display drive sizes

This commit is contained in:
RocketRobz 2020-02-04 21:40:19 -07:00
parent aebb7f1e91
commit fcf1dfa3c3
7 changed files with 80 additions and 24 deletions

View File

@ -170,19 +170,17 @@ void dm_drawBottomScreen(void) {
if (sdLabel[0] != '\0') { if (sdLabel[0] != '\0') {
iprintf (" (%s)", sdLabel); iprintf (" (%s)", sdLabel);
} }
printf ("\n(SD FAT)"); printf ("\n(SD FAT, ");
//printf ("\n(SD FAT, "); printDriveBytes(sdSize);
//printBytes(sdSize); printf(")");
//printf(")");
} else if (dmAssignedOp[dmCursorPosition] == 1) { } else if (dmAssignedOp[dmCursorPosition] == 1) {
printf ("[fat:] FLASHCART"); printf ("[fat:] FLASHCART");
if (fatLabel[0] != '\0') { if (fatLabel[0] != '\0') {
iprintf (" (%s)", fatLabel); iprintf (" (%s)", fatLabel);
} }
printf ("\n(Slot-1 SD FAT)"); printf ("\n(Slot-1 SD FAT, ");
//printf ("\n(Slot-1 SD FAT, "); printDriveBytes(fatSize);
//printBytes(fatSize); printf(")");
//printf(")");
} else if (dmAssignedOp[dmCursorPosition] == 2) { } else if (dmAssignedOp[dmCursorPosition] == 2) {
printf ("GBA GAMECART\n"); printf ("GBA GAMECART\n");
printf ("(GBA Game)"); printf ("(GBA Game)");
@ -194,10 +192,10 @@ void dm_drawBottomScreen(void) {
printf ("(NDS Game)"); printf ("(NDS Game)");
} else if (dmAssignedOp[dmCursorPosition] == 5) { } else if (dmAssignedOp[dmCursorPosition] == 5) {
printf ("[ram1:] RAMDRIVE\n"); printf ("[ram1:] RAMDRIVE\n");
printf ("(RAMdrive FAT)"); printf ("(RAMdrive FAT, 9 MB)");
} else if (dmAssignedOp[dmCursorPosition] == 6) { } else if (dmAssignedOp[dmCursorPosition] == 6) {
printf ("[ram2:] RAMDRIVE\n"); printf ("[ram2:] RAMDRIVE\n");
printf ("(RAMdrive FAT)"); printf ("(RAMdrive FAT, 16 MB)");
} }
} }

View File

@ -31,8 +31,45 @@ int nitroCurrentDrive = 0;
char sdLabel[12]; char sdLabel[12];
char fatLabel[12]; char fatLabel[12];
int sdSize = 0; u64 sdSize = 0;
int fatSize = 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) { const char* getDrivePath(void) {
switch (currentDrive) { switch (currentDrive) {
@ -45,6 +82,7 @@ const char* getDrivePath(void) {
case 3: case 3:
return "ram2:/"; return "ram2:/";
} }
return "";
} }
void fixLabel(bool fat) { void fixLabel(bool fat) {
@ -99,10 +137,10 @@ TWL_CODE bool sdMount(void) {
sdMountedDone = true; sdMountedDone = true;
fatGetVolumeLabel("sd", sdLabel); fatGetVolumeLabel("sd", sdLabel);
fixLabel(false); fixLabel(false);
/*struct statvfs st; struct statvfs st;
if (statvfs("sd:/", &st) == 0) { if (statvfs("sd:/", &st) == 0) {
sdSize = st.f_bsize * st.f_blocks; sdSize = st.f_bsize * st.f_blocks;
}*/ }
return true; return true;
} }
return false; return false;
@ -238,10 +276,10 @@ TWL_CODE bool twl_flashcardMount(void) {
if (flashcardFound()) { if (flashcardFound()) {
fatGetVolumeLabel("fat", fatLabel); fatGetVolumeLabel("fat", fatLabel);
fixLabel(true); fixLabel(true);
/*struct statvfs st; struct statvfs st;
if (statvfs("fat:/", &st) == 0) { if (statvfs("fat:/", &st) == 0) {
fatSize = st.f_bsize * st.f_blocks; fatSize = st.f_bsize * st.f_blocks;
}*/ }
return true; return true;
} }
} }
@ -254,10 +292,10 @@ bool flashcardMount(void) {
if (flashcardFound()) { if (flashcardFound()) {
fatGetVolumeLabel("fat", fatLabel); fatGetVolumeLabel("fat", fatLabel);
fixLabel(true); fixLabel(true);
/*struct statvfs st; struct statvfs st;
if (statvfs("fat:/", &st) == 0) { if (statvfs("fat:/", &st) == 0) {
fatSize = st.f_bsize * st.f_blocks; fatSize = st.f_bsize * st.f_blocks;
}*/ }
return true; return true;
} }
return false; return false;

View File

@ -16,8 +16,9 @@ extern int nitroCurrentDrive;
extern char sdLabel[12]; extern char sdLabel[12];
extern char fatLabel[12]; extern char fatLabel[12];
extern int sdSize; extern u64 sdSize;
extern int fatSize; extern u64 fatSize;
extern void printDriveBytes(u64 bytes);
extern const char* getDrivePath(void); extern const char* getDrivePath(void);

View File

@ -25,6 +25,24 @@ int clipboardDrive = false; // 0 == SD card, 1 == Flashcard, 2 == RAMdrive 1, 3
bool clipboardInNitro = false; bool clipboardInNitro = false;
void printBytes(int bytes) 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) if (bytes == 1)
iprintf("%4d Byte", bytes); iprintf("%4d Byte", bytes);
@ -32,10 +50,10 @@ void printBytes(int bytes)
else if (bytes < 1024) else if (bytes < 1024)
iprintf("%3d Bytes", bytes); iprintf("%3d Bytes", bytes);
else if (bytes < 1024 * 1024) else if (bytes < (1024 * 1024))
printf("%6d KB", bytes / 1024); printf("%6d KB", bytes / 1024);
else if (bytes < 1024 * 1024 * 1024) else if (bytes < (1024 * 1024 * 1024))
printf("%6d MB", bytes / 1024 / 1024); printf("%6d MB", bytes / 1024 / 1024);
else else

View File

@ -14,6 +14,7 @@ extern int clipboardDrive; // 0 == SD card, 1 == Flashcard, 2 == RAMdrive 1, 3 =
extern bool clipboardInNitro; extern bool clipboardInNitro;
extern void printBytes(int bytes); extern void printBytes(int bytes);
extern void printBytesAlign(int bytes);
extern off_t getFileSize(const char *fileName); extern off_t getFileSize(const char *fileName);
extern int fcopy(const char *sourcePath, const char *destinationPath); extern int fcopy(const char *sourcePath, const char *destinationPath);

View File

@ -181,7 +181,7 @@ void showDirectoryContents (const vector<DirEntry>& dirContents, int fileOffset,
printf ("(dir)"); printf ("(dir)");
} else { } else {
printf ("\x1b[%d;23H", i + ENTRIES_START_ROW); printf ("\x1b[%d;23H", i + ENTRIES_START_ROW);
printBytes((int)entry->size); printBytesAlign((int)entry->size);
} }
} }

View File

@ -29,7 +29,7 @@ using namespace std;
struct DirEntry { struct DirEntry {
string name; string name;
off_t size; size_t size;
bool isDirectory; bool isDirectory;
bool isApp; bool isApp;
} ; } ;