MCPcopy Create free account
hub / github.com/JACoders/OpenJK / FS_AddGameDirectory

Function FS_AddGameDirectory

code/qcommon/files.cpp:2708–2796  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2706*/
2707#define MAX_PAKFILES 1024
2708static void FS_AddGameDirectory( const char *path, const char *dir ) {
2709 searchpath_t *sp;
2710 int i;
2711 searchpath_t *search;
2712 searchpath_t *thedir;
2713 pack_t *pak;
2714 char curpath[MAX_OSPATH + 1], *pakfile;
2715 int numfiles;
2716 char **pakfiles;
2717 char *sorted[MAX_PAKFILES];
2718
2719 // this fixes the case where fs_basepath is the same as fs_cdpath
2720 // which happens on full installs
2721 for ( sp = fs_searchpaths ; sp ; sp = sp->next ) {
2722 // TODO Sys_PathCmp SDL-Port will contain this for SP as well
2723 // Should be Sys_PathCmp(sp->dir->path, path)
2724 if ( sp->dir && !Q_stricmp(sp->dir->path, path) && !Q_stricmp(sp->dir->gamedir, dir)) {
2725 return; // we've already got this one
2726 }
2727 }
2728
2729 Q_strncpyz( fs_gamedir, dir, sizeof( fs_gamedir ) );
2730
2731 // find all pak files in this directory
2732 Q_strncpyz(curpath, FS_BuildOSPath(path, dir, ""), sizeof(curpath));
2733 curpath[strlen(curpath) - 1] = '\0'; // strip the trailing slash
2734
2735 //
2736 // add the directory to the search path
2737 //
2738 search = (struct searchpath_s *)Z_Malloc (sizeof(searchpath_t), TAG_FILESYS, qtrue);
2739 search->dir = (directory_t *)Z_Malloc( sizeof( *search->dir ), TAG_FILESYS, qtrue );
2740
2741 Q_strncpyz( search->dir->path, path, sizeof( search->dir->path ) );
2742 Q_strncpyz( search->dir->fullpath, curpath, sizeof( search->dir->fullpath ) );
2743 Q_strncpyz( search->dir->gamedir, dir, sizeof( search->dir->gamedir ) );
2744 search->next = fs_searchpaths;
2745 fs_searchpaths = search;
2746
2747 thedir = search;
2748
2749 pakfiles = Sys_ListFiles( curpath, ".pk3", NULL, &numfiles, qfalse );
2750
2751 // sort them so that later alphabetic matches override
2752 // earlier ones. This makes pak1.pk3 override pak0.pk3
2753 if ( numfiles > MAX_PAKFILES ) {
2754 numfiles = MAX_PAKFILES;
2755 }
2756 for ( i = 0 ; i < numfiles ; i++ ) {
2757 sorted[i] = pakfiles[i];
2758 }
2759
2760 qsort( sorted, numfiles, sizeof(char*), paksort );
2761
2762 for ( i = 0 ; i < numfiles ; i++ ) {
2763 pakfile = FS_BuildOSPath( path, dir, sorted[i] );
2764 if ( ( pak = FS_LoadZipFile( pakfile, sorted[i] ) ) == 0 )
2765 continue;

Callers 1

FS_StartupFunction · 0.70

Calls 7

Q_stricmpFunction · 0.85
Q_strncpyzFunction · 0.85
FS_BuildOSPathFunction · 0.70
Z_MallocFunction · 0.70
FS_LoadZipFileFunction · 0.70
Sys_ListFilesFunction · 0.50
Sys_FreeFileListFunction · 0.50

Tested by

no test coverage detected