d3dxof: Remove unnecessary fields from IDirectXFileEnumObjectImpl.

This commit is contained in:
Dylan Smith 2011-06-08 15:38:51 -04:00 committed by Alexandre Julliard
parent 0f795650f8
commit 5819cc5c01
2 changed files with 17 additions and 35 deletions

View File

@ -141,17 +141,12 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
IDirectXFileEnumObjectImpl* object; IDirectXFileEnumObjectImpl* object;
HRESULT hr; HRESULT hr;
DWORD* header; DWORD* header;
HANDLE hFile = INVALID_HANDLE_VALUE; LPBYTE mapped_memory = NULL;
HANDLE file_mapping = 0;
LPBYTE buffer = NULL;
HGLOBAL resource_data = 0;
LPBYTE decomp_buffer = NULL; LPBYTE decomp_buffer = NULL;
DWORD decomp_size = 0; DWORD decomp_size = 0;
LPBYTE file_buffer; LPBYTE file_buffer;
DWORD file_size; DWORD file_size;
LPDXFILELOADMEMORY lpdxflm = NULL;
TRACE("(%p/%p)->(%p,%x,%p)\n", This, iface, pvSource, dwLoadOptions, ppEnumObj); TRACE("(%p/%p)->(%p,%x,%p)\n", This, iface, pvSource, dwLoadOptions, ppEnumObj);
if (!ppEnumObj) if (!ppEnumObj)
@ -162,6 +157,8 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
if (dwLoadOptions == DXFILELOAD_FROMFILE) if (dwLoadOptions == DXFILELOAD_FROMFILE)
{ {
HANDLE hFile, file_mapping;
TRACE("Open source file '%s'\n", (char*)pvSource); TRACE("Open source file '%s'\n", (char*)pvSource);
hFile = CreateFileA(pvSource, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); hFile = CreateFileA(pvSource, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
@ -176,21 +173,25 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
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)
{ {
CloseHandle(hFile);
hr = DXFILEERR_BADFILETYPE; hr = DXFILEERR_BADFILETYPE;
goto error; goto error;
} }
buffer = MapViewOfFile(file_mapping, FILE_MAP_READ, 0, 0, 0); mapped_memory = MapViewOfFile(file_mapping, FILE_MAP_READ, 0, 0, 0);
if (!buffer) CloseHandle(file_mapping);
CloseHandle(hFile);
if (!mapped_memory)
{ {
hr = DXFILEERR_BADFILETYPE; hr = DXFILEERR_BADFILETYPE;
goto error; goto error;
} }
file_buffer = buffer; file_buffer = mapped_memory;
} }
else if (dwLoadOptions == DXFILELOAD_FROMRESOURCE) else if (dwLoadOptions == DXFILELOAD_FROMRESOURCE)
{ {
HRSRC resource_info; HRSRC resource_info;
HGLOBAL resource_data;
LPDXFILELOADRESOURCE lpdxflr = pvSource; LPDXFILELOADRESOURCE lpdxflr = pvSource;
TRACE("Source in resource (module = %p, name = %s, type = %s\n", lpdxflr->hModule, debugstr_a(lpdxflr->lpName), debugstr_a(lpdxflr->lpType)); TRACE("Source in resource (module = %p, name = %s, type = %s\n", lpdxflr->hModule, debugstr_a(lpdxflr->lpName), debugstr_a(lpdxflr->lpType));
@ -220,7 +221,7 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
} }
else if (dwLoadOptions == DXFILELOAD_FROMMEMORY) else if (dwLoadOptions == DXFILELOAD_FROMMEMORY)
{ {
lpdxflm = pvSource; LPDXFILELOADMEMORY lpdxflm = pvSource;
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);
@ -312,10 +313,7 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
if (FAILED(hr)) if (FAILED(hr))
goto error; goto error;
object->source = dwLoadOptions; object->mapped_memory = mapped_memory;
object->hFile = hFile;
object->file_mapping = file_mapping;
object->buffer = buffer;
object->decomp_buffer = decomp_buffer; object->decomp_buffer = decomp_buffer;
object->pDirectXFile = This; object->pDirectXFile = This;
object->buf.pdxf = This; object->buf.pdxf = This;
@ -366,14 +364,8 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
return DXFILE_OK; return DXFILE_OK;
error: error:
if (buffer) if (mapped_memory)
UnmapViewOfFile(buffer); UnmapViewOfFile(mapped_memory);
if (file_mapping)
CloseHandle(file_mapping);
if (hFile != INVALID_HANDLE_VALUE)
CloseHandle(hFile);
if (resource_data)
FreeResource(resource_data);
HeapFree(GetProcessHeap(), 0, decomp_buffer); HeapFree(GetProcessHeap(), 0, decomp_buffer);
*ppEnumObj = NULL; *ppEnumObj = NULL;
@ -1134,14 +1126,8 @@ static ULONG WINAPI IDirectXFileEnumObjectImpl_Release(IDirectXFileEnumObject* i
int i; int i;
for (i = 0; i < This->nb_xobjects; i++) for (i = 0; i < This->nb_xobjects; i++)
IDirectXFileData_Release(This->pRefObjects[i]); IDirectXFileData_Release(This->pRefObjects[i]);
if (This->source == DXFILELOAD_FROMFILE) if (This->mapped_memory)
{ UnmapViewOfFile(This->mapped_memory);
UnmapViewOfFile(This->buffer);
CloseHandle(This->file_mapping);
CloseHandle(This->hFile);
}
else if (This->source == DXFILELOAD_FROMRESOURCE)
FreeResource(This->resource_data);
HeapFree(GetProcessHeap(), 0, This->decomp_buffer); HeapFree(GetProcessHeap(), 0, This->decomp_buffer);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
} }

View File

@ -146,11 +146,7 @@ typedef struct {
typedef struct { typedef struct {
IDirectXFileEnumObject IDirectXFileEnumObject_iface; IDirectXFileEnumObject IDirectXFileEnumObject_iface;
LONG ref; LONG ref;
DXFILELOADOPTIONS source; LPBYTE mapped_memory;
HANDLE hFile;
HANDLE file_mapping;
LPBYTE buffer;
HGLOBAL resource_data;
LPBYTE decomp_buffer; LPBYTE decomp_buffer;
parse_buffer buf; parse_buffer buf;
IDirectXFileImpl* pDirectXFile; IDirectXFileImpl* pDirectXFile;