From ddf6e11459bd2ab964c5781557f938c2f593e739 Mon Sep 17 00:00:00 2001 From: d0k3 Date: Tue, 9 Jan 2018 15:46:37 +0100 Subject: [PATCH] Scripting: fix 'dirsel' command --- arm9/source/utils/scripting.c | 20 +++++++++++--------- resources/sample/HelloScript.gm9 | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/arm9/source/utils/scripting.c b/arm9/source/utils/scripting.c index e9618fd..4ca6394 100644 --- a/arm9/source/utils/scripting.c +++ b/arm9/source/utils/scripting.c @@ -824,20 +824,22 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) { char path[_VAR_CNT_LEN]; strncpy(path, argv[1], _VAR_CNT_LEN); - char* npattern = strrchr(path, '/'); if (strncmp(path, "Z:", 2) == 0) { ret = false; if (err_str) snprintf(err_str, _ERR_STR_LEN, "forbidden drive"); - } else if (!npattern) { - ret = false; - if (err_str) snprintf(err_str, _ERR_STR_LEN, "invalid path"); } else if (id == CMD_ID_FILESEL) { - u32 flags_ext = (flags & _FLG('d')) ? 0 : NO_DIRS; - *(npattern++) = '\0'; - ret = FileSelector(choice, argv[0], path, npattern, flags_ext); - if (err_str) snprintf(err_str, _ERR_STR_LEN, "fileselect abort"); + char* npattern = strrchr(path, '/'); + if (!npattern) { + ret = false; + if (err_str) snprintf(err_str, _ERR_STR_LEN, "invalid path"); + } else { + u32 flags_ext = (flags & _FLG('d')) ? 0 : NO_DIRS; + *(npattern++) = '\0'; + ret = FileSelector(choice, argv[0], path, npattern, flags_ext); + if (err_str) snprintf(err_str, _ERR_STR_LEN, "fileselect abort"); + } } else { - ret = FileSelector(choice, argv[0], path, npattern, NO_FILES | SELECT_DIRS); + ret = FileSelector(choice, argv[0], path, NULL, NO_FILES | SELECT_DIRS); if (err_str) snprintf(err_str, _ERR_STR_LEN, "dirselect abort"); } diff --git a/resources/sample/HelloScript.gm9 b/resources/sample/HelloScript.gm9 index bef6fee..9aa5c41 100644 --- a/resources/sample/HelloScript.gm9 +++ b/resources/sample/HelloScript.gm9 @@ -110,8 +110,8 @@ filesel "Please select a file" 0:/*.* SELFILE # 'dirsel' COMMAND # The 'dirsel' command works identically to the 'filesel' command, but allows selecting a dir -# Note that a final slash ('/') and no wildcard pattern is expected here. -dirsel "Now, select a dir" 0:/ SELDIR +# Note that a final slash ('/') is not expected here and there can be no wildcard pattern. +dirsel "Now, select a dir" 0: SELDIR echo "You selected $[SELFILE]\nand $[SELDIR]\nWe'll do nothing with either :)." # 'allow' COMMAND