1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-26 05:42:07 +00:00

Add fs functions: Rewrite should be done

This commit is contained in:
Such Meme, Many Skill 2020-04-01 00:41:55 +02:00
parent 0e39c8dda9
commit 0e60746179
2 changed files with 97 additions and 15 deletions

View file

@ -23,22 +23,22 @@ int fsact_copy(const char *locin, const char *locout, u8 options){
if (!strcmp(locin, locout)){ if (!strcmp(locin, locout)){
gfx_errDisplay("copy", ERR_SAME_LOC, 1); gfx_errDisplay("copy", ERR_SAME_LOC, 1);
return -1; return 1;
} }
if ((res = f_open(&in, locin, FA_READ | FA_OPEN_EXISTING))){ if ((res = f_open(&in, locin, FA_READ | FA_OPEN_EXISTING))){
gfx_errDisplay("copy", res, 2); gfx_errDisplay("copy", res, 2);
return -1; return 1;
} }
if (f_stat(locin, &in_info)){ if (f_stat(locin, &in_info)){
gfx_errDisplay("copy", res, 3); gfx_errDisplay("copy", res, 3);
return -1; return 1;
} }
if (f_open(&out, locout, FA_CREATE_ALWAYS | FA_WRITE)){ if (f_open(&out, locout, FA_CREATE_ALWAYS | FA_WRITE)){
gfx_errDisplay("copy", res, 4); gfx_errDisplay("copy", res, 4);
return -1; return 1;
} }
buff = malloc (BUFSIZE); buff = malloc (BUFSIZE);
@ -48,17 +48,17 @@ int fsact_copy(const char *locin, const char *locout, u8 options){
while (sizeoffile > 0){ while (sizeoffile > 0){
if ((res = f_read(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp1))){ if ((res = f_read(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp1))){
gfx_errDisplay("copy", res, 5); gfx_errDisplay("copy", res, 5);
return -1; return 1;
} }
if ((res = f_write(&out, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp2))){ if ((res = f_write(&out, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp2))){
gfx_errDisplay("copy", res, 6); gfx_errDisplay("copy", res, 6);
return -1; return 1;
} }
if (temp1 != temp2){ if (temp1 != temp2){
gfx_errDisplay("copy", ERR_DISK_WRITE_FAILED, 7); gfx_errDisplay("copy", ERR_DISK_WRITE_FAILED, 7);
return -1; return 1;
} }
sizeoffile -= temp1; sizeoffile -= temp1;
@ -84,7 +84,7 @@ int fsact_copy(const char *locin, const char *locout, u8 options){
if ((res = f_chmod(locout, in_info.fattrib, 0x3A))){ if ((res = f_chmod(locout, in_info.fattrib, 0x3A))){
gfx_errDisplay("copy", res, 8); gfx_errDisplay("copy", res, 8);
return -1; return 1;
} }
f_stat(locin, &in_info); //somehow stops fatfs from being weird f_stat(locin, &in_info); //somehow stops fatfs from being weird
@ -103,7 +103,7 @@ int fsact_del_recursive(char *path){
if ((res = f_opendir(&dir, localpath))){ if ((res = f_opendir(&dir, localpath))){
gfx_errDisplay("del_recursive", res, 1); gfx_errDisplay("del_recursive", res, 1);
return -1; return 1;
} }
while (!f_readdir(&dir, &fno) && fno.fname[0]){ while (!f_readdir(&dir, &fno) && fno.fname[0]){
@ -117,7 +117,7 @@ int fsact_del_recursive(char *path){
if ((res = f_unlink(fsutil_getnextloc(localpath, fno.fname)))){ if ((res = f_unlink(fsutil_getnextloc(localpath, fno.fname)))){
gfx_errDisplay("del_recursive", res, 2); gfx_errDisplay("del_recursive", res, 2);
return -1; return 1;
} }
} }
} }
@ -126,7 +126,7 @@ int fsact_del_recursive(char *path){
if ((res = f_unlink(localpath))){ if ((res = f_unlink(localpath))){
gfx_errDisplay("del_recursive", res, 3); gfx_errDisplay("del_recursive", res, 3);
return -1; return 1;
} }
free(localpath); free(localpath);
@ -148,7 +148,7 @@ int fsact_copy_recursive(char *path, char *dstpath){
if ((res = f_opendir(&dir, startpath))){ if ((res = f_opendir(&dir, startpath))){
gfx_errDisplay("copy_recursive", res, 1); gfx_errDisplay("copy_recursive", res, 1);
return -1; return 1;
} }
f_mkdir(destpath); f_mkdir(destpath);
@ -166,7 +166,7 @@ int fsact_copy_recursive(char *path, char *dstpath){
if ((res = fsact_copy(temp, fsutil_getnextloc(destpath, fno.fname), COPY_MODE_PRINT))){ if ((res = fsact_copy(temp, fsutil_getnextloc(destpath, fno.fname), COPY_MODE_PRINT))){
gfx_errDisplay("copy_recursive", res, 2); gfx_errDisplay("copy_recursive", res, 2);
return -1; return 1;
} }
free(temp); free(temp);
@ -177,12 +177,12 @@ int fsact_copy_recursive(char *path, char *dstpath){
if ((res = (f_stat(startpath, &fno)))){ if ((res = (f_stat(startpath, &fno)))){
gfx_errDisplay("copy_recursive", res, 3); gfx_errDisplay("copy_recursive", res, 3);
return -1; return 1;
} }
if ((res = f_chmod(destpath, fno.fattrib, 0x3A))){ if ((res = f_chmod(destpath, fno.fattrib, 0x3A))){
gfx_errDisplay("copy_recursive", res, 4); gfx_errDisplay("copy_recursive", res, 4);
return -1; return 1;
} }
free(startpath); free(startpath);

View file

@ -18,6 +18,7 @@
#include "functions.h" #include "functions.h"
#include "../fs/fsutils.h" #include "../fs/fsutils.h"
#include "../../utils/sprintf.h" #include "../../utils/sprintf.h"
#include "../fs/fsactions.h"
extern FIL scriptin; extern FIL scriptin;
extern char **argv; extern char **argv;
@ -287,6 +288,81 @@ int part_Exit(){
return 0; return 0;
} }
int part_fs_Move(){
char *left, *right;
if (parseStringInput(argv[0], &left))
return -1;
if (parseStringInput(argv[1], &right))
return -1;
int res;
res = f_rename(left, right);
if (res)
res = f_rename(left, right);
return res;
}
int part_fs_Delete(){
char *arg;
if (parseStringInput(argv[0], &arg))
return -1;
int res;
res = f_unlink(arg);
if (res)
res = f_unlink(arg);
return res;
}
int part_fs_DeleteRecursive(){
char *arg;
if (parseStringInput(argv[0], &arg))
return -1;
return fsact_del_recursive(arg);
}
int part_fs_Copy(){
char *left, *right;
if (parseStringInput(argv[0], &left))
return -1;
if (parseStringInput(argv[1], &right))
return -1;
return fsact_copy(left, right, COPY_MODE_PRINT);
}
int part_fs_CopyRecursive(){
char *left, *right;
if (parseStringInput(argv[0], &left))
return -1;
if (parseStringInput(argv[1], &right))
return -1;
return fsact_copy_recursive(left, right);
}
int part_fs_MakeDir(){
char *arg;
if (parseStringInput(argv[0], &arg))
return -1;
int res;
res = f_mkdir(arg);
if (res)
res = f_mkdir(arg);
return res;
}
str_fnc_struct functions[] = { str_fnc_struct functions[] = {
{"printf", part_printf, 1}, {"printf", part_printf, 1},
{"printInt", part_print_int, 1}, {"printInt", part_print_int, 1},
@ -301,6 +377,12 @@ str_fnc_struct functions[] = {
{"combineStrings", part_addstrings, 3}, {"combineStrings", part_addstrings, 3},
{"invert", part_invert, 1}, {"invert", part_invert, 1},
{"fs_exists", part_fs_exists, 1}, {"fs_exists", part_fs_exists, 1},
{"fs_move", part_fs_Move, 2},
{"fs_mkdir", part_fs_MakeDir, 1},
{"fs_del", part_fs_Delete, 1},
{"fs_delRecursive", part_fs_DeleteRecursive, 1},
{"fs_copy", part_fs_Copy, 2},
{"fs_copyRecursive", part_fs_CopyRecursive, 2},
{"mmc_connect", part_ConnectMMC, 1}, {"mmc_connect", part_ConnectMMC, 1},
{"mmc_mount", part_MountMMC, 1}, {"mmc_mount", part_MountMMC, 1},
{"pause", part_Pause, 0}, {"pause", part_Pause, 0},