Scripting: improve handling for input, find & findnot

This commit is contained in:
d0k3 2017-08-25 00:20:50 +02:00
parent de230fd8e5
commit 34e5b23c80
3 changed files with 20 additions and 16 deletions

View File

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

View File

@ -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;
if (err_str) snprintf(err_str, _ERR_STR_LEN, "var fail");
} else {
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 if (id == CMD_ID_FINDNOT) {
char* path = set_var(argv[1], ""); // setup the variable, get pointer
if (!path) {
ret = false;
if (err_str) snprintf(err_str, _ERR_STR_LEN, "var fail");
} else {
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 if (id == CMD_ID_SHA) {
u8 sha256_fil[0x20];

View File

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