1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-26 13:52:06 +00:00

Begone lag! (+ begone big bad overflows)

This commit is contained in:
Such Meme, Many Skill 2019-08-16 23:57:54 +02:00
parent 45eb25270f
commit 819d08415d
2 changed files with 47 additions and 19 deletions

View file

@ -56,7 +56,7 @@ void meme_clearscreen(){
gfx_printf("%k%pTegraExplorer, by SuchMemeManySkill\n%k%p", COLOR_DEFAULT, COLOR_WHITE, COLOR_WHITE, COLOR_DEFAULT); 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]; char temp[39];
int i = 0; int i = 0;
int ret = 0; int ret = 0;
@ -73,14 +73,10 @@ void _printwithhighlight(int offset, int folderamount, char *items[], int highli
ret = ret - 1; ret = ret - 1;
} }
gfx_con.x = 720 - (16 * 7); gfx_con.x = 720 - (16 * 6);
if (!(muhbits[i + offset] & OPTION1)) { //should change later if (!(muhbits[i + offset] & OPTION1)) { //should change later
char temp[6]; char temp[6];
char temppath[PATHSIZE]; return_readable_byte_amounts(filesizes[i + offset], temp);
strcpy(temppath, path);
strcat(temppath, "/");
strcat(temppath, items[i + offset]);
return_readable_byte_amounts(getfilesize(temppath), temp);
gfx_printf("%s", temp); gfx_printf("%s", temp);
} }
i++; i++;
@ -93,12 +89,26 @@ int fileexplorergui(char *items[], unsigned int *muhbits, const char path[], int
int sleepvalue = 300; int sleepvalue = 300;
int offset = 0; int offset = 0;
char temp[43]; 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); _copystring(temp, path, 43);
gfx_con_setpos(0, 16);
gfx_printf("%k%s\n%k", COLOR_GREEN, temp, COLOR_WHITE); gfx_printf("%k%s\n%k", COLOR_GREEN, temp, COLOR_WHITE);
while(1){ while(1){
if (change){ if (change){
_printwithhighlight(offset, folderamount, items, select, muhbits, path); _printwithhighlight(offset, folderamount, items, select, muhbits, filesizes);
change = false; change = false;
msleep(sleepvalue); msleep(sleepvalue);
} }
@ -128,5 +138,6 @@ int fileexplorergui(char *items[], unsigned int *muhbits, const char path[], int
if (sleepvalue < 30) sleepvalue = 30; if (sleepvalue < 30) sleepvalue = 30;
} }
int ret = select + offset; int ret = select + offset;
free(filesizes);
return ret; return ret;
} }

View file

@ -8,6 +8,7 @@
#include "utils.h" #include "utils.h"
#include "../libs/fatfs/ff.h" #include "../libs/fatfs/ff.h"
#include "../storage/sdmmc.h" #include "../storage/sdmmc.h"
#include "graphics.h"
void utils_gfx_init(){ void utils_gfx_init(){
display_backlight_brightness(100, 1000); display_backlight_brightness(100, 1000);
@ -29,9 +30,8 @@ void addpartpath(char *path, char *add){
void return_readable_byte_amounts(int size, char *in){ void return_readable_byte_amounts(int size, char *in){
char type[3]; char type[3];
int sizetemp = size; unsigned long int sizetemp = size;
int muhbytes = 0; int muhbytes = 0;
strcpy(type, "B");
while(sizetemp > 1024){ while(sizetemp > 1024){
muhbytes++; muhbytes++;
sizetemp = sizetemp / 1024; sizetemp = sizetemp / 1024;
@ -47,6 +47,9 @@ void return_readable_byte_amounts(int size, char *in){
case 2: case 2:
strcpy(type, "MB"); strcpy(type, "MB");
break; break;
case 3:
strcpy(type, "GB");
break;
default: default:
strcpy(type, "GB"); strcpy(type, "GB");
break; break;
@ -109,30 +112,39 @@ int readfolder(char *items[], unsigned int *muhbits, const char *path){
int copy(const char *src, const char *dst){ int copy(const char *src, const char *dst){
FIL in; FIL in;
FIL out; 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){ if (f_open(&in, src, FA_READ) != FR_OK){
//something has gone wrong //something has gone wrong
return 0; return 1;
} }
if (f_open(&out, dst, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK){ if (f_open(&out, dst, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK){
//something has gone wrong //something has gone wrong
return 0; return 1;
} }
int BUFFSIZ = 32768; int BUFFSIZ = 32768;
u64 size = f_size(&in); u64 size = f_size(&in);
unsigned long totalsize = size, kbwritten = 0;
void *buff = malloc(BUFFSIZ); void *buff = malloc(BUFFSIZ);
int kbwritten = 0; int mbwritten = 0, percentage = 0;
gfx_printf("%d\n", size); bool abort = false;
meme_clearscreen();
gfx_printf("press VOL- to abort the file transfer!\n\n");
while(size > BUFFSIZ){ while(size > BUFFSIZ){
int res1, res2; int res1, res2;
res1 = f_read(&in, buff, BUFFSIZ, NULL); res1 = f_read(&in, buff, BUFFSIZ, NULL);
res2 = f_write(&out, 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; size = size - BUFFSIZ;
if (btn_read() & BTN_VOL_DOWN) size = 0, abort = true;
} }
if(size != 0){ if(size != 0){
@ -143,9 +155,14 @@ int copy(const char *src, const char *dst){
f_close(&in); f_close(&in);
f_close(&out); f_close(&out);
if(abort){
f_unlink(dst);
}
free(buff); free(buff);
return 1; return 0;
} }
int copywithpath(const char *src, const char *dstpath, int mode){ int copywithpath(const char *src, const char *dstpath, int mode){