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

Method ReadFile

neo/framework/FileSystem.cpp:1029–1126  ·  view source on GitHub ↗

============ idFileSystemLocal::ReadFile Filename are relative to the search path a null buffer will just return the file length and time without loading timestamp can be NULL if not required ============ */

Source from the content-addressed store, hash-verified

1027============
1028*/
1029int idFileSystemLocal::ReadFile( const char *relativePath, void **buffer, ID_TIME_T *timestamp ) {
1030 idFile * f;
1031 byte * buf;
1032 int len;
1033 bool isConfig;
1034
1035 if ( !searchPaths ) {
1036 common->FatalError( "Filesystem call made without initialization\n" );
1037 }
1038
1039 if ( !relativePath || !relativePath[0] ) {
1040 common->FatalError( "idFileSystemLocal::ReadFile with empty name\n" );
1041 }
1042
1043 if ( timestamp ) {
1044 *timestamp = FILE_NOT_FOUND_TIMESTAMP;
1045 }
1046
1047 if ( buffer ) {
1048 *buffer = NULL;
1049 }
1050
1051 buf = NULL; // quiet compiler warning
1052
1053 // if this is a .cfg file and we are playing back a journal, read
1054 // it from the journal file
1055 if ( strstr( relativePath, ".cfg" ) == relativePath + strlen( relativePath ) - 4 ) {
1056 isConfig = true;
1057 if ( eventLoop && eventLoop->JournalLevel() == 2 ) {
1058 int r;
1059
1060 loadCount++;
1061 loadStack++;
1062
1063 common->DPrintf( "Loading %s from journal file.\n", relativePath );
1064 len = 0;
1065 r = eventLoop->com_journalDataFile->Read( &len, sizeof( len ) );
1066 if ( r != sizeof( len ) ) {
1067 *buffer = NULL;
1068 return -1;
1069 }
1070 buf = (byte *)Mem_ClearedAlloc(len+1);
1071 *buffer = buf;
1072 r = eventLoop->com_journalDataFile->Read( buf, len );
1073 if ( r != len ) {
1074 common->FatalError( "Read from journalDataFile failed" );
1075 }
1076
1077 // guarantee that it will have a trailing 0 for string operations
1078 buf[len] = 0;
1079
1080 return len;
1081 }
1082 } else {
1083 isConfig = false;
1084 }
1085
1086 // look for it in the filesystem or pack files

Callers 15

NextMapMethod · 0.80
DumpOggSoundsMethod · 0.80
SpawnMethod · 0.80
CompileFileMethod · 0.80
ConvertMayaToMD5Method · 0.80
QE_LoadProjectFunction · 0.80
SetMaterialInfoMethod · 0.80
SetGuiInfoMethod · 0.80
OnLbnDblclkListkeyvalMethod · 0.80
AddCommentedItemsMethod · 0.80
OnBnClickedButtonAddMethod · 0.80

Calls 9

Mem_ClearedAllocFunction · 0.85
FatalErrorMethod · 0.45
JournalLevelMethod · 0.45
DPrintfMethod · 0.45
ReadMethod · 0.45
LengthMethod · 0.45
TimestampMethod · 0.45
WriteMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected