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

Method OpenForReading

neo/framework/DemoFile.cpp:85–127  ·  view source on GitHub ↗

================ idDemoFile::OpenForReading ================ */

Source from the content-addressed store, hash-verified

83================
84*/
85bool idDemoFile::OpenForReading( const char *fileName ) {
86 static const int magicLen = sizeof(DEMO_MAGIC) / sizeof(DEMO_MAGIC[0]);
87 char magicBuffer[magicLen];
88 int compression;
89 int fileLength;
90
91 Close();
92
93 f = fileSystem->OpenFileRead( fileName );
94 if ( !f ) {
95 return false;
96 }
97
98 fileLength = f->Length();
99
100 if ( com_preloadDemos.GetBool() ) {
101 fileImage = (byte *)Mem_Alloc( fileLength );
102 f->Read( fileImage, fileLength );
103 fileSystem->CloseFile( f );
104 f = new idFile_Memory( va( "preloaded(%s)", fileName ), (const char *)fileImage, fileLength );
105 }
106
107 if ( com_logDemos.GetBool() ) {
108 fLog = fileSystem->OpenFileWrite( "demoread.log" );
109 }
110
111 writing = false;
112
113 f->Read(magicBuffer, magicLen);
114 if ( memcmp(magicBuffer, DEMO_MAGIC, magicLen) == 0 ) {
115 f->ReadInt( compression );
116 } else {
117 // Ideally we would error out if the magic string isn't there,
118 // but for backwards compatibility we are going to assume it's just an uncompressed demo file
119 compression = 0;
120 f->Rewind();
121 }
122
123 compressor = AllocCompressor( compression );
124 compressor->Init( f, false, 8 );
125
126 return true;
127}
128
129/*
130================

Callers 2

CompressDemoFileMethod · 0.80

Calls 11

Mem_AllocFunction · 0.85
vaFunction · 0.85
OpenFileReadMethod · 0.80
CloseFileMethod · 0.80
OpenFileWriteMethod · 0.80
RewindMethod · 0.80
LengthMethod · 0.45
GetBoolMethod · 0.45
ReadMethod · 0.45
ReadIntMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected