Use proper filter instead of prefix to filter file lists

Added a new argument to ScanDirectory, a "filter" parameter. If it exists, it
will filter items regardless of where in the filename the filter appears (not
just in the beginning, as with the prefix). So if you type "ADV" as the filter,
both "Advance Wars" as well as "Ace Combat Advance" will pass through
This commit is contained in:
OskarSigvardsson
2020-07-02 17:41:38 +02:00
committed by GitHub
parent 6bac0b2eeb
commit 2b2c668d4f
3 changed files with 36 additions and 22 deletions

View File

@@ -1254,7 +1254,7 @@ static void get_display_name(direntext_t *dext, const char *ext, int options)
if (fext) *fext = 0;
}
int ScanDirectory(char* path, int mode, const char *extension, int options, const char *prefix)
int ScanDirectory(char* path, int mode, const char *extension, int options, const char *prefix, const char *filter)
{
static char file_name[1024];
static char full_path[1024];
@@ -1268,7 +1268,7 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons
}
int extlen = strlen(extension);
int filterlen = filter ? strlen(filter) : 0;
//printf("scan dir\n");
if (mode == SCANF_INIT)
@@ -1389,6 +1389,20 @@ int ScanDirectory(char* path, int mode, const char *extension, int options, cons
}
}
if (filter) {
bool passes_filter = false;
for(const char *str = de->d_name; *str; str++) {
if (strncasecmp(str, filter, filterlen) == 0) {
passes_filter = true;
break;
}
}
if (!passes_filter) continue;
}
if (options & SCANO_NEOGEO)
{
if (de->d_type == DT_REG && !strcasecmp(de->d_name + strlen(de->d_name) - 4, ".zip"))