mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-21 11:21:52 +00:00
Move FS_ListMods() upward, to a more appropriate place in the file.
This commit is contained in:
parent
36d64aaefb
commit
fa345ed38e
1 changed files with 101 additions and 102 deletions
|
@ -1254,6 +1254,107 @@ FS_FreeList(char **list, int nfiles)
|
|||
free(list);
|
||||
}
|
||||
|
||||
/*
|
||||
* Combs all Raw search paths to find game dirs containing PAK/PK2/PK3 files.
|
||||
* Returns an alphabetized array of unique relative dir names.
|
||||
*/
|
||||
char**
|
||||
FS_ListMods(int *nummods)
|
||||
{
|
||||
int nmods = 0, numdirchildren, numpacksinchilddir, searchpathlength;
|
||||
char findnamepattern[MAX_OSPATH], modname[MAX_QPATH], searchpath[MAX_OSPATH];
|
||||
char **dirchildren, **packsinchilddir, **modnames;
|
||||
|
||||
modnames = malloc((MAX_QPATH + 1) * (MAX_MODS + 1));
|
||||
memset(modnames, 0, (MAX_QPATH + 1) * (MAX_MODS + 1));
|
||||
|
||||
// iterate over all Raw paths
|
||||
for (fsRawPath_t *search = fs_rawPath; search; search = search->next)
|
||||
{
|
||||
searchpathlength = strlen(search->path);
|
||||
if(!searchpathlength)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// make sure this Raw path ends with a '/' otherwise FS_ListFiles will open its parent dir
|
||||
if(search->path[searchpathlength - 1] != '/')
|
||||
{
|
||||
Com_sprintf(searchpath, sizeof(searchpath), "%s/*", search->path);
|
||||
}
|
||||
else
|
||||
{
|
||||
Com_sprintf(searchpath, sizeof(searchpath), "%s*", search->path);
|
||||
}
|
||||
|
||||
dirchildren = FS_ListFiles(searchpath, &numdirchildren, 0, 0);
|
||||
|
||||
if (dirchildren == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// iterate over the children of this Raw path (unless we've already got enough mods)
|
||||
for (int i = 0; i < numdirchildren && nmods < MAX_MODS; i++)
|
||||
{
|
||||
if(dirchildren[i] == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
numpacksinchilddir = 0;
|
||||
|
||||
// iterate over supported pack types, but ignore ZIP files (they cause false positives)
|
||||
for (int j = 0; j < sizeof(fs_packtypes) / sizeof(fs_packtypes[0]); j++)
|
||||
{
|
||||
if (strcmp("zip", fs_packtypes[j].suffix) != 0)
|
||||
{
|
||||
Com_sprintf(findnamepattern, sizeof(findnamepattern), "%s/*.%s", dirchildren[i], fs_packtypes[j].suffix);
|
||||
|
||||
packsinchilddir = FS_ListFiles(findnamepattern, &numpacksinchilddir, 0, 0);
|
||||
FS_FreeList(packsinchilddir, numpacksinchilddir);
|
||||
|
||||
// if this dir has some pack files, add it if not already in the list
|
||||
if (numpacksinchilddir > 0)
|
||||
{
|
||||
qboolean matchfound = false;
|
||||
|
||||
Com_sprintf(modname, sizeof(modname), "%s", strrchr(dirchildren[i], '/') + 1);
|
||||
|
||||
for (int k = 0; k < nmods; k++)
|
||||
{
|
||||
if (strcmp(modname, modnames[k]) == 0)
|
||||
{
|
||||
matchfound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matchfound)
|
||||
{
|
||||
modnames[nmods] = malloc(strlen(modname) + 1);
|
||||
strcpy(modnames[nmods], modname);
|
||||
|
||||
nmods++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FS_FreeList(dirchildren, numdirchildren);
|
||||
}
|
||||
|
||||
modnames[nmods] = 0;
|
||||
|
||||
qsort(modnames, nmods, sizeof(modnames[0]), Q_sort_strcomp);
|
||||
|
||||
*nummods = nmods;
|
||||
return modnames;
|
||||
}
|
||||
|
||||
/*
|
||||
* Directory listing.
|
||||
*/
|
||||
|
@ -1801,105 +1902,3 @@ FS_InitFilesystem(void)
|
|||
// Debug output
|
||||
Com_Printf("Using '%s' for writing.\n", fs_gamedir);
|
||||
}
|
||||
|
||||
/*
|
||||
* Combs all Raw search paths to find game dirs containing PAK/PK2/PK3 files.
|
||||
* Returns an alphabetized array of unique relative dir names.
|
||||
*/
|
||||
char**
|
||||
FS_ListMods(int *nummods)
|
||||
{
|
||||
int nmods = 0, numdirchildren, numpacksinchilddir, searchpathlength;
|
||||
char findnamepattern[MAX_OSPATH], modname[MAX_QPATH], searchpath[MAX_OSPATH];
|
||||
char **dirchildren, **packsinchilddir, **modnames;
|
||||
|
||||
modnames = malloc((MAX_QPATH + 1) * (MAX_MODS + 1));
|
||||
memset(modnames, 0, (MAX_QPATH + 1) * (MAX_MODS + 1));
|
||||
|
||||
// iterate over all Raw paths
|
||||
for (fsRawPath_t *search = fs_rawPath; search; search = search->next)
|
||||
{
|
||||
searchpathlength = strlen(search->path);
|
||||
if(!searchpathlength)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// make sure this Raw path ends with a '/' otherwise FS_ListFiles will open its parent dir
|
||||
if(search->path[searchpathlength - 1] != '/')
|
||||
{
|
||||
Com_sprintf(searchpath, sizeof(searchpath), "%s/*", search->path);
|
||||
}
|
||||
else
|
||||
{
|
||||
Com_sprintf(searchpath, sizeof(searchpath), "%s*", search->path);
|
||||
}
|
||||
|
||||
dirchildren = FS_ListFiles(searchpath, &numdirchildren, 0, 0);
|
||||
|
||||
if (dirchildren == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// iterate over the children of this Raw path (unless we've already got enough mods)
|
||||
for (int i = 0; i < numdirchildren && nmods < MAX_MODS; i++)
|
||||
{
|
||||
if(dirchildren[i] == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
numpacksinchilddir = 0;
|
||||
|
||||
// iterate over supported pack types, but ignore ZIP files (they cause false positives)
|
||||
for (int j = 0; j < sizeof(fs_packtypes) / sizeof(fs_packtypes[0]); j++)
|
||||
{
|
||||
if (strcmp("zip", fs_packtypes[j].suffix) != 0)
|
||||
{
|
||||
Com_sprintf(findnamepattern, sizeof(findnamepattern), "%s/*.%s", dirchildren[i], fs_packtypes[j].suffix);
|
||||
|
||||
packsinchilddir = FS_ListFiles(findnamepattern, &numpacksinchilddir, 0, 0);
|
||||
FS_FreeList(packsinchilddir, numpacksinchilddir);
|
||||
|
||||
// if this dir has some pack files, add it if not already in the list
|
||||
if (numpacksinchilddir > 0)
|
||||
{
|
||||
qboolean matchfound = false;
|
||||
|
||||
Com_sprintf(modname, sizeof(modname), "%s", strrchr(dirchildren[i], '/') + 1);
|
||||
|
||||
for (int k = 0; k < nmods; k++)
|
||||
{
|
||||
if (strcmp(modname, modnames[k]) == 0)
|
||||
{
|
||||
matchfound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matchfound)
|
||||
{
|
||||
modnames[nmods] = malloc(strlen(modname) + 1);
|
||||
strcpy(modnames[nmods], modname);
|
||||
|
||||
nmods++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FS_FreeList(dirchildren, numdirchildren);
|
||||
}
|
||||
|
||||
modnames[nmods] = 0;
|
||||
|
||||
qsort(modnames, nmods, sizeof(modnames[0]), Q_sort_strcomp);
|
||||
|
||||
*nummods = nmods;
|
||||
return modnames;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue