2004-06-03 02:03:23 +02:00
|
|
|
/*
|
|
|
|
* Implementation of DirectX File Interfaces
|
|
|
|
*
|
2008-08-18 15:10:25 +02:00
|
|
|
* Copyright 2004, 2008 Christian Costa
|
2004-06-03 02:03:23 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-06-03 02:03:23 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2004-06-03 02:03:23 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
|
|
|
|
#include "d3dxof_private.h"
|
|
|
|
#include "dxfile.h"
|
|
|
|
|
2008-08-18 15:10:25 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2004-06-03 02:03:23 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3dxof);
|
|
|
|
|
2008-08-18 15:10:25 +02:00
|
|
|
#define MAKEFOUR(a,b,c,d) ((DWORD)a + ((DWORD)b << 8) + ((DWORD)c << 16) + ((DWORD)d << 24))
|
|
|
|
#define XOFFILE_FORMAT_MAGIC MAKEFOUR('x','o','f',' ')
|
2008-11-11 12:38:52 +01:00
|
|
|
#define XOFFILE_FORMAT_VERSION_302 MAKEFOUR('0','3','0','2')
|
|
|
|
#define XOFFILE_FORMAT_VERSION_303 MAKEFOUR('0','3','0','3')
|
2008-08-18 15:10:25 +02:00
|
|
|
#define XOFFILE_FORMAT_BINARY MAKEFOUR('b','i','n',' ')
|
|
|
|
#define XOFFILE_FORMAT_TEXT MAKEFOUR('t','x','t',' ')
|
2010-03-01 09:36:25 +01:00
|
|
|
#define XOFFILE_FORMAT_BINARY_MSZIP MAKEFOUR('b','z','i','p')
|
|
|
|
#define XOFFILE_FORMAT_TEXT_MSZIP MAKEFOUR('t','z','i','p')
|
2008-08-18 15:10:25 +02:00
|
|
|
#define XOFFILE_FORMAT_COMPRESSED MAKEFOUR('c','m','p',' ')
|
|
|
|
#define XOFFILE_FORMAT_FLOAT_BITS_32 MAKEFOUR('0','0','3','2')
|
|
|
|
#define XOFFILE_FORMAT_FLOAT_BITS_64 MAKEFOUR('0','0','6','4')
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const struct IDirectXFileVtbl IDirectXFile_Vtbl;
|
|
|
|
static const struct IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl;
|
|
|
|
static const struct IDirectXFileDataVtbl IDirectXFileData_Vtbl;
|
|
|
|
static const struct IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl;
|
|
|
|
static const struct IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl;
|
|
|
|
static const struct IDirectXFileObjectVtbl IDirectXFileObject_Vtbl;
|
|
|
|
static const struct IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-12-04 12:47:20 +01:00
|
|
|
static HRESULT IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImpl** ppObj);
|
|
|
|
static HRESULT IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl** ppObj);
|
2008-12-16 20:55:22 +01:00
|
|
|
static HRESULT IDirectXFileSaveObjectImpl_Create(IDirectXFileSaveObjectImpl** ppObj);
|
2008-10-16 22:21:43 +02:00
|
|
|
|
2010-03-01 09:36:25 +01:00
|
|
|
/* FOURCC to string conversion for debug messages */
|
|
|
|
const char *debugstr_fourcc(DWORD fourcc)
|
|
|
|
{
|
|
|
|
if (!fourcc) return "'null'";
|
|
|
|
return wine_dbg_sprintf ("\'%c%c%c%c\'",
|
|
|
|
(char)(fourcc), (char)(fourcc >> 8),
|
|
|
|
(char)(fourcc >> 16), (char)(fourcc >> 24));
|
|
|
|
}
|
|
|
|
|
2004-06-04 21:36:56 +02:00
|
|
|
HRESULT IDirectXFileImpl_Create(IUnknown* pUnkOuter, LPVOID* ppObj)
|
2004-06-03 02:03:23 +02:00
|
|
|
{
|
2004-06-04 21:36:56 +02:00
|
|
|
IDirectXFileImpl* object;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2004-06-04 21:36:56 +02:00
|
|
|
TRACE("(%p,%p)\n", pUnkOuter, ppObj);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileImpl));
|
2008-12-14 18:55:10 +01:00
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
return DXFILEERR_BADALLOC;
|
|
|
|
}
|
|
|
|
|
2010-01-12 09:54:36 +01:00
|
|
|
object->lpVtbl = &IDirectXFile_Vtbl;
|
2004-06-03 02:03:23 +02:00
|
|
|
object->ref = 1;
|
|
|
|
|
|
|
|
*ppObj = object;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** IUnknown methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileImpl_QueryInterface(IDirectXFile* iface, REFIID riid, void** ppvObject)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2004-06-04 21:36:56 +02:00
|
|
|
TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDirectXFile))
|
|
|
|
{
|
2010-03-01 09:36:37 +01:00
|
|
|
IUnknown_AddRef(iface);
|
2004-06-03 02:03:23 +02:00
|
|
|
*ppvObject = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IDirectXFileImpl_AddRef(IDirectXFile* iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
|
2005-01-20 11:53:56 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
return ref;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IDirectXFileImpl_Release(IDirectXFile* iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
|
2005-01-20 11:53:56 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
if (!ref)
|
2004-06-03 02:03:23 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
return ref;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IDirectXFile methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPVOID pvSource, DXFILELOADOPTIONS dwLoadOptions, LPDIRECTXFILEENUMOBJECT* ppEnumObj)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
|
2008-08-19 00:28:03 +02:00
|
|
|
IDirectXFileEnumObjectImpl* object;
|
|
|
|
HRESULT hr;
|
2009-02-10 14:08:11 +01:00
|
|
|
DWORD* header;
|
2008-09-01 22:55:44 +02:00
|
|
|
HANDLE hFile = INVALID_HANDLE_VALUE;
|
2009-02-03 22:58:34 +01:00
|
|
|
HANDLE file_mapping = 0;
|
|
|
|
LPBYTE buffer = NULL;
|
2009-02-10 14:12:47 +01:00
|
|
|
HGLOBAL resource_data = 0;
|
2009-02-10 14:08:11 +01:00
|
|
|
LPBYTE file_buffer;
|
|
|
|
DWORD file_size;
|
2009-02-03 22:58:34 +01:00
|
|
|
|
2008-11-11 12:40:31 +01:00
|
|
|
LPDXFILELOADMEMORY lpdxflm = NULL;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-22 20:27:09 +02:00
|
|
|
TRACE("(%p/%p)->(%p,%x,%p)\n", This, iface, pvSource, dwLoadOptions, ppEnumObj);
|
2008-09-01 22:55:44 +02:00
|
|
|
|
|
|
|
if (!ppEnumObj)
|
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2009-10-23 08:41:04 +02:00
|
|
|
/* Only lowest 4 bits are relevant in DXFILELOADOPTIONS */
|
|
|
|
dwLoadOptions &= 0xF;
|
|
|
|
|
2008-08-18 15:10:25 +02:00
|
|
|
if (dwLoadOptions == DXFILELOAD_FROMFILE)
|
2004-06-03 02:03:23 +02:00
|
|
|
{
|
2008-08-18 15:10:25 +02:00
|
|
|
TRACE("Open source file '%s'\n", (char*)pvSource);
|
2008-09-01 22:55:44 +02:00
|
|
|
|
2009-01-29 11:15:46 +01:00
|
|
|
hFile = CreateFileA(pvSource, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
2008-08-18 15:10:25 +02:00
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
TRACE("File '%s' not found\n", (char*)pvSource);
|
|
|
|
return DXFILEERR_FILENOTFOUND;
|
|
|
|
}
|
2008-09-01 22:55:44 +02:00
|
|
|
|
2009-02-03 22:58:34 +01:00
|
|
|
file_size = GetFileSize(hFile, NULL);
|
|
|
|
|
|
|
|
file_mapping = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
|
|
|
|
if (!file_mapping)
|
|
|
|
{
|
|
|
|
hr = DXFILEERR_BADFILETYPE;
|
2008-09-01 22:55:44 +02:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2009-02-03 22:58:34 +01:00
|
|
|
buffer = MapViewOfFile(file_mapping, FILE_MAP_READ, 0, 0, 0);
|
|
|
|
if (!buffer)
|
2008-09-01 22:55:44 +02:00
|
|
|
{
|
|
|
|
hr = DXFILEERR_BADFILETYPE;
|
|
|
|
goto error;
|
|
|
|
}
|
2009-02-10 14:08:11 +01:00
|
|
|
file_buffer = buffer;
|
2008-11-11 12:40:31 +01:00
|
|
|
}
|
2009-02-10 14:12:47 +01:00
|
|
|
else if (dwLoadOptions == DXFILELOAD_FROMRESOURCE)
|
|
|
|
{
|
|
|
|
HRSRC resource_info;
|
|
|
|
LPDXFILELOADRESOURCE lpdxflr = pvSource;
|
|
|
|
|
|
|
|
TRACE("Source in resource (module = %p, name = %s, type = %s\n", lpdxflr->hModule, debugstr_a(lpdxflr->lpName), debugstr_a(lpdxflr->lpType));
|
|
|
|
|
|
|
|
resource_info = FindResourceA(lpdxflr->hModule, lpdxflr->lpName, lpdxflr->lpType);
|
|
|
|
if (!resource_info)
|
|
|
|
{
|
|
|
|
hr = DXFILEERR_RESOURCENOTFOUND;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_size = SizeofResource(lpdxflr->hModule, resource_info);
|
|
|
|
|
|
|
|
resource_data = LoadResource(lpdxflr->hModule, resource_info);
|
|
|
|
if (!resource_data)
|
|
|
|
{
|
|
|
|
hr = DXFILEERR_BADRESOURCE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_buffer = LockResource(resource_data);
|
|
|
|
if (!file_buffer)
|
|
|
|
{
|
|
|
|
hr = DXFILEERR_BADRESOURCE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
2008-11-11 12:40:31 +01:00
|
|
|
else if (dwLoadOptions == DXFILELOAD_FROMMEMORY)
|
|
|
|
{
|
2009-01-29 11:15:46 +01:00
|
|
|
lpdxflm = pvSource;
|
2008-09-01 22:55:44 +02:00
|
|
|
|
2008-11-16 19:42:38 +01:00
|
|
|
TRACE("Source in memory at %p with size %d\n", lpdxflm->lpMemory, lpdxflm->dSize);
|
2008-11-11 12:40:31 +01:00
|
|
|
|
2009-02-10 14:08:11 +01:00
|
|
|
file_buffer = lpdxflm->lpMemory;
|
|
|
|
file_size = lpdxflm->dSize;
|
2008-08-18 15:10:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Source type %d is not handled yet\n", dwLoadOptions);
|
2008-09-01 22:55:44 +02:00
|
|
|
hr = DXFILEERR_NOTDONEYET;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2009-02-10 14:08:11 +01:00
|
|
|
header = (DWORD*)file_buffer;
|
|
|
|
|
2008-11-11 12:40:31 +01:00
|
|
|
if (TRACE_ON(d3dxof))
|
|
|
|
{
|
|
|
|
char string[17];
|
|
|
|
memcpy(string, header, 16);
|
|
|
|
string[16] = 0;
|
|
|
|
TRACE("header = '%s'\n", string);
|
|
|
|
}
|
|
|
|
|
2009-02-10 14:08:11 +01:00
|
|
|
if (file_size < 16)
|
|
|
|
{
|
|
|
|
hr = DXFILEERR_BADFILETYPE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2008-09-01 22:55:44 +02:00
|
|
|
if (header[0] != XOFFILE_FORMAT_MAGIC)
|
|
|
|
{
|
|
|
|
hr = DXFILEERR_BADFILETYPE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2008-11-11 12:38:52 +01:00
|
|
|
if ((header[1] != XOFFILE_FORMAT_VERSION_302) && (header[1] != XOFFILE_FORMAT_VERSION_303))
|
2008-09-01 22:55:44 +02:00
|
|
|
{
|
|
|
|
hr = DXFILEERR_BADFILEVERSION;
|
|
|
|
goto error;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
2010-03-01 09:36:25 +01:00
|
|
|
if ((header[2] != XOFFILE_FORMAT_BINARY) && (header[2] != XOFFILE_FORMAT_TEXT) &&
|
|
|
|
(header[2] != XOFFILE_FORMAT_BINARY_MSZIP) && (header[2] != XOFFILE_FORMAT_TEXT_MSZIP))
|
2008-09-01 22:55:44 +02:00
|
|
|
{
|
2010-03-01 09:36:25 +01:00
|
|
|
WARN("File type %s unknown\n", debugstr_fourcc(header[2]));
|
2008-09-01 22:55:44 +02:00
|
|
|
hr = DXFILEERR_BADFILETYPE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2010-03-01 09:36:25 +01:00
|
|
|
if ((header[2] == XOFFILE_FORMAT_BINARY_MSZIP) || (header[2] == XOFFILE_FORMAT_TEXT_MSZIP))
|
2008-09-01 22:55:44 +02:00
|
|
|
{
|
2010-03-01 09:36:25 +01:00
|
|
|
FIXME("Compressed format %s not supported yet\n", debugstr_fourcc(header[2]));
|
|
|
|
hr = DXFILEERR_BADALLOC;
|
2008-09-01 22:55:44 +02:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((header[3] != XOFFILE_FORMAT_FLOAT_BITS_32) && (header[3] != XOFFILE_FORMAT_FLOAT_BITS_64))
|
|
|
|
{
|
|
|
|
hr = DXFILEERR_BADFILEFLOATSIZE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Header is correct\n");
|
|
|
|
|
2008-08-19 00:28:03 +02:00
|
|
|
hr = IDirectXFileEnumObjectImpl_Create(&object);
|
2008-10-08 01:35:37 +02:00
|
|
|
if (FAILED(hr))
|
2008-09-01 22:55:44 +02:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
object->source = dwLoadOptions;
|
|
|
|
object->hFile = hFile;
|
2009-02-03 22:58:34 +01:00
|
|
|
object->file_mapping = file_mapping;
|
|
|
|
object->buffer = buffer;
|
2008-09-16 22:22:28 +02:00
|
|
|
object->pDirectXFile = This;
|
|
|
|
object->buf.pdxf = This;
|
2008-11-11 12:41:11 +01:00
|
|
|
object->buf.txt = (header[2] == XOFFILE_FORMAT_TEXT);
|
2008-09-20 12:34:00 +02:00
|
|
|
object->buf.token_present = FALSE;
|
2008-09-16 22:22:28 +02:00
|
|
|
|
2009-02-10 14:08:11 +01:00
|
|
|
TRACE("File size is %d bytes\n", file_size);
|
2008-11-11 12:40:31 +01:00
|
|
|
|
2009-02-10 14:08:11 +01:00
|
|
|
/* Go to data after header */
|
|
|
|
object->buf.buffer = file_buffer + 16;
|
|
|
|
object->buf.rem_bytes = file_size - 16;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
*ppEnumObj = (LPDIRECTXFILEENUMOBJECT)object;
|
2008-08-19 00:28:03 +02:00
|
|
|
|
2008-12-31 12:27:24 +01:00
|
|
|
while (object->buf.rem_bytes && is_template_available(&object->buf))
|
2008-11-09 11:09:07 +01:00
|
|
|
{
|
|
|
|
if (!parse_template(&object->buf))
|
|
|
|
{
|
2010-03-03 08:52:43 +01:00
|
|
|
WARN("Template is not correct\n");
|
2008-11-09 11:09:07 +01:00
|
|
|
hr = DXFILEERR_BADVALUE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Template successfully parsed:\n");
|
|
|
|
if (TRACE_ON(d3dxof))
|
|
|
|
dump_template(This->xtemplates, &This->xtemplates[This->nb_xtemplates - 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TRACE_ON(d3dxof))
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
TRACE("Registered templates (%d):\n", This->nb_xtemplates);
|
|
|
|
for (i = 0; i < This->nb_xtemplates; i++)
|
|
|
|
DPRINTF("%s - %s\n", This->xtemplates[i].name, debugstr_guid(&This->xtemplates[i].class_id));
|
|
|
|
}
|
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILE_OK;
|
2008-09-01 22:55:44 +02:00
|
|
|
|
|
|
|
error:
|
2009-02-03 22:58:34 +01:00
|
|
|
if (buffer)
|
|
|
|
UnmapViewOfFile(buffer);
|
|
|
|
if (file_mapping)
|
|
|
|
CloseHandle(file_mapping);
|
2008-09-01 22:55:44 +02:00
|
|
|
if (hFile != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle(hFile);
|
2009-02-10 14:12:47 +01:00
|
|
|
if (resource_data)
|
|
|
|
FreeResource(resource_data);
|
2008-09-01 22:55:44 +02:00
|
|
|
*ppEnumObj = NULL;
|
|
|
|
|
|
|
|
return hr;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileImpl_CreateSaveObject(IDirectXFile* iface, LPCSTR szFileName, DXFILEFORMAT dwFileFormat, LPDIRECTXFILESAVEOBJECT* ppSaveObj)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-12-16 20:55:22 +01:00
|
|
|
FIXME("(%p/%p)->(%s,%x,%p) partial stub!\n", This, iface, szFileName, dwFileFormat, ppSaveObj);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-12-16 20:55:22 +01:00
|
|
|
if (!szFileName || !ppSaveObj)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
return IDirectXFileSaveObjectImpl_Create((IDirectXFileSaveObjectImpl**)ppSaveObj);
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileImpl_RegisterTemplates(IDirectXFile* iface, LPVOID pvData, DWORD cbSize)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
|
2008-08-18 15:10:25 +02:00
|
|
|
DWORD token_header;
|
|
|
|
parse_buffer buf;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2009-01-29 11:15:46 +01:00
|
|
|
buf.buffer = pvData;
|
2008-08-18 15:10:25 +02:00
|
|
|
buf.rem_bytes = cbSize;
|
2008-08-19 14:00:32 +02:00
|
|
|
buf.txt = FALSE;
|
2008-09-20 12:34:00 +02:00
|
|
|
buf.token_present = FALSE;
|
2008-08-22 13:16:58 +02:00
|
|
|
buf.pdxf = This;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-16 22:22:28 +02:00
|
|
|
TRACE("(%p/%p)->(%p,%d)\n", This, iface, pvData, cbSize);
|
2008-08-18 15:10:25 +02:00
|
|
|
|
|
|
|
if (!pvData)
|
|
|
|
return DXFILEERR_BADVALUE;
|
|
|
|
|
|
|
|
if (cbSize < 16)
|
|
|
|
return DXFILEERR_BADFILETYPE;
|
|
|
|
|
|
|
|
if (TRACE_ON(d3dxof))
|
|
|
|
{
|
|
|
|
char string[17];
|
|
|
|
memcpy(string, pvData, 16);
|
|
|
|
string[16] = 0;
|
|
|
|
TRACE("header = '%s'\n", string);
|
|
|
|
}
|
|
|
|
|
|
|
|
read_bytes(&buf, &token_header, 4);
|
|
|
|
|
|
|
|
if (token_header != XOFFILE_FORMAT_MAGIC)
|
|
|
|
return DXFILEERR_BADFILETYPE;
|
|
|
|
|
|
|
|
read_bytes(&buf, &token_header, 4);
|
|
|
|
|
2008-11-11 12:38:52 +01:00
|
|
|
if ((token_header != XOFFILE_FORMAT_VERSION_302) && (token_header != XOFFILE_FORMAT_VERSION_303))
|
2008-08-18 15:10:25 +02:00
|
|
|
return DXFILEERR_BADFILEVERSION;
|
|
|
|
|
|
|
|
read_bytes(&buf, &token_header, 4);
|
|
|
|
|
2010-03-01 09:36:25 +01:00
|
|
|
if ((token_header != XOFFILE_FORMAT_BINARY) && (token_header != XOFFILE_FORMAT_TEXT) &&
|
|
|
|
(token_header != XOFFILE_FORMAT_BINARY_MSZIP) && (token_header != XOFFILE_FORMAT_TEXT_MSZIP))
|
2008-08-18 15:10:25 +02:00
|
|
|
{
|
2010-03-01 09:36:25 +01:00
|
|
|
WARN("File type %s unknown\n", debugstr_fourcc(token_header));
|
|
|
|
return DXFILEERR_BADFILETYPE;
|
2008-08-18 15:10:25 +02:00
|
|
|
}
|
|
|
|
|
2010-03-01 09:36:25 +01:00
|
|
|
if ((token_header == XOFFILE_FORMAT_BINARY_MSZIP) || (token_header == XOFFILE_FORMAT_TEXT_MSZIP))
|
2008-08-18 15:10:25 +02:00
|
|
|
{
|
2010-03-01 09:36:25 +01:00
|
|
|
FIXME("Compressed format %s not supported yet\n", debugstr_fourcc(token_header));
|
|
|
|
return DXFILEERR_BADALLOC;
|
2008-08-18 15:10:25 +02:00
|
|
|
}
|
|
|
|
|
2010-03-01 09:36:25 +01:00
|
|
|
if (token_header == XOFFILE_FORMAT_TEXT)
|
|
|
|
buf.txt = TRUE;
|
|
|
|
|
2008-08-18 15:10:25 +02:00
|
|
|
read_bytes(&buf, &token_header, 4);
|
|
|
|
|
|
|
|
if ((token_header != XOFFILE_FORMAT_FLOAT_BITS_32) && (token_header != XOFFILE_FORMAT_FLOAT_BITS_64))
|
|
|
|
return DXFILEERR_BADFILEFLOATSIZE;
|
|
|
|
|
2008-08-19 14:00:32 +02:00
|
|
|
TRACE("Header is correct\n");
|
|
|
|
|
2008-08-18 15:10:25 +02:00
|
|
|
while (buf.rem_bytes)
|
|
|
|
{
|
|
|
|
if (!parse_template(&buf))
|
|
|
|
{
|
2010-03-03 08:52:43 +01:00
|
|
|
WARN("Template is not correct\n");
|
2008-08-18 15:10:25 +02:00
|
|
|
return DXFILEERR_BADVALUE;
|
|
|
|
}
|
|
|
|
else
|
2008-08-22 13:16:58 +02:00
|
|
|
{
|
2008-08-18 15:10:25 +02:00
|
|
|
TRACE("Template successfully parsed:\n");
|
|
|
|
if (TRACE_ON(d3dxof))
|
2008-10-16 22:21:43 +02:00
|
|
|
dump_template(This->xtemplates, &This->xtemplates[This->nb_xtemplates - 1]);
|
2008-08-22 13:16:58 +02:00
|
|
|
}
|
2008-08-18 15:10:25 +02:00
|
|
|
}
|
|
|
|
|
2008-08-22 13:16:58 +02:00
|
|
|
if (TRACE_ON(d3dxof))
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
TRACE("Registered templates (%d):\n", This->nb_xtemplates);
|
|
|
|
for (i = 0; i < This->nb_xtemplates; i++)
|
|
|
|
DPRINTF("%s - %s\n", This->xtemplates[i].name, debugstr_guid(&This->xtemplates[i].class_id));
|
|
|
|
}
|
2008-08-18 15:10:25 +02:00
|
|
|
|
|
|
|
return DXFILE_OK;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirectXFileVtbl IDirectXFile_Vtbl =
|
2004-06-03 02:03:23 +02:00
|
|
|
{
|
|
|
|
IDirectXFileImpl_QueryInterface,
|
|
|
|
IDirectXFileImpl_AddRef,
|
|
|
|
IDirectXFileImpl_Release,
|
|
|
|
IDirectXFileImpl_CreateEnumObject,
|
|
|
|
IDirectXFileImpl_CreateSaveObject,
|
|
|
|
IDirectXFileImpl_RegisterTemplates
|
|
|
|
};
|
|
|
|
|
2008-12-16 20:57:45 +01:00
|
|
|
static HRESULT IDirectXFileBinaryImpl_Create(IDirectXFileBinaryImpl** ppObj)
|
|
|
|
{
|
|
|
|
IDirectXFileBinaryImpl* object;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", ppObj);
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileBinaryImpl));
|
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
return DXFILEERR_BADALLOC;
|
|
|
|
}
|
|
|
|
|
2010-01-12 09:54:36 +01:00
|
|
|
object->lpVtbl = &IDirectXFileBinary_Vtbl;
|
2008-12-16 20:57:45 +01:00
|
|
|
object->ref = 1;
|
|
|
|
|
|
|
|
*ppObj = object;
|
|
|
|
|
|
|
|
return DXFILE_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-03 02:03:23 +02:00
|
|
|
/*** IUnknown methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileBinaryImpl_QueryInterface(IDirectXFileBinary* iface, REFIID riid, void** ppvObject)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2004-06-04 21:36:56 +02:00
|
|
|
TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
2004-06-04 21:36:56 +02:00
|
|
|
|| IsEqualGUID(riid, &IID_IDirectXFileObject)
|
2004-06-03 02:03:23 +02:00
|
|
|
|| IsEqualGUID(riid, &IID_IDirectXFileBinary))
|
|
|
|
{
|
2010-03-01 09:36:37 +01:00
|
|
|
IUnknown_AddRef(iface);
|
2004-06-03 02:03:23 +02:00
|
|
|
*ppvObject = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-23 23:25:48 +02:00
|
|
|
/* Do not print an error for interfaces that can be queried to retrieve the type of the object */
|
|
|
|
if (!IsEqualGUID(riid, &IID_IDirectXFileData)
|
|
|
|
&& !IsEqualGUID(riid, &IID_IDirectXFileDataReference))
|
|
|
|
ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
|
|
|
|
|
2004-06-03 02:03:23 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IDirectXFileBinaryImpl_AddRef(IDirectXFileBinary* iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
|
2005-01-20 11:53:56 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
return ref;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IDirectXFileBinaryImpl_Release(IDirectXFileBinary* iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
|
2005-01-20 11:53:56 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
if (!ref)
|
2004-06-03 02:03:23 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
return ref;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IDirectXFileObject methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileBinaryImpl_GetName(IDirectXFileBinary* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
|
|
|
|
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pstrNameBuf, pdwBufLen);
|
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileBinaryImpl_GetId(IDirectXFileBinary* iface, LPGUID pGuid)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
FIXME("(%p/%p)->(%p) stub!\n", This, iface, pGuid);
|
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IDirectXFileBinary methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileBinaryImpl_GetSize(IDirectXFileBinary* iface, DWORD* pcbSize)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
FIXME("(%p/%p)->(%p) stub!\n", This, iface, pcbSize);
|
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileBinaryImpl_GetMimeType(IDirectXFileBinary* iface, LPCSTR* pszMimeType)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
FIXME("(%p/%p)->(%p) stub!\n", This, iface, pszMimeType);
|
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileBinaryImpl_Read(IDirectXFileBinary* iface, LPVOID pvData, DWORD cbSize, LPDWORD pcbRead)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
FIXME("(%p/%p)->(%p, %d, %p) stub!\n", This, iface, pvData, cbSize, pcbRead);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl =
|
2004-06-03 02:03:23 +02:00
|
|
|
{
|
|
|
|
IDirectXFileBinaryImpl_QueryInterface,
|
|
|
|
IDirectXFileBinaryImpl_AddRef,
|
|
|
|
IDirectXFileBinaryImpl_Release,
|
|
|
|
IDirectXFileBinaryImpl_GetName,
|
|
|
|
IDirectXFileBinaryImpl_GetId,
|
|
|
|
IDirectXFileBinaryImpl_GetSize,
|
|
|
|
IDirectXFileBinaryImpl_GetMimeType,
|
|
|
|
IDirectXFileBinaryImpl_Read
|
|
|
|
};
|
|
|
|
|
2008-12-04 12:47:20 +01:00
|
|
|
static HRESULT IDirectXFileDataImpl_Create(IDirectXFileDataImpl** ppObj)
|
2004-06-04 21:36:56 +02:00
|
|
|
{
|
|
|
|
IDirectXFileDataImpl* object;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", ppObj);
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileDataImpl));
|
2008-12-14 18:55:10 +01:00
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
return DXFILEERR_BADALLOC;
|
|
|
|
}
|
|
|
|
|
2010-01-12 09:54:36 +01:00
|
|
|
object->lpVtbl = &IDirectXFileData_Vtbl;
|
2004-06-04 21:36:56 +02:00
|
|
|
object->ref = 1;
|
|
|
|
|
|
|
|
*ppObj = object;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-03 02:03:23 +02:00
|
|
|
/*** IUnknown methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileDataImpl_QueryInterface(IDirectXFileData* iface, REFIID riid, void** ppvObject)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2004-06-04 21:36:56 +02:00
|
|
|
TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
2004-06-04 21:36:56 +02:00
|
|
|
|| IsEqualGUID(riid, &IID_IDirectXFileObject)
|
2004-06-03 02:03:23 +02:00
|
|
|
|| IsEqualGUID(riid, &IID_IDirectXFileData))
|
|
|
|
{
|
2010-03-01 09:36:37 +01:00
|
|
|
IUnknown_AddRef(iface);
|
2004-06-03 02:03:23 +02:00
|
|
|
*ppvObject = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-10 13:44:43 +02:00
|
|
|
/* Do not print an error for interfaces that can be queried to retrieve the type of the object */
|
2008-09-23 23:25:48 +02:00
|
|
|
if (!IsEqualGUID(riid, &IID_IDirectXFileBinary)
|
|
|
|
&& !IsEqualGUID(riid, &IID_IDirectXFileDataReference))
|
|
|
|
ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
|
|
|
|
|
2004-06-03 02:03:23 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IDirectXFileDataImpl_AddRef(IDirectXFileData* iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
|
2005-01-20 11:53:56 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
return ref;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IDirectXFileDataImpl_Release(IDirectXFileData* iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
|
2005-01-20 11:53:56 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
if (!ref)
|
2008-12-23 11:57:32 +01:00
|
|
|
{
|
2009-03-24 23:59:37 +01:00
|
|
|
if (!This->level && !This->from_ref)
|
2008-12-23 11:57:32 +01:00
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->pstrings);
|
2009-03-24 23:59:37 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->pobj->pdata);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->pobj);
|
2008-12-23 11:57:32 +01:00
|
|
|
}
|
2004-06-03 02:03:23 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2008-12-23 11:57:32 +01:00
|
|
|
}
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
return ref;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IDirectXFileObject methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileDataImpl_GetName(IDirectXFileData* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
|
|
|
|
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-16 22:22:28 +02:00
|
|
|
TRACE("(%p/%p)->(%p,%p)\n", This, iface, pstrNameBuf, pdwBufLen);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-16 22:22:28 +02:00
|
|
|
if (!pstrNameBuf)
|
|
|
|
return DXFILEERR_BADVALUE;
|
|
|
|
|
|
|
|
strcpy(pstrNameBuf, This->pobj->name);
|
|
|
|
|
|
|
|
return DXFILE_OK;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileDataImpl_GetId(IDirectXFileData* iface, LPGUID pGuid)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-16 22:22:28 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, pGuid);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-16 22:22:28 +02:00
|
|
|
if (!pGuid)
|
|
|
|
return DXFILEERR_BADVALUE;
|
|
|
|
|
|
|
|
memcpy(pGuid, &This->pobj->class_id, 16);
|
|
|
|
|
|
|
|
return DXFILE_OK;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IDirectXFileData methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileDataImpl_GetData(IDirectXFileData* iface, LPCSTR szMember, DWORD* pcbSize, void** ppvData)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-16 22:22:28 +02:00
|
|
|
TRACE("(%p/%p)->(%s,%p,%p)\n", This, iface, szMember, pcbSize, ppvData);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-16 22:22:28 +02:00
|
|
|
if (!pcbSize || !ppvData)
|
|
|
|
return DXFILEERR_BADVALUE;
|
|
|
|
|
|
|
|
if (szMember)
|
|
|
|
{
|
|
|
|
FIXME("Specifying a member is not supported yet!\n");
|
|
|
|
return DXFILEERR_BADVALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pcbSize = This->pobj->size;
|
2009-03-12 09:06:16 +01:00
|
|
|
*ppvData = This->pobj->root->pdata + This->pobj->pos_data;
|
2008-09-16 22:22:28 +02:00
|
|
|
|
|
|
|
return DXFILE_OK;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileDataImpl_GetType(IDirectXFileData* iface, const GUID** pguid)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
|
2008-09-16 22:22:28 +02:00
|
|
|
static GUID guid;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-16 22:22:28 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, pguid);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-16 22:22:28 +02:00
|
|
|
if (!pguid)
|
|
|
|
return DXFILEERR_BADVALUE;
|
|
|
|
|
2008-09-18 21:47:40 +02:00
|
|
|
memcpy(&guid, &This->pobj->type, 16);
|
2008-09-16 22:22:28 +02:00
|
|
|
*pguid = &guid;
|
|
|
|
|
|
|
|
return DXFILE_OK;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileDataImpl_GetNextObject(IDirectXFileData* iface, LPDIRECTXFILEOBJECT* ppChildObj)
|
|
|
|
{
|
2008-09-22 20:27:09 +02:00
|
|
|
HRESULT hr;
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-22 20:27:09 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, ppChildObj);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-16 22:22:28 +02:00
|
|
|
if (This->cur_enum_object >= This->pobj->nb_childs)
|
|
|
|
return DXFILEERR_NOMOREOBJECTS;
|
|
|
|
|
2008-10-07 22:52:55 +02:00
|
|
|
if (This->from_ref && (This->level >= 1))
|
|
|
|
{
|
2010-02-07 21:15:43 +01:00
|
|
|
/* Only 2 levels can be enumerated if the object is obtained from a reference */
|
2008-10-07 22:52:55 +02:00
|
|
|
return DXFILEERR_NOMOREOBJECTS;
|
|
|
|
}
|
|
|
|
|
2008-12-16 20:57:45 +01:00
|
|
|
if (This->pobj->childs[This->cur_enum_object]->binary)
|
|
|
|
{
|
|
|
|
IDirectXFileBinaryImpl *object;
|
|
|
|
|
|
|
|
hr = IDirectXFileBinaryImpl_Create(&object);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
*ppChildObj = (LPDIRECTXFILEOBJECT)object;
|
|
|
|
}
|
|
|
|
else if (This->pobj->childs[This->cur_enum_object]->ptarget)
|
2008-09-24 22:38:29 +02:00
|
|
|
{
|
|
|
|
IDirectXFileDataReferenceImpl *object;
|
2008-09-22 20:27:09 +02:00
|
|
|
|
2008-09-24 22:38:29 +02:00
|
|
|
hr = IDirectXFileDataReferenceImpl_Create(&object);
|
2008-12-14 18:55:10 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2008-09-24 22:38:29 +02:00
|
|
|
|
|
|
|
object->ptarget = This->pobj->childs[This->cur_enum_object++]->ptarget;
|
|
|
|
|
|
|
|
*ppChildObj = (LPDIRECTXFILEOBJECT)object;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IDirectXFileDataImpl *object;
|
|
|
|
|
|
|
|
hr = IDirectXFileDataImpl_Create(&object);
|
2008-12-14 18:55:10 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2008-09-22 20:27:09 +02:00
|
|
|
|
2008-09-24 22:38:29 +02:00
|
|
|
object->pobj = This->pobj->childs[This->cur_enum_object++];
|
|
|
|
object->cur_enum_object = 0;
|
2008-10-07 22:52:55 +02:00
|
|
|
object->from_ref = This->from_ref;
|
|
|
|
object->level = This->level + 1;
|
2008-09-24 22:38:29 +02:00
|
|
|
|
|
|
|
*ppChildObj = (LPDIRECTXFILEOBJECT)object;
|
|
|
|
}
|
2008-09-22 20:27:09 +02:00
|
|
|
|
|
|
|
return DXFILE_OK;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileDataImpl_AddDataObject(IDirectXFileData* iface, LPDIRECTXFILEDATA pDataObj)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDataObj);
|
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileDataImpl_AddDataReference(IDirectXFileData* iface, LPCSTR szRef, const GUID* pguidRef)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
FIXME("(%p/%p)->(%s,%p) stub!\n", This, iface, szRef, pguidRef);
|
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileDataImpl_AddBinaryObject(IDirectXFileData* iface, LPCSTR szName, const GUID* pguid, LPCSTR szMimeType, LPVOID pvData, DWORD cbSize)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
FIXME("(%p/%p)->(%s,%p,%s,%p,%d) stub!\n", This, iface, szName, pguid, szMimeType, pvData, cbSize);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirectXFileDataVtbl IDirectXFileData_Vtbl =
|
2004-06-03 02:03:23 +02:00
|
|
|
{
|
|
|
|
IDirectXFileDataImpl_QueryInterface,
|
|
|
|
IDirectXFileDataImpl_AddRef,
|
|
|
|
IDirectXFileDataImpl_Release,
|
|
|
|
IDirectXFileDataImpl_GetName,
|
|
|
|
IDirectXFileDataImpl_GetId,
|
|
|
|
IDirectXFileDataImpl_GetData,
|
|
|
|
IDirectXFileDataImpl_GetType,
|
|
|
|
IDirectXFileDataImpl_GetNextObject,
|
|
|
|
IDirectXFileDataImpl_AddDataObject,
|
|
|
|
IDirectXFileDataImpl_AddDataReference,
|
|
|
|
IDirectXFileDataImpl_AddBinaryObject
|
|
|
|
};
|
|
|
|
|
2008-12-04 12:47:20 +01:00
|
|
|
static HRESULT IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImpl** ppObj)
|
2004-06-04 21:36:56 +02:00
|
|
|
{
|
|
|
|
IDirectXFileDataReferenceImpl* object;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", ppObj);
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileDataReferenceImpl));
|
2008-12-14 18:55:10 +01:00
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
return DXFILEERR_BADALLOC;
|
|
|
|
}
|
2004-06-04 21:36:56 +02:00
|
|
|
|
2010-01-12 09:54:36 +01:00
|
|
|
object->lpVtbl = &IDirectXFileDataReference_Vtbl;
|
2004-06-04 21:36:56 +02:00
|
|
|
object->ref = 1;
|
|
|
|
|
|
|
|
*ppObj = object;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-03 02:03:23 +02:00
|
|
|
/*** IUnknown methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileDataReferenceImpl_QueryInterface(IDirectXFileDataReference* iface, REFIID riid, void** ppvObject)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2004-06-04 21:36:56 +02:00
|
|
|
TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
2004-06-04 21:36:56 +02:00
|
|
|
|| IsEqualGUID(riid, &IID_IDirectXFileObject)
|
2004-06-03 02:03:23 +02:00
|
|
|
|| IsEqualGUID(riid, &IID_IDirectXFileDataReference))
|
|
|
|
{
|
2010-03-01 09:36:37 +01:00
|
|
|
IUnknown_AddRef(iface);
|
2004-06-03 02:03:23 +02:00
|
|
|
*ppvObject = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-10 13:44:43 +02:00
|
|
|
/* Do not print an error for interfaces that can be queried to retrieve the type of the object */
|
2008-09-23 23:25:48 +02:00
|
|
|
if (!IsEqualGUID(riid, &IID_IDirectXFileData)
|
|
|
|
&& !IsEqualGUID(riid, &IID_IDirectXFileBinary))
|
|
|
|
ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
|
|
|
|
|
2004-06-03 02:03:23 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IDirectXFileDataReferenceImpl_AddRef(IDirectXFileDataReference* iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
|
2005-01-20 11:53:56 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
return ref;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IDirectXFileDataReferenceImpl_Release(IDirectXFileDataReference* iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
|
2005-01-20 11:53:56 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
if (!ref)
|
2004-06-03 02:03:23 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
return ref;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IDirectXFileObject methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileDataReferenceImpl_GetName(IDirectXFileDataReference* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-24 22:38:29 +02:00
|
|
|
TRACE("(%p/%p)->(%p,%p)\n", This, iface, pstrNameBuf, pdwBufLen);
|
|
|
|
|
|
|
|
if (!pstrNameBuf)
|
|
|
|
return DXFILEERR_BADVALUE;
|
|
|
|
|
|
|
|
strcpy(pstrNameBuf, This->ptarget->name);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileDataReferenceImpl_GetId(IDirectXFileDataReference* iface, LPGUID pGuid)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-24 22:38:29 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, pGuid);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-24 22:38:29 +02:00
|
|
|
if (!pGuid)
|
|
|
|
return DXFILEERR_BADVALUE;
|
|
|
|
|
|
|
|
memcpy(pGuid, &This->ptarget->class_id, 16);
|
|
|
|
|
|
|
|
return DXFILE_OK;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IDirectXFileDataReference ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileDataReferenceImpl_Resolve(IDirectXFileDataReference* iface, LPDIRECTXFILEDATA* ppDataObj)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
|
2008-09-24 22:38:29 +02:00
|
|
|
IDirectXFileDataImpl *object;
|
|
|
|
HRESULT hr;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-24 22:38:29 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-09-24 22:38:29 +02:00
|
|
|
if (!ppDataObj)
|
|
|
|
return DXFILEERR_BADVALUE;
|
|
|
|
|
|
|
|
hr = IDirectXFileDataImpl_Create(&object);
|
2008-12-14 18:55:10 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2008-09-24 22:38:29 +02:00
|
|
|
|
|
|
|
object->pobj = This->ptarget;
|
|
|
|
object->cur_enum_object = 0;
|
2008-10-07 22:52:55 +02:00
|
|
|
object->level = 0;
|
|
|
|
object->from_ref = TRUE;
|
2008-09-24 22:38:29 +02:00
|
|
|
|
|
|
|
*ppDataObj = (LPDIRECTXFILEDATA)object;
|
|
|
|
|
|
|
|
return DXFILE_OK;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl =
|
2004-06-03 02:03:23 +02:00
|
|
|
{
|
|
|
|
IDirectXFileDataReferenceImpl_QueryInterface,
|
|
|
|
IDirectXFileDataReferenceImpl_AddRef,
|
|
|
|
IDirectXFileDataReferenceImpl_Release,
|
|
|
|
IDirectXFileDataReferenceImpl_GetName,
|
|
|
|
IDirectXFileDataReferenceImpl_GetId,
|
|
|
|
IDirectXFileDataReferenceImpl_Resolve
|
|
|
|
};
|
|
|
|
|
2008-12-04 12:47:20 +01:00
|
|
|
static HRESULT IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl** ppObj)
|
2004-06-04 21:36:56 +02:00
|
|
|
{
|
|
|
|
IDirectXFileEnumObjectImpl* object;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", ppObj);
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileEnumObjectImpl));
|
2008-12-14 18:55:10 +01:00
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
return DXFILEERR_BADALLOC;
|
|
|
|
}
|
2004-06-04 21:36:56 +02:00
|
|
|
|
2010-01-12 09:54:36 +01:00
|
|
|
object->lpVtbl = &IDirectXFileEnumObject_Vtbl;
|
2004-06-04 21:36:56 +02:00
|
|
|
object->ref = 1;
|
|
|
|
|
|
|
|
*ppObj = object;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-03 02:03:23 +02:00
|
|
|
/*** IUnknown methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileEnumObjectImpl_QueryInterface(IDirectXFileEnumObject* iface, REFIID riid, void** ppvObject)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2004-06-04 21:36:56 +02:00
|
|
|
TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDirectXFileEnumObject))
|
|
|
|
{
|
2010-03-01 09:36:37 +01:00
|
|
|
IUnknown_AddRef(iface);
|
2004-06-03 02:03:23 +02:00
|
|
|
*ppvObject = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IDirectXFileEnumObjectImpl_AddRef(IDirectXFileEnumObject* iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
|
2005-01-20 11:53:56 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
return ref;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IDirectXFileEnumObjectImpl_Release(IDirectXFileEnumObject* iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
|
2005-01-20 11:53:56 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
if (!ref)
|
2008-11-09 11:09:56 +01:00
|
|
|
{
|
2008-12-23 12:47:48 +01:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < This->nb_xobjects; i++)
|
|
|
|
IDirectXFileData_Release(This->pRefObjects[i]);
|
2008-12-23 11:57:32 +01:00
|
|
|
if (This->source == DXFILELOAD_FROMFILE)
|
2008-12-24 11:04:02 +01:00
|
|
|
{
|
2009-02-03 22:58:34 +01:00
|
|
|
UnmapViewOfFile(This->buffer);
|
|
|
|
CloseHandle(This->file_mapping);
|
2008-12-23 11:57:32 +01:00
|
|
|
CloseHandle(This->hFile);
|
2008-12-24 11:04:02 +01:00
|
|
|
}
|
2009-02-10 14:12:47 +01:00
|
|
|
else if (This->source == DXFILELOAD_FROMRESOURCE)
|
|
|
|
FreeResource(This->resource_data);
|
2004-06-03 02:03:23 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2008-11-09 11:09:56 +01:00
|
|
|
}
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
return ref;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IDirectXFileEnumObject methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileEnumObject* iface, LPDIRECTXFILEDATA* ppDataObj)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
IDirectXFileDataImpl* object;
|
2008-08-19 00:29:09 +02:00
|
|
|
HRESULT hr;
|
2008-12-23 11:55:36 +01:00
|
|
|
LPBYTE pstrings = NULL;
|
2008-10-16 22:22:52 +02:00
|
|
|
|
2008-09-22 20:27:09 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj);
|
2008-09-16 22:22:28 +02:00
|
|
|
|
2008-11-11 12:39:46 +01:00
|
|
|
if (This->nb_xobjects >= MAX_OBJECTS)
|
|
|
|
{
|
|
|
|
ERR("Too many objects\n");
|
|
|
|
return DXFILEERR_NOMOREOBJECTS;
|
|
|
|
}
|
|
|
|
|
2010-03-01 09:36:19 +01:00
|
|
|
/* Check if there are templates defined before the object */
|
|
|
|
while (This->buf.rem_bytes && is_template_available(&This->buf))
|
|
|
|
{
|
|
|
|
if (!parse_template(&This->buf))
|
|
|
|
{
|
2010-03-03 08:52:43 +01:00
|
|
|
WARN("Template is not correct\n");
|
2010-03-01 09:36:19 +01:00
|
|
|
hr = DXFILEERR_BADVALUE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Template successfully parsed:\n");
|
|
|
|
if (TRACE_ON(d3dxof))
|
|
|
|
dump_template(This->pDirectXFile->xtemplates, &This->pDirectXFile->xtemplates[This->pDirectXFile->nb_xtemplates - 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-16 22:22:28 +02:00
|
|
|
if (!This->buf.rem_bytes)
|
|
|
|
return DXFILEERR_NOMOREOBJECTS;
|
|
|
|
|
2008-08-19 00:29:09 +02:00
|
|
|
hr = IDirectXFileDataImpl_Create(&object);
|
2008-10-08 01:35:37 +02:00
|
|
|
if (FAILED(hr))
|
2008-08-19 00:29:09 +02:00
|
|
|
return hr;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2008-12-23 11:56:27 +01:00
|
|
|
This->buf.pxo_globals = This->xobjects;
|
2008-09-24 22:38:29 +02:00
|
|
|
This->buf.nb_pxo_globals = This->nb_xobjects;
|
2008-11-09 11:11:40 +01:00
|
|
|
This->buf.level = 0;
|
2008-09-16 22:22:28 +02:00
|
|
|
|
2008-12-23 11:56:27 +01:00
|
|
|
This->buf.pxo_tab = HeapAlloc(GetProcessHeap(), 0, sizeof(xobject)*MAX_SUBOBJECTS);
|
|
|
|
if (!This->buf.pxo_tab)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
hr = DXFILEERR_BADALLOC;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
This->buf.pxo = This->xobjects[This->nb_xobjects] = This->buf.pxo_tab;
|
|
|
|
|
2009-03-24 23:59:37 +01:00
|
|
|
This->buf.pxo->pdata = This->buf.pdata = NULL;
|
|
|
|
This->buf.capacity = 0;
|
2009-03-12 09:06:16 +01:00
|
|
|
This->buf.cur_pos_data = 0;
|
2009-12-30 22:06:11 +01:00
|
|
|
This->buf.pxo->nb_subobjects = 1;
|
2008-11-09 11:11:40 +01:00
|
|
|
|
|
|
|
pstrings = HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER);
|
|
|
|
if (!pstrings)
|
|
|
|
{
|
2008-12-14 18:55:10 +01:00
|
|
|
ERR("Out of memory\n");
|
2008-12-23 11:55:36 +01:00
|
|
|
hr = DXFILEERR_BADALLOC;
|
|
|
|
goto error;
|
2008-11-09 11:11:40 +01:00
|
|
|
}
|
2008-12-23 11:57:32 +01:00
|
|
|
This->buf.cur_pstrings = This->buf.pstrings = object->pstrings = pstrings;
|
2008-09-16 22:22:28 +02:00
|
|
|
|
|
|
|
if (!parse_object(&This->buf))
|
|
|
|
{
|
2010-03-03 08:52:43 +01:00
|
|
|
WARN("Object is not correct\n");
|
2008-12-23 11:55:36 +01:00
|
|
|
hr = DXFILEERR_PARSEERROR;
|
|
|
|
goto error;
|
2008-09-16 22:22:28 +02:00
|
|
|
}
|
|
|
|
|
2008-11-09 11:11:40 +01:00
|
|
|
object->pstrings = pstrings;
|
2008-09-16 22:22:28 +02:00
|
|
|
object->pobj = This->buf.pxo;
|
2008-09-22 20:27:09 +02:00
|
|
|
object->cur_enum_object = 0;
|
2008-10-07 22:52:55 +02:00
|
|
|
object->level = 0;
|
|
|
|
object->from_ref = FALSE;
|
2008-09-16 22:22:28 +02:00
|
|
|
|
2004-06-03 02:03:23 +02:00
|
|
|
*ppDataObj = (LPDIRECTXFILEDATA)object;
|
|
|
|
|
2008-12-23 12:47:48 +01:00
|
|
|
/* Get a reference to created object */
|
|
|
|
This->pRefObjects[This->nb_xobjects] = (LPDIRECTXFILEDATA)object;
|
|
|
|
IDirectXFileData_AddRef(This->pRefObjects[This->nb_xobjects]);
|
|
|
|
|
2008-09-24 22:38:29 +02:00
|
|
|
This->nb_xobjects++;
|
|
|
|
|
2008-08-19 00:29:09 +02:00
|
|
|
return DXFILE_OK;
|
2008-12-23 11:55:36 +01:00
|
|
|
|
|
|
|
error:
|
|
|
|
|
2008-12-23 11:56:27 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->buf.pxo_tab);
|
2010-02-07 21:16:33 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->buf.pdata);
|
2008-12-23 11:55:36 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pstrings);
|
|
|
|
|
|
|
|
return hr;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetDataObjectById(IDirectXFileEnumObject* iface, REFGUID rguid, LPDIRECTXFILEDATA* ppDataObj)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, rguid, ppDataObj);
|
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetDataObjectByName(IDirectXFileEnumObject* iface, LPCSTR szName, LPDIRECTXFILEDATA* ppDataObj)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
FIXME("(%p/%p)->(%s,%p) stub!\n", This, iface, szName, ppDataObj);
|
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl =
|
2004-06-03 02:03:23 +02:00
|
|
|
{
|
|
|
|
IDirectXFileEnumObjectImpl_QueryInterface,
|
|
|
|
IDirectXFileEnumObjectImpl_AddRef,
|
|
|
|
IDirectXFileEnumObjectImpl_Release,
|
|
|
|
IDirectXFileEnumObjectImpl_GetNextDataObject,
|
|
|
|
IDirectXFileEnumObjectImpl_GetDataObjectById,
|
|
|
|
IDirectXFileEnumObjectImpl_GetDataObjectByName
|
|
|
|
};
|
|
|
|
|
2008-12-16 20:55:22 +01:00
|
|
|
static HRESULT IDirectXFileSaveObjectImpl_Create(IDirectXFileSaveObjectImpl** ppObj)
|
|
|
|
{
|
|
|
|
IDirectXFileSaveObjectImpl* object;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", ppObj);
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileSaveObjectImpl));
|
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
return DXFILEERR_BADALLOC;
|
|
|
|
}
|
|
|
|
|
2010-01-12 09:54:36 +01:00
|
|
|
object->lpVtbl = &IDirectXFileSaveObject_Vtbl;
|
2008-12-16 20:55:22 +01:00
|
|
|
object->ref = 1;
|
|
|
|
|
|
|
|
*ppObj = object;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-03 02:03:23 +02:00
|
|
|
/*** IUnknown methods ***/
|
|
|
|
static HRESULT WINAPI IDirectXFileSaveObjectImpl_QueryInterface(IDirectXFileSaveObject* iface, REFIID riid, void** ppvObject)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2004-06-04 21:36:56 +02:00
|
|
|
TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDirectXFileSaveObject))
|
|
|
|
{
|
2010-03-01 09:36:37 +01:00
|
|
|
IUnknown_AddRef(iface);
|
2004-06-03 02:03:23 +02:00
|
|
|
*ppvObject = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IDirectXFileSaveObjectImpl_AddRef(IDirectXFileSaveObject* iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
|
2005-01-20 11:53:56 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
return ref;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IDirectXFileSaveObjectImpl_Release(IDirectXFileSaveObject* iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
|
2005-01-20 11:53:56 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
if (!ref)
|
2004-06-03 02:03:23 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
2005-01-20 11:53:56 +01:00
|
|
|
return ref;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileSaveObjectImpl_SaveTemplates(IDirectXFileSaveObject* iface, DWORD cTemplates, const GUID** ppguidTemplates)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
FIXME("(%p/%p)->(%d,%p) stub!\n", This, iface, cTemplates, ppguidTemplates);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileSaveObjectImpl_CreateDataObject(IDirectXFileSaveObject* iface, REFGUID rguidTemplate, LPCSTR szName, const GUID* pguid, DWORD cbSize, LPVOID pvData, LPDIRECTXFILEDATA* ppDataObj)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2006-10-08 18:59:55 +02:00
|
|
|
FIXME("(%p/%p)->(%p,%s,%p,%d,%p,%p) stub!\n", This, iface, rguidTemplate, szName, pguid, cbSize, pvData, ppDataObj);
|
2004-06-03 02:03:23 +02:00
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectXFileSaveObjectImpl_SaveData(IDirectXFileSaveObject* iface, LPDIRECTXFILEDATA ppDataObj)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
|
2004-06-03 02:03:23 +02:00
|
|
|
|
|
|
|
FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppDataObj);
|
|
|
|
|
2007-11-08 05:55:01 +01:00
|
|
|
return DXFILEERR_BADVALUE;
|
2004-06-03 02:03:23 +02:00
|
|
|
}
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl =
|
2004-06-03 02:03:23 +02:00
|
|
|
{
|
|
|
|
IDirectXFileSaveObjectImpl_QueryInterface,
|
|
|
|
IDirectXFileSaveObjectImpl_AddRef,
|
|
|
|
IDirectXFileSaveObjectImpl_Release,
|
|
|
|
IDirectXFileSaveObjectImpl_SaveTemplates,
|
|
|
|
IDirectXFileSaveObjectImpl_CreateDataObject,
|
|
|
|
IDirectXFileSaveObjectImpl_SaveData
|
|
|
|
};
|