From 993b838f2766c49d176793b15d9464a4e51fc9c8 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sat, 4 Jul 2015 20:42:57 -0500 Subject: [PATCH] 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. --- code/sys/sys_win32.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/code/sys/sys_win32.c b/code/sys/sys_win32.c index 14be1364..50d1bb4b 100644 --- a/code/sys/sys_win32.c +++ b/code/sys/sys_win32.c @@ -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; }