Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

files.c File Reference

#include "../game/q_shared.h"
#include "qcommon.h"
#include "unzip.h"

Include dependency graph for files.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  directory_t
struct  fileHandleData_t
struct  fileInPack_s
struct  pack_t
union  qfile_gus
struct  qfile_us
struct  searchpath_s

Defines

#define DEMO_PAK_CHECKSUM   437558517u
#define DEMOGAME   "demota"
#define MAX_FILEHASH_SIZE   1024
#define MAX_FOUND_FILES   0x1000
#define MAX_PAKFILES   1024
#define MAX_SEARCH_PATHS   4096
#define MAX_ZPATH   256

Typedefs

typedef fileInPack_s fileInPack_t
typedef qfile_gus qfile_gut
typedef qfile_us qfile_ut
typedef searchpath_s searchpath_t

Functions

void Com_AppendCDKey (const char *filename)
void Com_ReadCDKey (const char *filename)
int FS_AddFileToList (char *name, char *list[MAX_FOUND_FILES], int nfiles)
void FS_AddGameDirectory (const char *path, const char *dir)
char * FS_BuildOSPath (const char *base, const char *game, const char *qpath)
void FS_ClearPakReferences (int flags)
qboolean FS_ComparePaks (char *neededpaks, int len, qboolean dlstring)
qboolean FS_ConditionalRestart (int checksumFeed)
void FS_ConvertPath (char *s)
void FS_CopyFile (char *fromOSPath, char *toOSPath)
qboolean FS_CreatePath (char *OSPath)
void FS_Dir_f (void)
void FS_FCloseFile (fileHandle_t f)
qboolean FS_FileExists (const char *file)
FILEFS_FileForHandle (fileHandle_t f)
int FS_FileIsInPAK (const char *filename, int *pChecksum)
int FS_filelength (fileHandle_t f)
qboolean FS_FilenameCompare (const char *s1, const char *s2)
void FS_Flush (fileHandle_t f)
fileHandle_t FS_FOpenFileAppend (const char *filename)
int FS_FOpenFileByMode (const char *qpath, fileHandle_t *f, fsMode_t mode)
int FS_FOpenFileRead (const char *filename, fileHandle_t *file, qboolean uniqueFILE)
fileHandle_t FS_FOpenFileWrite (const char *filename)
void FS_ForceFlush (fileHandle_t f)
void FS_FreeFile (void *buffer)
void FS_FreeFileList (char **list)
int FS_FTell (fileHandle_t f)
const char * FS_GamePureChecksum (void)
int FS_GetFileList (const char *path, const char *extension, char *listbuf, int bufsize)
int FS_GetModList (char *listbuf, int bufsize)
fileHandle_t FS_HandleForFile (void)
long FS_HashFileName (const char *fname, int hashSize)
qboolean FS_idPak (char *pak, char *base)
void FS_InitFilesystem (void)
qboolean FS_Initialized ()
char ** FS_ListFiles (const char *path, const char *extension, int *numfiles)
char ** FS_ListFilteredFiles (const char *path, const char *extension, char *filter, int *numfiles)
const char * FS_LoadedPakChecksums (void)
const char * FS_LoadedPakNames (void)
const char * FS_LoadedPakPureChecksums (void)
int FS_LoadStack ()
pack_tFS_LoadZipFile (char *zipfile, const char *basename)
void FS_NewDir_f (void)
qboolean FS_PakIsPure (pack_t *pack)
void FS_Path_f (void)
int FS_PathCmp (const char *s1, const char *s2)
void QDECL FS_Printf (fileHandle_t h, const char *fmt,...)
void FS_PureServerSetLoadedPaks (const char *pakSums, const char *pakNames)
void FS_PureServerSetReferencedPaks (const char *pakSums, const char *pakNames)
int FS_Read (void *buffer, int len, fileHandle_t f)
int FS_Read2 (void *buffer, int len, fileHandle_t f)
int FS_ReadFile (const char *qpath, void **buffer)
const char * FS_ReferencedPakChecksums (void)
const char * FS_ReferencedPakNames (void)
const char * FS_ReferencedPakPureChecksums (void)
void FS_Remove (const char *osPath)
void FS_Rename (const char *from, const char *to)
void FS_ReorderPurePaks ()
void FS_ReplaceSeparators (char *path)
void FS_Restart (int checksumFeed)
int FS_ReturnPath (const char *zname, char *zpath, int *depth)
int FS_Seek (fileHandle_t f, long offset, int origin)
void FS_SetRestrictions (void)
char * FS_ShiftedStrStr (const char *string, const char *substring, int shift)
void FS_Shutdown (qboolean closemfp)
void FS_SortFileList (char **filelist, int numfiles)
void FS_Startup (const char *gameName)
qboolean FS_SV_FileExists (const char *file)
int FS_SV_FOpenFileRead (const char *filename, fileHandle_t *fp)
fileHandle_t FS_SV_FOpenFileWrite (const char *filename)
void FS_SV_Rename (const char *from, const char *to)
void FS_TouchFile_f (void)
int FS_Write (const void *buffer, int len, fileHandle_t h)
void FS_WriteFile (const char *qpath, const void *buffer, int size)
int QDECL paksort (const void *a, const void *b)
char ** Sys_ConcatenateFileLists (char **list0, char **list1, char **list2)
unsigned int Sys_CountFileList (char **list)

