diff --git a/stepmania/src/RageFileDriverDeflate.cpp b/stepmania/src/RageFileDriverDeflate.cpp index bbf66907c0..c2fa386cb2 100644 --- a/stepmania/src/RageFileDriverDeflate.cpp +++ b/stepmania/src/RageFileDriverDeflate.cpp @@ -487,6 +487,44 @@ int RageFileObjGzip::Finish() return this->Flush(); } +#include "RageFileDriverMemory.h" + +void GzipString( const CString &sIn, CString &sOut ) +{ + /* Gzip it. */ + RageFileObjMem mem; + RageFileObjGzip gzip( &mem ); + gzip.Start(); + gzip.Write( sIn ); + gzip.Finish(); + + sOut = mem.GetString(); +} + +bool GunzipString( const CString &sIn, CString &sOut ) +{ + RageFileObjMem mem; + mem.PutString( sIn ); + + CString sError; + uint32_t iCRC32; + RageFileBasic *pFile = GunzipFile( mem, sError, &iCRC32 ); + if( pFile == NULL ) + return false; + + pFile->Read( sOut ); + + /* Check the CRC. */ + unsigned iRet; + ASSERT( pFile->GetCRC32( &iRet ) ); + SAFE_DELETE( pFile ); + + if( iRet != iCRC32 ) + return false; + + return true; +} + /* * Copyright (c) 2003-2004 Glenn Maynard * All rights reserved. diff --git a/stepmania/src/RageFileDriverDeflate.h b/stepmania/src/RageFileDriverDeflate.h index 059493f484..44fc3ca156 100644 --- a/stepmania/src/RageFileDriverDeflate.h +++ b/stepmania/src/RageFileDriverDeflate.h @@ -68,6 +68,10 @@ private: RageFileBasic *GunzipFile( RageFileBasic &file, CString &sError, uint32_t *iCRC32 ); +/* Quick helpers: */ +void GzipString( const CString &sIn, CString &sOut ); +bool GunzipString( const CString &sIn, CString &sOut ); // returns false on CRC, etc. error + #endif /*