support optionally gzipped .vdi files

This commit is contained in:
Glenn Maynard
2006-02-14 06:21:46 +00:00
parent 3ddf9bc5e8
commit a40af5b2e7
@@ -20,6 +20,7 @@
#include "RageUtil.h" #include "RageUtil.h"
#include "XmlFile.h" #include "XmlFile.h"
#include "LocalizedString.h" #include "LocalizedString.h"
#include "RageFileDriverDeflate.h"
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma comment(lib, "archutils/Win32/ddk/dbghelp.lib") #pragma comment(lib, "archutils/Win32/ddk/dbghelp.lib")
@@ -35,7 +36,7 @@ namespace VDDebugInfo
{ {
Context() { pRVAHeap=NULL; } Context() { pRVAHeap=NULL; }
bool Loaded() const { return pRVAHeap != NULL; } bool Loaded() const { return pRVAHeap != NULL; }
void *pRawBlock; RString sRawBlock;
int nBuildNumber; int nBuildNumber;
@@ -60,9 +61,24 @@ namespace VDDebugInfo
strcat( buf, ".vdi" ); strcat( buf, ".vdi" );
} }
bool VDDebugInfoInitFromMemory( Context *pctx, const void *src_ ) bool VDDebugInfoInitFromMemory( Context *pctx )
{ {
const unsigned char *src = (const unsigned char *)src_; if( pctx->sRawBlock[0] == '\x1f' &&
pctx->sRawBlock[1] == '\x8b' )
{
RString sBufOut;
RString sError;
if( !GunzipString(pctx->sRawBlock, sBufOut, sError) )
{
pctx->sError = werr_ssprintf( GetLastError(), "VDI error: %s", sError.c_str() );
return false;
}
pctx->sRawBlock = sBufOut;
}
const unsigned char *src = (const unsigned char *) pctx->sRawBlock.data();
pctx->pRVAHeap = NULL; pctx->pRVAHeap = NULL;
@@ -89,11 +105,8 @@ namespace VDDebugInfo
void VDDebugInfoDeinit( Context *pctx ) void VDDebugInfoDeinit( Context *pctx )
{ {
if( pctx->pRawBlock ) if( !pctx->sRawBlock.empty() )
{ pctx->sRawBlock = RString();
VirtualFree(pctx->pRawBlock, 0, MEM_RELEASE);
pctx->pRawBlock = NULL;
}
} }
bool VDDebugInfoInitFromFile( Context *pctx ) bool VDDebugInfoInitFromFile( Context *pctx )
@@ -101,7 +114,7 @@ namespace VDDebugInfo
if( pctx->Loaded() ) if( pctx->Loaded() )
return true; return true;
pctx->pRawBlock = NULL; pctx->sRawBlock = RString();
pctx->pRVAHeap = NULL; pctx->pRVAHeap = NULL;
GetVDIPath( pctx->sFilename, ARRAYSIZE(pctx->sFilename) ); GetVDIPath( pctx->sFilename, ARRAYSIZE(pctx->sFilename) );
pctx->sError = RString(); pctx->sError = RString();
@@ -118,22 +131,20 @@ namespace VDDebugInfo
if( dwFileSize == INVALID_FILE_SIZE ) if( dwFileSize == INVALID_FILE_SIZE )
break; break;
pctx->pRawBlock = VirtualAlloc( NULL, dwFileSize, MEM_COMMIT, PAGE_READWRITE ); char *pBuf = pctx->sRawBlock.GetBuffer( dwFileSize );
if( !pctx->pRawBlock ) if( pBuf == NULL )
break; break;
DWORD dwActual; DWORD dwActual;
if( !ReadFile(h, pctx->pRawBlock, dwFileSize, &dwActual, NULL) || dwActual != dwFileSize ) int iRet = ReadFile(h, pBuf, dwFileSize, &dwActual, NULL);
CloseHandle(h);
pctx->sRawBlock.ReleaseBuffer( dwActual );
if( !iRet || dwActual != dwFileSize )
break; break;
CloseHandle(h); if( VDDebugInfoInitFromMemory(pctx) )
if( VDDebugInfoInitFromMemory(pctx, pctx->pRawBlock) )
{
return true; return true;
}
VirtualFree( pctx->pRawBlock, 0, MEM_RELEASE );
} while(0); } while(0);
VDDebugInfoDeinit(pctx); VDDebugInfoDeinit(pctx);