Add folder navigating!

This commit is contained in:
Such Meme, Many Skill
2019-08-15 22:16:48 +02:00
parent 82a941bb13
commit a190a07016
9 changed files with 172 additions and 27 deletions

View File

@@ -15,6 +15,18 @@ void utils_gfx_init(){
gfx_con_setpos(0, 0);
}
void removepartpath(char *path){
char *ret;
ret = strrchr(path, '/');
memset(ret, '\0', 1);
if (strcmp(path, "sd:") == 0) strcpy(path, "sd:/");
}
void addpartpath(char *path, char *add){
if (strcmp(path, "sd:/") != 0) strcat(path, "/");
strcat(path, add);
}
void utils_waitforpower(){
u32 btn = btn_wait();
if (btn & BTN_VOL_UP)
@@ -25,22 +37,36 @@ void utils_waitforpower(){
power_off();
}
int readfolder(char *items[], unsigned int *muhbits, const char path[]){
void _addchartoarray(char *add, char *items[], int spot){
size_t size = strlen(add) + 1;
items[spot] = (char*) malloc (size);
strlcpy(items[spot], add, size);
}
void _mallocandaddfolderbit(unsigned int *muhbits, int spot, bool value){
muhbits[spot] = (unsigned int) malloc (sizeof(int));
if (value) muhbits[spot] |= (OPTION1);
}
int readfolder(char *items[], unsigned int *muhbits, const char *path){
DIR dir;
FILINFO fno;
int i = 0;
int i = 2;
_addchartoarray(".", items, 0);
_addchartoarray("..", items, 1);
_mallocandaddfolderbit(muhbits, 0, true);
_mallocandaddfolderbit(muhbits, 1, true);
if (f_opendir(&dir, path)) {
gfx_printf("\nFailed to open %s", path);
}
else{
else {
while (!f_readdir(&dir, &fno) && fno.fname[0]){
size_t size = strlen(fno.fname) + 1;
items[i] = (char*) malloc (size);
strlcpy(items[i], fno.fname, size);
if (fno.fattrib & AM_DIR) muhbits[i] |= (OPTION1);
_addchartoarray(fno.fname, items, i);
_mallocandaddfolderbit(muhbits, i, fno.fattrib & AM_DIR);
i++;
}
}
f_closedir(&dir);
return i;
}