Small optimizations
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "../script/parser.h"
|
||||
#include "../emmc/emmcoperations.h"
|
||||
#include "../../hid/hid.h"
|
||||
#include "../utils/menuUtils.h"
|
||||
|
||||
extern char *currentpath;
|
||||
extern char *clipboard;
|
||||
@@ -120,38 +121,42 @@ void copyfile(const char *src_in, const char *outfolder){
|
||||
|
||||
int filemenu(menu_entry file){
|
||||
int temp;
|
||||
FILINFO attribs;
|
||||
char *tempchar;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
/*
|
||||
for (int i = 0; i < 2; i++)
|
||||
if (fs_menu_file[i].name != NULL)
|
||||
free(fs_menu_file[i].name);
|
||||
|
||||
utils_copystring(file.name, &fs_menu_file[0].name);
|
||||
*/
|
||||
mu_copySingle(file.name, fs_menu_file[0].storage, fs_menu_file[0].property, &fs_menu_file[0]);
|
||||
|
||||
|
||||
if (fs_menu_file[1].name != NULL)
|
||||
free(fs_menu_file[1].name);
|
||||
|
||||
fs_menu_file[1].name = malloc(16);
|
||||
fs_menu_file[2].name = malloc(16);
|
||||
|
||||
for (temp = 4; temp < 8; temp++)
|
||||
if ((file.property & (1 << temp)))
|
||||
break;
|
||||
sprintf(fs_menu_file[1].name, "\nSize: %d %s", file.storage, gfx_file_size_names[file.size]);
|
||||
|
||||
|
||||
sprintf(fs_menu_file[1].name, "\nSize: %d %s", file.storage, gfx_file_size_names[temp - 4]);
|
||||
|
||||
if (f_stat(fsutil_getnextloc(currentpath, file.name), &attribs))
|
||||
SETBIT(fs_menu_file[2].property, ISHIDE, 1);
|
||||
if ((tempchar = fsutil_formatFileAttribs(fsutil_getnextloc(currentpath, file.name))) == NULL)
|
||||
fs_menu_file[2].isHide = 1;
|
||||
else {
|
||||
SETBIT(fs_menu_file[2].property, ISHIDE, 0);
|
||||
sprintf(fs_menu_file[2].name, "Attribs: %c%c%c%c",
|
||||
(attribs.fattrib & AM_RDO) ? 'R' : '-',
|
||||
(attribs.fattrib & AM_SYS) ? 'S' : '-',
|
||||
(attribs.fattrib & AM_HID) ? 'H' : '-',
|
||||
(attribs.fattrib & AM_ARC) ? 'A' : '-');
|
||||
fs_menu_file[2].isHide = 0;
|
||||
mu_copySingle(tempchar, fs_menu_file[2].storage, fs_menu_file[2].property, &fs_menu_file[2]);
|
||||
}
|
||||
|
||||
fs_menu_file[6].isHide = !hidConnected();
|
||||
fs_menu_file[8].isHide = (!(strstr(file.name, ".bin") != NULL && file.size == 1) && strstr(file.name, ".rom") == NULL);
|
||||
fs_menu_file[9].isHide = (strstr(file.name, ".te") == NULL);
|
||||
fs_menu_file[11].isHide = (strstr(file.name, ".bis") == NULL);
|
||||
|
||||
/*
|
||||
SETBIT(fs_menu_file[6].property, ISHIDE, !hidConnected());
|
||||
SETBIT(fs_menu_file[8].property, ISHIDE, !(strstr(file.name, ".bin") != NULL && file.property & ISKB) && strstr(file.name, ".rom") == NULL);
|
||||
SETBIT(fs_menu_file[8].property, ISHIDE, !(strstr(file.name, ".bin") != NULL && file.size == 1) && strstr(file.name, ".rom") == NULL);
|
||||
SETBIT(fs_menu_file[9].property, ISHIDE, strstr(file.name, ".te") == NULL);
|
||||
SETBIT(fs_menu_file[11].property, ISHIDE, strstr(file.name, ".bis") == NULL);
|
||||
*/
|
||||
|
||||
temp = menu_make(fs_menu_file, 12, "-- File Menu --");
|
||||
switch (temp){
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "../../utils/sprintf.h"
|
||||
#include "../utils/utils.h"
|
||||
#include "../../hid/hid.h"
|
||||
#include "../utils/menuUtils.h"
|
||||
|
||||
extern char *currentpath;
|
||||
extern char *clipboard;
|
||||
@@ -42,21 +43,23 @@ void copyfolder(char *in, char *out){
|
||||
int foldermenu(){
|
||||
int res, hidConn;
|
||||
char *name;
|
||||
FILINFO attribs;
|
||||
|
||||
if (fs_menu_folder[0].name != NULL)
|
||||
free(fs_menu_folder[0].name);
|
||||
|
||||
fs_menu_folder[0].name = malloc(16);
|
||||
|
||||
hidConn = hidConnected();
|
||||
|
||||
res = strlen(currentpath);
|
||||
|
||||
fs_menu_folder[3].isHide = (*(currentpath + res - 1) == '/');
|
||||
fs_menu_folder[4].isHide = (*(currentpath + res - 1) == '/');
|
||||
fs_menu_folder[5].isHide = (*(currentpath + res - 1) == '/' || !hidConn);
|
||||
fs_menu_folder[6].isHide = !hidConn;
|
||||
|
||||
/*
|
||||
|
||||
SETBIT(fs_menu_folder[3].property, ISHIDE, (*(currentpath + res - 1) == '/'));
|
||||
SETBIT(fs_menu_folder[4].property, ISHIDE, (*(currentpath + res - 1) == '/'));
|
||||
SETBIT(fs_menu_folder[5].property, ISHIDE, (*(currentpath + res - 1) == '/') || !hidConn);
|
||||
SETBIT(fs_menu_folder[6].property, ISHIDE, !hidConn);
|
||||
|
||||
|
||||
if (f_stat(currentpath, &attribs))
|
||||
SETBIT(fs_menu_folder[0].property, ISHIDE, 1);
|
||||
else {
|
||||
@@ -67,6 +70,17 @@ int foldermenu(){
|
||||
(attribs.fattrib & AM_HID) ? 'H' : '-',
|
||||
(attribs.fattrib & AM_ARC) ? 'A' : '-');
|
||||
}
|
||||
*/
|
||||
|
||||
if ((name = fsutil_formatFileAttribs(currentpath)) == NULL){
|
||||
fs_menu_folder[0].isHide = 1;
|
||||
}
|
||||
else {
|
||||
fs_menu_folder[0].isHide = 0;
|
||||
mu_copySingle(name, fs_menu_folder[0].storage, fs_menu_folder[0].property, &fs_menu_folder[0]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
res = menu_make(fs_menu_folder, 7, currentpath);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "../common/common.h"
|
||||
#include "../../libs/fatfs/ff.h"
|
||||
#include "entrymenu.h"
|
||||
#include "../utils/menuUtils.h"
|
||||
|
||||
extern char *currentpath;
|
||||
extern char *clipboard;
|
||||
@@ -35,7 +36,7 @@ void fileexplorer(const char *startpath, int type){
|
||||
*/
|
||||
|
||||
while (1){
|
||||
res = menu_make(fsreader_files, fsutil_getfileobjamount(fsreader_files), currentpath);
|
||||
res = menu_make(fsreader_files, mu_countObjects(fsreader_files, 0), currentpath);
|
||||
switch (res){
|
||||
case FILEMENU_RETURN:
|
||||
if (!strcmp(startpath, currentpath))
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "../gfx/gfxutils.h"
|
||||
#include "../utils/utils.h"
|
||||
#include "../../mem/heap.h"
|
||||
#include "../utils/menuUtils.h"
|
||||
|
||||
menu_entry *fsreader_files = NULL;
|
||||
char *currentpath = NULL;
|
||||
@@ -29,59 +30,16 @@ void fsreader_writeclipboard(const char *in, u8 args){
|
||||
utils_copystring(in, &clipboard);
|
||||
}
|
||||
|
||||
void clearfileobjects(menu_entry **menu){
|
||||
if ((*menu) != NULL){
|
||||
for (int i = 0; (*menu)[i].name != NULL; i++){
|
||||
free((*menu)[i].name);
|
||||
(*menu)[i].name = NULL;
|
||||
}
|
||||
free((*menu));
|
||||
(*menu) = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void createfileobjects(int size, menu_entry **menu){
|
||||
(*menu) = calloc (size + 1, sizeof(menu_entry));
|
||||
(*menu)[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));
|
||||
u8 property = 0;
|
||||
|
||||
if (attribs & AM_DIR)
|
||||
fsreader_files[spot].property |= (ISDIR);
|
||||
else {
|
||||
/*
|
||||
size = fsutil_getfilesize(fsutil_getnextloc(currentpath, name));
|
||||
|
||||
while (size > 1024){
|
||||
size /= 1024;
|
||||
sizes++;
|
||||
}
|
||||
property |= ISDIR;
|
||||
else
|
||||
property |= ISNULL;
|
||||
|
||||
if (sizes > 3)
|
||||
sizes = 0;
|
||||
|
||||
fsreader_files[spot].property |= (1 << (4 + sizes));
|
||||
fsreader_files[spot].storage = size;
|
||||
*/
|
||||
fsreader_files[spot].storage = 0;
|
||||
fsreader_files[spot].property = ISNULL;
|
||||
}
|
||||
|
||||
if (attribs & AM_ARC)
|
||||
fsreader_files[spot].property |= (ISARC);
|
||||
mu_copySingle(name, 0, property, &fsreader_files[spot]);
|
||||
}
|
||||
|
||||
int fsreader_readfolder(const char *path){
|
||||
@@ -89,14 +47,13 @@ int fsreader_readfolder(const char *path){
|
||||
FILINFO fno;
|
||||
int folderamount, res;
|
||||
|
||||
clearfileobjects(&fsreader_files);
|
||||
createfileobjects(fsutil_getfolderentryamount(path) + 3, &fsreader_files);
|
||||
mu_clearObjects(&fsreader_files);
|
||||
mu_createObjects(fsutil_getfolderentryamount(path) + 3, &fsreader_files);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
for (folderamount = 0; folderamount < 3; folderamount++)
|
||||
mu_copySingle(fs_menu_startdir[folderamount].name, fs_menu_startdir[folderamount].storage, fs_menu_startdir[folderamount].property, &fsreader_files[folderamount]);
|
||||
|
||||
if ((res = f_opendir(&dir, path))){
|
||||
gfx_errDisplay("readfolder", res, 0);
|
||||
|
||||
@@ -47,15 +47,6 @@ char *fsutil_getprevloc(char *current){
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fsutil_getfileobjamount(menu_entry *entries){
|
||||
int amount = 0;
|
||||
|
||||
while (entries[amount].name != NULL)
|
||||
amount++;
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
bool fsutil_checkfile(char* path){
|
||||
FRESULT fr;
|
||||
FILINFO fno;
|
||||
@@ -87,4 +78,21 @@ int fsutil_getfolderentryamount(const char *path){
|
||||
|
||||
f_closedir(&dir);
|
||||
return folderamount;
|
||||
}
|
||||
|
||||
char *fsutil_formatFileAttribs(char *path){
|
||||
FILINFO attribs;
|
||||
char *out;
|
||||
out = malloc(16);
|
||||
|
||||
if (f_stat(path, &attribs))
|
||||
return NULL;
|
||||
|
||||
sprintf(out, "Attribs: %c%c%c%c",
|
||||
(attribs.fattrib & AM_RDO) ? 'R' : '-',
|
||||
(attribs.fattrib & AM_SYS) ? 'S' : '-',
|
||||
(attribs.fattrib & AM_HID) ? 'H' : '-',
|
||||
(attribs.fattrib & AM_ARC) ? 'A' : '-');
|
||||
|
||||
return out;
|
||||
}
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
char *fsutil_getnextloc(const char *current, const char *add);
|
||||
char *fsutil_getprevloc(char *current);
|
||||
int fsutil_getfileobjamount(menu_entry *entries);
|
||||
bool fsutil_checkfile(char* path);
|
||||
u64 fsutil_getfilesize(char *path);
|
||||
int fsutil_getfolderentryamount(const char *path);
|
||||
int extract_bis_file(char *path, char *outfolder);
|
||||
int extract_bis_file(char *path, char *outfolder);
|
||||
char *fsutil_formatFileAttribs(char *path);
|
||||
Reference in New Issue
Block a user