Variables

qboolean com_fullyInitialized
cvar_tfs_basegame
cvar_tfs_basepath
cvar_tfs_cdpath
int fs_checksumFeed
cvar_tfs_copyfiles
cvar_tfs_debug
int fs_fakeChkSum
char fs_gamedir [MAX_OSPATH]
cvar_tfs_gamedirvar
cvar_tfs_homepath
int fs_loadCount
int fs_loadStack
int fs_numServerPaks
int fs_numServerReferencedPaks
int fs_packFiles
int fs_readCount
qboolean fs_reordered
cvar_tfs_restrict
byte fs_scrambledProductId [152]
searchpath_tfs_searchpaths
char * fs_serverPakNames [MAX_SEARCH_PATHS]
int fs_serverPaks [MAX_SEARCH_PATHS]
char * fs_serverReferencedPakNames [MAX_SEARCH_PATHS]
int fs_serverReferencedPaks [MAX_SEARCH_PATHS]
fileHandleData_t fsh [MAX_FILE_HANDLES]
char lastValidBase [MAX_OSPATH]
char lastValidGame [MAX_OSPATH]


Define Documentation

#define DEMO_PAK_CHECKSUM   437558517u
 

Definition at line 203 of file files.c.

Referenced by FS_SetRestrictions().

#define DEMOGAME   "demota"
 

Definition at line 199 of file files.c.

Referenced by FS_SetRestrictions().

#define MAX_FILEHASH_SIZE   1024
 

Definition at line 215 of file files.c.

#define MAX_FOUND_FILES   0x1000
 

Definition at line 1786 of file files.c.

Referenced by FS_AddFileToList(), Sys_ListFiles(), and Sys_ListFilteredFiles().

#define MAX_PAKFILES   1024
 

Definition at line 2459 of file files.c.

#define MAX_SEARCH_PATHS   4096
 

Definition at line 214 of file files.c.

#define MAX_ZPATH   256
 

Definition at line 213 of file files.c.


Typedef Documentation

typedef struct fileInPack_s fileInPack_t
 

Referenced by FS_FileIsInPAK(), FS_FOpenFileRead(), FS_ListFilteredFiles(), and FS_LoadZipFile().

typedef union qfile_gus qfile_gut
 

typedef struct qfile_us qfile_ut
 

typedef struct searchpath_s searchpath_t
 

