Fix Windows file list extension check

Windows' Sys_ListFiles would add files that contain the extension anywhere,
not only at the end of the file name.

Example: "word.pk3omghacks" use to be loaded as a pk3 file.
This commit is contained in:
Zack Middleton 2015-07-04 20:42:57 -05:00
parent b152cf1423
commit 993b838f27

View file

@ -410,6 +410,7 @@ char **Sys_ListFiles( const char *directory, const char *extension, char *filter
intptr_t findhandle;
int flag;
int i;
int extLen;
if (filter) {
@ -443,6 +444,8 @@ char **Sys_ListFiles( const char *directory, const char *extension, char *filter
flag = _A_SUBDIR;
}
extLen = strlen( extension );
Com_sprintf( search, sizeof(search), "%s\\*%s", directory, extension );
// search
@ -456,6 +459,14 @@ char **Sys_ListFiles( const char *directory, const char *extension, char *filter
do {
if ( (!wantsubs && flag ^ ( findinfo.attrib & _A_SUBDIR )) || (wantsubs && findinfo.attrib & _A_SUBDIR) ) {
if (*extension) {
if ( strlen( findinfo.name ) < extLen ||
Q_stricmp(
findinfo.name + strlen( findinfo.name ) - extLen,
extension ) ) {
continue; // didn't match
}
}
if ( nfiles == MAX_FOUND_FILES - 1 ) {
break;
}