mirror of
https://github.com/blendogames/thirtyflightsofloving.git
synced 2024-11-14 08:31:04 +00:00
Replace strstr with non-ambiguous check for file extensions.
This commit is contained in:
parent
6733c0cf6c
commit
e3a80955cd
5 changed files with 44 additions and 42 deletions
|
@ -265,6 +265,8 @@ static char *creditsBuffer;
|
|||
void ActionStartMod (char *mod);
|
||||
|
||||
// ui_subsystem.c
|
||||
qboolean IsValidImageFilename (char *name);
|
||||
|
||||
void UI_AddButton (buttonmenuobject_t *thisObj, int index, float x, float y, float w, float h);
|
||||
void UI_AddMainButton (mainmenuobject_t *thisObj, int index, int x, int y, char *name);
|
||||
void UI_RefreshCursorMenu (void);
|
||||
|
|
|
@ -223,7 +223,7 @@ void UI_LoadArenas (void)
|
|||
char longname[MAX_TOKEN_CHARS];
|
||||
char gametypes[MAX_TOKEN_CHARS];
|
||||
char scratch[200];
|
||||
int i, j, narenas = 0, narenanames = 0;
|
||||
int i, j, len, narenas = 0, narenanames = 0;
|
||||
qboolean type_supported[NUM_MAPTYPES];
|
||||
|
||||
//
|
||||
|
@ -255,11 +255,12 @@ void UI_LoadArenas (void)
|
|||
if (!arenafiles || !arenafiles[i])
|
||||
continue;
|
||||
|
||||
p = arenafiles[i] + strlen(path) + 1; // skip over path and next slash
|
||||
|
||||
if (!strstr(p, ".arena"))
|
||||
len = (int)strlen(arenafiles[i]);
|
||||
if ( strcmp(arenafiles[i]+max(len-6,0), ".arena") )
|
||||
continue;
|
||||
|
||||
p = arenafiles[i] + strlen(path) + 1; // skip over path and next slash
|
||||
|
||||
if (!FS_ItemInList(p, narenanames, tmplist)) // check if already in list
|
||||
{
|
||||
if (UI_ParseArenaFromFile (p, shortname, longname, gametypes, MAX_TOKEN_CHARS))
|
||||
|
@ -317,11 +318,12 @@ void UI_LoadArenas (void)
|
|||
if (!arenafiles || !arenafiles[i])
|
||||
continue;
|
||||
|
||||
p = arenafiles[i];
|
||||
|
||||
if (!strstr(p, ".arena"))
|
||||
len = (int)strlen(arenafiles[i]);
|
||||
if ( strcmp(arenafiles[i]+max(len-6,0), ".arena") )
|
||||
continue;
|
||||
|
||||
p = arenafiles[i];
|
||||
|
||||
if (!FS_ItemInList(p, narenanames, tmplist)) // check if already in list
|
||||
{
|
||||
if (UI_ParseArenaFromFile (p, shortname, longname, gametypes, MAX_TOKEN_CHARS))
|
||||
|
|
|
@ -187,17 +187,11 @@ char **SetFontNames (void)
|
|||
if (!fontfiles || !fontfiles[i]) // Knightmare added array base check
|
||||
continue;
|
||||
|
||||
p = strstr(fontfiles[i], "/fonts/"); p++;
|
||||
p = strstr(p, "/"); p++;
|
||||
|
||||
if ( !strstr(p, ".tga")
|
||||
#ifdef PNG_SUPPORT
|
||||
&& !strstr(p, ".png")
|
||||
#endif // PNG_SUPPORT
|
||||
&& !strstr(p, ".jpg")
|
||||
&& !strstr(p, ".pcx") )
|
||||
if ( !IsValidImageFilename(fontfiles[i]) )
|
||||
continue;
|
||||
|
||||
p = strrchr(fontfiles[i], '/'); p++;
|
||||
|
||||
num = strlen(p)-4;
|
||||
p[num] = 0;//NULL;
|
||||
|
||||
|
@ -228,18 +222,13 @@ char **SetFontNames (void)
|
|||
if (!fontfiles || !fontfiles[i]) // Knightmare added array base check
|
||||
continue;
|
||||
|
||||
p = strstr(fontfiles[i], "/"); p++;
|
||||
|
||||
if ( !strstr(p, ".tga")
|
||||
#ifdef PNG_SUPPORT
|
||||
&& !strstr(p, ".png")
|
||||
#endif // PNG_SUPPORT
|
||||
&& !strstr(p, ".jpg")
|
||||
&& !strstr(p, ".pcx") )
|
||||
if ( !IsValidImageFilename(fontfiles[i]) )
|
||||
continue;
|
||||
|
||||
p = strrchr(fontfiles[i], '/'); p++;
|
||||
|
||||
num = strlen(p)-4;
|
||||
p[num] = 0; //NULL;
|
||||
p[num] = 0; // NULL
|
||||
|
||||
curFont = p;
|
||||
|
||||
|
|
|
@ -185,17 +185,11 @@ char **SetCrosshairNames (void)
|
|||
if (!crosshairfiles || !crosshairfiles[i])
|
||||
continue;
|
||||
|
||||
p = strstr(crosshairfiles[i], "/pics/"); p++;
|
||||
p = strstr(p, "/"); p++;
|
||||
|
||||
if ( !strstr(p, ".tga")
|
||||
#ifdef PNG_SUPPORT
|
||||
&& !strstr(p, ".png")
|
||||
#endif // PNG_SUPPORT
|
||||
&& !strstr(p, ".jpg")
|
||||
&& !strstr(p, ".pcx") )
|
||||
if ( !IsValidImageFilename(crosshairfiles[i]) )
|
||||
continue;
|
||||
|
||||
p = strrchr(crosshairfiles[i], '/'); p++;
|
||||
|
||||
// filename must be chxxx
|
||||
if (strncmp(p, "ch", 2))
|
||||
continue;
|
||||
|
@ -240,16 +234,11 @@ char **SetCrosshairNames (void)
|
|||
if (!crosshairfiles || !crosshairfiles[i])
|
||||
continue;
|
||||
|
||||
p = strstr(crosshairfiles[i], "/"); p++;
|
||||
|
||||
if ( !strstr(p, ".tga")
|
||||
#ifdef PNG_SUPPORT
|
||||
&& !strstr(p, ".png")
|
||||
#endif // PNG_SUPPORT
|
||||
&& !strstr(p, ".jpg")
|
||||
&& !strstr(p, ".pcx") )
|
||||
if ( !IsValidImageFilename(crosshairfiles[i]) )
|
||||
continue;
|
||||
|
||||
p = strrchr(crosshairfiles[i], '/'); p++;
|
||||
|
||||
// filename must be chxxx
|
||||
if (strncmp(p, "ch", 2))
|
||||
continue;
|
||||
|
|
|
@ -100,6 +100,26 @@ void InsertInList (char **list, char *insert, int len, int start)
|
|||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
==========================
|
||||
IsValidImageFilename
|
||||
==========================
|
||||
*/
|
||||
qboolean IsValidImageFilename (char *name)
|
||||
{
|
||||
int len = (int)strlen(name);
|
||||
|
||||
if ( !strcmp(name+max(len-4,0), ".pcx")
|
||||
|| !strcmp(name+max(len-4,0), ".tga")
|
||||
#ifdef PNG_SUPPORT
|
||||
|| !strcmp(name+max(len-4,0), ".png")
|
||||
#endif // PNG_SUPPORT
|
||||
|| !strcmp(name+max(len-4,0), ".jpg")
|
||||
)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
=======================================================================
|
||||
|
|
Loading…
Reference in a new issue