From 0e60746179dcf32699e596453f84520ccd4ca1fa Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Wed, 1 Apr 2020 00:41:55 +0200 Subject: [PATCH] Add fs functions: Rewrite should be done --- source/tegraexplorer/fs/fsactions.c | 30 ++++----- source/tegraexplorer/script/functions.c | 82 +++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 15 deletions(-) diff --git a/source/tegraexplorer/fs/fsactions.c b/source/tegraexplorer/fs/fsactions.c index d193d89..63200aa 100644 --- a/source/tegraexplorer/fs/fsactions.c +++ b/source/tegraexplorer/fs/fsactions.c @@ -23,22 +23,22 @@ int fsact_copy(const char *locin, const char *locout, u8 options){ if (!strcmp(locin, locout)){ gfx_errDisplay("copy", ERR_SAME_LOC, 1); - return -1; + return 1; } if ((res = f_open(&in, locin, FA_READ | FA_OPEN_EXISTING))){ gfx_errDisplay("copy", res, 2); - return -1; + return 1; } if (f_stat(locin, &in_info)){ gfx_errDisplay("copy", res, 3); - return -1; + return 1; } if (f_open(&out, locout, FA_CREATE_ALWAYS | FA_WRITE)){ gfx_errDisplay("copy", res, 4); - return -1; + return 1; } buff = malloc (BUFSIZE); @@ -48,17 +48,17 @@ int fsact_copy(const char *locin, const char *locout, u8 options){ while (sizeoffile > 0){ if ((res = f_read(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp1))){ gfx_errDisplay("copy", res, 5); - return -1; + return 1; } if ((res = f_write(&out, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp2))){ gfx_errDisplay("copy", res, 6); - return -1; + return 1; } if (temp1 != temp2){ gfx_errDisplay("copy", ERR_DISK_WRITE_FAILED, 7); - return -1; + return 1; } 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))){ gfx_errDisplay("copy", res, 8); - return -1; + return 1; } 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))){ gfx_errDisplay("del_recursive", res, 1); - return -1; + return 1; } 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)))){ 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))){ gfx_errDisplay("del_recursive", res, 3); - return -1; + return 1; } free(localpath); @@ -148,7 +148,7 @@ int fsact_copy_recursive(char *path, char *dstpath){ if ((res = f_opendir(&dir, startpath))){ gfx_errDisplay("copy_recursive", res, 1); - return -1; + return 1; } 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))){ gfx_errDisplay("copy_recursive", res, 2); - return -1; + return 1; } free(temp); @@ -177,12 +177,12 @@ int fsact_copy_recursive(char *path, char *dstpath){ if ((res = (f_stat(startpath, &fno)))){ gfx_errDisplay("copy_recursive", res, 3); - return -1; + return 1; } if ((res = f_chmod(destpath, fno.fattrib, 0x3A))){ gfx_errDisplay("copy_recursive", res, 4); - return -1; + return 1; } free(startpath); diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index 241d2c6..8b20886 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -18,6 +18,7 @@ #include "functions.h" #include "../fs/fsutils.h" #include "../../utils/sprintf.h" +#include "../fs/fsactions.h" extern FIL scriptin; extern char **argv; @@ -287,6 +288,81 @@ int part_Exit(){ 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[] = { {"printf", part_printf, 1}, {"printInt", part_print_int, 1}, @@ -301,6 +377,12 @@ str_fnc_struct functions[] = { {"combineStrings", part_addstrings, 3}, {"invert", part_invert, 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_mount", part_MountMMC, 1}, {"pause", part_Pause, 0},