Browse Source

filesystem: replace va function calls.

pull/2/head
Andrey Akhmichin 2 years ago committed by Alibek Omarov
parent
commit
34160151a4
  1. 21
      filesystem/VFileSystem009.cpp
  2. 45
      filesystem/filesystem.c
  3. 6
      filesystem/wad.c

21
filesystem/VFileSystem009.cpp

@ -42,12 +42,15 @@ static inline qboolean IsIdGamedir( const char *id )
!Q_strcmp( id, "GAMEDOWNLOAD" ); !Q_strcmp( id, "GAMEDOWNLOAD" );
} }
static inline const char *IdToDir( const char *id ) static inline const char *IdToDir( char *dir, size_t size, const char *id )
{ {
if( !Q_strcmp( id, "GAME" )) if( !Q_strcmp( id, "GAME" ))
return GI->gamefolder; return GI->gamefolder;
else if( !Q_strcmp( id, "GAMEDOWNLOAD" )) else if( !Q_strcmp( id, "GAMEDOWNLOAD" ))
return va( "%s/downloaded", GI->gamefolder ); {
Q_snprintf( dir, size, "%s/downloaded", GI->gamefolder );
return dir;
}
else if( !Q_strcmp( id, "GAMECONFIG" )) else if( !Q_strcmp( id, "GAMECONFIG" ))
return fs_writepath->filename; // full path here so it's totally our write allowed directory return fs_writepath->filename; // full path here so it's totally our write allowed directory
else if( !Q_strcmp( id, "PLATFORM" )) else if( !Q_strcmp( id, "PLATFORM" ))
@ -145,7 +148,10 @@ public:
void CreateDirHierarchy( const char *path, const char *id ) override void CreateDirHierarchy( const char *path, const char *id ) override
{ {
FS_CreatePath( va( "%s/%s", IdToDir( id ), path )); // FS_CreatePath is aware of slashes char dir[MAX_VA_STRING], fullpath[MAX_VA_STRING];
Q_snprintf( fullpath, sizeof( fullpath ), "%s/%s", IdToDir( dir, sizeof( dir ), id ), path );
FS_CreatePath( fullpath ); // FS_CreatePath is aware of slashes
} }
bool FileExists( const char *path ) override bool FileExists( const char *path ) override
@ -365,7 +371,6 @@ public:
return buf; return buf;
} }
const char *fullpath = FS_GetDiskPath( p, false ); const char *fullpath = FS_GetDiskPath( p, false );
if( !fullpath ) if( !fullpath )
return NULL; return NULL;
@ -449,10 +454,12 @@ public:
bool AddPackFile( const char *path, const char *id ) override bool AddPackFile( const char *path, const char *id ) override
{ {
char *p = va( "%s/%s", IdToDir( id ), path ); char dir[MAX_VA_STRING], fullpath[MAX_VA_STRING];
CopyAndFixSlashes( p, path );
Q_snprintf( fullpath, sizeof( fullpath ), "%s/%s", IdToDir( dir, sizeof( dir ), id ), path );
CopyAndFixSlashes( fullpath, path );
return !!FS_AddPak_Fullpath( p, NULL, FS_CUSTOM_PATH ); return !!FS_AddPak_Fullpath( fullpath, NULL, FS_CUSTOM_PATH );
} }
FileHandle_t OpenFromCacheForRead( const char *path , const char *mode, const char *id ) override FileHandle_t OpenFromCacheForRead( const char *path , const char *mode, const char *id ) override

45
filesystem/filesystem.c