Referenced by FS_AddGameDirectory(), FS_ClearPakReferences(), FS_ComparePaks(), FS_FileIsInPAK(), FS_FOpenFileRead(), FS_GamePureChecksum(), FS_ListFilteredFiles(), FS_LoadedPakChecksums(), FS_LoadedPakNames(), FS_LoadedPakPureChecksums(), FS_Path_f(), FS_ReferencedPakChecksums(), FS_ReferencedPakNames(), FS_ReferencedPakPureChecksums(), FS_ReorderPurePaks(), FS_SetRestrictions(), and FS_Shutdown().


Function Documentation

void Com_AppendCDKey const char *  filename  ) 
 

Definition at line 2283 of file common.c.

References buffer, cl_cdkey, CL_CDKeyValidate(), Com_Memset(), f, fileHandle_t, FS_FCloseFile(), FS_Read(), FS_SV_FOpenFileRead(), NULL, Q_strncpyz(), sprintf(), and strcat().

Referenced by FS_Startup().

02283                                              {
02284     fileHandle_t    f;
02285     char            buffer[33];
02286     char            fbuffer[MAX_OSPATH];
02287 
02288     sprintf(fbuffer, "%s/q3key", filename);
02289 
02290     FS_SV_FOpenFileRead( fbuffer, &f );
02291     if (!f) {
02292         Q_strncpyz( &cl_cdkey[16], "                ", 17 );
02293         return;
02294     }
02295 
02296     Com_Memset( buffer, 0, sizeof(buffer) );
02297 
02298     FS_Read( buffer, 16, f );
02299     FS_FCloseFile( f );
02300 
02301     if (CL_CDKeyValidate(buffer, NULL)) {
02302         strcat( &cl_cdkey[16], buffer );
02303     } else {
02304         Q_strncpyz( &cl_cdkey[16], "                ", 17 );
02305     }
02306 }

Here is the call graph for this function:

void Com_ReadCDKey const char *  filename  ) 
 

Definition at line 2253 of file common.c.

References buffer, cl_cdkey, CL_CDKeyValidate(), Com_Memset(), f, fileHandle_t, FS_FCloseFile(), FS_Read(), FS_SV_FOpenFileRead(), NULL, Q_strncpyz(), and sprintf().

Referenced by FS_Startup().

02253                                            {
02254     fileHandle_t    f;
02255     char            buffer[33];
02256     char            fbuffer[MAX_OSPATH];
02257 
02258     sprintf(fbuffer, "%s/q3key", filename);
02259 
02260     FS_SV_FOpenFileRead( fbuffer, &f );
02261     if ( !f ) {
02262         Q_strncpyz( cl_cdkey, "                ", 17 );
02263         return;
02264     }
02265 
02266     Com_Memset( buffer, 0, sizeof(buffer) );
02267 
02268     FS_Read( buffer, 16, f );
02269     FS_FCloseFile( f );
02270 
02271     if (CL_CDKeyValidate(buffer, NULL)) {
02272         Q_strncpyz( cl_cdkey, buffer, 17 );
02273     } else {
02274         Q_strncpyz( cl_cdkey, "                ", 17 );
02275     }
02276 }

Here is the call graph for this function:

int FS_AddFileToList char *  name,
char *  list[MAX_FOUND_FILES],
int  nfiles
[static]
 

Definition at line 1816 of file files.c.

References CopyString(), i, MAX_FOUND_FILES, name, and Q_stricmp().

Referenced by FS_ListFilteredFiles().

01816                                                                                    {
01817     int     i;
01818 
01819     if ( nfiles == MAX_FOUND_FILES - 1 ) {
01820         return nfiles;
01821     }
01822     for ( i = 0 ; i < nfiles ; i++ ) {
01823         if ( !Q_stricmp( name, list[i] ) ) {
01824             return nfiles;      // allready in list
01825         }
01826     }
01827     list[nfiles] = CopyString( name );
01828     nfiles++;
01829 
01830     return nfiles;
01831 }

Here is the call graph for this function:

void FS_AddGameDirectory const char *  path,
const char *  dir
[static]
 

Definition at line 2460 of file files.c.

