Blame | Last modification | View Log | RSS feed
#include "HiP.h"
bool g_bCanceled;
BOOL __stdcall CompressionCallback( DWORD cbDone, DWORD cbTotal )
{
if ( g_bCanceled )
return false;
float percent = ((float)cbDone / (float)cbTotal) * 100;
return true;
}
//
// Purpose:
// The root routine to decompress a single file
//
//bool CCompression::DecompressFile( char* szFile, char* szOutFile )
bool DecompressFile( char* szFile, char* szOutFile )
{
clsFILE infile, outfile;
PHipPack pEngine = NULL;
//
// map the input file into memory
//
if ( !infile.GetFileHandle( szFile, F_OPENEXISTING_R ) ||
!infile.MapFile() )
return false;
//
// analyse the file
//
// 0 byte file ?
if ( infile.GetFSize() == 0 )
return FALSE; // ERR
// initialize engine
pEngine = new HipPack( infile.GetMapPtr(), infile.GetFSize() );
pEngine->SetCallback( CompressionCallback );
void* pOut;
DWORD cbOut;
bool done = (pEngine->PerformDecompression( &pOut, &cbOut )) ? true : false;
//
// write the output 2 disk
//
if ( !outfile.GetFileHandle( szOutFile, F_CREATENEW ) )
{
if ( pEngine )
delete pEngine;
return false;
}
outfile.Write( pOut, cbOut );
outfile.Destroy();
if ( pEngine )
delete pEngine;
return done;
}