/* Get CRC32 of stream */ ULONG CTStream::GetStreamCRC32_t(void) { // remember where stream is now SLONG slOldPos = GetPos_t(); // go to start of file SetPos_t(0); // get size of file SLONG slFileSize = GetStreamSize(); ULONG ulCRC; CRC_Start(ulCRC); // for each block in file const SLONG slBlockSize = 4096; for(SLONG slPos=0; slPos<slFileSize; slPos+=slBlockSize) { // read the block UBYTE aubBlock[slBlockSize]; SLONG slThisBlockSize = Min(slFileSize-slPos, slBlockSize); Read_t(aubBlock, slThisBlockSize); // checksum it CRC_AddBlock(ulCRC, aubBlock, slThisBlockSize); } // restore position SetPos_t(slOldPos); CRC_Finish(ulCRC); return ulCRC; }
void CPlayerCharacter::Load_t( const CTFileName &fnFile) // throw char * { CTFileStream strm; strm.Open_t(fnFile); Read_t(&strm); strm.Close(); }
SLONG CTStream::GetSize_t(void) // throws char * { SLONG chunkSize; Read_t( (char *) &chunkSize, sizeof( SLONG)); return( chunkSize); }
/* * Load entire world (both brushes and current state). */ void CWorld::Load_t(const CTFileName &fnmWorld) // throw char * { // remember the file wo_fnmFileName = fnmWorld; // open the file CTFileStream strmFile; strmFile.Open_t(fnmWorld); // check engine build allowing reinit BOOL bNeedsReinit; _pNetwork->CheckVersion_t(strmFile, TRUE, bNeedsReinit); // read the world from the file Read_t(&strmFile); // close the file strmFile.Close(); // if reinit is needed if (bNeedsReinit) { // reinitialize SetProgressDescription(TRANS("converting from old version")); CallProgressHook_t(0.0f); ReinitializeEntities(); CallProgressHook_t(1.0f); // reinitialize SetProgressDescription(TRANS("saving converted file")); CallProgressHook_t(0.0f); Save_t(fnmWorld); CallProgressHook_t(1.0f); } }
CChunkID CTStream::PeekID_t(void) // throw char * { // read the chunk id CChunkID cidToReturn; Read_t( &cidToReturn.cid_ID[0], CID_LENGTH); // return the stream back Seek_t(-CID_LENGTH, SD_CUR); return( cidToReturn); }
void CTStream::ExpectID_t(const CChunkID &cidExpected) // throws char * { CChunkID cidToCompare; Read_t( &cidToCompare.cid_ID[0], CID_LENGTH); if( !(cidToCompare == cidExpected)) { ThrowF_t(TRANS("Chunk ID validation failed.\nExpected ID \"%s\" but found \"%s\"\n"), cidExpected.cid_ID, cidToCompare.cid_ID); } }
void* CTStream::ReadChunkAlloc_t(SLONG slSize) // throws char * { UBYTE *buffer; SLONG chunkSize; if( slSize != 0) chunkSize = slSize; else chunkSize = GetSize_t(); // throws char * buffer = (UBYTE *) AllocMemory( chunkSize); if( buffer == NULL) throw TRANS("ReadChunkAlloc: Unable to allocate needed amount of memory."); Read_t((char *)buffer, chunkSize); // throws char * return buffer; }
// throws char * void CTStream::GetLine_t(char *strBuffer, SLONG slBufferSize, char cDelimiter /*='\n'*/ ) { // check parameters ASSERT(strBuffer!=NULL && slBufferSize>0); // check that the stream can be read ASSERT(IsReadable()); // letters slider INDEX iLetters = 0; // test if EOF reached if(AtEOF()) { ThrowF_t(TRANS("EOF reached, file %s"), (const char *) strm_strStreamDescription); } // get line from istream FOREVER { char c; Read_t(&c, 1); if(AtEOF()) { // cut off strBuffer[ iLetters] = 0; break; } // don't read "\r" characters but rather act like they don't exist if( c != '\r') { strBuffer[ iLetters] = c; // stop reading when delimiter loaded if( strBuffer[ iLetters] == cDelimiter) { // convert delimiter to zero strBuffer[ iLetters] = 0; // jump over delimiter //Seek_t(1, SD_CUR); break; } // jump to next destination letter iLetters++; } // test if maximum buffer lenght reached if( iLetters==slBufferSize) { return; } } }
void CTStream::ReadChunk_t(void *pvBuffer, SLONG slExpectedSize) // throws char * { if( slExpectedSize != GetSize_t()) throw TRANS("Chunk size not equal as expected size"); Read_t((char *)pvBuffer, slExpectedSize); }
void CTStream::ReadRawChunk_t(void *pvBuffer, SLONG slSize) // throws char * { Read_t((char *)pvBuffer, slSize); }
CChunkID CTStream::GetID_t(void) // throws char * { CChunkID cidToReturn; Read_t( &cidToReturn.cid_ID[0], CID_LENGTH); return( cidToReturn); }