Skip to content

Commit

Permalink
Display storage bar for current mounted device
Browse files Browse the repository at this point in the history
  • Loading branch information
joel16 committed Oct 31, 2018
1 parent e2b19f7 commit f943c2c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/dirbrowse.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ extern int initialPosition;
extern int position;
extern int fileCount;

extern u64 total_storage, used_storage;

int multi_select_index; // Multi-select index.
bool multi_select[256]; // Array of indices selected.
int multi_select_indices[256]; // Array to hold the indices.
Expand Down
4 changes: 3 additions & 1 deletion include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ void Utils_SetMax(int *set, int value, int max);
void Utils_SetMin(int *set, int value, int min);
int Utils_Alphasort(const void *p1, const void *p2);
void Utils_AppendArr(char subject[], const char insert[], int pos);
u64 Utils_GetTotalStorage(FsStorageId storage_id);
u64 Utils_GetUsedStorage(FsStorageId storage_id);

#endif
#endif
2 changes: 2 additions & 0 deletions source/dirbrowse.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ void Dirbrowse_DisplayFiles(void) {
SDL_DrawImage(icon_nav_drawer, 20, 58);
SDL_DrawImage(icon_actions, (1260 - 64), 58);
SDL_DrawText(170, 40 + ((100 - title_height) / 2), 30, WHITE, cwd);
SDL_DrawRect(170, 40 + ((100 - title_height) / 2) + title_height + 10, 940, 6, config.dark_theme? SELECTOR_COLOUR_DARK : FC_MakeColor(10, 73, 163, 255));
SDL_DrawRect(170, 40 + ((100 - title_height) / 2) + title_height + 10, (((double)used_storage/(double)total_storage) * 940.0), 6, config.dark_theme? TITLE_COLOUR_DARK : FC_MakeColor(49, 161, 224, 255));

int i = 0, printed = 0;
File *file = files; // Draw file list
Expand Down
4 changes: 4 additions & 0 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static void Term_Services(void) {
socketExit();
#endif

nsExit();
usbCommsExit();
timeExit();
SDL_HelperTerm();
Expand Down Expand Up @@ -52,6 +53,9 @@ static Result Init_Services(void) {
if (R_FAILED(ret = usbCommsInitialize()))
return ret;

if (R_FAILED(ret = nsInitialize()))
return ret;

#ifdef DEBUG
socketInitializeDefault();
nxlinkStdio();
Expand Down
4 changes: 4 additions & 0 deletions source/menus/menu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define MENUBAR_X_BOUNDARY 0
static float menubar_x = -400.0;
static char multi_select_dir_old[512];
u64 total_storage = 0, used_storage = 0;

void AnimateMenuBar(float delta_time) {
menubar_x += 400.0f * (delta_time * 0.01);
Expand Down Expand Up @@ -194,6 +195,9 @@ void Menu_Main(void) {

u64 current_time = 0, last_time = 0;

total_storage = Utils_GetTotalStorage(FsStorageId_SdCard);
used_storage = Utils_GetUsedStorage(FsStorageId_SdCard);

while(appletMainLoop()) {
last_time = current_time;
current_time = SDL_GetPerformanceCounter();
Expand Down
24 changes: 24 additions & 0 deletions source/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,27 @@ void Utils_AppendArr(char subject[], const char insert[], int pos) {
strcpy(subject, buf); // copy it back to subject
// deallocate buf[] here, if used malloc()
}

u64 Utils_GetTotalStorage(FsStorageId storage_id) {
Result ret = 0;
u64 total = 0;

if (R_FAILED(ret = nsGetTotalSpaceSize(storage_id, &total)))
printf("nsGetFreeSpaceSize() failed: 0x%x.\n\n", ret);

return total;
}

static u64 Utils_GetFreeStorage(FsStorageId storage_id) {
Result ret = 0;
u64 free = 0;

if (R_FAILED(ret = nsGetFreeSpaceSize(storage_id, &free)))
printf("nsGetFreeSpaceSize() failed: 0x%x.\n\n", ret);

return free;
}

u64 Utils_GetUsedStorage(FsStorageId storage_id) {
return (Utils_GetTotalStorage(storage_id) - Utils_GetFreeStorage(storage_id));
}

0 comments on commit f943c2c

Please sign in to comment.