diff options
author | Andrew Browne <dersaidin@gmail.com> | 2013-02-11 17:58:24 -0600 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-02-16 21:54:32 +0000 |
commit | 0d52c5a17c28a55e5b66f4af8eb727f30b7692c3 (patch) | |
tree | c2b140fef6151292f7ca0593737a93727b916279 /src | |
parent | 41965ebc3a59b1ecd23a033a6e9674f2d2ddb1bb (diff) |
5289 - Support for .pk3dir
Diffstat (limited to 'src')
-rw-r--r-- | src/qcommon/files.c | 94 |
1 files changed, 81 insertions, 13 deletions
diff --git a/src/qcommon/files.c b/src/qcommon/files.c index 06bd6fc6..4a8ee0cf 100644 --- a/src/qcommon/files.c +++ b/src/qcommon/files.c @@ -2791,12 +2791,20 @@ then loads the zip headers */ void FS_AddGameDirectory( const char *path, const char *dir ) { searchpath_t *sp; - int i; searchpath_t *search; pack_t *pak; char curpath[MAX_OSPATH + 1], *pakfile; int numfiles; char **pakfiles; + int pakfilesi; + char **pakfilestmp; + int numdirs; + char **pakdirs; + int pakdirsi; + char **pakdirstmp; + + int pakwhich; + int len; // Unique for ( sp = fs_searchpaths ; sp ; sp = sp->next ) { @@ -2811,29 +2819,89 @@ void FS_AddGameDirectory( const char *path, const char *dir ) { Q_strncpyz(curpath, FS_BuildOSPath(path, dir, ""), sizeof(curpath)); curpath[strlen(curpath) - 1] = '\0'; // strip the trailing slash + // Get .pk3 files pakfiles = Sys_ListFiles(curpath, ".pk3", NULL, &numfiles, qfalse); + // Get top level directories (we'll filter them later since the Sys_ListFiles filtering is terrible) + pakdirs = Sys_ListFiles(curpath, "/", NULL, &numdirs, qfalse); + qsort( pakfiles, numfiles, sizeof(char*), paksort ); + qsort( pakdirs, numdirs, sizeof(char *), paksort ); - for ( i = 0 ; i < numfiles ; i++ ) { - pakfile = FS_BuildOSPath( path, dir, pakfiles[i] ); - if ( ( pak = FS_LoadZipFile( pakfile, pakfiles[i] ) ) == 0 ) - continue; + pakfilesi = 0; + pakdirsi = 0; + + while((pakfilesi < numfiles) || (pakdirsi < numdirs)) + { + // Check if a pakfile or pakdir comes next + if (pakfilesi >= numfiles) { + // We've used all the pakfiles, it must be a pakdir. + pakwhich = 0; + } + else if (pakdirsi >= numdirs) { + // We've used all the pakdirs, it must be a pakfile. + pakwhich = 1; + } + else { + // Could be either, compare to see which name comes first + // Need tmp variables for appropriate indirection for paksort() + pakfilestmp = &pakfiles[pakfilesi]; + pakdirstmp = &pakdirs[pakdirsi]; + pakwhich = (paksort(pakfilestmp, pakdirstmp) < 0); + } + + if (pakwhich) { + // The next .pk3 file is before the next .pk3dir + pakfile = FS_BuildOSPath(path, dir, pakfiles[pakfilesi]); + if ((pak = FS_LoadZipFile(pakfile, pakfiles[pakfilesi])) == 0) { + // This isn't a .pk3! Next! + pakfilesi++; + continue; + } - Q_strncpyz(pak->pakPathname, curpath, sizeof(pak->pakPathname)); - // store the game name for downloading - Q_strncpyz(pak->pakGamename, dir, sizeof(pak->pakGamename)); + Q_strncpyz(pak->pakPathname, curpath, sizeof(pak->pakPathname)); + // store the game name for downloading + Q_strncpyz(pak->pakGamename, dir, sizeof(pak->pakGamename)); - fs_packFiles += pak->numfiles; + fs_packFiles += pak->numfiles; - search = Z_Malloc (sizeof(searchpath_t)); - search->pack = pak; - search->next = fs_searchpaths; - fs_searchpaths = search; + search = Z_Malloc(sizeof(searchpath_t)); + search->pack = pak; + search->next = fs_searchpaths; + fs_searchpaths = search; + + pakfilesi++; + } + else { + // The next .pk3dir is before the next .pk3 file + // But wait, this could be any directory, we're filtering to only ending with ".pk3dir" here. + len = strlen(pakdirs[pakdirsi]); + if (!FS_IsExt(pakdirs[pakdirsi], ".pk3dir", len)) { + // This isn't a .pk3dir! Next! + pakdirsi++; + continue; + } + + pakfile = FS_BuildOSPath(path, dir, pakdirs[pakdirsi]); + + // add the directory to the search path + search = Z_Malloc(sizeof(searchpath_t)); + search->dir = Z_Malloc(sizeof(*search->dir)); + + Q_strncpyz(search->dir->path, curpath, sizeof(search->dir->path)); // c:\xreal\base + Q_strncpyz(search->dir->fullpath, pakfile, sizeof(search->dir->fullpath)); // c:\xreal\base\mypak.pk3dir + Q_strncpyz(search->dir->gamedir, pakdirs[pakdirsi], sizeof(search->dir->gamedir)); // mypak.pk3dir + + search->next = fs_searchpaths; + fs_searchpaths = search; + + pakdirsi++; + } } // done Sys_FreeFileList( pakfiles ); + Sys_FreeFileList( pakdirs ); // // add the directory to the search path |