d3dxof: Cleanup IDirectXFileImpl_CreateEnumObject a bit.

This commit is contained in:
Christian Costa 2009-02-10 14:08:11 +01:00 committed by Alexandre Julliard
parent db30aa149e
commit 279e49030a
1 changed files with 18 additions and 20 deletions

View File

@ -127,11 +127,12 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
IDirectXFileImpl *This = (IDirectXFileImpl *)iface; IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
IDirectXFileEnumObjectImpl* object; IDirectXFileEnumObjectImpl* object;
HRESULT hr; HRESULT hr;
DWORD header[4]; DWORD* header;
HANDLE hFile = INVALID_HANDLE_VALUE; HANDLE hFile = INVALID_HANDLE_VALUE;
HANDLE file_mapping = 0; HANDLE file_mapping = 0;
LPBYTE buffer = NULL; LPBYTE buffer = NULL;
DWORD file_size = 0; LPBYTE file_buffer;
DWORD file_size;
LPDXFILELOADMEMORY lpdxflm = NULL; LPDXFILELOADMEMORY lpdxflm = NULL;
@ -152,11 +153,6 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
} }
file_size = GetFileSize(hFile, NULL); file_size = GetFileSize(hFile, NULL);
if (file_size < 16)
{
hr = DXFILEERR_BADFILETYPE;
goto error;
}
file_mapping = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL); file_mapping = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if (!file_mapping) if (!file_mapping)
@ -171,7 +167,7 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
hr = DXFILEERR_BADFILETYPE; hr = DXFILEERR_BADFILETYPE;
goto error; goto error;
} }
memcpy(header, buffer, 16); file_buffer = buffer;
} }
else if (dwLoadOptions == DXFILELOAD_FROMMEMORY) else if (dwLoadOptions == DXFILELOAD_FROMMEMORY)
{ {
@ -179,7 +175,8 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
TRACE("Source in memory at %p with size %d\n", lpdxflm->lpMemory, lpdxflm->dSize); TRACE("Source in memory at %p with size %d\n", lpdxflm->lpMemory, lpdxflm->dSize);
memcpy(header, lpdxflm->lpMemory, 16); file_buffer = lpdxflm->lpMemory;
file_size = lpdxflm->dSize;
} }
else else
{ {
@ -188,6 +185,8 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
goto error; goto error;
} }
header = (DWORD*)file_buffer;
if (TRACE_ON(d3dxof)) if (TRACE_ON(d3dxof))
{ {
char string[17]; char string[17];
@ -196,6 +195,12 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
TRACE("header = '%s'\n", string); TRACE("header = '%s'\n", string);
} }
if (file_size < 16)
{
hr = DXFILEERR_BADFILETYPE;
goto error;
}
if (header[0] != XOFFILE_FORMAT_MAGIC) if (header[0] != XOFFILE_FORMAT_MAGIC)
{ {
hr = DXFILEERR_BADFILETYPE; hr = DXFILEERR_BADFILETYPE;
@ -243,18 +248,11 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
object->buf.token_present = FALSE; object->buf.token_present = FALSE;
object->buf.cur_subobject = 0; object->buf.cur_subobject = 0;
if (dwLoadOptions == DXFILELOAD_FROMFILE) TRACE("File size is %d bytes\n", file_size);
{
object->buf.buffer = buffer + 16;
object->buf.rem_bytes = file_size - 16;
}
else
{
object->buf.buffer = ((LPBYTE)lpdxflm->lpMemory) + 16;
object->buf.rem_bytes = lpdxflm->dSize;
}
TRACE("Object size is %d bytes\n", object->buf.rem_bytes + 16); /* Go to data after header */
object->buf.buffer = file_buffer + 16;
object->buf.rem_bytes = file_size - 16;
*ppEnumObj = (LPDIRECTXFILEENUMOBJECT)object; *ppEnumObj = (LPDIRECTXFILEENUMOBJECT)object;