References searchpath_s::dir, FS_BuildOSPath(), fs_gamedir, FS_LoadZipFile(), fs_searchpaths, directory_t::gamedir, i, searchpath_s::next, NULL, searchpath_s::pack, pakfile, pack_t::pakGamename, paksort(), directory_t::path, Q_stricmp(), Q_strncpyz(), qfalse, qsort(), searchpath_t, strcpy(), strlen(), Sys_FreeFileList(), Sys_ListFiles(), and Z_Malloc().

Referenced by FS_Startup().

02460                                                                      {
02461     searchpath_t    *sp;
02462     int             i;
02463     searchpath_t    *search;
02464     pack_t          *pak;
02465     char            *pakfile;
02466     int             numfiles;
02467     char            **pakfiles;
02468     char            *sorted[MAX_PAKFILES];
02469 
02470     // this fixes the case where fs_basepath is the same as fs_cdpath
02471     // which happens on full installs
02472     for ( sp = fs_searchpaths ; sp ; sp = sp->next ) {
02473         if ( sp->dir && !Q_stricmp(sp->dir->path, path) && !Q_stricmp(sp->dir->gamedir, dir)) {
02474             return;         // we've already got this one
02475         }
02476     }
02477     
02478     Q_strncpyz( fs_gamedir, dir, sizeof( fs_gamedir ) );
02479 
02480     //
02481     // add the directory to the search path
02482     //
02483     search = Z_Malloc (sizeof(searchpath_t));
02484     search->dir = Z_Malloc( sizeof( *search->dir ) );
02485 
02486     Q_strncpyz( search->dir->path, path, sizeof( search->dir->path ) );
02487     Q_strncpyz( search->dir->gamedir, dir, sizeof( search->dir->gamedir ) );
02488     search->next = fs_searchpaths;
02489     fs_searchpaths = search;
02490 
02491     // find all pak files in this directory
02492     pakfile = FS_BuildOSPath( path, dir, "" );
02493     pakfile[ strlen(pakfile) - 1 ] = 0; // strip the trailing slash
02494 
02495     pakfiles = Sys_ListFiles( pakfile, ".pk3", NULL, &numfiles, qfalse );
02496 
02497     // sort them so that later alphabetic matches override
02498     // earlier ones.  This makes pak1.pk3 override pak0.pk3
02499     if ( numfiles > MAX_PAKFILES ) {
02500         numfiles = MAX_PAKFILES;
02501     }
02502     for ( i = 0 ; i < numfiles ; i++ ) {
02503         sorted[i] = pakfiles[i];
02504     }
02505 
02506     qsort( sorted, numfiles, 4, paksort );
02507 
02508     for ( i = 0 ; i < numfiles ; i++ ) {
02509         pakfile = FS_BuildOSPath( path, dir, sorted[i] );
02510         if ( ( pak = FS_LoadZipFile( pakfile, sorted[i] ) ) == 0 )
02511             continue;
02512         // store the game name for downloading
02513         strcpy(pak->pakGamename, dir);
02514 
02515         search = Z_Malloc (sizeof(searchpath_t));
02516         search->pack = pak;
02517         search->next = fs_searchpaths;
02518         fs_searchpaths = search;
02519     }
02520 
02521     // done
02522     Sys_FreeFileList( pakfiles );
02523 }

Here is the call graph for this function:

char* FS_BuildOSPath const char *  base,
const char *  game,
const char *  qpath
 

Definition at line 467 of file files.c.

References Com_sprintf(), and FS_ReplaceSeparators().

Referenced by FS_AddGameDirectory(), FS_FileExists(), FS_FOpenFileAppend(), FS_FOpenFileRead(), FS_FOpenFileWrite(), FS_GetModList(), FS_ListFilteredFiles(), FS_Rename(), FS_SV_FileExists(), FS_SV_FOpenFileRead(), FS_SV_FOpenFileWrite(), FS_SV_Rename(), and Sys_LoadDll().