@ -819,7 +819,8 @@ void FS_ParseGenericGameInfo( gameinfo_t *GameInfo, const char *buf, const qbool
} }
// make sure what gamedir is really exist // make sure what gamedir is really exist
if( !FS_SysFolderExists( va( "%s/%s", fs_rootdir, GameInfo->falldir ))) Q_snprintf( token, sizeof( token ), "%s/%s", fs_rootdir, GameInfo->falldir );
if( !FS_SysFolderExists( token ))
GameInfo->falldir[0] = '\0'; GameInfo->falldir[0] = '\0';
} }
@ -911,16 +912,21 @@ FS_CheckForGameDir
*/ */
static qboolean FS_CheckForGameDir( const char *gamedir ) static qboolean FS_CheckForGameDir( const char *gamedir )
{ {
char buf[MAX_VA_STRING];
// if directory contain config.cfg it's 100% gamedir // if directory contain config.cfg it's 100% gamedir
if( FS_FileExists( va( "%s/config.cfg", gamedir ), false )) Q_snprintf( buf, sizeof( buf ), "%s/config.cfg", gamedir );
if( FS_FileExists( buf, false ))
return true; return true;
// if directory contain progs.dat it's 100% gamedir // if directory contain progs.dat it's 100% gamedir
if( FS_FileExists( va( "%s/progs.dat", gamedir ), false )) Q_snprintf( buf, sizeof( buf ), "%s/progs.dat", gamedir );
if( FS_FileExists( buf, false ))
return true; return true;
// quake mods probably always archived but can missed config.cfg before first running // quake mods probably always archived but can missed config.cfg before first running
if( FS_FileExists( va( "%s/pak0.pak", gamedir ), false )) Q_snprintf( buf, sizeof( buf ), "%s/pak0.pak", gamedir );
if( FS_FileExists( buf, false ))
return true; return true;
// NOTE; adds here some additional checks if you wished // NOTE; adds here some additional checks if you wished
@ -1014,6 +1020,7 @@ void FS_AddGameHierarchy( const char *dir, uint flags )
{ {
int i; int i;
qboolean isGameDir = flags & FS_GAMEDIR_PATH; qboolean isGameDir = flags & FS_GAMEDIR_PATH;
char buf[MAX_VA_STRING];
GI->added = true; GI->added = true;
@ -1046,15 +1053,23 @@ void FS_AddGameHierarchy( const char *dir, uint flags )
newFlags |= FS_GAMERODIR_PATH; newFlags |= FS_GAMERODIR_PATH;
FS_AllowDirectPaths( true ); FS_AllowDirectPaths( true );
FS_AddGameDirectory( va( "%s/%s/", fs_rodir, dir ), newFlags ); Q_snprintf( buf, sizeof( buf ), "%s/%s/", fs_rodir, dir );
FS_AddGameDirectory( buf, newFlags );
FS_AllowDirectPaths( false ); FS_AllowDirectPaths( false );
} }
if( isGameDir ) if( isGameDir )
FS_AddGameDirectory( va( "%s/downloaded/", dir ), FS_NOWRITE_PATH | FS_CUSTOM_PATH ); {
FS_AddGameDirectory( va( "%s/", dir ), flags ); Q_snprintf( buf, sizeof( buf ), "%s/downloaded/", dir );
FS_AddGameDirectory( buf, FS_NOWRITE_PATH | FS_CUSTOM_PATH );
}
Q_snprintf( buf, sizeof( buf ), "%s/", dir );
FS_AddGameDirectory( buf, flags );
if( isGameDir ) if( isGameDir )
FS_AddGameDirectory( va( "%s/custom/", dir ), FS_NOWRITE_PATH | FS_CUSTOM_PATH ); {
Q_snprintf( buf, sizeof( buf ), "%s/custom/", dir );
FS_AddGameDirectory( buf, FS_NOWRITE_PATH | FS_CUSTOM_PATH );
}
} }
/* /*
@ -1072,8 +1087,12 @@ void FS_Rescan( void )
#if XASH_IOS #if XASH_IOS
{ {
FS_AddPak_Fullpath( va( "%sextras.pak", SDL_GetBasePath() ), NULL, extrasFlags ); char buf[MAX_VA_STRING];
FS_AddPak_Fullpath( va( "%sextras_%s.pak", SDL_GetBasePath(), GI->gamefolder ), NULL, extrasFlags );
Q_snprintf( buf, sizeof( buf ), "%sextras.pak", SDL_GetBasePath() );
FS_AddPak_Fullpath( buf, NULL, extrasFlags );
Q_snprintf( buf, sizeof( buf ), "%sextras_%s.pak", SDL_GetBasePath(), GI->gamefolder );
FS_AddPak_Fullpath( buf, NULL, extrasFlags );
} }
#else #else
str = getenv( "XASH3D_EXTRAS_PAK1" ); str = getenv( "XASH3D_EXTRAS_PAK1" );
@ -1293,6 +1312,7 @@ qboolean FS_InitStdio( qboolean caseinsensitive, const char *rootdir, const char
qboolean hasBaseDir = false; qboolean hasBaseDir = false;
qboolean hasGameDir = false; qboolean hasGameDir = false;
int i; int i;
char buf[MAX_VA_STRING];
FS_InitMemory(); FS_InitMemory();
#if !XASH_WIN32 #if !XASH_WIN32
@ -1358,7 +1378,10 @@ qboolean FS_InitStdio( qboolean caseinsensitive, const char *rootdir, const char
// build list of game directories here // build list of game directories here
if( COM_CheckStringEmpty( fs_rodir )) if( COM_CheckStringEmpty( fs_rodir ))
FS_AddGameDirectory( va( "%s/", fs_rodir ), FS_STATIC_PATH|FS_NOWRITE_PATH ); {
Q_snprintf( buf, sizeof( buf ), "%s/", fs_rodir );
FS_AddGameDirectory( buf, FS_STATIC_PATH|FS_NOWRITE_PATH );
}
FS_AddGameDirectory( "./", FS_STATIC_PATH ); FS_AddGameDirectory( "./", FS_STATIC_PATH );
for( i = 0; i < dirs.numstrings; i++ ) for( i = 0; i < dirs.numstrings; i++ )

6
filesystem/wad.c

@ -503,6 +503,7 @@ static void FS_Search_WAD( searchpath_t *search, stringlist_t *list, const char
string wadfolder, temp; string wadfolder, temp;
int j, i; int j, i;
const char *slash, *backslash, *colon, *separator; const char *slash, *backslash, *colon, *separator;
char buf[MAX_VA_STRING];
// quick reject by filetype // quick reject by filetype
if( type == TYP_NONE ) if( type == TYP_NONE )
@ -550,8 +551,9 @@ static void FS_Search_WAD( searchpath_t *search, stringlist_t *list, const char
if( j == list->numstrings ) if( j == list->numstrings )
{ {
// build path: wadname/lumpname.ext // build path: wadname/lumpname.ext
Q_snprintf( temp2, sizeof(temp2), "%s/%s", wadfolder, temp ); Q_snprintf( temp2, sizeof( temp2 ), "%s/%s", wadfolder, temp );
COM_DefaultExtension( temp2, va(".%s", W_ExtFromType( search->wad->lumps[i].type ))); Q_snprintf( buf, sizeof( buf ), ".%s", W_ExtFromType( search->wad->lumps[i].type ));
COM_DefaultExtension( temp2, buf );
stringlistappend( list, temp2 ); stringlistappend( list, temp2 );
} }
} }

Loading…
Cancel
Save