From 2d777a51a51a111d0aa4c0336029e99cbd174b8b Mon Sep 17 00:00:00 2001 From: sezero Date: Fri, 1 Aug 2014 11:21:54 +0000 Subject: [PATCH] - ExtraMaps_Init: instead strstr(), directly compare the file extension bsp. - Modlist_Init: cleanup: instead strstr(), compare the file extension pak. no need extra checking for "." and ".." in the inner while loop. break out of the inner while loop as soon as a pak file or progs.dat is found. - ExtraMaps_Init, Modlist_Init, windows: instead of using dirent emulation, use windows' native FindFirstFile/FindNextFile/FindClose directly. adapted from fitzquake-0.85. git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@946 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/host_cmd.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Quake/host_cmd.c b/Quake/host_cmd.c index 8b4ff02d..36e2d535 100644 --- a/Quake/host_cmd.c +++ b/Quake/host_cmd.c @@ -21,7 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "quakedef.h" +#ifndef _WIN32 #include +#endif extern cvar_t pausable; @@ -266,8 +268,13 @@ void ExtraMaps_Add (const char *name) void ExtraMaps_Init (void) { +#ifdef _WIN32 + WIN32_FIND_DATA fdat; + HANDLE fhnd; +#else DIR *dir_p; struct dirent *dir_t; +#endif char filestring[MAX_OSPATH]; char mapname[32]; char ignorepakdir[32]; @@ -283,6 +290,18 @@ void ExtraMaps_Init (void) { if (*search->filename) //directory { +#ifdef _WIN32 + q_snprintf (filestring, sizeof(filestring), "%s/maps/*.bsp", search->filename); + fhnd = FindFirstFile(filestring, &fdat); + if (fhnd == INVALID_HANDLE_VALUE) + continue; + do + { + COM_StripExtension(fdat.cFileName, mapname, sizeof(mapname)); + ExtraMaps_Add (mapname); + } while (FindNextFile(fhnd, &fdat)); + FindClose(fhnd); +#else q_snprintf (filestring, sizeof(filestring), "%s/maps/", search->filename); dir_p = opendir(filestring); if (dir_p == NULL) @@ -295,6 +314,7 @@ void ExtraMaps_Init (void) ExtraMaps_Add (mapname); } closedir(dir_p); +#endif } else //pakfile { @@ -400,6 +420,39 @@ void Modlist_Add (const char *name) } } +#ifdef _WIN32 +void Modlist_Init (void) +{ + WIN32_FIND_DATA fdat, mod_fdat; + HANDLE fhnd, mod_fhnd; + char dir_string[MAX_OSPATH], mod_string[MAX_OSPATH]; + + q_snprintf (dir_string, sizeof(dir_string), "%s/*", com_basedir); + fhnd = FindFirstFile(dir_string, &fdat); + if (fhnd == INVALID_HANDLE_VALUE) + return; + + do + { + q_snprintf (mod_string, sizeof(mod_string), "%s/%s/progs.dat", com_basedir, fdat.cFileName); + mod_fhnd = FindFirstFile(mod_string, &mod_fdat); + if (mod_fhnd != INVALID_HANDLE_VALUE) { + FindClose(mod_fhnd); + Modlist_Add(fdat.cFileName); + } + else { + q_snprintf (mod_string, sizeof(mod_string), "%s/%s/*.pak", com_basedir, fdat.cFileName); + mod_fhnd = FindFirstFile(mod_string, &mod_fdat); + if (mod_fhnd != INVALID_HANDLE_VALUE) { + FindClose(mod_fhnd); + Modlist_Add(fdat.cFileName); + } + } + } while (FindNextFile(fhnd, &fdat)); + + FindClose(fhnd); +} +#else void Modlist_Init (void) { DIR *dir_p, *mod_dir_p; @@ -436,6 +489,7 @@ void Modlist_Init (void) closedir(dir_p); } +#endif /* ==================