mirror of
https://github.com/blendogames/thirtyflightsofloving.git
synced 2025-02-21 11:10:58 +00:00
Changed SetCrosshairNames(), SetFontNames(), and S_OGG_LoadFileList() to use FS_GetFileList().
Added zeroing of ogg_filelist pointer after free.
This commit is contained in:
parent
2959cb730a
commit
92ef67ef44
4 changed files with 131 additions and 17 deletions
|
@ -37,9 +37,9 @@ qboolean ogg_started = false; // Initialization flag
|
|||
ogg_status_t ogg_status; // Status indicator
|
||||
|
||||
#define MAX_OGGLIST 512
|
||||
char **ogg_filelist; // List of Ogg Vorbis files
|
||||
int ogg_curfile; // Index of currently played file
|
||||
int ogg_numfiles; // Number of Ogg Vorbis files
|
||||
char **ogg_filelist = NULL; // List of Ogg Vorbis files
|
||||
int ogg_curfile; // Index of currently played file
|
||||
int ogg_numfiles = 0; // Number of Ogg Vorbis files
|
||||
int ogg_loopcounter;
|
||||
|
||||
cvar_t *ogg_loopcount;
|
||||
|
@ -616,6 +616,8 @@ void S_OGG_Shutdown (void)
|
|||
free(ogg_filelist[i]);
|
||||
if (ogg_numfiles > 0)
|
||||
free(ogg_filelist);
|
||||
ogg_filelist = NULL;
|
||||
ogg_numfiles = 0;
|
||||
|
||||
// Remove console commands
|
||||
Cmd_RemoveCommand("ogg");
|
||||
|
@ -651,14 +653,36 @@ void S_OGG_LoadFileList (void)
|
|||
{
|
||||
char *p, *path = NULL;
|
||||
char **list; // List of .ogg files
|
||||
char findname[MAX_OSPATH];
|
||||
// char findname[MAX_OSPATH];
|
||||
char lastPath[MAX_OSPATH]; // Knightmare added
|
||||
int i, numfiles = 0;
|
||||
int i, len, numfiles = 0;
|
||||
|
||||
ogg_filelist = malloc(sizeof(char *) * MAX_OGGLIST);
|
||||
memset( ogg_filelist, 0, sizeof( char * ) * MAX_OGGLIST );
|
||||
lastPath[0] = 0;
|
||||
|
||||
#if 1
|
||||
list = FS_GetFileList("music", "ogg", &numfiles);
|
||||
// Add valid Ogg Vorbis file to the list
|
||||
for (i=0; i<numfiles && ogg_numfiles<MAX_OGGLIST; i++)
|
||||
{
|
||||
if (!list || !list[i])
|
||||
continue;
|
||||
|
||||
len = (int)strlen(list[i]);
|
||||
if ( strcmp(list[i]+max(len-4,0), ".ogg") )
|
||||
continue;
|
||||
|
||||
p = list[i];
|
||||
|
||||
if (!FS_ItemInList(p, ogg_numfiles, ogg_filelist)) // check if already in list
|
||||
{
|
||||
ogg_filelist[ogg_numfiles] = malloc(strlen(p)+1);
|
||||
Com_sprintf (ogg_filelist[ogg_numfiles], strlen(p)+1, "%s\0", p);
|
||||
ogg_numfiles++;
|
||||
}
|
||||
}
|
||||
#else
|
||||
// Set search path
|
||||
path = FS_NextPath(path);
|
||||
while (path)
|
||||
|
@ -677,15 +701,20 @@ void S_OGG_LoadFileList (void)
|
|||
{
|
||||
if (!list || !list[i])
|
||||
continue;
|
||||
p = list[i];
|
||||
if (!strstr(p, ".ogg"))
|
||||
|
||||
len = (int)strlen(list[i]);
|
||||
if ( strcmp(list[i]+max(len-4,0), ".ogg") )
|
||||
continue;
|
||||
|
||||
p = list[i];
|
||||
// if (!strstr(p, ".ogg"))
|
||||
// continue;
|
||||
// if (!S_OGG_Check(p))
|
||||
// continue;
|
||||
if (!FS_ItemInList(p, ogg_numfiles, ogg_filelist)) // check if already in list
|
||||
{
|
||||
ogg_filelist[ogg_numfiles] = malloc(strlen(p)+1);
|
||||
sprintf(ogg_filelist[ogg_numfiles], "%s\0", p);
|
||||
Com_sprintf (ogg_filelist[ogg_numfiles], strlen(p)+1, "%s\0", p);
|
||||
ogg_numfiles++;
|
||||
}
|
||||
}
|
||||
|
@ -703,19 +732,26 @@ void S_OGG_LoadFileList (void)
|
|||
{
|
||||
if (!list || !list[i])
|
||||
continue;
|
||||
p = list[i];
|
||||
if (!strstr(p, ".ogg"))
|
||||
|
||||
len = (int)strlen(list[i]);
|
||||
if ( strcmp(list[i]+max(len-4,0), ".ogg") )
|
||||
continue;
|
||||
|
||||
p = list[i];
|
||||
// if (!strstr(p, ".ogg"))
|
||||
// continue;
|
||||
// if (!S_OGG_Check(p))
|
||||
// continue;
|
||||
if (!FS_ItemInList(p, ogg_numfiles, ogg_filelist)) // check if already in list
|
||||
{
|
||||
ogg_filelist[ogg_numfiles] = malloc(strlen(p)+1);
|
||||
sprintf(ogg_filelist[ogg_numfiles], "%s\0", p);
|
||||
Com_sprintf (ogg_filelist[ogg_numfiles], strlen(p)+1, "%s\0", p);
|
||||
ogg_numfiles++;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (numfiles)
|
||||
FS_FreeFileList(list, numfiles);
|
||||
}
|
||||
|
|
|
@ -948,7 +948,7 @@ void VID_Printf (int print_level, char *str, ...);
|
|||
// or a discrete file from anywhere in the quake search path
|
||||
// a -1 return means the file does not exist
|
||||
// NULL can be passed for buf to just determine existance
|
||||
char **FS_ListPak (char *find, int *num);
|
||||
char **FS_GetFileList (const char *path, const char *extension, int *num);
|
||||
int FS_LoadFile (char *name, void **buf);
|
||||
void FS_FreeFile (void *buf);
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ void insertFont (char **list, char *insert, int len )
|
|||
int i, j;
|
||||
if (!list) return;
|
||||
|
||||
//i=1 so default stays first!
|
||||
// i=1 so default stays first!
|
||||
for (i=1; i<len; i++)
|
||||
{
|
||||
if (!list[i])
|
||||
|
@ -161,7 +161,7 @@ char **SetFontNames (void)
|
|||
{
|
||||
char *curFont;
|
||||
char **list = 0, *p;//, *s;
|
||||
char findname[1024];
|
||||
// char findname[1024];
|
||||
int nfonts = 0, nfontnames;
|
||||
char **fontfiles;
|
||||
char *path = NULL;
|
||||
|
@ -174,6 +174,37 @@ char **SetFontNames (void)
|
|||
|
||||
nfontnames = 1;
|
||||
|
||||
#if 1
|
||||
fontfiles = FS_GetFileList("fonts/*.*", NULL, &nfonts);
|
||||
for (i=0;i<nfonts && nfontnames<MAX_FONTS;i++)
|
||||
{
|
||||
int num;
|
||||
|
||||
if (!fontfiles || !fontfiles[i]) // Knightmare added array base check
|
||||
continue;
|
||||
|
||||
if ( !IsValidImageFilename(fontfiles[i]) )
|
||||
continue;
|
||||
|
||||
p = strrchr(fontfiles[i], '/'); p++;
|
||||
|
||||
num = strlen(p)-4;
|
||||
p[num] = 0; // NULL
|
||||
|
||||
curFont = p;
|
||||
|
||||
if (!FS_ItemInList(curFont, nfontnames, list))
|
||||
{
|
||||
// insertFont not needed due to sorting in FS_GetFileList()
|
||||
// insertFont (list, strdup(curFont), nfontnames);
|
||||
FS_InsertInList(list, strdup(curFont), nfontnames, 1); // start=1 so default stays first!
|
||||
nfontnames++;
|
||||
}
|
||||
|
||||
// set back so whole string get deleted.
|
||||
p[num] = '.';
|
||||
}
|
||||
#else
|
||||
path = FS_NextPath( path );
|
||||
while (path)
|
||||
{
|
||||
|
@ -199,7 +230,7 @@ char **SetFontNames (void)
|
|||
|
||||
if (!FS_ItemInList(curFont, nfontnames, list))
|
||||
{
|
||||
insertFont(list, strdup(curFont),nfontnames);
|
||||
insertFont (list, strdup(curFont), nfontnames);
|
||||
nfontnames++;
|
||||
}
|
||||
|
||||
|
@ -238,10 +269,12 @@ char **SetFontNames (void)
|
|||
nfontnames++;
|
||||
}
|
||||
|
||||
//set back so whole string get deleted.
|
||||
// set back so whole string get deleted.
|
||||
p[num] = '.';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (nfonts)
|
||||
FS_FreeFileList( fontfiles, nfonts );
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ char **SetCrosshairNames (void)
|
|||
{
|
||||
char *curCrosshair;
|
||||
char **list = 0, *p;
|
||||
char findname[1024];
|
||||
// char findname[1024];
|
||||
int ncrosshairs = 0, ncrosshairnames;
|
||||
char **crosshairfiles;
|
||||
char *path = NULL;
|
||||
|
@ -172,6 +172,49 @@ char **SetCrosshairNames (void)
|
|||
list[0] = strdup("none"); // was default
|
||||
ncrosshairnames = 1;
|
||||
|
||||
#if 1
|
||||
crosshairfiles = FS_GetFileList("pics/ch*.*", NULL, &ncrosshairs);
|
||||
for (i=0; i<ncrosshairs && ncrosshairnames < MAX_CROSSHAIRS; i++)
|
||||
{
|
||||
int num, namelen;
|
||||
|
||||
if ( !crosshairfiles || !crosshairfiles[i] )
|
||||
continue;
|
||||
|
||||
if ( !IsValidImageFilename(crosshairfiles[i]) )
|
||||
continue;
|
||||
|
||||
p = strrchr(crosshairfiles[i], '/'); p++;
|
||||
|
||||
// filename must be chxxx
|
||||
if (strncmp(p, "ch", 2))
|
||||
continue;
|
||||
namelen = strlen(strdup(p));
|
||||
if (namelen < 7 || namelen > 9)
|
||||
continue;
|
||||
if (!isNumeric(p[2]))
|
||||
continue;
|
||||
if (namelen >= 8 && !isNumeric(p[3]))
|
||||
continue;
|
||||
// ch100 is only valid 5-char name
|
||||
if (namelen == 9 && (p[2] != '1' || p[3] != '0' || p[4] != '0'))
|
||||
continue;
|
||||
|
||||
num = strlen(p)-4;
|
||||
p[num] = 0; //NULL;
|
||||
|
||||
curCrosshair = p;
|
||||
|
||||
if (!FS_ItemInList(curCrosshair, ncrosshairnames, list))
|
||||
{
|
||||
FS_InsertInList(list, strdup(curCrosshair), ncrosshairnames, 1); // i=1 so none stays first!
|
||||
ncrosshairnames++;
|
||||
}
|
||||
|
||||
//set back so whole string get deleted.
|
||||
p[num] = '.';
|
||||
}
|
||||
#else
|
||||
path = FS_NextPath( path );
|
||||
while (path)
|
||||
{
|
||||
|
@ -268,6 +311,8 @@ char **SetCrosshairNames (void)
|
|||
p[num] = '.';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// sort the list
|
||||
sortCrosshairs (list, ncrosshairnames);
|
||||
|
||||
|
|
Loading…
Reference in a new issue