00467                                                                               {
00468     char    temp[MAX_OSPATH];
00469     static char ospath[2][MAX_OSPATH];
00470     static int toggle;
00471     
00472     toggle ^= 1;        // flip-flop to allow two returns without clash
00473 
00474     if( !game || !game[0] ) {
00475         game = fs_gamedir;
00476     }
00477 
00478     Com_sprintf( temp, sizeof(temp), "/%s/%s", game, qpath );
00479     FS_ReplaceSeparators( temp );   
00480     Com_sprintf( ospath[toggle], sizeof( ospath[0] ), "%s%s", base, temp );
00481     
00482     return ospath[toggle];
00483 }

Here is the call graph for this function:

void FS_ClearPakReferences int  flags  ) 
 

Definition at line 3113 of file files.c.

References searchpath_s::next, searchpath_s::pack, pack_t::referenced, and searchpath_t.

Referenced by CL_Vid_Restart_f(), FS_Restart(), and SV_SpawnServer().

03113                                         {
03114     searchpath_t *search;
03115 
03116     if ( !flags ) {
03117         flags = -1;
03118     }
03119     for ( search = fs_searchpaths; search; search = search->next ) {
03120         // is the element a pak file and has it been referenced?
03121         if ( search->pack ) {
03122             search->pack->referenced &= ~flags;
03123         }
03124     }
03125 }

qboolean FS_ComparePaks char *  neededpaks,
int  len,
qboolean  dlstring
 

Definition at line 2570 of file files.c.

References pack_t::checksum, Com_sprintf(), FS_idPak(), fs_serverReferencedPakNames, fs_serverReferencedPaks, FS_SV_FileExists(), i, searchpath_s::next, searchpath_s::pack, Q_strcat(), qboolean, searchpath_t, and va().

Referenced by CL_InitDownloads().

02570                                                                         {
02571     searchpath_t    *sp;
02572     qboolean havepak, badchecksum;
02573     int i;
02574 
02575     if ( !fs_numServerReferencedPaks ) {
02576         return qfalse; // Server didn't send any pack information along
02577     }
02578 
02579     *neededpaks = 0;
02580 
02581     for ( i = 0 ; i < fs_numServerReferencedPaks ; i++ ) {
02582         // Ok, see if we have this pak file
02583         badchecksum = qfalse;
02584         havepak = qfalse;
02585 
02586         // never autodownload any of the id paks
02587         if ( FS_idPak(fs_serverReferencedPakNames[i], "baseq3") || FS_idPak(fs_serverReferencedPakNames[i], "missionpack") ) {
02588             continue;
02589         }
02590 
02591         for ( sp = fs_searchpaths ; sp ; sp = sp->next ) {
02592             if ( sp->pack && sp->pack->checksum == fs_serverReferencedPaks[i] ) {
02593                 havepak = qtrue; // This is it!
02594                 break;
02595             }
02596         }
02597 
02598         if ( !havepak && fs_serverReferencedPakNames[i] && *fs_serverReferencedPakNames[i] ) { 
02599             // Don't got it
02600 
02601       if (dlstring)
02602       {
02603         // Remote name
02604         Q_strcat( neededpaks, len, "@");
02605         Q_strcat( neededpaks, len, fs_serverReferencedPakNames[i] );
02606         Q_strcat( neededpaks, len, ".pk3" );
02607 
02608         // Local name
02609         Q_strcat( neededpaks, len, "@");
02610         // Do we have one with the same name?
02611         if ( FS_SV_FileExists( va( "%s.pk3", fs_serverReferencedPakNames[i] ) ) )
02612         {
02613           char st[MAX_ZPATH];
02614           // We already have one called this, we need to download it to another name
02615           // Make something up with the checksum in it
02616           Com_sprintf( st, sizeof( st ), "%s.%08x.pk3", fs_serverReferencedPakNames[i], fs_serverReferencedPaks[i] );
02617           Q_strcat( neededpaks, len, st );
02618         } else
02619         {
02620           Q_strcat( neededpaks, len, fs_serverReferencedPakNames[i] );
02621           Q_strcat( neededpaks, len, ".pk3" );
02622         }
02623       }
02624       else
02625       {
02626         Q_strcat( neededpaks, len, fs_serverReferencedPakNames[i] );
02627               Q_strcat( neededpaks, len, ".pk3" );
02628         // Do we have one with the same name?
02629         if ( FS_SV_FileExists( va( "%s.pk3", fs_serverReferencedPakNames[i] ) ) )
02630         {
02631           Q_strcat( neededpaks, len, " (local file exists with wrong checksum)");
02632         }
02633         Q_strcat( neededpaks, len, "\n");
02634       }
02635         }
02636     }
02637 
02638     if ( *neededpaks ) {
02639         return qtrue;
02640     }
02641 
02642     return qfalse; // We have them all
02643 }

