store SD card size in an unsigned long long

Fixes compatibility with >64GB cards?
This commit is contained in:
JeffRuLz 2018-11-07 21:23:37 -06:00 committed by GitHub
parent aa64efd0e2
commit 370be53528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 30 deletions

View File

@ -307,7 +307,7 @@ void install(Menu* m)
} }
//Print file size //Print file size
int fileSize = -1; unsigned long long fileSize = 0;
{ {
iprintf("File Size: "); iprintf("File Size: ");

View File

@ -2,7 +2,7 @@
#include "menu.h" #include "menu.h"
#include <time.h> #include <time.h>
#define VERSION "0.5.1" #define VERSION "0.5.2"
enum { enum {
MAIN_MENU_INSTALL, MAIN_MENU_INSTALL,
@ -18,6 +18,10 @@ int main(int argc, char **argv)
{ {
srand(time(0)); srand(time(0));
//Setup top screen
REG_DISPCNT = MODE_FB0;
VRAM_A_CR = VRAM_ENABLE;
videoSetMode(MODE_0_2D); videoSetMode(MODE_0_2D);
videoSetModeSub(MODE_0_2D); videoSetModeSub(MODE_0_2D);
@ -30,13 +34,18 @@ int main(int argc, char **argv)
consoleSelect(&bottomScreen); consoleSelect(&bottomScreen);
consoleClear(); consoleClear();
VRAM_A[100] = 0xFFFF;
if (!fatInitDefault()) if (!fatInitDefault())
{ {
consoleSelect(&bottomScreen); consoleSelect(&bottomScreen);
consoleClear(); consoleClear();
iprintf("fatInitDefault...Failed\n"); //iprintf("fatInitDefault...Failed\n");
iprintf("\nPress B to exit.\n"); //iprintf("\nPress B to exit.\n");
for (int i = 0; i < 32*24; i++)
iprintf("%c", i);
keyWait(KEY_B | KEY_A | KEY_START); keyWait(KEY_B | KEY_A | KEY_START);
} }

View File

@ -8,15 +8,15 @@
#define TITLE_LIMIT 39 #define TITLE_LIMIT 39
//Printing //Printing
void printBytes(int bytes) void printBytes(unsigned long long bytes)
{ {
if (abs(bytes) < 1024) if (bytes < 1024)
iprintf("%dB", bytes); iprintf("%dB", (unsigned int)bytes);
else if (abs(bytes) < 1024 * 1024) else if (bytes < 1024 * 1024)
printf("%.2fKB", (float)bytes / 1024); printf("%.2fKB", (float)bytes / 1024);
else if (abs(bytes) < 1024 * 1024 * 1024) else if (bytes < 1024 * 1024 * 1024)
printf("%.2fMB", (float)bytes / 1024 / 1024); printf("%.2fMB", (float)bytes / 1024 / 1024);
else else
@ -209,25 +209,25 @@ int copyFile(const char* in, char* out)
return result; return result;
} }
int getFileSize(FILE* f) unsigned long long getFileSize(FILE* f)
{ {
if (!f) if (!f)
return 0; return 0;
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
int size = ftell(f); unsigned long long size = ftell(f);
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
return size; return size;
} }
int getFileSizePath(const char* path) unsigned long long getFileSizePath(const char* path)
{ {
if (path == NULL) if (path == NULL)
return -1; return -1;
FILE* f = fopen(path, "rb"); FILE* f = fopen(path, "rb");
int size = getFileSize(f); unsigned long long size = getFileSize(f);
fclose(f); fclose(f);
return size; return size;
@ -372,12 +372,12 @@ int deleteDir(const char* path)
return 1; return 1;
} }
int getDirSize(const char* path) unsigned long long getDirSize(const char* path)
{ {
if (path == NULL) if (path == NULL)
return 0; return 0;
int size = 0; unsigned long long size = 0;
DIR* dir; DIR* dir;
struct dirent *ent; struct dirent *ent;
@ -472,7 +472,7 @@ int sdIsInserted()
return 1; return 1;
} }
int getSDCardSize() unsigned long long getSDCardSize()
{ {
if (sdIsInserted()) if (sdIsInserted())
{ {
@ -484,7 +484,7 @@ int getSDCardSize()
return 0; return 0;
} }
int getSDCardFree() unsigned long long getSDCardFree()
{ {
if (sdIsInserted()) if (sdIsInserted())
{ {

View File

@ -9,7 +9,7 @@
#define BYTES_PER_BLOCK (1024*128) #define BYTES_PER_BLOCK (1024*128)
//Printing //Printing
void printBytes(int bytes); void printBytes(unsigned long long bytes);
void printFileInfo(const char* path); void printFileInfo(const char* path);
//Progress bar //Progress bar
@ -18,15 +18,15 @@ void clearProgressBar();
//Files //Files
int copyFile(const char* in, char* out); int copyFile(const char* in, char* out);
int getFileSize(FILE* f); unsigned long long getFileSize(FILE* f);
int getFileSizePath(const char* path); unsigned long long getFileSizePath(const char* path);
int padFile(const char* path, int size); int padFile(const char* path, int size);
//Directories //Directories
int dirExists(const char* path); int dirExists(const char* path);
//int copyDir(const char* in, char* out); //int copyDir(const char* in, char* out);
int deleteDir(const char* path); int deleteDir(const char* path);
int getDirSize(const char* path); unsigned long long getDirSize(const char* path);
//Home menu //Home menu
int getMenuSlots(); int getMenuSlots();
@ -36,8 +36,8 @@ int getMenuSlotsFree();
//SD Card //SD Card
int sdIsInserted(); int sdIsInserted();
int getSDCardSize(); unsigned long long getSDCardSize();
int getSDCardFree(); unsigned long long getSDCardFree();
#define getSDCardUsedSpace() (getSDCardSize() - getSDCardFree()) #define getSDCardUsedSpace() (getSDCardSize() - getSDCardFree())
//Internal storage //Internal storage

View File

@ -12,8 +12,8 @@ void testMenu()
consoleSelect(&bottomScreen); consoleSelect(&bottomScreen);
consoleClear(); consoleClear();
int free = -1; unsigned int free = 0;
int size = -1; unsigned int size = 0;
//Home menu slots //Home menu slots
{ {
@ -30,15 +30,15 @@ void testMenu()
{ {
iprintf("\nFree SD Space:\n\t"); swiWaitForVBlank(); iprintf("\nFree SD Space:\n\t"); swiWaitForVBlank();
free = getSDCardFree(); unsigned long long sdfree = getSDCardFree();
printBytes(free); printBytes(sdfree);
iprintf(" / "); swiWaitForVBlank(); iprintf(" / "); swiWaitForVBlank();
size = getSDCardSize(); unsigned long long sdsize = getSDCardSize();
printBytes(size); printBytes(sdsize);
iprintf("\n"); swiWaitForVBlank(); iprintf("\n"); swiWaitForVBlank();
printf("\t%.0f / %.0f blocks\n", (float)free / BYTES_PER_BLOCK, (float)size / BYTES_PER_BLOCK); printf("\t%d / %d blocks\n", (unsigned int)(sdfree / BYTES_PER_BLOCK), (unsigned int)(sdsize / BYTES_PER_BLOCK));
} }
//Emunand //Emunand