Ejemplo n.º 1
0
/*
================
idDemoFile::OpenForWriting
================
*/
bool idDemoFile::OpenForWriting( const char *fileName )
{
	Close();
	
	f = fileSystem->OpenFileWrite( fileName );
	
	if( f == NULL )
	{
		return false;
	}
	
	if( com_logDemos.GetBool() )
	{
		fLog = fileSystem->OpenFileWrite( "demowrite.log" );
	}
	
	writing = true;
	
	f->Write( DEMO_MAGIC, sizeof( DEMO_MAGIC ) );
	f->WriteInt( com_compressDemos.GetInteger() );
	f->Flush();
	
	compressor = AllocCompressor( com_compressDemos.GetInteger() );
	compressor->Init( f, true, 8 );
	
	return true;
}
Ejemplo n.º 2
0
/*
================
idDemoFile::OpenForReading
================
*/
bool idDemoFile::OpenForReading( const char *fileName ) {
	static const int magicLen = sizeof( DEMO_MAGIC ) / sizeof( DEMO_MAGIC[0] );
	char magicBuffer[magicLen];
	int compression;
	int fileLength;
	Close();
	f = fileSystem->OpenFileRead( fileName );
	if( !f ) {
		return false;
	}
	fileLength = f->Length();
	if( com_preloadDemos.GetBool() ) {
		fileImage = ( byte * )Mem_Alloc( fileLength );
		f->Read( fileImage, fileLength );
		fileSystem->CloseFile( f );
		f = new idFile_Memory( va( "preloaded(%s)", fileName ), ( const char * )fileImage, fileLength );
	}
	if( com_logDemos.GetBool() ) {
		fLog = fileSystem->OpenFileWrite( "demoread.log" );
	}
	writing = false;
	f->Read( magicBuffer, magicLen );
	if( memcmp( magicBuffer, DEMO_MAGIC, magicLen ) == 0 ) {
		f->ReadInt( compression );
	} else {
		// Ideally we would error out if the magic string isn't there,
		// but for backwards compatibility we are going to assume it's just an uncompressed demo file
		compression = 0;
		f->Rewind();
	}
	compressor = AllocCompressor( compression );
	compressor->Init( f, false, 8 );
	return true;
}