From f4388272630d5bb7b4c5a63ba6ceef7ba4e5c7fb Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Wed, 1 Apr 2020 13:57:25 +0200 Subject: [PATCH] add more functions --- source/tegraexplorer/fs/filemenu.c | 1 + source/tegraexplorer/script/functions.c | 71 ++++++++++++++++++++++++- source/tegraexplorer/script/parser.c | 9 ++-- source/tegraexplorer/script/variables.c | 2 +- 4 files changed, 75 insertions(+), 8 deletions(-) diff --git a/source/tegraexplorer/fs/filemenu.c b/source/tegraexplorer/fs/filemenu.c index 32a6f8b..1516daa 100644 --- a/source/tegraexplorer/fs/filemenu.c +++ b/source/tegraexplorer/fs/filemenu.c @@ -167,6 +167,7 @@ int filemenu(menu_entry file){ case FILE_SCRIPT: //ParseScript(fsutil_getnextloc(currentpath, file.name)); tester(fsutil_getnextloc(currentpath, file.name)); + fsreader_readfolder(currentpath); break; case FILE_HEXVIEW: viewbytes(fsutil_getnextloc(currentpath, file.name)); diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index 8b20886..ee86755 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -63,8 +63,10 @@ int parseStringInput(char *in, char **out){ u32 currentcolor = COLOR_WHITE; int part_printf(){ char *toprint; + if (parseStringInput(argv[0], &toprint)) + return -1; + SWAPCOLOR(currentcolor); - parseStringInput(argv[0], &toprint); gfx_printf(toprint); gfx_printf("\n"); return 0; @@ -74,6 +76,8 @@ int part_print_int(){ int toprint; if (parseIntInput(argv[0], &toprint)) return -1; + + SWAPCOLOR(currentcolor); gfx_printf("%s: %d\n", argv[0], toprint); return 0; } @@ -363,9 +367,71 @@ int part_fs_MakeDir(){ return res; } +DIR dir; +FILINFO fno; +int isdirvalid = false; +int part_fs_OpenDir(){ + char *path; + + if (parseStringInput(argv[0], &path)) + return -1; + + if (f_opendir(&dir, path)) + return -1; + + isdirvalid = true; + str_int_add("@ISDIRVALID", isdirvalid); + return 0; +} + +int part_fs_CloseDir(){ + if (!isdirvalid) + return 0; + + f_closedir(&dir); + isdirvalid = false; + str_int_add("@ISDIRVALID", isdirvalid); + return 0; +} + +int part_fs_ReadDir(){ + if (!isdirvalid) + return -1; + + if (!f_readdir(&dir, &fno) && fno.fname[0]){ + str_str_add("$FSOBJNAME", fno.fname); + str_int_add("@ISDIR", (fno.fattrib & AM_DIR) ? 1 : 0); + } + else { + part_fs_CloseDir(); + } + + return 0; +} + +int part_setPrintPos(){ + int left, right; + + if (parseIntInput(argv[0], &left)) + return -1; + + if (parseIntInput(argv[1], &right)) + return -1; + + if (left > 42) + return -1; + + if (right > 78) + return -1; + + gfx_con_setpos(left * 16, right * 16); + return 0; +} + str_fnc_struct functions[] = { {"printf", part_printf, 1}, {"printInt", part_print_int, 1}, + {"setPrintPos", part_setPrintPos, 2}, {"if", part_if, 1}, {"math", part_Math, 3}, {"check", part_Check, 3}, @@ -383,6 +449,9 @@ str_fnc_struct functions[] = { {"fs_delRecursive", part_fs_DeleteRecursive, 1}, {"fs_copy", part_fs_Copy, 2}, {"fs_copyRecursive", part_fs_CopyRecursive, 2}, + {"fs_openDir", part_fs_OpenDir, 1}, + {"fs_closeDir", part_fs_CloseDir, 0}, + {"fs_readDir", part_fs_ReadDir, 0}, {"mmc_connect", part_ConnectMMC, 1}, {"mmc_mount", part_MountMMC, 1}, {"pause", part_Pause, 0}, diff --git a/source/tegraexplorer/script/parser.c b/source/tegraexplorer/script/parser.c index 6c3d34c..e449d1c 100644 --- a/source/tegraexplorer/script/parser.c +++ b/source/tegraexplorer/script/parser.c @@ -14,6 +14,7 @@ #include "../fs/fsactions.h" #include "functions.h" #include "variables.h" +#include "../fs/fsreader.h" u32 countchars(char* in, char target) { @@ -133,8 +134,6 @@ char *readtilchar(char end, char ignore){ char *funcbuff = NULL; void functionparser(){ char *unsplitargs; - FSIZE_t fileoffset; - u32 argsize = 0; /* if (funcbuff != NULL) @@ -162,8 +161,6 @@ void functionparser(){ char *gettargetvar(){ char *variable = NULL; - FSIZE_t fileoffset; - u32 varsize = 0; variable = readtilchar('=', ' '); @@ -176,8 +173,6 @@ char *gettargetvar(){ void mainparser(){ char *variable = NULL; int res, out = 0; - FSIZE_t fileoffset; - u32 varsize = 0; getnextvalidchar(); @@ -257,6 +252,7 @@ void skipbrackets(){ } extern u32 currentcolor; +extern char *currentpath; void tester(char *path){ int res; forceExit = false; @@ -278,6 +274,7 @@ void tester(char *path){ str_int_add("@BTN_POWER", 0); str_int_add("@BTN_VOL+", 0); str_int_add("@BTN_VOL-", 0); + str_str_add("$CURRENTPATH", currentpath); //str_int_printall(); diff --git a/source/tegraexplorer/script/variables.c b/source/tegraexplorer/script/variables.c index 81fe63c..26cb559 100644 --- a/source/tegraexplorer/script/variables.c +++ b/source/tegraexplorer/script/variables.c @@ -221,7 +221,7 @@ int str_str_index(int index, char **out){ dict_str_str *temp; temp = str_str_table; - for (int i = 0; i < (index - 1); i++){ + for (int i = 0; i < index; i++){ if (temp == NULL) return -1; temp = temp->next;