core/logic/smn_maplists.cpp
changeset 3929 0bc0ffdb2eba
parent 3789 42e367aa4a00
child 3966 5d8b87f98355
     1.1 --- a/core/logic/smn_maplists.cpp	Sun Jun 30 22:04:04 2013 -0400
     1.2 +++ b/core/logic/smn_maplists.cpp	Wed Jul 03 23:14:55 2013 -0400
     1.3 @@ -37,6 +37,7 @@
     1.4  #include <ILibrarySys.h>
     1.5  #include <ITextParsers.h>
     1.6  #include <ISourceMod.h>
     1.7 +#include "stringutil.h"
     1.8  
     1.9  using namespace SourceHook;
    1.10  
    1.11 @@ -349,51 +350,39 @@
    1.12  		if ((success && pNewArray == NULL)
    1.13  			|| (!success && ((flags & MAPLIST_FLAG_MAPSFOLDER) == MAPLIST_FLAG_MAPSFOLDER)))
    1.14  		{
    1.15 -			char path[255];
    1.16 -			IDirectory *pDir;
    1.17 -
    1.18  			pNewArray = new CellArray(64);
    1.19  			free_new_array = true;
    1.20 -			g_pSM->BuildPath(Path_Game, path, sizeof(path), "maps");
    1.21 +
    1.22 +			cell_t *blk;
    1.23  
    1.24 -			if ((pDir = libsys->OpenDirectory(path)) != NULL)
    1.25 +			FileFindHandle_t findHandle;
    1.26 +			const char *fileName = smcore.filesystem->FindFirstEx("maps/*.bsp", "GAME", &findHandle);
    1.27 +
    1.28 +			while (fileName)
    1.29  			{
    1.30 -				char *ptr;
    1.31 -				cell_t *blk;
    1.32  				char buffer[PLATFORM_MAX_PATH];
    1.33  
    1.34 -				while (pDir->MoreFiles())
    1.35 +				UTIL_StripExtension(fileName, buffer, sizeof(buffer));
    1.36 +
    1.37 +				if (!engine->IsMapValid(buffer))
    1.38 +				{
    1.39 +					fileName = smcore.filesystem->FindNext(findHandle);
    1.40 +					continue;
    1.41 +				}
    1.42 +
    1.43 +				if ((blk = pNewArray->push()) == NULL)
    1.44  				{
    1.45 -					if (!pDir->IsEntryFile()
    1.46 -						|| strcmp(pDir->GetEntryName(), ".") == 0
    1.47 -						|| strcmp(pDir->GetEntryName(), "..") == 0)
    1.48 -					{
    1.49 -						pDir->NextEntry();
    1.50 -						continue;
    1.51 -					}
    1.52 -					smcore.strncopy(buffer, pDir->GetEntryName(), sizeof(buffer));
    1.53 -					if ((ptr = strstr(buffer, ".bsp")) == NULL || ptr[4] != '\0')
    1.54 -					{
    1.55 -						pDir->NextEntry();
    1.56 -						continue;
    1.57 -					}
    1.58 -					*ptr = '\0';
    1.59 -					if (!engine->IsMapValid(buffer))
    1.60 -					{
    1.61 -						pDir->NextEntry();
    1.62 -						continue;
    1.63 -					}
    1.64 -					if ((blk = pNewArray->push()) == NULL)
    1.65 -					{
    1.66 -						pDir->NextEntry();
    1.67 -						continue;
    1.68 -					}
    1.69 -					smcore.strncopy((char *)blk, buffer, 255);
    1.70 -					pDir->NextEntry();
    1.71 +					fileName = smcore.filesystem->FindNext(findHandle);
    1.72 +					continue;
    1.73  				}
    1.74 -				libsys->CloseDirectory(pDir);
    1.75 +
    1.76 +				smcore.strncopy((char *)blk, buffer, 255);
    1.77 +
    1.78 +				fileName = smcore.filesystem->FindNext(findHandle);
    1.79  			}
    1.80  
    1.81 +			smcore.filesystem->FindClose(findHandle);
    1.82 +
    1.83  			/* Remove the array if there were no items. */
    1.84  			if (pNewArray->size() == 0)
    1.85  			{