From 34e5b23c80bdc072791da3f04fc58dd45a99614d Mon Sep 17 00:00:00 2001 From: d0k3 Date: Fri, 25 Aug 2017 00:20:50 +0200 Subject: [PATCH] Scripting: improve handling for input, find & findnot --- source/filesys/fsdrive.c | 2 +- source/filesys/fsscript.c | 32 ++++++++++++++++++-------------- source/filesys/vff.c | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/source/filesys/fsdrive.c b/source/filesys/fsdrive.c index 09e682a..7d12095 100644 --- a/source/filesys/fsdrive.c +++ b/source/filesys/fsdrive.c @@ -174,7 +174,7 @@ void SearchDirContents(DirStruct* contents, const char* path, const char* patter } void GetDirContents(DirStruct* contents, const char* path) { - if (*search_path && DriveType(path) & DRV_SEARCH) { + if (*search_path && (DriveType(path) & DRV_SEARCH)) { ShowString("Searching, please wait..."); SearchDirContents(contents, search_path, search_pattern, true); if (search_title_mode) SetDirGoodNames(contents); diff --git a/source/filesys/fsscript.c b/source/filesys/fsscript.c index 8fe2994..7d2f644 100644 --- a/source/filesys/fsscript.c +++ b/source/filesys/fsscript.c @@ -378,10 +378,16 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) { ret = ShowPrompt(true, argv[0]); if (err_str) snprintf(err_str, _ERR_STR_LEN, "user abort"); } else if (id == CMD_ID_INPUT) { + char input[_VAR_CNT_LEN] = { 0 }; char* var = get_var(argv[1], NULL); - if (!*var) set_var(argv[1], ""); // make sure the var exists - ret = ShowStringPrompt(var, _VAR_CNT_LEN, argv[0]); + strncpy(input, var, _VAR_CNT_LEN); + ret = ShowStringPrompt(input, _VAR_CNT_LEN, argv[0]); + if (ret) set_var(argv[1], ""); if (err_str) snprintf(err_str, _ERR_STR_LEN, "user abort"); + if (ret) { + ret = set_var(argv[1], input); + if (err_str) snprintf(err_str, _ERR_STR_LEN, "var fail"); + } } else if (id == CMD_ID_SET) { ret = set_var(argv[0], argv[1]); if (err_str) snprintf(err_str, _ERR_STR_LEN, "set fail"); @@ -432,22 +438,20 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) { } else if (id == CMD_ID_UMOUNT) { InitImgFS(NULL); } else if (id == CMD_ID_FIND) { - char* path = set_var(argv[1], ""); // setup the variable, get pointer - if (!path) { - ret = false; + char path[_VAR_CNT_LEN]; + ret = (fvx_findpath(path, argv[0]) == FR_OK); + if (err_str) snprintf(err_str, _ERR_STR_LEN, "find fail"); + if (ret) { + ret = set_var(argv[1], path); if (err_str) snprintf(err_str, _ERR_STR_LEN, "var fail"); - } else { - ret = (fvx_findpath(path, argv[0]) == FR_OK); - if (err_str) snprintf(err_str, _ERR_STR_LEN, "find fail"); } } else if (id == CMD_ID_FINDNOT) { - char* path = set_var(argv[1], ""); // setup the variable, get pointer - if (!path) { - ret = false; + char path[_VAR_CNT_LEN]; + ret = (fvx_findnopath(path, argv[0]) == FR_OK); + if (err_str) snprintf(err_str, _ERR_STR_LEN, "findnot fail"); + if (ret) { + ret = set_var(argv[1], path); if (err_str) snprintf(err_str, _ERR_STR_LEN, "var fail"); - } else { - ret = (fvx_findnopath(path, argv[0]) == FR_OK); - if (err_str) snprintf(err_str, _ERR_STR_LEN, "findnot fail"); } } else if (id == CMD_ID_SHA) { u8 sha256_fil[0x20]; diff --git a/source/filesys/vff.c b/source/filesys/vff.c index 83ab5e5..69aa89b 100644 --- a/source/filesys/vff.c +++ b/source/filesys/vff.c @@ -347,7 +347,7 @@ FRESULT fvx_findnopath (TCHAR* path, const TCHAR* pattern) { } if (n_rep >= 16) return FR_DENIED; } - if (!n_rep) return fvx_stat(path, NULL); + if (!n_rep) return (fvx_stat(path, NULL) == FR_OK) ? FR_NO_PATH : FR_OK; while (fvx_stat(path, NULL) == FR_OK) { for (INT i = n_rep - 1; (i >= 0); i--) {