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

Function FS_GetModList

code/qcommon/files.cpp:2297–2414  ·  view source on GitHub ↗

================ FS_GetModList Returns a list of mod directory names A mod directory is a peer to base with a pk3 in it The directories are searched in base path, cd path and home path ================ */

Source from the content-addressed store, hash-verified

2295================
2296*/
2297int FS_GetModList( char *listbuf, int bufsize ) {
2298 int nMods, i, j, nTotal, nLen, nPaks, nPotential, nDescLen;
2299 char **pFiles = NULL;
2300 char **pPaks = NULL;
2301 char *name, *path;
2302 char descPath[MAX_OSPATH];
2303 fileHandle_t descHandle;
2304
2305 int dummy;
2306 char **pFiles0 = NULL;
2307 char **pFiles1 = NULL;
2308 char **pFiles2 = NULL;
2309 qboolean bDrop = qfalse;
2310
2311 *listbuf = 0;
2312 nMods = nPotential = nTotal = 0;
2313
2314 pFiles0 = Sys_ListFiles( fs_homepath->string, NULL, NULL, &dummy, qtrue );
2315 pFiles1 = Sys_ListFiles( fs_basepath->string, NULL, NULL, &dummy, qtrue );
2316 pFiles2 = Sys_ListFiles( fs_cdpath->string, NULL, NULL, &dummy, qtrue );
2317 // we searched for mods in the three paths
2318 // it is likely that we have duplicate names now, which we will cleanup below
2319 pFiles = Sys_ConcatenateFileLists( pFiles0, pFiles1, pFiles2 );
2320 nPotential = Sys_CountFileList(pFiles);
2321
2322 for ( i = 0 ; i < nPotential ; i++ ) {
2323 name = pFiles[i];
2324 // NOTE: cleaner would involve more changes
2325 // ignore duplicate mod directories
2326 if (i!=0) {
2327 bDrop = qfalse;
2328 for(j=0; j<i; j++)
2329 {
2330 if (Q_stricmp(pFiles[j],name)==0) {
2331 // this one can be dropped
2332 bDrop = qtrue;
2333 break;
2334 }
2335 }
2336 }
2337 if (bDrop) {
2338 continue;
2339 }
2340 // we drop "." and ".."
2341 if (Q_stricmpn(name, ".", 1)) {
2342 // now we need to find some .pk3 files to validate the mod
2343 // NOTE TTimo: (actually I'm not sure why .. what if it's a mod under developement with no .pk3?)
2344 // we didn't keep the information when we merged the directory names, as to what OS Path it was found under
2345 // so it could be in base path, cd path or home path
2346 // we will try each three of them here (yes, it's a bit messy)
2347 path = FS_BuildOSPath( fs_basepath->string, name, "" );
2348 nPaks = 0;
2349 pPaks = Sys_ListFiles(path, ".pk3", NULL, &nPaks, qfalse);
2350 Sys_FreeFileList( pPaks ); // we only use Sys_ListFiles to check wether .pk3 files are present
2351
2352 /* Try on cd path */
2353 if( nPaks <= 0 ) {
2354 path = FS_BuildOSPath( fs_cdpath->string, name, "" );

Callers 1

FS_GetFileListFunction · 0.70

Calls 11

Q_stricmpFunction · 0.85
Q_stricmpnFunction · 0.85
Sys_ConcatenateFileListsFunction · 0.70
Sys_CountFileListFunction · 0.70
FS_BuildOSPathFunction · 0.70
FS_SV_FOpenFileReadFunction · 0.70
FS_FileForHandleFunction · 0.70
FS_FCloseFileFunction · 0.70
SE_GetStringFunction · 0.70
Sys_ListFilesFunction · 0.50
Sys_FreeFileListFunction · 0.50

Tested by

no test coverage detected