Here is the call graph for this function:

qboolean FS_ConditionalRestart int  checksumFeed  ) 
 

Definition at line 3336 of file files.c.

References fs_gamedirvar, FS_Restart(), cvar_s::modified, and qboolean.

Referenced by CL_ParseGamestate(), and CL_Vid_Restart_f().

03336                                                    {
03337     if( fs_gamedirvar->modified || checksumFeed != fs_checksumFeed ) {
03338         FS_Restart( checksumFeed );
03339         return qtrue;
03340     }
03341     return qfalse;
03342 }

Here is the call graph for this function:

void FS_ConvertPath char *  s  ) 
 

Definition at line 2273 of file files.c.

References s.

Referenced by FS_NewDir_f().

02273                                {
02274     while (*s) {
02275         if ( *s == '\\' || *s == ':' ) {
02276             *s = '/';
02277         }
02278         s++;
02279     }
02280 }

void FS_CopyFile char *  fromOSPath,
char *  toOSPath
[static]
 

Definition at line 521 of file files.c.

References byte, Com_Error(), Com_Printf(), ERR_FATAL, f, fclose(), fopen(), fread(), free(), FS_CreatePath(), fseek(), ftell(), fwrite(), malloc(), SEEK_END, SEEK_SET, and strstr().

Referenced by FS_FOpenFileRead(), FS_Rename(), and FS_SV_Rename().

00521                                                             {
00522     FILE    *f;
00523     int     len;
00524     byte    *buf;
00525 
00526     Com_Printf( "copy %s to %s\n", fromOSPath, toOSPath );
00527 
00528     if (strstr(fromOSPath, "journal.dat") || strstr(fromOSPath, "journaldata.dat")) {
00529         Com_Printf( "Ignoring journal files\n");
00530         return;
00531     }
00532 
00533     f = fopen( fromOSPath, "rb" );
00534     if ( !f ) {
00535         return;
00536     }
00537     fseek (f, 0, SEEK_END);
00538     len = ftell (f);
00539     fseek (f, 0, SEEK_SET);
00540 
00541     // we are using direct malloc instead of Z_Malloc here, so it
00542     // probably won't work on a mac... Its only for developers anyway...
00543     buf = malloc( len );
00544     if (fread( buf, 1, len, f ) != len)
00545         Com_Error( ERR_FATAL, "Short read in FS_Copyfiles()\n" );
00546     fclose( f );
00547 
00548     if( FS_CreatePath( toOSPath ) ) {
00549         return;
00550     }
00551 
00552     f = fopen( toOSPath, "wb" );
00553     if ( !f ) {
00554         return;
00555     }
00556     if (fwrite( buf, 1, len, f ) != len)
00557         Com_Error( ERR_FATAL, "Short write in FS_Copyfiles()\n" );
00558     fclose( f );
00559     free( buf );
00560 }

Here is the call graph for this function:

qboolean FS_CreatePath char *  OSPath  )  [static]
 

Definition at line 493 of file files.c.

References Com_Printf(), qboolean, strstr(), and Sys_Mkdir().

Referenced by FS_CopyFile(), FS_FOpenFileAppend(), FS_FOpenFileWrite(), and FS_SV_FOpenFileWrite().

