Scripting: fix 'dirsel' command

This commit is contained in:
d0k3 2018-01-09 15:46:37 +01:00
parent 7befb8f1b5
commit ddf6e11459
2 changed files with 13 additions and 11 deletions

View File

@ -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");
}

View File

@ -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