diff --git a/source/meme/graphics.c b/source/meme/graphics.c index a74c8ff..3669118 100644 --- a/source/meme/graphics.c +++ b/source/meme/graphics.c @@ -56,7 +56,7 @@ void meme_clearscreen(){ gfx_printf("%k%pTegraExplorer, by SuchMemeManySkill\n%k%p", COLOR_DEFAULT, COLOR_WHITE, COLOR_WHITE, COLOR_DEFAULT); } -void _printwithhighlight(int offset, int folderamount, char *items[], int highlight, unsigned int *muhbits, const char path[]){ +void _printwithhighlight(int offset, int folderamount, char *items[], int highlight, unsigned int *muhbits, int *filesizes){ char temp[39]; int i = 0; int ret = 0; @@ -73,14 +73,10 @@ void _printwithhighlight(int offset, int folderamount, char *items[], int highli ret = ret - 1; } - gfx_con.x = 720 - (16 * 7); + gfx_con.x = 720 - (16 * 6); if (!(muhbits[i + offset] & OPTION1)) { //should change later char temp[6]; - char temppath[PATHSIZE]; - strcpy(temppath, path); - strcat(temppath, "/"); - strcat(temppath, items[i + offset]); - return_readable_byte_amounts(getfilesize(temppath), temp); + return_readable_byte_amounts(filesizes[i + offset], temp); gfx_printf("%s", temp); } i++; @@ -93,12 +89,26 @@ int fileexplorergui(char *items[], unsigned int *muhbits, const char path[], int int sleepvalue = 300; int offset = 0; char temp[43]; - gfx_con_setpos(0, 16); + int *filesizes; + int i = 0; + filesizes = (int*) calloc(500, sizeof(int)); + gfx_con_setpos(0, 48); + for (i = 0; i < folderamount; i++){ + if(!(muhbits[i] & OPTION1)){ + char temppath[PATHSIZE]; + strcpy(temppath, path); + strcat(temppath, "/"); + strcat(temppath, items[i]); + filesizes[i] = getfilesize(temppath); + gfx_printf("Calcing filesizes: %d / %d\r", i, folderamount - 2); + } + } _copystring(temp, path, 43); + gfx_con_setpos(0, 16); gfx_printf("%k%s\n%k", COLOR_GREEN, temp, COLOR_WHITE); while(1){ if (change){ - _printwithhighlight(offset, folderamount, items, select, muhbits, path); + _printwithhighlight(offset, folderamount, items, select, muhbits, filesizes); change = false; msleep(sleepvalue); } @@ -128,5 +138,6 @@ int fileexplorergui(char *items[], unsigned int *muhbits, const char path[], int if (sleepvalue < 30) sleepvalue = 30; } int ret = select + offset; + free(filesizes); return ret; } \ No newline at end of file diff --git a/source/meme/utils.c b/source/meme/utils.c index d23496f..b88d62a 100644 --- a/source/meme/utils.c +++ b/source/meme/utils.c @@ -8,6 +8,7 @@ #include "utils.h" #include "../libs/fatfs/ff.h" #include "../storage/sdmmc.h" +#include "graphics.h" void utils_gfx_init(){ display_backlight_brightness(100, 1000); @@ -29,9 +30,8 @@ void addpartpath(char *path, char *add){ void return_readable_byte_amounts(int size, char *in){ char type[3]; - int sizetemp = size; + unsigned long int sizetemp = size; int muhbytes = 0; - strcpy(type, "B"); while(sizetemp > 1024){ muhbytes++; sizetemp = sizetemp / 1024; @@ -47,6 +47,9 @@ void return_readable_byte_amounts(int size, char *in){ case 2: strcpy(type, "MB"); break; + case 3: + strcpy(type, "GB"); + break; default: strcpy(type, "GB"); break; @@ -109,30 +112,39 @@ int readfolder(char *items[], unsigned int *muhbits, const char *path){ int copy(const char *src, const char *dst){ FIL in; FIL out; - + if (strcmp(src, dst) == 0){ + //in and out are the same, aborting! + return 2; + } if (f_open(&in, src, FA_READ) != FR_OK){ //something has gone wrong - return 0; + return 1; } if (f_open(&out, dst, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK){ //something has gone wrong - return 0; + return 1; } int BUFFSIZ = 32768; u64 size = f_size(&in); + unsigned long totalsize = size, kbwritten = 0; void *buff = malloc(BUFFSIZ); - int kbwritten = 0; - gfx_printf("%d\n", size); + int mbwritten = 0, percentage = 0; + bool abort = false; + meme_clearscreen(); + gfx_printf("press VOL- to abort the file transfer!\n\n"); while(size > BUFFSIZ){ int res1, res2; res1 = f_read(&in, buff, BUFFSIZ, NULL); res2 = f_write(&out, buff, BUFFSIZ, NULL); - kbwritten = kbwritten + BUFFSIZ; + kbwritten = kbwritten + (BUFFSIZ / 1024); + mbwritten = kbwritten / 1024; + percentage = (mbwritten * 100) / (totalsize / 1024 / 1024); - gfx_printf("Written %d\r", kbwritten); + gfx_printf("Written %dMB [%k%d%k%%]\r", mbwritten, COLOR_GREEN, percentage, COLOR_WHITE); size = size - BUFFSIZ; + if (btn_read() & BTN_VOL_DOWN) size = 0, abort = true; } if(size != 0){ @@ -143,9 +155,14 @@ int copy(const char *src, const char *dst){ f_close(&in); f_close(&out); + if(abort){ + f_unlink(dst); + } + + free(buff); - return 1; + return 0; } int copywithpath(const char *src, const char *dstpath, int mode){