MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / OpenFileReadFlags

Method OpenFileReadFlags

neo/framework/FileSystem.cpp:2969–3189  ·  view source on GitHub ↗

=========== idFileSystemLocal::OpenFileReadFlags Finds the file in the search path, following search flag recommendations Returns filesize and an open FILE pointer. Used for streaming data out of either a separate file or a ZIP file. =========== */

Source from the content-addressed store, hash-verified

2967===========
2968*/
2969idFile *idFileSystemLocal::OpenFileReadFlags( const char *relativePath, int searchFlags, pack_t **foundInPak, bool allowCopyFiles, const char* gamedir ) {
2970 searchpath_t * search;
2971 idStr netpath;
2972 pack_t * pak;
2973 fileInPack_t * pakFile;
2974 directory_t * dir;
2975 int hash;
2976 FILE * fp;
2977
2978 if ( !searchPaths ) {
2979 common->FatalError( "Filesystem call made without initialization\n" );
2980 }
2981
2982 if ( !relativePath ) {
2983 common->FatalError( "idFileSystemLocal::OpenFileRead: NULL 'relativePath' parameter passed\n" );
2984 }
2985
2986 if ( foundInPak ) {
2987 *foundInPak = NULL;
2988 }
2989
2990 // qpaths are not supposed to have a leading slash
2991 if ( relativePath[0] == '/' || relativePath[0] == '\\' ) {
2992 relativePath++;
2993 }
2994
2995 // make absolutely sure that it can't back up the path.
2996 // The searchpaths do guarantee that something will always
2997 // be prepended, so we don't need to worry about "c:" or "//limbo"
2998 if ( strstr( relativePath, ".." ) || strstr( relativePath, "::" ) ) {
2999 return NULL;
3000 }
3001
3002 // edge case
3003 if ( relativePath[0] == '\0' ) {
3004 return NULL;
3005 }
3006
3007 // make sure the doomkey file is only readable by game at initialization
3008 // any other time the key should only be accessed in memory using the provided functions
3009 if( common->IsInitialized() && ( idStr::Icmp( relativePath, CDKEY_FILE ) == 0 || idStr::Icmp( relativePath, XPKEY_FILE ) == 0 ) ) {
3010 return NULL;
3011 }
3012
3013 //
3014 // search through the path, one element at a time
3015 //
3016
3017 hash = HashFileName( relativePath );
3018
3019 for ( search = searchPaths; search; search = search->next ) {
3020 if ( search->dir && ( searchFlags & FSFLAG_SEARCH_DIRS ) ) {
3021 // check a file in the directory tree
3022
3023 // if we are running restricted, the only files we
3024 // will allow to come from the directory are .cfg files
3025 if ( fs_restrict.GetBool() || serverPaks.Num() ) {
3026 if ( !FileAllowedFromDir( relativePath ) ) {

Callers

nothing calls this directly

Calls 13

GetIntegerMethod · 0.80
ExtractFileNameMethod · 0.80
Sys_FileTimeStampFunction · 0.50
FatalErrorMethod · 0.45
IsInitializedMethod · 0.45
GetBoolMethod · 0.45
NumMethod · 0.45
PrintfMethod · 0.45
c_strMethod · 0.45
DPrintfMethod · 0.45
GetStringMethod · 0.45
CmpMethod · 0.45

Tested by

no test coverage detected