2 * Implementation of DirectX File Interfaces
4 * Copyright 2004, 2008, 2010 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/debug.h"
29 #include "d3dxof_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(d3dxof
);
35 WINE_DECLARE_DEBUG_CHANNEL(d3dxof_dump
);
37 static const struct IDirectXFileVtbl IDirectXFile_Vtbl
;
38 static const struct IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl
;
39 static const struct IDirectXFileDataVtbl IDirectXFileData_Vtbl
;
40 static const struct IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl
;
41 static const struct IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl
;
42 static const struct IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl
;
44 static HRESULT
IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImpl
** ppObj
);
45 static HRESULT
IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl
** ppObj
);
46 static HRESULT
IDirectXFileSaveObjectImpl_Create(IDirectXFileSaveObjectImpl
** ppObj
);
48 #define TOKEN_DWORD 41
49 #define TOKEN_FLOAT 42
51 HRESULT
IDirectXFileImpl_Create(IUnknown
* pUnkOuter
, LPVOID
* ppObj
)
53 IDirectXFileImpl
* object
;
55 TRACE("(%p,%p)\n", pUnkOuter
, ppObj
);
57 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectXFileImpl
));
59 return DXFILEERR_BADALLOC
;
61 object
->IDirectXFile_iface
.lpVtbl
= &IDirectXFile_Vtbl
;
64 /* Reserve first template to handle the case sensitive legacy type indexColor */
65 object
->nb_xtemplates
= 1;
66 strcpy(object
->xtemplates
[0].name
, "indexColor");
67 object
->xtemplates
[0].nb_members
= 2;
68 object
->xtemplates
[0].members
[0].type
= TOKEN_DWORD
;
69 object
->xtemplates
[0].members
[0].nb_dims
= 0;
70 object
->xtemplates
[0].members
[1].type
= TOKEN_FLOAT
;
71 object
->xtemplates
[0].members
[1].nb_dims
= 1;
72 object
->xtemplates
[0].members
[1].dim_fixed
[0] = TRUE
;
73 object
->xtemplates
[0].members
[1].dim_value
[0] = 4;
75 *ppObj
= &object
->IDirectXFile_iface
;
80 static inline IDirectXFileImpl
*impl_from_IDirectXFile(IDirectXFile
*iface
)
82 return CONTAINING_RECORD(iface
, IDirectXFileImpl
, IDirectXFile_iface
);
85 /*** IUnknown methods ***/
86 static HRESULT WINAPI
IDirectXFileImpl_QueryInterface(IDirectXFile
* iface
, REFIID riid
, void** ppvObject
)
88 IDirectXFileImpl
*This
= impl_from_IDirectXFile(iface
);
90 TRACE("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
92 if (IsEqualGUID(riid
, &IID_IUnknown
)
93 || IsEqualGUID(riid
, &IID_IDirectXFile
))
95 IUnknown_AddRef(iface
);
96 *ppvObject
= &This
->IDirectXFile_iface
;
100 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
101 return E_NOINTERFACE
;
104 static ULONG WINAPI
IDirectXFileImpl_AddRef(IDirectXFile
* iface
)
106 IDirectXFileImpl
*This
= impl_from_IDirectXFile(iface
);
107 ULONG ref
= InterlockedIncrement(&This
->ref
);
109 TRACE("(%p/%p)->(): new ref %d\n", iface
, This
, ref
);
114 static ULONG WINAPI
IDirectXFileImpl_Release(IDirectXFile
* iface
)
116 IDirectXFileImpl
*This
= impl_from_IDirectXFile(iface
);
117 ULONG ref
= InterlockedDecrement(&This
->ref
);
119 TRACE("(%p/%p)->(): new ref %d\n", iface
, This
, ref
);
122 HeapFree(GetProcessHeap(), 0, This
);
127 /*** IDirectXFile methods ***/
128 static HRESULT WINAPI
IDirectXFileImpl_CreateEnumObject(IDirectXFile
* iface
, LPVOID pvSource
, DXFILELOADOPTIONS dwLoadOptions
, LPDIRECTXFILEENUMOBJECT
* ppEnumObj
)
130 IDirectXFileImpl
*This
= impl_from_IDirectXFile(iface
);
131 IDirectXFileEnumObjectImpl
* object
;
137 TRACE("(%p/%p)->(%p,%x,%p)\n", This
, iface
, pvSource
, dwLoadOptions
, ppEnumObj
);
140 return DXFILEERR_BADVALUE
;
142 /* Only lowest 4 bits are relevant in DXFILELOADOPTIONS */
143 dwLoadOptions
&= 0xF;
145 hr
= IDirectXFileEnumObjectImpl_Create(&object
);
149 if (dwLoadOptions
== DXFILELOAD_FROMFILE
)
151 HANDLE hFile
, file_mapping
;
153 TRACE("Open source file '%s'\n", (char*)pvSource
);
155 hFile
= CreateFileA(pvSource
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
156 if (hFile
== INVALID_HANDLE_VALUE
)
158 TRACE("File '%s' not found\n", (char*)pvSource
);
159 return DXFILEERR_FILENOTFOUND
;
162 file_size
= GetFileSize(hFile
, NULL
);
164 file_mapping
= CreateFileMappingA(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
168 hr
= DXFILEERR_BADFILETYPE
;
172 object
->mapped_memory
= MapViewOfFile(file_mapping
, FILE_MAP_READ
, 0, 0, 0);
173 CloseHandle(file_mapping
);
174 if (!object
->mapped_memory
)
176 hr
= DXFILEERR_BADFILETYPE
;
179 file_buffer
= object
->mapped_memory
;
181 else if (dwLoadOptions
== DXFILELOAD_FROMRESOURCE
)
184 HGLOBAL resource_data
;
185 LPDXFILELOADRESOURCE lpdxflr
= pvSource
;
187 TRACE("Source in resource (module = %p, name = %s, type = %s)\n", lpdxflr
->hModule
, debugstr_a(lpdxflr
->lpName
), debugstr_a(lpdxflr
->lpType
));
189 resource_info
= FindResourceA(lpdxflr
->hModule
, lpdxflr
->lpName
, lpdxflr
->lpType
);
192 hr
= DXFILEERR_RESOURCENOTFOUND
;
196 file_size
= SizeofResource(lpdxflr
->hModule
, resource_info
);
198 resource_data
= LoadResource(lpdxflr
->hModule
, resource_info
);
201 hr
= DXFILEERR_BADRESOURCE
;
205 file_buffer
= LockResource(resource_data
);
208 hr
= DXFILEERR_BADRESOURCE
;
212 else if (dwLoadOptions
== DXFILELOAD_FROMMEMORY
)
214 LPDXFILELOADMEMORY lpdxflm
= pvSource
;
216 TRACE("Source in memory at %p with size %d\n", lpdxflm
->lpMemory
, lpdxflm
->dSize
);
218 file_buffer
= lpdxflm
->lpMemory
;
219 file_size
= lpdxflm
->dSize
;
223 FIXME("Source type %d is not handled yet\n", dwLoadOptions
);
224 hr
= DXFILEERR_NOTDONEYET
;
228 TRACE("File size is %d bytes\n", file_size
);
230 if (TRACE_ON(d3dxof_dump
))
235 sprintf(tmp
, "file%05u.x", num
++);
237 file
= CreateFileA(tmp
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
, CREATE_ALWAYS
, 0, NULL
);
238 if (file
!= INVALID_HANDLE_VALUE
)
240 WriteFile(file
, file_buffer
, file_size
, &bytes_written
, NULL
);
245 object
->pDirectXFile
= This
;
247 object
->buf
.pdxf
= This
;
248 object
->buf
.token_present
= FALSE
;
249 object
->buf
.buffer
= file_buffer
;
250 object
->buf
.rem_bytes
= file_size
;
251 hr
= parse_header(&object
->buf
, &object
->decomp_buffer
);
255 /* Check if there are templates defined before the object */
256 if (!parse_templates(&object
->buf
, TRUE
))
258 hr
= DXFILEERR_PARSEERROR
;
262 if (TRACE_ON(d3dxof
))
265 TRACE("Registered templates (%d):\n", This
->nb_xtemplates
);
266 for (i
= 1; i
< This
->nb_xtemplates
; i
++)
267 DPRINTF("%s - %s\n", This
->xtemplates
[i
].name
, debugstr_guid(&This
->xtemplates
[i
].class_id
));
270 *ppEnumObj
= &object
->IDirectXFileEnumObject_iface
;
275 IDirectXFileEnumObject_Release(&object
->IDirectXFileEnumObject_iface
);
281 static HRESULT WINAPI
IDirectXFileImpl_CreateSaveObject(IDirectXFile
* iface
, LPCSTR szFileName
, DXFILEFORMAT dwFileFormat
, LPDIRECTXFILESAVEOBJECT
* ppSaveObj
)
283 IDirectXFileImpl
*This
= impl_from_IDirectXFile(iface
);
284 IDirectXFileSaveObjectImpl
*object
;
287 FIXME("(%p/%p)->(%s,%x,%p) partial stub!\n", This
, iface
, szFileName
, dwFileFormat
, ppSaveObj
);
289 if (!szFileName
|| !ppSaveObj
)
292 hr
= IDirectXFileSaveObjectImpl_Create(&object
);
294 *ppSaveObj
= &object
->IDirectXFileSaveObject_iface
;
298 static HRESULT WINAPI
IDirectXFileImpl_RegisterTemplates(IDirectXFile
* iface
, LPVOID pvData
, DWORD cbSize
)
300 IDirectXFileImpl
*This
= impl_from_IDirectXFile(iface
);
303 LPBYTE decomp_buffer
= NULL
;
306 ZeroMemory(&buf
, sizeof(buf
));
308 buf
.rem_bytes
= cbSize
;
311 TRACE("(%p/%p)->(%p,%d)\n", This
, iface
, pvData
, cbSize
);
314 return DXFILEERR_BADVALUE
;
316 if (TRACE_ON(d3dxof_dump
))
321 sprintf(tmp
, "template%05u.x", num
++);
323 file
= CreateFileA(tmp
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
, CREATE_ALWAYS
, 0, NULL
);
324 if (file
!= INVALID_HANDLE_VALUE
)
326 WriteFile(file
, pvData
, cbSize
, &bytes_written
, NULL
);
331 hr
= parse_header(&buf
, &decomp_buffer
);
335 if (!parse_templates(&buf
, FALSE
))
337 hr
= DXFILEERR_PARSEERROR
;
341 if (TRACE_ON(d3dxof
))
344 TRACE("Registered templates (%d):\n", This
->nb_xtemplates
);
345 for (i
= 1; i
< This
->nb_xtemplates
; i
++)
346 DPRINTF("%s - %s\n", This
->xtemplates
[i
].name
, debugstr_guid(&This
->xtemplates
[i
].class_id
));
351 HeapFree(GetProcessHeap(), 0, decomp_buffer
);
355 static const IDirectXFileVtbl IDirectXFile_Vtbl
=
357 IDirectXFileImpl_QueryInterface
,
358 IDirectXFileImpl_AddRef
,
359 IDirectXFileImpl_Release
,
360 IDirectXFileImpl_CreateEnumObject
,
361 IDirectXFileImpl_CreateSaveObject
,
362 IDirectXFileImpl_RegisterTemplates
365 static HRESULT
IDirectXFileBinaryImpl_Create(IDirectXFileBinaryImpl
** ppObj
)
367 IDirectXFileBinaryImpl
* object
;
369 TRACE("(%p)\n", ppObj
);
371 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectXFileBinaryImpl
));
373 return DXFILEERR_BADALLOC
;
375 object
->IDirectXFileBinary_iface
.lpVtbl
= &IDirectXFileBinary_Vtbl
;
383 static inline IDirectXFileBinaryImpl
*impl_from_IDirectXFileBinary(IDirectXFileBinary
*iface
)
385 return CONTAINING_RECORD(iface
, IDirectXFileBinaryImpl
, IDirectXFileBinary_iface
);
388 /*** IUnknown methods ***/
389 static HRESULT WINAPI
IDirectXFileBinaryImpl_QueryInterface(IDirectXFileBinary
* iface
, REFIID riid
, void** ppvObject
)
391 IDirectXFileBinaryImpl
*This
= impl_from_IDirectXFileBinary(iface
);
393 TRACE("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
395 if (IsEqualGUID(riid
, &IID_IUnknown
)
396 || IsEqualGUID(riid
, &IID_IDirectXFileObject
)
397 || IsEqualGUID(riid
, &IID_IDirectXFileBinary
))
399 IUnknown_AddRef(iface
);
400 *ppvObject
= &This
->IDirectXFileBinary_iface
;
404 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
405 if (!IsEqualGUID(riid
, &IID_IDirectXFileData
)
406 && !IsEqualGUID(riid
, &IID_IDirectXFileDataReference
))
407 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
409 return E_NOINTERFACE
;
412 static ULONG WINAPI
IDirectXFileBinaryImpl_AddRef(IDirectXFileBinary
* iface
)
414 IDirectXFileBinaryImpl
*This
= impl_from_IDirectXFileBinary(iface
);
415 ULONG ref
= InterlockedIncrement(&This
->ref
);
417 TRACE("(%p/%p)->(): new ref %d\n", iface
, This
, ref
);
422 static ULONG WINAPI
IDirectXFileBinaryImpl_Release(IDirectXFileBinary
* iface
)
424 IDirectXFileBinaryImpl
*This
= impl_from_IDirectXFileBinary(iface
);
425 ULONG ref
= InterlockedDecrement(&This
->ref
);
427 TRACE("(%p/%p)->(): new ref %d\n", iface
, This
, ref
);
430 HeapFree(GetProcessHeap(), 0, This
);
435 /*** IDirectXFileObject methods ***/
436 static HRESULT WINAPI
IDirectXFileBinaryImpl_GetName(IDirectXFileBinary
* iface
, LPSTR pstrNameBuf
, LPDWORD pdwBufLen
)
439 IDirectXFileBinaryImpl
*This
= impl_from_IDirectXFileBinary(iface
);
441 FIXME("(%p/%p)->(%p,%p) stub!\n", This
, iface
, pstrNameBuf
, pdwBufLen
);
443 return DXFILEERR_BADVALUE
;
446 static HRESULT WINAPI
IDirectXFileBinaryImpl_GetId(IDirectXFileBinary
* iface
, LPGUID pGuid
)
448 IDirectXFileBinaryImpl
*This
= impl_from_IDirectXFileBinary(iface
);
450 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pGuid
);
452 return DXFILEERR_BADVALUE
;
455 /*** IDirectXFileBinary methods ***/
456 static HRESULT WINAPI
IDirectXFileBinaryImpl_GetSize(IDirectXFileBinary
* iface
, DWORD
* pcbSize
)
458 IDirectXFileBinaryImpl
*This
= impl_from_IDirectXFileBinary(iface
);
460 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pcbSize
);
462 return DXFILEERR_BADVALUE
;
465 static HRESULT WINAPI
IDirectXFileBinaryImpl_GetMimeType(IDirectXFileBinary
* iface
, LPCSTR
* pszMimeType
)
467 IDirectXFileBinaryImpl
*This
= impl_from_IDirectXFileBinary(iface
);
469 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pszMimeType
);
471 return DXFILEERR_BADVALUE
;
474 static HRESULT WINAPI
IDirectXFileBinaryImpl_Read(IDirectXFileBinary
* iface
, LPVOID pvData
, DWORD cbSize
, LPDWORD pcbRead
)
476 IDirectXFileBinaryImpl
*This
= impl_from_IDirectXFileBinary(iface
);
478 FIXME("(%p/%p)->(%p, %d, %p) stub!\n", This
, iface
, pvData
, cbSize
, pcbRead
);
480 return DXFILEERR_BADVALUE
;
483 static const IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl
=
485 IDirectXFileBinaryImpl_QueryInterface
,
486 IDirectXFileBinaryImpl_AddRef
,
487 IDirectXFileBinaryImpl_Release
,
488 IDirectXFileBinaryImpl_GetName
,
489 IDirectXFileBinaryImpl_GetId
,
490 IDirectXFileBinaryImpl_GetSize
,
491 IDirectXFileBinaryImpl_GetMimeType
,
492 IDirectXFileBinaryImpl_Read
495 static HRESULT
IDirectXFileDataImpl_Create(IDirectXFileDataImpl
** ppObj
)
497 IDirectXFileDataImpl
* object
;
499 TRACE("(%p)\n", ppObj
);
501 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectXFileDataImpl
));
503 return DXFILEERR_BADALLOC
;
505 object
->IDirectXFileData_iface
.lpVtbl
= &IDirectXFileData_Vtbl
;
513 static inline IDirectXFileDataImpl
*impl_from_IDirectXFileData(IDirectXFileData
*iface
)
515 return CONTAINING_RECORD(iface
, IDirectXFileDataImpl
, IDirectXFileData_iface
);
518 /*** IUnknown methods ***/
519 static HRESULT WINAPI
IDirectXFileDataImpl_QueryInterface(IDirectXFileData
* iface
, REFIID riid
, void** ppvObject
)
521 IDirectXFileDataImpl
*This
= impl_from_IDirectXFileData(iface
);
523 TRACE("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
525 if (IsEqualGUID(riid
, &IID_IUnknown
)
526 || IsEqualGUID(riid
, &IID_IDirectXFileObject
)
527 || IsEqualGUID(riid
, &IID_IDirectXFileData
))
529 IUnknown_AddRef(iface
);
530 *ppvObject
= &This
->IDirectXFileData_iface
;
534 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
535 if (!IsEqualGUID(riid
, &IID_IDirectXFileBinary
)
536 && !IsEqualGUID(riid
, &IID_IDirectXFileDataReference
))
537 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
539 return E_NOINTERFACE
;
542 static ULONG WINAPI
IDirectXFileDataImpl_AddRef(IDirectXFileData
* iface
)
544 IDirectXFileDataImpl
*This
= impl_from_IDirectXFileData(iface
);
545 ULONG ref
= InterlockedIncrement(&This
->ref
);
547 TRACE("(%p/%p)->(): new ref %d\n", iface
, This
, ref
);
552 static ULONG WINAPI
IDirectXFileDataImpl_Release(IDirectXFileData
* iface
)
554 IDirectXFileDataImpl
*This
= impl_from_IDirectXFileData(iface
);
555 ULONG ref
= InterlockedDecrement(&This
->ref
);
557 TRACE("(%p/%p)->(): new ref %d\n", iface
, This
, ref
);
561 if (!This
->level
&& !This
->from_ref
)
563 HeapFree(GetProcessHeap(), 0, This
->pstrings
);
566 HeapFree(GetProcessHeap(), 0, This
->pobj
->pdata
);
567 HeapFree(GetProcessHeap(), 0, This
->pobj
);
570 HeapFree(GetProcessHeap(), 0, This
);
576 /*** IDirectXFileObject methods ***/
577 static HRESULT WINAPI
IDirectXFileDataImpl_GetName(IDirectXFileData
* iface
, LPSTR pstrNameBuf
, LPDWORD pdwBufLen
)
579 IDirectXFileDataImpl
*This
= impl_from_IDirectXFileData(iface
);
582 TRACE("(%p/%p)->(%p,%p)\n", This
, iface
, pstrNameBuf
, pdwBufLen
);
585 return DXFILEERR_BADVALUE
;
587 len
= strlen(This
->pobj
->name
);
592 if (*pdwBufLen
< len
)
593 return DXFILEERR_BADVALUE
;
594 CopyMemory(pstrNameBuf
, This
->pobj
->name
, len
);
595 /* Even if we return a size of 0, an empty string with a null byte must be returned */
596 if (*pdwBufLen
&& !len
)
604 static HRESULT WINAPI
IDirectXFileDataImpl_GetId(IDirectXFileData
* iface
, LPGUID pGuid
)
606 IDirectXFileDataImpl
*This
= impl_from_IDirectXFileData(iface
);
608 TRACE("(%p/%p)->(%p)\n", This
, iface
, pGuid
);
611 return DXFILEERR_BADVALUE
;
613 *pGuid
= This
->pobj
->class_id
;
618 /*** IDirectXFileData methods ***/
619 static HRESULT WINAPI
IDirectXFileDataImpl_GetData(IDirectXFileData
* iface
, LPCSTR szMember
, DWORD
* pcbSize
, void** ppvData
)
621 IDirectXFileDataImpl
*This
= impl_from_IDirectXFileData(iface
);
623 TRACE("(%p/%p)->(%s,%p,%p)\n", This
, iface
, debugstr_a(szMember
), pcbSize
, ppvData
);
625 if (!pcbSize
|| !ppvData
)
626 return DXFILEERR_BADVALUE
;
631 for (i
= 0; i
< This
->pobj
->nb_members
; i
++)
632 if (!strcmp(This
->pobj
->members
[i
].name
, szMember
))
634 if (i
== This
->pobj
->nb_members
)
636 WARN("Unknown member '%s'\n", szMember
);
637 return DXFILEERR_BADDATAREFERENCE
;
639 *pcbSize
= This
->pobj
->members
[i
].size
;
640 *ppvData
= This
->pobj
->root
->pdata
+ This
->pobj
->members
[i
].start
;
644 *pcbSize
= This
->pobj
->size
;
645 *ppvData
= This
->pobj
->root
->pdata
+ This
->pobj
->pos_data
;
651 static HRESULT WINAPI
IDirectXFileDataImpl_GetType(IDirectXFileData
* iface
, const GUID
** pguid
)
653 IDirectXFileDataImpl
*This
= impl_from_IDirectXFileData(iface
);
656 TRACE("(%p/%p)->(%p)\n", This
, iface
, pguid
);
659 return DXFILEERR_BADVALUE
;
661 guid
= This
->pobj
->type
;
667 static HRESULT WINAPI
IDirectXFileDataImpl_GetNextObject(IDirectXFileData
* iface
, LPDIRECTXFILEOBJECT
* ppChildObj
)
670 IDirectXFileDataImpl
*This
= impl_from_IDirectXFileData(iface
);
672 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppChildObj
);
674 if (This
->cur_enum_object
>= This
->pobj
->nb_children
)
677 return DXFILEERR_NOMOREOBJECTS
;
680 if (This
->from_ref
&& (This
->level
>= 1))
682 /* Only 2 levels can be enumerated if the object is obtained from a reference */
684 return DXFILEERR_NOMOREOBJECTS
;
687 if (This
->pobj
->children
[This
->cur_enum_object
]->binary
)
689 IDirectXFileBinaryImpl
*object
;
691 hr
= IDirectXFileBinaryImpl_Create(&object
);
695 *ppChildObj
= (LPDIRECTXFILEOBJECT
)&object
->IDirectXFileBinary_iface
;
697 else if (This
->pobj
->children
[This
->cur_enum_object
]->ptarget
)
699 IDirectXFileDataReferenceImpl
*object
;
701 hr
= IDirectXFileDataReferenceImpl_Create(&object
);
705 object
->ptarget
= This
->pobj
->children
[This
->cur_enum_object
++]->ptarget
;
707 *ppChildObj
= (LPDIRECTXFILEOBJECT
)&object
->IDirectXFileDataReference_iface
;
711 IDirectXFileDataImpl
*object
;
713 hr
= IDirectXFileDataImpl_Create(&object
);
717 object
->pobj
= This
->pobj
->children
[This
->cur_enum_object
++];
718 object
->cur_enum_object
= 0;
719 object
->from_ref
= This
->from_ref
;
720 object
->level
= This
->level
+ 1;
722 *ppChildObj
= (LPDIRECTXFILEOBJECT
)&object
->IDirectXFileData_iface
;
728 static HRESULT WINAPI
IDirectXFileDataImpl_AddDataObject(IDirectXFileData
* iface
, LPDIRECTXFILEDATA pDataObj
)
730 IDirectXFileDataImpl
*This
= impl_from_IDirectXFileData(iface
);
732 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pDataObj
);
734 return DXFILEERR_BADVALUE
;
737 static HRESULT WINAPI
IDirectXFileDataImpl_AddDataReference(IDirectXFileData
* iface
, LPCSTR szRef
, const GUID
* pguidRef
)
739 IDirectXFileDataImpl
*This
= impl_from_IDirectXFileData(iface
);
741 FIXME("(%p/%p)->(%s,%p) stub!\n", This
, iface
, szRef
, pguidRef
);
743 return DXFILEERR_BADVALUE
;
746 static HRESULT WINAPI
IDirectXFileDataImpl_AddBinaryObject(IDirectXFileData
* iface
, LPCSTR szName
, const GUID
* pguid
, LPCSTR szMimeType
, LPVOID pvData
, DWORD cbSize
)
748 IDirectXFileDataImpl
*This
= impl_from_IDirectXFileData(iface
);
750 FIXME("(%p/%p)->(%s,%p,%s,%p,%d) stub!\n", This
, iface
, szName
, pguid
, szMimeType
, pvData
, cbSize
);
752 return DXFILEERR_BADVALUE
;
755 static const IDirectXFileDataVtbl IDirectXFileData_Vtbl
=
757 IDirectXFileDataImpl_QueryInterface
,
758 IDirectXFileDataImpl_AddRef
,
759 IDirectXFileDataImpl_Release
,
760 IDirectXFileDataImpl_GetName
,
761 IDirectXFileDataImpl_GetId
,
762 IDirectXFileDataImpl_GetData
,
763 IDirectXFileDataImpl_GetType
,
764 IDirectXFileDataImpl_GetNextObject
,
765 IDirectXFileDataImpl_AddDataObject
,
766 IDirectXFileDataImpl_AddDataReference
,
767 IDirectXFileDataImpl_AddBinaryObject
770 static HRESULT
IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImpl
** ppObj
)
772 IDirectXFileDataReferenceImpl
* object
;
774 TRACE("(%p)\n", ppObj
);
776 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectXFileDataReferenceImpl
));
778 return DXFILEERR_BADALLOC
;
780 object
->IDirectXFileDataReference_iface
.lpVtbl
= &IDirectXFileDataReference_Vtbl
;
788 static inline IDirectXFileDataReferenceImpl
*impl_from_IDirectXFileDataReference(IDirectXFileDataReference
*iface
)
790 return CONTAINING_RECORD(iface
, IDirectXFileDataReferenceImpl
, IDirectXFileDataReference_iface
);
793 /*** IUnknown methods ***/
794 static HRESULT WINAPI
IDirectXFileDataReferenceImpl_QueryInterface(IDirectXFileDataReference
* iface
, REFIID riid
, void** ppvObject
)
796 IDirectXFileDataReferenceImpl
*This
= impl_from_IDirectXFileDataReference(iface
);
798 TRACE("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
800 if (IsEqualGUID(riid
, &IID_IUnknown
)
801 || IsEqualGUID(riid
, &IID_IDirectXFileObject
)
802 || IsEqualGUID(riid
, &IID_IDirectXFileDataReference
))
804 IUnknown_AddRef(iface
);
805 *ppvObject
= &This
->IDirectXFileDataReference_iface
;
809 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
810 if (!IsEqualGUID(riid
, &IID_IDirectXFileData
)
811 && !IsEqualGUID(riid
, &IID_IDirectXFileBinary
))
812 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
814 return E_NOINTERFACE
;
817 static ULONG WINAPI
IDirectXFileDataReferenceImpl_AddRef(IDirectXFileDataReference
* iface
)
819 IDirectXFileDataReferenceImpl
*This
= impl_from_IDirectXFileDataReference(iface
);
820 ULONG ref
= InterlockedIncrement(&This
->ref
);
822 TRACE("(%p/%p)->(): new ref %d\n", iface
, This
, ref
);
827 static ULONG WINAPI
IDirectXFileDataReferenceImpl_Release(IDirectXFileDataReference
* iface
)
829 IDirectXFileDataReferenceImpl
*This
= impl_from_IDirectXFileDataReference(iface
);
830 ULONG ref
= InterlockedDecrement(&This
->ref
);
832 TRACE("(%p/%p)->(): new ref %d\n", iface
, This
, ref
);
835 HeapFree(GetProcessHeap(), 0, This
);
840 /*** IDirectXFileObject methods ***/
841 static HRESULT WINAPI
IDirectXFileDataReferenceImpl_GetName(IDirectXFileDataReference
* iface
, LPSTR pstrNameBuf
, LPDWORD pdwBufLen
)
843 IDirectXFileDataReferenceImpl
*This
= impl_from_IDirectXFileDataReference(iface
);
846 TRACE("(%p/%p)->(%p,%p)\n", This
, iface
, pstrNameBuf
, pdwBufLen
);
849 return DXFILEERR_BADVALUE
;
851 len
= strlen(This
->ptarget
->name
);
856 if (*pdwBufLen
< len
)
857 return DXFILEERR_BADVALUE
;
858 CopyMemory(pstrNameBuf
, This
->ptarget
->name
, len
);
859 /* Even if we return a size of 0, an empty string with a null byte must be returned */
860 if (*pdwBufLen
&& !len
)
868 static HRESULT WINAPI
IDirectXFileDataReferenceImpl_GetId(IDirectXFileDataReference
* iface
, LPGUID pGuid
)
870 IDirectXFileDataReferenceImpl
*This
= impl_from_IDirectXFileDataReference(iface
);
872 TRACE("(%p/%p)->(%p)\n", This
, iface
, pGuid
);
875 return DXFILEERR_BADVALUE
;
877 *pGuid
= This
->ptarget
->class_id
;
882 /*** IDirectXFileDataReference ***/
883 static HRESULT WINAPI
IDirectXFileDataReferenceImpl_Resolve(IDirectXFileDataReference
* iface
, LPDIRECTXFILEDATA
* ppDataObj
)
885 IDirectXFileDataReferenceImpl
*This
= impl_from_IDirectXFileDataReference(iface
);
886 IDirectXFileDataImpl
*object
;
889 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppDataObj
);
892 return DXFILEERR_BADVALUE
;
894 hr
= IDirectXFileDataImpl_Create(&object
);
898 object
->pobj
= This
->ptarget
;
899 object
->cur_enum_object
= 0;
901 object
->from_ref
= TRUE
;
903 *ppDataObj
= &object
->IDirectXFileData_iface
;
908 static const IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl
=
910 IDirectXFileDataReferenceImpl_QueryInterface
,
911 IDirectXFileDataReferenceImpl_AddRef
,
912 IDirectXFileDataReferenceImpl_Release
,
913 IDirectXFileDataReferenceImpl_GetName
,
914 IDirectXFileDataReferenceImpl_GetId
,
915 IDirectXFileDataReferenceImpl_Resolve
918 static HRESULT
IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl
** ppObj
)
920 IDirectXFileEnumObjectImpl
* object
;
922 TRACE("(%p)\n", ppObj
);
924 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectXFileEnumObjectImpl
));
926 return DXFILEERR_BADALLOC
;
928 object
->IDirectXFileEnumObject_iface
.lpVtbl
= &IDirectXFileEnumObject_Vtbl
;
936 static inline IDirectXFileEnumObjectImpl
*impl_from_IDirectXFileEnumObject(IDirectXFileEnumObject
*iface
)
938 return CONTAINING_RECORD(iface
, IDirectXFileEnumObjectImpl
, IDirectXFileEnumObject_iface
);
941 /*** IUnknown methods ***/
942 static HRESULT WINAPI
IDirectXFileEnumObjectImpl_QueryInterface(IDirectXFileEnumObject
* iface
, REFIID riid
, void** ppvObject
)
944 IDirectXFileEnumObjectImpl
*This
= impl_from_IDirectXFileEnumObject(iface
);
946 TRACE("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
948 if (IsEqualGUID(riid
, &IID_IUnknown
)
949 || IsEqualGUID(riid
, &IID_IDirectXFileEnumObject
))
951 IUnknown_AddRef(iface
);
952 *ppvObject
= &This
->IDirectXFileEnumObject_iface
;
956 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
957 return E_NOINTERFACE
;
960 static ULONG WINAPI
IDirectXFileEnumObjectImpl_AddRef(IDirectXFileEnumObject
* iface
)
962 IDirectXFileEnumObjectImpl
*This
= impl_from_IDirectXFileEnumObject(iface
);
963 ULONG ref
= InterlockedIncrement(&This
->ref
);
965 TRACE("(%p/%p)->(): new ref %d\n", iface
, This
, ref
);
970 static ULONG WINAPI
IDirectXFileEnumObjectImpl_Release(IDirectXFileEnumObject
* iface
)
972 IDirectXFileEnumObjectImpl
*This
= impl_from_IDirectXFileEnumObject(iface
);
973 ULONG ref
= InterlockedDecrement(&This
->ref
);
975 TRACE("(%p/%p)->(): new ref %d\n", iface
, This
, ref
);
980 for (i
= 0; i
< This
->nb_xobjects
; i
++)
981 IDirectXFileData_Release(This
->pRefObjects
[i
]);
982 if (This
->mapped_memory
)
983 UnmapViewOfFile(This
->mapped_memory
);
984 HeapFree(GetProcessHeap(), 0, This
->decomp_buffer
);
985 HeapFree(GetProcessHeap(), 0, This
);
991 /*** IDirectXFileEnumObject methods ***/
992 static HRESULT WINAPI
IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileEnumObject
* iface
, LPDIRECTXFILEDATA
* ppDataObj
)
994 IDirectXFileEnumObjectImpl
*This
= impl_from_IDirectXFileEnumObject(iface
);
995 IDirectXFileDataImpl
* object
;
1003 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppDataObj
);
1005 if (This
->nb_xobjects
>= MAX_OBJECTS
)
1007 ERR("Too many objects\n");
1008 return DXFILEERR_NOMOREOBJECTS
;
1011 /* Check if there are templates defined before the object */
1012 if (!parse_templates(&This
->buf
, TRUE
))
1013 return DXFILEERR_PARSEERROR
;
1015 if (!This
->buf
.rem_bytes
)
1016 return DXFILEERR_NOMOREOBJECTS
;
1018 hr
= IDirectXFileDataImpl_Create(&object
);
1022 object
->pobj
= HeapAlloc(GetProcessHeap(), 0, sizeof(xobject
)*MAX_SUBOBJECTS
);
1025 hr
= DXFILEERR_BADALLOC
;
1029 object
->pstrings
= HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER
);
1030 if (!object
->pstrings
)
1032 hr
= DXFILEERR_BADALLOC
;
1036 object
->cur_enum_object
= 0;
1038 object
->from_ref
= FALSE
;
1040 This
->buf
.pxo_globals
= This
->xobjects
;
1041 This
->buf
.nb_pxo_globals
= This
->nb_xobjects
;
1042 This
->buf
.level
= 0;
1043 This
->buf
.pdata
= NULL
;
1044 This
->buf
.capacity
= 0;
1045 This
->buf
.cur_pos_data
= 0;
1046 This
->buf
.cur_pstrings
= This
->buf
.pstrings
= object
->pstrings
;
1047 This
->buf
.pxo
= This
->xobjects
[This
->nb_xobjects
] = This
->buf
.pxo_tab
= object
->pobj
;
1048 This
->buf
.pxo
->pdata
= NULL
;
1049 This
->buf
.pxo
->nb_subobjects
= 1;
1051 if (!parse_object(&This
->buf
))
1053 WARN("Object is not correct\n");
1054 hr
= DXFILEERR_PARSEERROR
;
1058 *ppDataObj
= &object
->IDirectXFileData_iface
;
1060 /* Get a reference to created object */
1061 This
->pRefObjects
[This
->nb_xobjects
] = &object
->IDirectXFileData_iface
;
1062 IDirectXFileData_AddRef(This
->pRefObjects
[This
->nb_xobjects
]);
1064 This
->nb_xobjects
++;
1070 IDirectXFileData_Release(&object
->IDirectXFileData_iface
);
1075 static HRESULT WINAPI
IDirectXFileEnumObjectImpl_GetDataObjectById(IDirectXFileEnumObject
* iface
, REFGUID rguid
, LPDIRECTXFILEDATA
* ppDataObj
)
1077 IDirectXFileEnumObjectImpl
*This
= impl_from_IDirectXFileEnumObject(iface
);
1079 FIXME("(%p/%p)->(%p,%p) stub!\n", This
, iface
, rguid
, ppDataObj
);
1081 return DXFILEERR_BADVALUE
;
1084 static HRESULT WINAPI
IDirectXFileEnumObjectImpl_GetDataObjectByName(IDirectXFileEnumObject
* iface
, LPCSTR szName
, LPDIRECTXFILEDATA
* ppDataObj
)
1086 IDirectXFileEnumObjectImpl
*This
= impl_from_IDirectXFileEnumObject(iface
);
1088 FIXME("(%p/%p)->(%s,%p) stub!\n", This
, iface
, szName
, ppDataObj
);
1090 return DXFILEERR_BADVALUE
;
1093 static const IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl
=
1095 IDirectXFileEnumObjectImpl_QueryInterface
,
1096 IDirectXFileEnumObjectImpl_AddRef
,
1097 IDirectXFileEnumObjectImpl_Release
,
1098 IDirectXFileEnumObjectImpl_GetNextDataObject
,
1099 IDirectXFileEnumObjectImpl_GetDataObjectById
,
1100 IDirectXFileEnumObjectImpl_GetDataObjectByName
1103 static HRESULT
IDirectXFileSaveObjectImpl_Create(IDirectXFileSaveObjectImpl
** ppObj
)
1105 IDirectXFileSaveObjectImpl
* object
;
1107 TRACE("(%p)\n", ppObj
);
1109 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectXFileSaveObjectImpl
));
1111 return DXFILEERR_BADALLOC
;
1113 object
->IDirectXFileSaveObject_iface
.lpVtbl
= &IDirectXFileSaveObject_Vtbl
;
1121 static inline IDirectXFileSaveObjectImpl
*impl_from_IDirectXFileSaveObject(IDirectXFileSaveObject
*iface
)
1123 return CONTAINING_RECORD(iface
, IDirectXFileSaveObjectImpl
, IDirectXFileSaveObject_iface
);
1126 /*** IUnknown methods ***/
1127 static HRESULT WINAPI
IDirectXFileSaveObjectImpl_QueryInterface(IDirectXFileSaveObject
* iface
, REFIID riid
, void** ppvObject
)
1129 IDirectXFileSaveObjectImpl
*This
= impl_from_IDirectXFileSaveObject(iface
);
1131 TRACE("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
1133 if (IsEqualGUID(riid
, &IID_IUnknown
)
1134 || IsEqualGUID(riid
, &IID_IDirectXFileSaveObject
))
1136 IUnknown_AddRef(iface
);
1137 *ppvObject
= &This
->IDirectXFileSaveObject_iface
;
1141 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
1142 return E_NOINTERFACE
;
1145 static ULONG WINAPI
IDirectXFileSaveObjectImpl_AddRef(IDirectXFileSaveObject
* iface
)
1147 IDirectXFileSaveObjectImpl
*This
= impl_from_IDirectXFileSaveObject(iface
);
1148 ULONG ref
= InterlockedIncrement(&This
->ref
);
1150 TRACE("(%p/%p)->(): new ref %d\n", iface
, This
, ref
);
1155 static ULONG WINAPI
IDirectXFileSaveObjectImpl_Release(IDirectXFileSaveObject
* iface
)
1157 IDirectXFileSaveObjectImpl
*This
= impl_from_IDirectXFileSaveObject(iface
);
1158 ULONG ref
= InterlockedDecrement(&This
->ref
);
1160 TRACE("(%p/%p)->(): new ref %d\n", iface
, This
, ref
);
1163 HeapFree(GetProcessHeap(), 0, This
);
1168 static HRESULT WINAPI
IDirectXFileSaveObjectImpl_SaveTemplates(IDirectXFileSaveObject
* iface
, DWORD cTemplates
, const GUID
** ppguidTemplates
)
1170 IDirectXFileSaveObjectImpl
*This
= impl_from_IDirectXFileSaveObject(iface
);
1172 FIXME("(%p/%p)->(%d,%p) stub!\n", This
, iface
, cTemplates
, ppguidTemplates
);
1177 static HRESULT WINAPI
IDirectXFileSaveObjectImpl_CreateDataObject(IDirectXFileSaveObject
* iface
, REFGUID rguidTemplate
, LPCSTR szName
, const GUID
* pguid
, DWORD cbSize
, LPVOID pvData
, LPDIRECTXFILEDATA
* ppDataObj
)
1179 IDirectXFileSaveObjectImpl
*This
= impl_from_IDirectXFileSaveObject(iface
);
1181 FIXME("(%p/%p)->(%p,%s,%p,%d,%p,%p) stub!\n", This
, iface
, rguidTemplate
, szName
, pguid
, cbSize
, pvData
, ppDataObj
);
1183 return DXFILEERR_BADVALUE
;
1186 static HRESULT WINAPI
IDirectXFileSaveObjectImpl_SaveData(IDirectXFileSaveObject
* iface
, LPDIRECTXFILEDATA ppDataObj
)
1188 IDirectXFileSaveObjectImpl
*This
= impl_from_IDirectXFileSaveObject(iface
);
1190 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, ppDataObj
);
1192 return DXFILEERR_BADVALUE
;
1195 static const IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl
=
1197 IDirectXFileSaveObjectImpl_QueryInterface
,
1198 IDirectXFileSaveObjectImpl_AddRef
,
1199 IDirectXFileSaveObjectImpl_Release
,
1200 IDirectXFileSaveObjectImpl_SaveTemplates
,
1201 IDirectXFileSaveObjectImpl_CreateDataObject
,
1202 IDirectXFileSaveObjectImpl_SaveData