============ 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 ============ */
| 1027 | ============ |
| 1028 | */ |
| 1029 | int 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 |
no test coverage detected