mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-26 13:52:06 +00:00
106 lines
No EOL
2.7 KiB
C
106 lines
No EOL
2.7 KiB
C
#include "fsreader.h"
|
|
#include "../common/types.h"
|
|
#include "../common/common.h"
|
|
#include "fsutils.h"
|
|
#include "../../utils/types.h"
|
|
#include "../../libs/fatfs/ff.h"
|
|
#include "../gfx/gfxutils.h"
|
|
#include "../utils/utils.h"
|
|
#include "../../mem/heap.h"
|
|
|
|
menu_entry *fsreader_files = NULL;
|
|
char *currentpath = NULL;
|
|
char *clipboard = NULL;
|
|
u8 clipboardhelper = 0;
|
|
|
|
void fsreader_writecurpath(const char *in){
|
|
if (currentpath != NULL)
|
|
free(currentpath);
|
|
|
|
utils_copystring(in, ¤tpath);
|
|
}
|
|
|
|
void fsreader_writeclipboard(const char *in, u8 args){
|
|
if (clipboard != NULL)
|
|
free(clipboard);
|
|
|
|
clipboardhelper = args;
|
|
|
|
utils_copystring(in, &clipboard);
|
|
}
|
|
|
|
void clearfileobjects(){
|
|
if (fsreader_files != NULL){
|
|
for (int i = 0; fsreader_files[i].name != NULL; i++){
|
|
free(fsreader_files[i].name);
|
|
fsreader_files[i].name = NULL;
|
|
}
|
|
free(fsreader_files);
|
|
fsreader_files = NULL;
|
|
}
|
|
}
|
|
|
|
void createfileobjects(int size){
|
|
fsreader_files = calloc (size + 1, sizeof(menu_entry));
|
|
fsreader_files[size].name = NULL;
|
|
}
|
|
|
|
void addobject(char* name, int spot, u8 attribs){
|
|
u64 size = 0;
|
|
int sizes = 0;
|
|
fsreader_files[spot].property = 0;
|
|
|
|
if (fsreader_files[spot].name != NULL){
|
|
free(fsreader_files[spot].name);
|
|
fsreader_files[spot].name = NULL;
|
|
}
|
|
|
|
utils_copystring(name, &(fsreader_files[spot].name));
|
|
|
|
if (attribs & AM_DIR)
|
|
fsreader_files[spot].property |= (ISDIR);
|
|
else {
|
|
size = fsutil_getfilesize(fsutil_getnextloc(currentpath, name));
|
|
|
|
while (size > 1024){
|
|
size /= 1024;
|
|
sizes++;
|
|
}
|
|
|
|
if (sizes > 3)
|
|
sizes = 0;
|
|
|
|
fsreader_files[spot].property |= (1 << (4 + sizes));
|
|
fsreader_files[spot].storage = size;
|
|
}
|
|
|
|
if (attribs & AM_ARC)
|
|
fsreader_files[spot].property |= (ISARC);
|
|
}
|
|
|
|
int fsreader_readfolder(const char *path){
|
|
DIR dir;
|
|
FILINFO fno;
|
|
int folderamount, res;
|
|
|
|
clearfileobjects();
|
|
createfileobjects(fsutil_getfolderentryamount(path) + 3);
|
|
|
|
for (folderamount = 0; folderamount < 3; folderamount++){
|
|
utils_copystring(fs_menu_startdir[folderamount].name, &(fsreader_files[folderamount].name));
|
|
fsreader_files[folderamount].storage = fs_menu_startdir[folderamount].storage;
|
|
fsreader_files[folderamount].property = fs_menu_startdir[folderamount].property;
|
|
}
|
|
|
|
if ((res = f_opendir(&dir, path))){
|
|
gfx_errDisplay("readfolder", res, 0);
|
|
return -1;
|
|
}
|
|
|
|
while (!f_readdir(&dir, &fno) && fno.fname[0]){
|
|
addobject(fno.fname, folderamount++, fno.fattrib);
|
|
}
|
|
|
|
f_closedir(&dir);
|
|
return folderamount;
|
|
} |