================ idDemoFile::OpenForReading ================ */
| 83 | ================ |
| 84 | */ |
| 85 | bool 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 | ================ |