00493                                              {
00494     char    *ofs;
00495     
00496     // make absolutely sure that it can't back up the path
00497     // FIXME: is c: allowed???
00498     if ( strstr( OSPath, ".." ) || strstr( OSPath, "::" ) ) {
00499         Com_Printf( "WARNING: refusing to create relative path \"%s\"\n", OSPath );
00500         return qtrue;
00501     }
00502 
00503     for (ofs = OSPath+1 ; *ofs ; ofs++) {
00504         if (*ofs == PATH_SEP) { 
00505             // create the directory
00506             *ofs = 0;
00507             Sys_Mkdir (OSPath);
00508             *ofs = PATH_SEP;
00509         }
00510     }
00511     return qfalse;
00512 }

Here is the call graph for this function:

void FS_Dir_f void   ) 
 

Definition at line 2237 of file files.c.

References Cmd_Argc(), Cmd_Argv(), Com_Printf(), FS_FreeFileList(), FS_ListFiles(), and i.

Referenced by FS_Startup().

02237                       {
02238     char    *path;
02239     char    *extension;
02240     char    **dirnames;
02241     int     ndirs;
02242     int     i;
02243 
02244     if ( Cmd_Argc() < 2 || Cmd_Argc() > 3 ) {
02245         Com_Printf( "usage: dir <directory> [extension]\n" );
02246         return;
02247     }
02248 
02249     if ( Cmd_Argc() == 2 ) {
02250         path = Cmd_Argv( 1 );
02251         extension = "";
02252     } else {
02253         path = Cmd_Argv( 1 );
02254         extension = Cmd_Argv( 2 );
02255     }
02256 
02257     Com_Printf( "Directory of %s %s\n", path, extension );
02258     Com_Printf( "---------------\n" );
02259 
02260     dirnames = FS_ListFiles( path, extension, &ndirs );
02261 
02262     for ( i = 0; i < ndirs; i++ ) {
02263         Com_Printf( "%s\n", dirnames[i] );
02264     }
02265     FS_FreeFileList( dirnames );
02266 }

Here is the call graph for this function:

void FS_FCloseFile fileHandle_t  f  ) 
 

Definition at line 819 of file files.c.

00819                                      {
00820     if ( !fs_searchpaths ) {
00821         Com_Error( ERR_FATAL, "Filesystem call made without initialization\n" );
00822     }
00823 
00824     if (fsh[f].streamed) {
00825         Sys_EndStreamedFile(f);
00826     }
00827     if (fsh[f].zipFile == qtrue) {
00828         unzCloseCurrentFile( fsh[f].handleFiles.file.z );
00829         if ( fsh[f].handleFiles.unique ) {
00830             unzClose( fsh[f].handleFiles.file.z );
00831         }
00832         Com_Memset( &fsh[f], 0, sizeof( fsh[f] ) );
00833         return;
00834     }
00835 
00836     // we didn't find it as a pak, so close it as a unique file
00837     if (fsh[f].handleFiles.file.o) {
00838         fclose (fsh[f].handleFiles.file.o);
00839     }
00840     Com_Memset( &fsh[f], 0, sizeof( fsh[f] ) );
00841 }

qboolean FS_FileExists const char *  file  ) 
 

Definition at line 582 of file files.c.

References f, fclose(), file, fopen(), FS_BuildOSPath(), fs_gamedir, fs_homepath, qboolean, and cvar_s::string.

Referenced by Sys_LoadDll().

00583 {
00584     FILE *f;
00585     char *testpath;
00586 
00587     testpath = FS_BuildOSPath( fs_homepath->string, fs_gamedir, file );
00588 
00589     f = fopen( testpath, "rb" );
00590     if (f) {
00591         fclose( f );
00592         return qtrue;
00593     }
00594     return qfalse;
00595 }

Here is the call graph for this function:

FILE* FS_FileForHandle fileHandle_t  f  )  [static]
 

Definition at line 399 of file files.c.

References Com_Error(), ERR_DROP, qfile_us::file, fsh, fileHandleData_t::handleFiles, qfile_gus::o, and fileHandleData_t::zipFile.

Referenced by FS_filelength(), FS_ForceFlush(), FS_GetModList(), FS_Seek(), and FS_Write().

