2 * Implementation of DirectX File Interfaces
4 * Copyright 2004, 2008 Christian Costa
6 * This file contains the (internal) driver registration functions,
7 * driver enumeration APIs and DirectDraw creation functions.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/debug.h"
32 #include "d3dxof_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3dxof);
39 #define MAKEFOUR(a,b,c,d) ((DWORD)a + ((DWORD)b << 8) + ((DWORD)c << 16) + ((DWORD)d << 24))
40 #define XOFFILE_FORMAT_MAGIC MAKEFOUR('x','o','f',' ')
41 #define XOFFILE_FORMAT_VERSION_302 MAKEFOUR('0','3','0','2')
42 #define XOFFILE_FORMAT_VERSION_303 MAKEFOUR('0','3','0','3')
43 #define XOFFILE_FORMAT_BINARY MAKEFOUR('b','i','n',' ')
44 #define XOFFILE_FORMAT_TEXT MAKEFOUR('t','x','t',' ')
45 #define XOFFILE_FORMAT_COMPRESSED MAKEFOUR('c','m','p',' ')
46 #define XOFFILE_FORMAT_FLOAT_BITS_32 MAKEFOUR('0','0','3','2')
47 #define XOFFILE_FORMAT_FLOAT_BITS_64 MAKEFOUR('0','0','6','4')
50 #define TOKEN_STRING 2
51 #define TOKEN_INTEGER 3
53 #define TOKEN_INTEGER_LIST 6
54 #define TOKEN_FLOAT_LIST 7
55 #define TOKEN_OBRACE 10
56 #define TOKEN_CBRACE 11
57 #define TOKEN_OPAREN 12
58 #define TOKEN_CPAREN 13
59 #define TOKEN_OBRACKET 14
60 #define TOKEN_CBRACKET 15
61 #define TOKEN_OANGLE 16
62 #define TOKEN_CANGLE 17
64 #define TOKEN_COMMA 19
65 #define TOKEN_SEMICOLON 20
66 #define TOKEN_TEMPLATE 31
68 #define TOKEN_DWORD 41
69 #define TOKEN_FLOAT 42
70 #define TOKEN_DOUBLE 43
72 #define TOKEN_UCHAR 45
73 #define TOKEN_SWORD 46
74 #define TOKEN_SDWORD 47
76 #define TOKEN_LPSTR 49
77 #define TOKEN_UNICODE 50
78 #define TOKEN_CSTRING 51
79 #define TOKEN_ARRAY 52
81 #define CLSIDFMT "<%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X>"
83 #define MAX_INPUT_SIZE 2000000
84 #define MAX_DATA_SIZE 400000
86 static const struct IDirectXFileVtbl IDirectXFile_Vtbl;
87 static const struct IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl;
88 static const struct IDirectXFileDataVtbl IDirectXFileData_Vtbl;
89 static const struct IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl;
90 static const struct IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl;
91 static const struct IDirectXFileObjectVtbl IDirectXFileObject_Vtbl;
92 static const struct IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl;
94 static BOOL parse_object_parts(parse_buffer * buf, BOOL allow_optional);
95 static BOOL parse_object(parse_buffer * buf);
96 static const char* get_primitive_string(WORD token);
97 static WORD check_TOKEN(parse_buffer * buf);
98 static BOOL parse_template(parse_buffer * buf);
99 static HRESULT IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImpl** ppObj);
100 static HRESULT IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl** ppObj);
101 static HRESULT IDirectXFileSaveObjectImpl_Create(IDirectXFileSaveObjectImpl** ppObj);
103 static void dump_template(xtemplate* templates_array, xtemplate* ptemplate)
108 clsid = &ptemplate->class_id;
110 DPRINTF("template %s\n", ptemplate->name);
112 DPRINTF(CLSIDFMT "\n", clsid->Data1, clsid->Data2, clsid->Data3, clsid->Data4[0],
113 clsid->Data4[1], clsid->Data4[2], clsid->Data4[3], clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7]);
114 for (j = 0; j < ptemplate->nb_members; j++)
116 if (ptemplate->members[j].nb_dims)
118 if (ptemplate->members[j].type == TOKEN_NAME)
119 DPRINTF("%s ", templates_array[ptemplate->members[j].idx_template].name);
121 DPRINTF("%s ", get_primitive_string(ptemplate->members[j].type));
122 DPRINTF("%s", ptemplate->members[j].name);
123 for (k = 0; k < ptemplate->members[j].nb_dims; k++)
125 if (ptemplate->members[j].dim_fixed[k])
126 DPRINTF("[%d]", ptemplate->members[j].dim_value[k]);
128 DPRINTF("[%s]", ptemplate->members[ptemplate->members[j].dim_value[k]].name);
134 else if (ptemplate->nb_childs)
136 DPRINTF("[%s", ptemplate->childs[0]);
137 for (j = 1; j < ptemplate->nb_childs; j++)
138 DPRINTF(",%s", ptemplate->childs[j]);
144 HRESULT IDirectXFileImpl_Create(IUnknown* pUnkOuter, LPVOID* ppObj)
146 IDirectXFileImpl* object;
148 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
150 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileImpl));
153 ERR("Out of memory\n");
154 return DXFILEERR_BADALLOC;
157 object->lpVtbl.lpVtbl = &IDirectXFile_Vtbl;
165 /*** IUnknown methods ***/
166 static HRESULT WINAPI IDirectXFileImpl_QueryInterface(IDirectXFile* iface, REFIID riid, void** ppvObject)
168 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
170 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
172 if (IsEqualGUID(riid, &IID_IUnknown)
173 || IsEqualGUID(riid, &IID_IDirectXFile))
175 IClassFactory_AddRef(iface);
180 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
181 return E_NOINTERFACE;
184 static ULONG WINAPI IDirectXFileImpl_AddRef(IDirectXFile* iface)
186 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
187 ULONG ref = InterlockedIncrement(&This->ref);
189 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
194 static ULONG WINAPI IDirectXFileImpl_Release(IDirectXFile* iface)
196 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
197 ULONG ref = InterlockedDecrement(&This->ref);
199 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
202 HeapFree(GetProcessHeap(), 0, This);
207 /*** IDirectXFile methods ***/
208 static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPVOID pvSource, DXFILELOADOPTIONS dwLoadOptions, LPDIRECTXFILEENUMOBJECT* ppEnumObj)
210 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
211 IDirectXFileEnumObjectImpl* object;
215 HANDLE hFile = INVALID_HANDLE_VALUE;
216 LPDXFILELOADMEMORY lpdxflm = NULL;
218 TRACE("(%p/%p)->(%p,%x,%p)\n", This, iface, pvSource, dwLoadOptions, ppEnumObj);
221 return DXFILEERR_BADVALUE;
223 if (dwLoadOptions == DXFILELOAD_FROMFILE)
225 TRACE("Open source file '%s'\n", (char*)pvSource);
227 hFile = CreateFileA((char*)pvSource, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
228 if (hFile == INVALID_HANDLE_VALUE)
230 TRACE("File '%s' not found\n", (char*)pvSource);
231 return DXFILEERR_FILENOTFOUND;
234 if (!ReadFile(hFile, header, 16, &size, NULL))
236 hr = DXFILEERR_BADVALUE;
242 hr = DXFILEERR_BADFILETYPE;
246 else if (dwLoadOptions == DXFILELOAD_FROMMEMORY)
248 lpdxflm = (LPDXFILELOADMEMORY)pvSource;
250 TRACE("Source in memory at %p with size %d\n", lpdxflm->lpMemory, lpdxflm->dSize);
252 memcpy(header, (char*)lpdxflm->lpMemory, 16);
256 FIXME("Source type %d is not handled yet\n", dwLoadOptions);
257 hr = DXFILEERR_NOTDONEYET;
261 if (TRACE_ON(d3dxof))
264 memcpy(string, header, 16);
266 TRACE("header = '%s'\n", string);
269 if (header[0] != XOFFILE_FORMAT_MAGIC)
271 hr = DXFILEERR_BADFILETYPE;
275 if ((header[1] != XOFFILE_FORMAT_VERSION_302) && (header[1] != XOFFILE_FORMAT_VERSION_303))
277 hr = DXFILEERR_BADFILEVERSION;
281 if ((header[2] != XOFFILE_FORMAT_BINARY) && (header[2] != XOFFILE_FORMAT_TEXT) && (header[2] != XOFFILE_FORMAT_COMPRESSED))
283 hr = DXFILEERR_BADFILETYPE;
287 if (header[2] == XOFFILE_FORMAT_COMPRESSED)
289 FIXME("Compressed formats not supported yet\n");
290 hr = DXFILEERR_BADVALUE;
294 if ((header[3] != XOFFILE_FORMAT_FLOAT_BITS_32) && (header[3] != XOFFILE_FORMAT_FLOAT_BITS_64))
296 hr = DXFILEERR_BADFILEFLOATSIZE;
300 TRACE("Header is correct\n");
302 hr = IDirectXFileEnumObjectImpl_Create(&object);
306 object->source = dwLoadOptions;
307 object->hFile = hFile;
308 object->pDirectXFile = This;
309 object->buf.pdxf = This;
310 object->buf.txt = (header[2] == XOFFILE_FORMAT_TEXT);
311 object->buf.token_present = FALSE;
312 object->buf.cur_subobject = 0;
314 if (dwLoadOptions == DXFILELOAD_FROMFILE)
316 object->buf.buffer = HeapAlloc(GetProcessHeap(), 0, MAX_INPUT_SIZE+1);
317 if (!object->buf.buffer)
319 ERR("Out of memory\n");
320 hr = DXFILEERR_BADALLOC;
324 ReadFile(hFile, object->buf.buffer, MAX_INPUT_SIZE+1, &object->buf.rem_bytes, NULL);
325 if (object->buf.rem_bytes > MAX_INPUT_SIZE)
327 FIXME("File size > %d not supported yet\n", MAX_INPUT_SIZE);
328 HeapFree(GetProcessHeap(), 0, object->buf.buffer);
329 hr = DXFILEERR_PARSEERROR;
335 object->buf.buffer = ((LPBYTE)lpdxflm->lpMemory) + 16;
336 object->buf.rem_bytes = lpdxflm->dSize;
339 TRACE("Read %d bytes\n", object->buf.rem_bytes);
341 *ppEnumObj = (LPDIRECTXFILEENUMOBJECT)object;
343 while (object->buf.rem_bytes && (check_TOKEN(&object->buf) == TOKEN_TEMPLATE))
345 if (!parse_template(&object->buf))
347 TRACE("Template is not correct\n");
348 hr = DXFILEERR_BADVALUE;
353 TRACE("Template successfully parsed:\n");
354 if (TRACE_ON(d3dxof))
355 dump_template(This->xtemplates, &This->xtemplates[This->nb_xtemplates - 1]);
359 if (TRACE_ON(d3dxof))
362 TRACE("Registered templates (%d):\n", This->nb_xtemplates);
363 for (i = 0; i < This->nb_xtemplates; i++)
364 DPRINTF("%s - %s\n", This->xtemplates[i].name, debugstr_guid(&This->xtemplates[i].class_id));
370 if (hFile != INVALID_HANDLE_VALUE)
377 static HRESULT WINAPI IDirectXFileImpl_CreateSaveObject(IDirectXFile* iface, LPCSTR szFileName, DXFILEFORMAT dwFileFormat, LPDIRECTXFILESAVEOBJECT* ppSaveObj)
379 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
381 FIXME("(%p/%p)->(%s,%x,%p) partial stub!\n", This, iface, szFileName, dwFileFormat, ppSaveObj);
383 if (!szFileName || !ppSaveObj)
386 return IDirectXFileSaveObjectImpl_Create((IDirectXFileSaveObjectImpl**)ppSaveObj);
389 static BOOL read_bytes(parse_buffer * buf, LPVOID data, DWORD size)
391 if (buf->rem_bytes < size)
393 memcpy(data, buf->buffer, size);
395 buf->rem_bytes -= size;
399 static void dump_TOKEN(WORD token)
401 #define DUMP_TOKEN(t) case t: TRACE(#t "\n"); break
404 DUMP_TOKEN(TOKEN_NAME);
405 DUMP_TOKEN(TOKEN_STRING);
406 DUMP_TOKEN(TOKEN_INTEGER);
407 DUMP_TOKEN(TOKEN_GUID);
408 DUMP_TOKEN(TOKEN_INTEGER_LIST);
409 DUMP_TOKEN(TOKEN_FLOAT_LIST);
410 DUMP_TOKEN(TOKEN_OBRACE);
411 DUMP_TOKEN(TOKEN_CBRACE);
412 DUMP_TOKEN(TOKEN_OPAREN);
413 DUMP_TOKEN(TOKEN_CPAREN);
414 DUMP_TOKEN(TOKEN_OBRACKET);
415 DUMP_TOKEN(TOKEN_CBRACKET);
416 DUMP_TOKEN(TOKEN_OANGLE);
417 DUMP_TOKEN(TOKEN_CANGLE);
418 DUMP_TOKEN(TOKEN_DOT);
419 DUMP_TOKEN(TOKEN_COMMA);
420 DUMP_TOKEN(TOKEN_SEMICOLON);
421 DUMP_TOKEN(TOKEN_TEMPLATE);
422 DUMP_TOKEN(TOKEN_WORD);
423 DUMP_TOKEN(TOKEN_DWORD);
424 DUMP_TOKEN(TOKEN_FLOAT);
425 DUMP_TOKEN(TOKEN_DOUBLE);
426 DUMP_TOKEN(TOKEN_CHAR);
427 DUMP_TOKEN(TOKEN_UCHAR);
428 DUMP_TOKEN(TOKEN_SWORD);
429 DUMP_TOKEN(TOKEN_SDWORD);
430 DUMP_TOKEN(TOKEN_VOID);
431 DUMP_TOKEN(TOKEN_LPSTR);
432 DUMP_TOKEN(TOKEN_UNICODE);
433 DUMP_TOKEN(TOKEN_CSTRING);
434 DUMP_TOKEN(TOKEN_ARRAY);
437 TRACE("Unknown token %d\n", token);
443 static BOOL is_space(char c)
457 static BOOL is_operator(char c)
476 static inline BOOL is_separator(char c)
478 return is_space(c) || is_operator(c);
481 static WORD get_operator_token(char c)
490 return TOKEN_OBRACKET;
492 return TOKEN_CBRACKET;
504 return TOKEN_SEMICOLON;
509 static BOOL is_keyword(parse_buffer* buf, const char* keyword)
511 DWORD len = strlen(keyword);
512 if (!strncasecmp((char*)buf->buffer, keyword,len) && is_separator(*(buf->buffer+len)))
515 buf->rem_bytes -= len;
521 static WORD get_keyword_token(parse_buffer* buf)
523 if (is_keyword(buf, "template"))
524 return TOKEN_TEMPLATE;
525 if (is_keyword(buf, "WORD"))
527 if (is_keyword(buf, "DWORD"))
529 if (is_keyword(buf, "FLOAT"))
531 if (is_keyword(buf, "DOUBLE"))
533 if (is_keyword(buf, "CHAR"))
535 if (is_keyword(buf, "UCHAR"))
537 if (is_keyword(buf, "SWORD"))
539 if (is_keyword(buf, "SDWORD"))
541 if (is_keyword(buf, "VOID"))
543 if (is_keyword(buf, "STRING"))
545 if (is_keyword(buf, "UNICODE"))
546 return TOKEN_UNICODE;
547 if (is_keyword(buf, "CSTRING"))
548 return TOKEN_CSTRING;
549 if (is_keyword(buf, "array"))
555 static BOOL is_guid(parse_buffer* buf)
563 if (*buf->buffer != '<')
566 while (*(buf->buffer+pos) != '>')
568 tmp[pos] = *(buf->buffer+pos);
573 if (pos != 38 /* <+36+> */)
575 TRACE("Wrong guid %s (%d)\n", tmp, pos);
579 buf->rem_bytes -= pos;
581 ret = sscanf(tmp, CLSIDFMT, &class_id.Data1, tab, tab+1, tab+2, tab+3, tab+4, tab+5, tab+6, tab+7, tab+8, tab+9);
584 TRACE("Wrong guid %s (%d)\n", tmp, pos);
587 TRACE("Found guid %s (%d)\n", tmp, pos);
589 class_id.Data2 = tab[0];
590 class_id.Data3 = tab[1];
591 class_id.Data4[0] = tab[2];
592 class_id.Data4[1] = tab[3];
593 class_id.Data4[2] = tab[4];
594 class_id.Data4[3] = tab[5];
595 class_id.Data4[4] = tab[6];
596 class_id.Data4[5] = tab[7];
597 class_id.Data4[6] = tab[8];
598 class_id.Data4[7] = tab[9];
600 *(GUID*)buf->value = class_id;
605 static BOOL is_name(parse_buffer* buf)
611 while (!is_separator(c = *(buf->buffer+pos)))
613 if (!(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9')) || (c == '_') || (c == '-')))
621 TRACE("Wrong name %s\n", tmp);
626 buf->rem_bytes -= pos;
628 TRACE("Found name %s\n", tmp);
629 strcpy((char*)buf->value, tmp);
634 static BOOL is_float(parse_buffer* buf)
642 while (!is_separator(c = *(buf->buffer+pos)))
644 if (!((!pos && (c == '-')) || ((c >= '0') && (c <= '9')) || (!dot && (c == '.'))))
653 buf->rem_bytes -= pos;
655 sscanf(tmp, "%f", &decimal);
657 TRACE("Found float %s - %f\n", tmp, decimal);
659 *(float*)buf->value = decimal;
664 static BOOL is_integer(parse_buffer* buf)
671 while (!is_separator(c = *(buf->buffer+pos)))
673 if (!((c >= '0') && (c <= '9')))
680 buf->rem_bytes -= pos;
682 sscanf(tmp, "%d", &integer);
684 TRACE("Found integer %s - %d\n", tmp, integer);
686 *(DWORD*)buf->value = integer;
691 static BOOL is_string(parse_buffer* buf)
698 if (*buf->buffer != '"')
701 while (!is_separator(c = *(buf->buffer+pos+1)) && (pos < 31))
714 TRACE("Wrong string %s\n", tmp);
718 buf->buffer += pos + 2;
719 buf->rem_bytes -= pos + 2;
721 TRACE("Found string %s\n", tmp);
722 strcpy((char*)buf->value, tmp);
727 static WORD parse_TOKEN(parse_buffer * buf)
736 if (!read_bytes(buf, &c, 1))
738 /*TRACE("char = '%c'\n", is_space(c) ? ' ' : c);*/
739 if ((c == '#') || (c == '/'))
741 /* Handle comment (# or //) */
744 if (!read_bytes(buf, &c, 1))
752 if (!read_bytes(buf, &c, 1))
759 if (is_operator(c) && (c != '<'))
761 token = get_operator_token(c);
774 if ((token = get_keyword_token(buf)))
784 token = TOKEN_INTEGER;
803 FIXME("Unrecognize element\n");
815 if (!read_bytes(buf, &token, 2))
818 /* Convert integer and float list into separate elements */
819 if (token == TOKEN_INTEGER_LIST)
821 if (!read_bytes(buf, &nb_elem, 4))
823 token = TOKEN_INTEGER;
825 TRACE("Integer list (TOKEN_INTEGER_LIST) of size %d\n", nb_elem);
827 else if (token == TOKEN_FLOAT_LIST)
829 if (!read_bytes(buf, &nb_elem, 4))
833 TRACE("Float list (TOKEN_FLOAT_LIST) of size %d\n", nb_elem);
839 token = is_float ? TOKEN_FLOAT : TOKEN_INTEGER;
844 if (!read_bytes(buf, &integer, 4))
847 *(DWORD*)buf->value = integer;
860 if (!read_bytes(buf, &count, 4))
862 if (!read_bytes(buf, strname, count))
865 /*TRACE("name = %s\n", strname);*/
867 strcpy((char*)buf->value, strname);
874 if (!read_bytes(buf, &integer, 4))
876 /*TRACE("integer = %ld\n", integer);*/
878 *(DWORD*)buf->value = integer;
886 if (!read_bytes(buf, &class_id, 16))
888 sprintf(strguid, CLSIDFMT, class_id.Data1, class_id.Data2, class_id.Data3, class_id.Data4[0],
889 class_id.Data4[1], class_id.Data4[2], class_id.Data4[3], class_id.Data4[4], class_id.Data4[5],
890 class_id.Data4[6], class_id.Data4[7]);
891 /*TRACE("guid = {%s}\n", strguid);*/
893 *(GUID*)buf->value = class_id;
901 if (!read_bytes(buf, &count, 4))
903 if (!read_bytes(buf, strname, count))
906 if (!read_bytes(buf, &tmp_token, 2))
908 if ((tmp_token != TOKEN_COMMA) && (tmp_token != TOKEN_SEMICOLON))
909 ERR("No comma or semicolon (got %d)\n", tmp_token);
910 /*TRACE("name = %s\n", strname);*/
912 strcpy((char*)buf->value, strname);
926 case TOKEN_SEMICOLON:
952 static const char* get_primitive_string(WORD token)
986 static WORD get_TOKEN(parse_buffer * buf)
988 if (buf->token_present)
990 buf->token_present = FALSE;
991 return buf->current_token;
994 buf->current_token = parse_TOKEN(buf);
996 return buf->current_token;
999 static WORD check_TOKEN(parse_buffer * buf)
1001 if (buf->token_present)
1002 return buf->current_token;
1004 buf->current_token = parse_TOKEN(buf);
1005 buf->token_present = TRUE;
1007 return buf->current_token;
1010 static inline BOOL is_primitive_type(WORD token)
1035 static BOOL parse_template_option_info(parse_buffer * buf)
1037 xtemplate* cur_template = &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates];
1039 if (check_TOKEN(buf) == TOKEN_DOT)
1042 if (get_TOKEN(buf) != TOKEN_DOT)
1044 if (get_TOKEN(buf) != TOKEN_DOT)
1046 cur_template->open = TRUE;
1052 if (get_TOKEN(buf) != TOKEN_NAME)
1054 strcpy(cur_template->childs[cur_template->nb_childs], (char*)buf->value);
1055 if (check_TOKEN(buf) == TOKEN_GUID)
1057 cur_template->nb_childs++;
1058 if (check_TOKEN(buf) != TOKEN_COMMA)
1062 cur_template->open = FALSE;
1068 static BOOL parse_template_members_list(parse_buffer * buf)
1077 cur_member = &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[idx_member];
1079 if (check_TOKEN(buf) == TOKEN_ARRAY)
1085 if (check_TOKEN(buf) == TOKEN_NAME)
1087 cur_member->type = get_TOKEN(buf);
1088 cur_member->idx_template = 0;
1089 while (cur_member->idx_template < buf->pdxf->nb_xtemplates)
1091 if (!strcmp((char*)buf->value, buf->pdxf->xtemplates[cur_member->idx_template].name))
1093 cur_member->idx_template++;
1095 if (cur_member->idx_template == buf->pdxf->nb_xtemplates)
1097 TRACE("Reference to a nonexistent template '%s'\n", (char*)buf->value);
1101 else if (is_primitive_type(check_TOKEN(buf)))
1102 cur_member->type = get_TOKEN(buf);
1106 if (get_TOKEN(buf) != TOKEN_NAME)
1108 strcpy(cur_member->name, (char*)buf->value);
1112 while (check_TOKEN(buf) == TOKEN_OBRACKET)
1114 if (nb_dims >= MAX_ARRAY_DIM)
1116 FIXME("Too many dimensions (%d) for multi-dimensional array\n", nb_dims + 1);
1120 if (check_TOKEN(buf) == TOKEN_INTEGER)
1123 cur_member->dim_fixed[nb_dims] = TRUE;
1124 cur_member->dim_value[nb_dims] = *(DWORD*)buf->value;
1129 if (get_TOKEN(buf) != TOKEN_NAME)
1131 for (i = 0; i < idx_member; i++)
1133 if (!strcmp((char*)buf->value, buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[i].name))
1135 if (buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[i].nb_dims)
1137 ERR("Array cannot be used to specify variable array size\n");
1140 if (buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[i].type != TOKEN_DWORD)
1142 FIXME("Only DWORD supported to specify variable array size\n");
1148 if (i == idx_member)
1150 ERR("Reference to unknown member %s\n", (char*)buf->value);
1153 cur_member->dim_fixed[nb_dims] = FALSE;
1154 cur_member->dim_value[nb_dims] = i;
1156 if (get_TOKEN(buf) != TOKEN_CBRACKET)
1162 cur_member->nb_dims = nb_dims;
1164 if (get_TOKEN(buf) != TOKEN_SEMICOLON)
1170 buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].nb_members = idx_member;
1175 static BOOL parse_template_parts(parse_buffer * buf)
1177 if (!parse_template_members_list(buf))
1179 if (check_TOKEN(buf) == TOKEN_OBRACKET)
1182 if (!parse_template_option_info(buf))
1184 if (get_TOKEN(buf) != TOKEN_CBRACKET)
1191 static void go_to_next_definition(parse_buffer * buf)
1193 while (buf->rem_bytes)
1195 char c = *buf->buffer;
1196 if ((c == '#') || (c == '/'))
1198 read_bytes(buf, &c, 1);
1199 /* Handle comment (# or //) */
1202 if (!read_bytes(buf, &c, 1))
1210 if (!read_bytes(buf, &c, 1))
1215 else if (is_space(*buf->buffer))
1225 static BOOL parse_template(parse_buffer * buf)
1227 if (get_TOKEN(buf) != TOKEN_TEMPLATE)
1229 if (get_TOKEN(buf) != TOKEN_NAME)
1231 strcpy(buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].name, (char*)buf->value);
1232 if (get_TOKEN(buf) != TOKEN_OBRACE)
1234 if (get_TOKEN(buf) != TOKEN_GUID)
1236 buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].class_id = *(GUID*)buf->value;
1237 if (!parse_template_parts(buf))
1239 if (get_TOKEN(buf) != TOKEN_CBRACE)
1243 /* Go to the next template */
1244 go_to_next_definition(buf);
1247 TRACE("%d - %s - %s\n", buf->pdxf->nb_xtemplates, buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].name, debugstr_guid(&buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].class_id));
1248 buf->pdxf->nb_xtemplates++;
1253 static HRESULT WINAPI IDirectXFileImpl_RegisterTemplates(IDirectXFile* iface, LPVOID pvData, DWORD cbSize)
1255 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
1259 buf.buffer = (LPBYTE)pvData;
1260 buf.rem_bytes = cbSize;
1262 buf.token_present = FALSE;
1265 TRACE("(%p/%p)->(%p,%d)\n", This, iface, pvData, cbSize);
1268 return DXFILEERR_BADVALUE;
1271 return DXFILEERR_BADFILETYPE;
1273 if (TRACE_ON(d3dxof))
1276 memcpy(string, pvData, 16);
1278 TRACE("header = '%s'\n", string);
1281 read_bytes(&buf, &token_header, 4);
1283 if (token_header != XOFFILE_FORMAT_MAGIC)
1284 return DXFILEERR_BADFILETYPE;
1286 read_bytes(&buf, &token_header, 4);
1288 if ((token_header != XOFFILE_FORMAT_VERSION_302) && (token_header != XOFFILE_FORMAT_VERSION_303))
1289 return DXFILEERR_BADFILEVERSION;
1291 read_bytes(&buf, &token_header, 4);
1293 if ((token_header != XOFFILE_FORMAT_BINARY) && (token_header != XOFFILE_FORMAT_TEXT) && (token_header != XOFFILE_FORMAT_COMPRESSED))
1294 return DXFILEERR_BADFILETYPE;
1296 if (token_header == XOFFILE_FORMAT_TEXT)
1301 if (token_header == XOFFILE_FORMAT_COMPRESSED)
1303 FIXME("Compressed formats not supported yet\n");
1304 return DXFILEERR_BADVALUE;
1307 read_bytes(&buf, &token_header, 4);
1309 if ((token_header != XOFFILE_FORMAT_FLOAT_BITS_32) && (token_header != XOFFILE_FORMAT_FLOAT_BITS_64))
1310 return DXFILEERR_BADFILEFLOATSIZE;
1312 TRACE("Header is correct\n");
1314 while (buf.rem_bytes)
1316 if (!parse_template(&buf))
1318 TRACE("Template is not correct\n");
1319 return DXFILEERR_BADVALUE;
1323 TRACE("Template successfully parsed:\n");
1324 if (TRACE_ON(d3dxof))
1325 dump_template(This->xtemplates, &This->xtemplates[This->nb_xtemplates - 1]);
1329 if (TRACE_ON(d3dxof))
1332 TRACE("Registered templates (%d):\n", This->nb_xtemplates);
1333 for (i = 0; i < This->nb_xtemplates; i++)
1334 DPRINTF("%s - %s\n", This->xtemplates[i].name, debugstr_guid(&This->xtemplates[i].class_id));
1340 static const IDirectXFileVtbl IDirectXFile_Vtbl =
1342 IDirectXFileImpl_QueryInterface,
1343 IDirectXFileImpl_AddRef,
1344 IDirectXFileImpl_Release,
1345 IDirectXFileImpl_CreateEnumObject,
1346 IDirectXFileImpl_CreateSaveObject,
1347 IDirectXFileImpl_RegisterTemplates
1350 static HRESULT IDirectXFileBinaryImpl_Create(IDirectXFileBinaryImpl** ppObj)
1352 IDirectXFileBinaryImpl* object;
1354 TRACE("(%p)\n", ppObj);
1356 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileBinaryImpl));
1359 ERR("Out of memory\n");
1360 return DXFILEERR_BADALLOC;
1363 object->lpVtbl.lpVtbl = &IDirectXFileBinary_Vtbl;
1371 /*** IUnknown methods ***/
1372 static HRESULT WINAPI IDirectXFileBinaryImpl_QueryInterface(IDirectXFileBinary* iface, REFIID riid, void** ppvObject)
1374 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1376 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1378 if (IsEqualGUID(riid, &IID_IUnknown)
1379 || IsEqualGUID(riid, &IID_IDirectXFileObject)
1380 || IsEqualGUID(riid, &IID_IDirectXFileBinary))
1382 IClassFactory_AddRef(iface);
1387 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
1388 if (!IsEqualGUID(riid, &IID_IDirectXFileData)
1389 && !IsEqualGUID(riid, &IID_IDirectXFileDataReference))
1390 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1392 return E_NOINTERFACE;
1395 static ULONG WINAPI IDirectXFileBinaryImpl_AddRef(IDirectXFileBinary* iface)
1397 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1398 ULONG ref = InterlockedIncrement(&This->ref);
1400 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1405 static ULONG WINAPI IDirectXFileBinaryImpl_Release(IDirectXFileBinary* iface)
1407 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1408 ULONG ref = InterlockedDecrement(&This->ref);
1410 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1413 HeapFree(GetProcessHeap(), 0, This);
1418 /*** IDirectXFileObject methods ***/
1419 static HRESULT WINAPI IDirectXFileBinaryImpl_GetName(IDirectXFileBinary* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
1422 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1424 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pstrNameBuf, pdwBufLen);
1426 return DXFILEERR_BADVALUE;
1429 static HRESULT WINAPI IDirectXFileBinaryImpl_GetId(IDirectXFileBinary* iface, LPGUID pGuid)
1431 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1433 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pGuid);
1435 return DXFILEERR_BADVALUE;
1438 /*** IDirectXFileBinary methods ***/
1439 static HRESULT WINAPI IDirectXFileBinaryImpl_GetSize(IDirectXFileBinary* iface, DWORD* pcbSize)
1441 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1443 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pcbSize);
1445 return DXFILEERR_BADVALUE;
1448 static HRESULT WINAPI IDirectXFileBinaryImpl_GetMimeType(IDirectXFileBinary* iface, LPCSTR* pszMimeType)
1450 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1452 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pszMimeType);
1454 return DXFILEERR_BADVALUE;
1457 static HRESULT WINAPI IDirectXFileBinaryImpl_Read(IDirectXFileBinary* iface, LPVOID pvData, DWORD cbSize, LPDWORD pcbRead)
1459 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1461 FIXME("(%p/%p)->(%p, %d, %p) stub!\n", This, iface, pvData, cbSize, pcbRead);
1463 return DXFILEERR_BADVALUE;
1466 static const IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl =
1468 IDirectXFileBinaryImpl_QueryInterface,
1469 IDirectXFileBinaryImpl_AddRef,
1470 IDirectXFileBinaryImpl_Release,
1471 IDirectXFileBinaryImpl_GetName,
1472 IDirectXFileBinaryImpl_GetId,
1473 IDirectXFileBinaryImpl_GetSize,
1474 IDirectXFileBinaryImpl_GetMimeType,
1475 IDirectXFileBinaryImpl_Read
1478 static HRESULT IDirectXFileDataImpl_Create(IDirectXFileDataImpl** ppObj)
1480 IDirectXFileDataImpl* object;
1482 TRACE("(%p)\n", ppObj);
1484 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileDataImpl));
1487 ERR("Out of memory\n");
1488 return DXFILEERR_BADALLOC;
1491 object->lpVtbl.lpVtbl = &IDirectXFileData_Vtbl;
1499 /*** IUnknown methods ***/
1500 static HRESULT WINAPI IDirectXFileDataImpl_QueryInterface(IDirectXFileData* iface, REFIID riid, void** ppvObject)
1502 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1504 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1506 if (IsEqualGUID(riid, &IID_IUnknown)
1507 || IsEqualGUID(riid, &IID_IDirectXFileObject)
1508 || IsEqualGUID(riid, &IID_IDirectXFileData))
1510 IClassFactory_AddRef(iface);
1515 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
1516 if (!IsEqualGUID(riid, &IID_IDirectXFileBinary)
1517 && !IsEqualGUID(riid, &IID_IDirectXFileDataReference))
1518 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1520 return E_NOINTERFACE;
1523 static ULONG WINAPI IDirectXFileDataImpl_AddRef(IDirectXFileData* iface)
1525 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1526 ULONG ref = InterlockedIncrement(&This->ref);
1528 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1533 static ULONG WINAPI IDirectXFileDataImpl_Release(IDirectXFileData* iface)
1535 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1536 ULONG ref = InterlockedDecrement(&This->ref);
1538 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1541 HeapFree(GetProcessHeap(), 0, This);
1546 /*** IDirectXFileObject methods ***/
1547 static HRESULT WINAPI IDirectXFileDataImpl_GetName(IDirectXFileData* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
1550 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1552 TRACE("(%p/%p)->(%p,%p)\n", This, iface, pstrNameBuf, pdwBufLen);
1555 return DXFILEERR_BADVALUE;
1557 strcpy(pstrNameBuf, This->pobj->name);
1562 static HRESULT WINAPI IDirectXFileDataImpl_GetId(IDirectXFileData* iface, LPGUID pGuid)
1564 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1566 TRACE("(%p/%p)->(%p)\n", This, iface, pGuid);
1569 return DXFILEERR_BADVALUE;
1571 memcpy(pGuid, &This->pobj->class_id, 16);
1576 /*** IDirectXFileData methods ***/
1577 static HRESULT WINAPI IDirectXFileDataImpl_GetData(IDirectXFileData* iface, LPCSTR szMember, DWORD* pcbSize, void** ppvData)
1579 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1581 TRACE("(%p/%p)->(%s,%p,%p)\n", This, iface, szMember, pcbSize, ppvData);
1583 if (!pcbSize || !ppvData)
1584 return DXFILEERR_BADVALUE;
1588 FIXME("Specifying a member is not supported yet!\n");
1589 return DXFILEERR_BADVALUE;
1592 *pcbSize = This->pobj->size;
1593 *ppvData = This->pobj->pdata;
1598 static HRESULT WINAPI IDirectXFileDataImpl_GetType(IDirectXFileData* iface, const GUID** pguid)
1600 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1603 TRACE("(%p/%p)->(%p)\n", This, iface, pguid);
1606 return DXFILEERR_BADVALUE;
1608 memcpy(&guid, &This->pobj->type, 16);
1614 static HRESULT WINAPI IDirectXFileDataImpl_GetNextObject(IDirectXFileData* iface, LPDIRECTXFILEOBJECT* ppChildObj)
1617 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1619 TRACE("(%p/%p)->(%p)\n", This, iface, ppChildObj);
1621 if (This->cur_enum_object >= This->pobj->nb_childs)
1622 return DXFILEERR_NOMOREOBJECTS;
1624 if (This->from_ref && (This->level >= 1))
1626 /* Only 2 levels can enumerated if the object is obtained from a reference */
1627 return DXFILEERR_NOMOREOBJECTS;
1630 if (This->pobj->childs[This->cur_enum_object]->binary)
1632 IDirectXFileBinaryImpl *object;
1634 hr = IDirectXFileBinaryImpl_Create(&object);
1638 *ppChildObj = (LPDIRECTXFILEOBJECT)object;
1640 else if (This->pobj->childs[This->cur_enum_object]->ptarget)
1642 IDirectXFileDataReferenceImpl *object;
1644 hr = IDirectXFileDataReferenceImpl_Create(&object);
1648 object->ptarget = This->pobj->childs[This->cur_enum_object++]->ptarget;
1650 *ppChildObj = (LPDIRECTXFILEOBJECT)object;
1654 IDirectXFileDataImpl *object;
1656 hr = IDirectXFileDataImpl_Create(&object);
1660 object->pobj = This->pobj->childs[This->cur_enum_object++];
1661 object->cur_enum_object = 0;
1662 object->from_ref = This->from_ref;
1663 object->level = This->level + 1;
1665 *ppChildObj = (LPDIRECTXFILEOBJECT)object;
1671 static HRESULT WINAPI IDirectXFileDataImpl_AddDataObject(IDirectXFileData* iface, LPDIRECTXFILEDATA pDataObj)
1673 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1675 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDataObj);
1677 return DXFILEERR_BADVALUE;
1680 static HRESULT WINAPI IDirectXFileDataImpl_AddDataReference(IDirectXFileData* iface, LPCSTR szRef, const GUID* pguidRef)
1682 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1684 FIXME("(%p/%p)->(%s,%p) stub!\n", This, iface, szRef, pguidRef);
1686 return DXFILEERR_BADVALUE;
1689 static HRESULT WINAPI IDirectXFileDataImpl_AddBinaryObject(IDirectXFileData* iface, LPCSTR szName, const GUID* pguid, LPCSTR szMimeType, LPVOID pvData, DWORD cbSize)
1691 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1693 FIXME("(%p/%p)->(%s,%p,%s,%p,%d) stub!\n", This, iface, szName, pguid, szMimeType, pvData, cbSize);
1695 return DXFILEERR_BADVALUE;
1698 static const IDirectXFileDataVtbl IDirectXFileData_Vtbl =
1700 IDirectXFileDataImpl_QueryInterface,
1701 IDirectXFileDataImpl_AddRef,
1702 IDirectXFileDataImpl_Release,
1703 IDirectXFileDataImpl_GetName,
1704 IDirectXFileDataImpl_GetId,
1705 IDirectXFileDataImpl_GetData,
1706 IDirectXFileDataImpl_GetType,
1707 IDirectXFileDataImpl_GetNextObject,
1708 IDirectXFileDataImpl_AddDataObject,
1709 IDirectXFileDataImpl_AddDataReference,
1710 IDirectXFileDataImpl_AddBinaryObject
1713 static HRESULT IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImpl** ppObj)
1715 IDirectXFileDataReferenceImpl* object;
1717 TRACE("(%p)\n", ppObj);
1719 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileDataReferenceImpl));
1722 ERR("Out of memory\n");
1723 return DXFILEERR_BADALLOC;
1726 object->lpVtbl.lpVtbl = &IDirectXFileDataReference_Vtbl;
1734 /*** IUnknown methods ***/
1735 static HRESULT WINAPI IDirectXFileDataReferenceImpl_QueryInterface(IDirectXFileDataReference* iface, REFIID riid, void** ppvObject)
1737 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1739 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1741 if (IsEqualGUID(riid, &IID_IUnknown)
1742 || IsEqualGUID(riid, &IID_IDirectXFileObject)
1743 || IsEqualGUID(riid, &IID_IDirectXFileDataReference))
1745 IClassFactory_AddRef(iface);
1750 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
1751 if (!IsEqualGUID(riid, &IID_IDirectXFileData)
1752 && !IsEqualGUID(riid, &IID_IDirectXFileBinary))
1753 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1755 return E_NOINTERFACE;
1758 static ULONG WINAPI IDirectXFileDataReferenceImpl_AddRef(IDirectXFileDataReference* iface)
1760 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1761 ULONG ref = InterlockedIncrement(&This->ref);
1763 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1768 static ULONG WINAPI IDirectXFileDataReferenceImpl_Release(IDirectXFileDataReference* iface)
1770 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1771 ULONG ref = InterlockedDecrement(&This->ref);
1773 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1776 HeapFree(GetProcessHeap(), 0, This);
1781 /*** IDirectXFileObject methods ***/
1782 static HRESULT WINAPI IDirectXFileDataReferenceImpl_GetName(IDirectXFileDataReference* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
1784 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1786 TRACE("(%p/%p)->(%p,%p)\n", This, iface, pstrNameBuf, pdwBufLen);
1789 return DXFILEERR_BADVALUE;
1791 strcpy(pstrNameBuf, This->ptarget->name);
1793 return DXFILEERR_BADVALUE;
1796 static HRESULT WINAPI IDirectXFileDataReferenceImpl_GetId(IDirectXFileDataReference* iface, LPGUID pGuid)
1798 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1800 TRACE("(%p/%p)->(%p)\n", This, iface, pGuid);
1803 return DXFILEERR_BADVALUE;
1805 memcpy(pGuid, &This->ptarget->class_id, 16);
1810 /*** IDirectXFileDataReference ***/
1811 static HRESULT WINAPI IDirectXFileDataReferenceImpl_Resolve(IDirectXFileDataReference* iface, LPDIRECTXFILEDATA* ppDataObj)
1813 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1814 IDirectXFileDataImpl *object;
1817 TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj);
1820 return DXFILEERR_BADVALUE;
1822 hr = IDirectXFileDataImpl_Create(&object);
1826 object->pobj = This->ptarget;
1827 object->cur_enum_object = 0;
1829 object->from_ref = TRUE;
1831 *ppDataObj = (LPDIRECTXFILEDATA)object;
1836 static const IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl =
1838 IDirectXFileDataReferenceImpl_QueryInterface,
1839 IDirectXFileDataReferenceImpl_AddRef,
1840 IDirectXFileDataReferenceImpl_Release,
1841 IDirectXFileDataReferenceImpl_GetName,
1842 IDirectXFileDataReferenceImpl_GetId,
1843 IDirectXFileDataReferenceImpl_Resolve
1846 static HRESULT IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl** ppObj)
1848 IDirectXFileEnumObjectImpl* object;
1850 TRACE("(%p)\n", ppObj);
1852 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileEnumObjectImpl));
1855 ERR("Out of memory\n");
1856 return DXFILEERR_BADALLOC;
1859 object->lpVtbl.lpVtbl = &IDirectXFileEnumObject_Vtbl;
1867 /*** IUnknown methods ***/
1868 static HRESULT WINAPI IDirectXFileEnumObjectImpl_QueryInterface(IDirectXFileEnumObject* iface, REFIID riid, void** ppvObject)
1870 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
1872 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1874 if (IsEqualGUID(riid, &IID_IUnknown)
1875 || IsEqualGUID(riid, &IID_IDirectXFileEnumObject))
1877 IClassFactory_AddRef(iface);
1882 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1883 return E_NOINTERFACE;
1886 static ULONG WINAPI IDirectXFileEnumObjectImpl_AddRef(IDirectXFileEnumObject* iface)
1888 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
1889 ULONG ref = InterlockedIncrement(&This->ref);
1891 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1896 static ULONG WINAPI IDirectXFileEnumObjectImpl_Release(IDirectXFileEnumObject* iface)
1898 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
1899 ULONG ref = InterlockedDecrement(&This->ref);
1901 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1905 CloseHandle(This->hFile);
1906 HeapFree(GetProcessHeap(), 0, This);
1912 static BOOL parse_object_members_list(parse_buffer * buf)
1916 xtemplate* pt = buf->pxt[buf->level];
1917 DWORD last_dword = 0;
1919 for (i = 0; i < pt->nb_members; i++)
1924 buf->pxo->members[i].start = buf->cur_pdata;
1926 for (k = 0; k < pt->members[i].nb_dims; k++)
1928 if (pt->members[i].dim_fixed[k])
1929 nb_elems *= pt->members[i].dim_value[k];
1931 nb_elems *= *(DWORD*)buf->pxo->members[pt->members[i].dim_value[k]].start;
1934 TRACE("Elements to consider: %d\n", nb_elems);
1936 for (k = 0; k < nb_elems; k++)
1940 token = check_TOKEN(buf);
1941 if (token == TOKEN_COMMA)
1947 /* Allow comma omission */
1948 if (!((token == TOKEN_FLOAT) || (token == TOKEN_INTEGER)))
1953 if (pt->members[i].type == TOKEN_NAME)
1957 TRACE("Found sub-object %s\n", buf->pdxf->xtemplates[pt->members[i].idx_template].name);
1959 /* To do template lookup */
1960 for (j = 0; j < buf->pdxf->nb_xtemplates; j++)
1962 if (!strcmp(buf->pdxf->xtemplates[pt->members[i].idx_template].name, buf->pdxf->xtemplates[j].name))
1964 buf->pxt[buf->level] = &buf->pdxf->xtemplates[j];
1968 if (j == buf->pdxf->nb_xtemplates)
1970 FIXME("Unknown template %s\n", (char*)buf->value);
1974 TRACE("Enter %s\n", buf->pdxf->xtemplates[pt->members[i].idx_template].name);
1975 if (!parse_object_parts(buf, FALSE))
1984 token = check_TOKEN(buf);
1985 if (token == TOKEN_INTEGER)
1988 last_dword = *(DWORD*)buf->value;
1989 TRACE("%s = %d\n", pt->members[i].name, *(DWORD*)buf->value);
1990 /* Assume larger size */
1991 if ((buf->cur_pdata - buf->pdata + 4) > MAX_DATA_SIZE)
1993 FIXME("Buffer too small\n");
1996 if (pt->members[i].type == TOKEN_WORD)
1998 *(((WORD*)(buf->cur_pdata))) = (WORD)(*(DWORD*)buf->value);
1999 buf->cur_pdata += 2;
2001 else if (pt->members[i].type == TOKEN_DWORD)
2003 *(((DWORD*)(buf->cur_pdata))) = (DWORD)(*(DWORD*)buf->value);
2004 buf->cur_pdata += 4;
2008 FIXME("Token %d not supported\n", pt->members[i].type);
2012 else if (token == TOKEN_FLOAT)
2015 TRACE("%s = %f\n", pt->members[i].name, *(float*)buf->value);
2016 /* Assume larger size */
2017 if ((buf->cur_pdata - buf->pdata + 4) > MAX_DATA_SIZE)
2019 FIXME("Buffer too small\n");
2022 if (pt->members[i].type == TOKEN_FLOAT)
2024 *(((float*)(buf->cur_pdata))) = (float)(*(float*)buf->value);
2025 buf->cur_pdata += 4;
2029 FIXME("Token %d not supported\n", pt->members[i].type);
2033 else if (token == TOKEN_LPSTR)
2036 TRACE("%s = %s\n", pt->members[i].name, (char*)buf->value);
2037 /* Assume larger size */
2038 if ((buf->cur_pdata - buf->pdata + 4) > MAX_DATA_SIZE)
2040 FIXME("Buffer too small\n");
2043 if (pt->members[i].type == TOKEN_LPSTR)
2045 int len = strlen((char*)buf->value) + 1;
2046 if ((buf->cur_pstrings - buf->pstrings + len) > MAX_STRINGS_BUFFER)
2048 FIXME("Buffer too small %p %p %d\n", buf->cur_pstrings, buf->pstrings, len);
2051 strcpy((char*)buf->cur_pstrings, (char*)buf->value);
2052 *(((LPCSTR*)(buf->cur_pdata))) = (char*)buf->cur_pstrings;
2053 buf->cur_pstrings += len;
2054 buf->cur_pdata += 4;
2058 FIXME("Token %d not supported\n", pt->members[i].type);
2064 FIXME("Unexpected token %d\n", token);
2070 if (buf->txt && (check_TOKEN(buf) != TOKEN_CBRACE))
2072 token = get_TOKEN(buf);
2073 if ((token != TOKEN_SEMICOLON) && (token != TOKEN_COMMA))
2075 /* Allow comma instead of semicolon in some specific cases */
2076 if (!((token == TOKEN_COMMA) && ((i+1) < pt->nb_members) && (pt->members[i].type == pt->members[i+1].type)
2077 && (!pt->members[i].nb_dims) && (!pt->members[i+1].nb_dims)))
2086 static BOOL parse_object_parts(parse_buffer * buf, BOOL allow_optional)
2088 if (!parse_object_members_list(buf))
2093 buf->pxo->size = buf->cur_pdata - buf->pxo->pdata;
2095 /* Skip trailing semicolon */
2096 while (check_TOKEN(buf) == TOKEN_SEMICOLON)
2101 if (check_TOKEN(buf) == TOKEN_OBRACE)
2105 if (get_TOKEN(buf) != TOKEN_NAME)
2107 if (get_TOKEN(buf) != TOKEN_CBRACE)
2109 TRACE("Found optional reference %s\n", (char*)buf->value);
2110 for (i = 0; i < buf->nb_pxo_globals; i++)
2112 for (j = 0; j < buf->pxo_globals[i*MAX_SUBOBJECTS].nb_subobjects; j++)
2114 if (!strcmp(buf->pxo_globals[i*MAX_SUBOBJECTS+j].name, (char*)buf->value))
2119 if (i == buf->nb_pxo_globals)
2121 ERR("Reference to unknown object %s\n", (char*)buf->value);
2124 buf->pxo->childs[buf->pxo->nb_childs] = &buf->pxo_tab[buf->cur_subobject++];
2125 buf->pxo->childs[buf->pxo->nb_childs]->ptarget = &buf->pxo_globals[i*MAX_SUBOBJECTS+j];
2126 buf->pxo->nb_childs++;
2128 else if (check_TOKEN(buf) == TOKEN_NAME)
2130 xobject* pxo = buf->pxo;
2131 buf->pxo = buf->pxo->childs[buf->pxo->nb_childs] = &buf->pxo_tab[buf->cur_subobject++];
2133 TRACE("Enter optional %s\n", (char*)buf->value);
2135 if (!parse_object(buf))
2142 buf->pxo->nb_childs++;
2149 if (buf->pxo->nb_childs > MAX_CHILDS)
2151 FIXME("Too many childs %d\n", buf->pxo->nb_childs);
2158 static BOOL parse_object(parse_buffer * buf)
2162 buf->pxo->pdata = buf->cur_pdata;
2163 buf->pxo->ptarget = NULL;
2165 if (get_TOKEN(buf) != TOKEN_NAME)
2168 /* To do template lookup */
2169 for (i = 0; i < buf->pdxf->nb_xtemplates; i++)
2171 if (!strcmp((char*)buf->value, buf->pdxf->xtemplates[i].name))
2173 buf->pxt[buf->level] = &buf->pdxf->xtemplates[i];
2174 memcpy(&buf->pxo->type, &buf->pdxf->xtemplates[i].class_id, 16);
2178 if (i == buf->pdxf->nb_xtemplates)
2180 FIXME("Unknown template %s\n", (char*)buf->value);
2184 if (check_TOKEN(buf) == TOKEN_NAME)
2187 strcpy(buf->pxo->name, (char*)buf->value);
2190 buf->pxo->name[0] = 0;
2192 if (get_TOKEN(buf) != TOKEN_OBRACE)
2194 if (check_TOKEN(buf) == TOKEN_GUID)
2197 memcpy(&buf->pxo->class_id, buf->value, 16);
2200 memset(&buf->pxo->class_id, 0, 16);
2202 if (!parse_object_parts(buf, TRUE))
2204 if (get_TOKEN(buf) != TOKEN_CBRACE)
2209 /* Go to the next object */
2210 go_to_next_definition(buf);
2216 /*** IDirectXFileEnumObject methods ***/
2217 static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileEnumObject* iface, LPDIRECTXFILEDATA* ppDataObj)
2219 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
2220 IDirectXFileDataImpl* object;
2222 LPBYTE pdata = NULL;
2223 LPBYTE pstrings = NULL;
2225 TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj);
2227 if (This->nb_xobjects >= MAX_OBJECTS)
2229 ERR("Too many objects\n");
2230 return DXFILEERR_NOMOREOBJECTS;
2233 if (!This->buf.rem_bytes)
2234 return DXFILEERR_NOMOREOBJECTS;
2236 hr = IDirectXFileDataImpl_Create(&object);
2240 This->buf.pxo_globals = &This->xobjects[0][0];
2241 This->buf.nb_pxo_globals = This->nb_xobjects;
2242 This->buf.pxo_tab = &This->xobjects[This->nb_xobjects][0];
2243 This->buf.cur_subobject = 0;
2244 This->buf.pxo = &This->buf.pxo_tab[This->buf.cur_subobject++];
2245 This->buf.level = 0;
2247 pdata = HeapAlloc(GetProcessHeap(), 0, MAX_DATA_SIZE);
2250 ERR("Out of memory\n");
2251 hr = DXFILEERR_BADALLOC;
2254 This->buf.cur_pdata = This->buf.pdata = pdata;
2256 pstrings = HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER);
2259 ERR("Out of memory\n");
2260 hr = DXFILEERR_BADALLOC;
2263 This->buf.cur_pstrings = This->buf.pstrings = pstrings;
2265 if (!parse_object(&This->buf))
2267 TRACE("Object is not correct\n");
2268 hr = DXFILEERR_PARSEERROR;
2272 This->buf.pxo->nb_subobjects = This->buf.cur_subobject;
2273 if (This->buf.cur_subobject > MAX_SUBOBJECTS)
2275 FIXME("Too many suobjects %d\n", This->buf.cur_subobject);
2276 hr = DXFILEERR_BADALLOC;
2280 object->pstrings = pstrings;
2281 object->pobj = This->buf.pxo;
2282 object->cur_enum_object = 0;
2284 object->from_ref = FALSE;
2286 *ppDataObj = (LPDIRECTXFILEDATA)object;
2288 This->nb_xobjects++;
2294 HeapFree(GetProcessHeap(), 0, pdata);
2295 HeapFree(GetProcessHeap(), 0, pstrings);
2300 static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetDataObjectById(IDirectXFileEnumObject* iface, REFGUID rguid, LPDIRECTXFILEDATA* ppDataObj)
2302 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
2304 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, rguid, ppDataObj);
2306 return DXFILEERR_BADVALUE;
2309 static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetDataObjectByName(IDirectXFileEnumObject* iface, LPCSTR szName, LPDIRECTXFILEDATA* ppDataObj)
2311 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
2313 FIXME("(%p/%p)->(%s,%p) stub!\n", This, iface, szName, ppDataObj);
2315 return DXFILEERR_BADVALUE;
2318 static const IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl =
2320 IDirectXFileEnumObjectImpl_QueryInterface,
2321 IDirectXFileEnumObjectImpl_AddRef,
2322 IDirectXFileEnumObjectImpl_Release,
2323 IDirectXFileEnumObjectImpl_GetNextDataObject,
2324 IDirectXFileEnumObjectImpl_GetDataObjectById,
2325 IDirectXFileEnumObjectImpl_GetDataObjectByName
2328 static HRESULT IDirectXFileSaveObjectImpl_Create(IDirectXFileSaveObjectImpl** ppObj)
2330 IDirectXFileSaveObjectImpl* object;
2332 TRACE("(%p)\n", ppObj);
2334 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileSaveObjectImpl));
2337 ERR("Out of memory\n");
2338 return DXFILEERR_BADALLOC;
2341 object->lpVtbl.lpVtbl = &IDirectXFileSaveObject_Vtbl;
2349 /*** IUnknown methods ***/
2350 static HRESULT WINAPI IDirectXFileSaveObjectImpl_QueryInterface(IDirectXFileSaveObject* iface, REFIID riid, void** ppvObject)
2352 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2354 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
2356 if (IsEqualGUID(riid, &IID_IUnknown)
2357 || IsEqualGUID(riid, &IID_IDirectXFileSaveObject))
2359 IClassFactory_AddRef(iface);
2364 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
2365 return E_NOINTERFACE;
2368 static ULONG WINAPI IDirectXFileSaveObjectImpl_AddRef(IDirectXFileSaveObject* iface)
2370 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2371 ULONG ref = InterlockedIncrement(&This->ref);
2373 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
2378 static ULONG WINAPI IDirectXFileSaveObjectImpl_Release(IDirectXFileSaveObject* iface)
2380 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2381 ULONG ref = InterlockedDecrement(&This->ref);
2383 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
2386 HeapFree(GetProcessHeap(), 0, This);
2391 static HRESULT WINAPI IDirectXFileSaveObjectImpl_SaveTemplates(IDirectXFileSaveObject* iface, DWORD cTemplates, const GUID** ppguidTemplates)
2393 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2395 FIXME("(%p/%p)->(%d,%p) stub!\n", This, iface, cTemplates, ppguidTemplates);
2397 return DXFILEERR_BADVALUE;
2400 static HRESULT WINAPI IDirectXFileSaveObjectImpl_CreateDataObject(IDirectXFileSaveObject* iface, REFGUID rguidTemplate, LPCSTR szName, const GUID* pguid, DWORD cbSize, LPVOID pvData, LPDIRECTXFILEDATA* ppDataObj)
2402 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2404 FIXME("(%p/%p)->(%p,%s,%p,%d,%p,%p) stub!\n", This, iface, rguidTemplate, szName, pguid, cbSize, pvData, ppDataObj);
2406 return DXFILEERR_BADVALUE;
2409 static HRESULT WINAPI IDirectXFileSaveObjectImpl_SaveData(IDirectXFileSaveObject* iface, LPDIRECTXFILEDATA ppDataObj)
2411 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2413 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppDataObj);
2415 return DXFILEERR_BADVALUE;
2418 static const IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl =
2420 IDirectXFileSaveObjectImpl_QueryInterface,
2421 IDirectXFileSaveObjectImpl_AddRef,
2422 IDirectXFileSaveObjectImpl_Release,
2423 IDirectXFileSaveObjectImpl_SaveTemplates,
2424 IDirectXFileSaveObjectImpl_CreateDataObject,
2425 IDirectXFileSaveObjectImpl_SaveData