00399                                                 {
00400     if ( f < 0 || f > MAX_FILE_HANDLES ) {
00401         Com_Error( ERR_DROP, "FS_FileForHandle: out of reange" );
00402     }
00403     if (fsh[f].zipFile == qtrue) {
00404         Com_Error( ERR_DROP, "FS_FileForHandle: can't get FILE on zip file" );
00405     }
00406     if ( ! fsh[f].handleFiles.file.o ) {
00407         Com_Error( ERR_DROP, "FS_FileForHandle: NULL" );
00408     }
00409     
00410     return fsh[f].handleFiles.file.o;
00411 }

Here is the call graph for this function:

int FS_FileIsInPAK const char *  filename,
int *  pChecksum
 

Definition at line 1431 of file files.c.

References Com_Error(), ERR_FATAL, fileInPack_t, FS_FilenameCompare(), FS_HashFileName(), FS_PakIsPure(), pack_t::hashSize, pack_t::hashTable, fileInPack_s::name, searchpath_s::next, fileInPack_s::next, searchpath_s::pack, pack_t::pure_checksum, searchpath_t, and strstr().

Referenced by SV_VerifyPaks_f().

01431                                                           {
01432     searchpath_t    *search;
01433     pack_t          *pak;
01434     fileInPack_t    *pakFile;
01435     long            hash = 0;
01436 
01437     if ( !fs_searchpaths ) {
01438         Com_Error( ERR_FATAL, "Filesystem call made without initialization\n" );
01439     }
01440 
01441     if ( !filename ) {
01442         Com_Error( ERR_FATAL, "FS_FOpenFileRead: NULL 'filename' parameter passed\n" );
01443     }
01444 
01445     // qpaths are not supposed to have a leading slash
01446     if ( filename[0] == '/' || filename[0] == '\\' ) {
01447         filename++;
01448     }
01449 
01450     // make absolutely sure that it can't back up the path.
01451     // The searchpaths do guarantee that something will always
01452     // be prepended, so we don't need to worry about "c:" or "//limbo" 
01453     if ( strstr( filename, ".." ) || strstr( filename, "::" ) ) {
01454         return -1;
01455     }
01456 
01457     //
01458     // search through the path, one element at a time
01459     //
01460 
01461     for ( search = fs_searchpaths ; search ; search = search->next ) {
01462         //
01463         if (search->pack) {
01464             hash = FS_HashFileName(filename, search->pack->hashSize);
01465         }
01466         // is the element a pak file?
01467         if ( search->pack && search->pack->hashTable[hash] ) {
01468             // disregard if it doesn't match one of the allowed pure pak files
01469             if ( !FS_PakIsPure(search->pack) ) {
01470                 continue;
01471             }
01472 
01473             // look through all the pak file elements
01474             pak = search->pack;
01475             pakFile = pak->hashTable[hash];
01476             do {
01477                 // case and separator insensitive comparisons
01478                 if ( !FS_FilenameCompare( pakFile->name, filename ) ) {
01479                     if (pChecksum) {
01480                         *pChecksum = pak->pure_checksum;
01481                     }
01482                     return 1;
01483                 }
01484                 pakFile = pakFile->next;
01485             } while(pakFile != NULL);
01486         }
01487     }
01488     return -1;
01489 }

Here is the call graph for this function:

int FS_filelength fileHandle_t  f  ) 
 

Definition at line 429 of file files.c.

References f, FS_FileForHandle(), fseek(), ftell(), h(), SEEK_END, and SEEK_SET.

Referenced by FS_FOpenFileRead(), and FS_SV_FOpenFileRead().

00429                                     {
00430     int     pos;
00431     int     end;
00432     FILE*   h;
00433 
00434     h = FS_FileForHandle(f);
00435     pos = ftell (h);
00436     fseek (h, 0, SEEK_END);
00437     end = ftell (h);
00438     fseek (h, pos, SEEK_SET);
00439 
00440     return end;
00441 }

Here is the call graph for this function: