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);
102 static void dump_template(xtemplate* templates_array, xtemplate* ptemplate)
107 clsid = &ptemplate->class_id;
109 DPRINTF("template %s\n", ptemplate->name);
111 DPRINTF(CLSIDFMT "\n", clsid->Data1, clsid->Data2, clsid->Data3, clsid->Data4[0],
112 clsid->Data4[1], clsid->Data4[2], clsid->Data4[3], clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7]);
113 for (j = 0; j < ptemplate->nb_members; j++)
115 if (ptemplate->members[j].nb_dims)
117 if (ptemplate->members[j].type == TOKEN_NAME)
118 DPRINTF("%s ", templates_array[ptemplate->members[j].idx_template].name);
120 DPRINTF("%s ", get_primitive_string(ptemplate->members[j].type));
121 DPRINTF("%s", ptemplate->members[j].name);
122 for (k = 0; k < ptemplate->members[j].nb_dims; k++)
124 if (ptemplate->members[j].dim_fixed[k])
125 DPRINTF("[%d]", ptemplate->members[j].dim_value[k]);
127 DPRINTF("[%s]", ptemplate->members[ptemplate->members[j].dim_value[k]].name);
133 else if (ptemplate->nb_childs)
135 DPRINTF("[%s", ptemplate->childs[0]);
136 for (j = 1; j < ptemplate->nb_childs; j++)
137 DPRINTF(",%s", ptemplate->childs[j]);
143 HRESULT IDirectXFileImpl_Create(IUnknown* pUnkOuter, LPVOID* ppObj)
145 IDirectXFileImpl* object;
147 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
149 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileImpl));
152 ERR("Out of memory\n");
153 return DXFILEERR_BADALLOC;
156 object->lpVtbl.lpVtbl = &IDirectXFile_Vtbl;
164 /*** IUnknown methods ***/
165 static HRESULT WINAPI IDirectXFileImpl_QueryInterface(IDirectXFile* iface, REFIID riid, void** ppvObject)
167 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
169 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
171 if (IsEqualGUID(riid, &IID_IUnknown)
172 || IsEqualGUID(riid, &IID_IDirectXFile))
174 IClassFactory_AddRef(iface);
179 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
180 return E_NOINTERFACE;
183 static ULONG WINAPI IDirectXFileImpl_AddRef(IDirectXFile* iface)
185 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
186 ULONG ref = InterlockedIncrement(&This->ref);
188 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
193 static ULONG WINAPI IDirectXFileImpl_Release(IDirectXFile* iface)
195 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
196 ULONG ref = InterlockedDecrement(&This->ref);
198 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
201 HeapFree(GetProcessHeap(), 0, This);
206 /*** IDirectXFile methods ***/
207 static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPVOID pvSource, DXFILELOADOPTIONS dwLoadOptions, LPDIRECTXFILEENUMOBJECT* ppEnumObj)
209 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
210 IDirectXFileEnumObjectImpl* object;
214 HANDLE hFile = INVALID_HANDLE_VALUE;
215 LPDXFILELOADMEMORY lpdxflm = NULL;
217 TRACE("(%p/%p)->(%p,%x,%p)\n", This, iface, pvSource, dwLoadOptions, ppEnumObj);
220 return DXFILEERR_BADVALUE;
222 if (dwLoadOptions == DXFILELOAD_FROMFILE)
224 TRACE("Open source file '%s'\n", (char*)pvSource);
226 hFile = CreateFileA((char*)pvSource, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
227 if (hFile == INVALID_HANDLE_VALUE)
229 TRACE("File '%s' not found\n", (char*)pvSource);
230 return DXFILEERR_FILENOTFOUND;
233 if (!ReadFile(hFile, header, 16, &size, NULL))
235 hr = DXFILEERR_BADVALUE;
241 hr = DXFILEERR_BADFILETYPE;
245 else if (dwLoadOptions == DXFILELOAD_FROMMEMORY)
247 lpdxflm = (LPDXFILELOADMEMORY)pvSource;
249 TRACE("Source in memory at %p with size %d\n", lpdxflm->lpMemory, lpdxflm->dSize);
251 memcpy(header, (char*)lpdxflm->lpMemory, 16);
255 FIXME("Source type %d is not handled yet\n", dwLoadOptions);
256 hr = DXFILEERR_NOTDONEYET;
260 if (TRACE_ON(d3dxof))
263 memcpy(string, header, 16);
265 TRACE("header = '%s'\n", string);
268 if (header[0] != XOFFILE_FORMAT_MAGIC)
270 hr = DXFILEERR_BADFILETYPE;
274 if ((header[1] != XOFFILE_FORMAT_VERSION_302) && (header[1] != XOFFILE_FORMAT_VERSION_303))
276 hr = DXFILEERR_BADFILEVERSION;
280 if ((header[2] != XOFFILE_FORMAT_BINARY) && (header[2] != XOFFILE_FORMAT_TEXT) && (header[2] != XOFFILE_FORMAT_COMPRESSED))
282 hr = DXFILEERR_BADFILETYPE;
286 if (header[2] == XOFFILE_FORMAT_COMPRESSED)
288 FIXME("Compressed formats not supported yet\n");
289 hr = DXFILEERR_BADVALUE;
293 if ((header[3] != XOFFILE_FORMAT_FLOAT_BITS_32) && (header[3] != XOFFILE_FORMAT_FLOAT_BITS_64))
295 hr = DXFILEERR_BADFILEFLOATSIZE;
299 TRACE("Header is correct\n");
301 hr = IDirectXFileEnumObjectImpl_Create(&object);
305 object->source = dwLoadOptions;
306 object->hFile = hFile;
307 object->pDirectXFile = This;
308 object->buf.pdxf = This;
309 object->buf.txt = (header[2] == XOFFILE_FORMAT_TEXT);
310 object->buf.token_present = FALSE;
311 object->buf.cur_subobject = 0;
313 if (dwLoadOptions == DXFILELOAD_FROMFILE)
315 object->buf.buffer = HeapAlloc(GetProcessHeap(), 0, MAX_INPUT_SIZE+1);
316 if (!object->buf.buffer)
318 ERR("Out of memory\n");
319 hr = DXFILEERR_BADALLOC;
323 ReadFile(hFile, object->buf.buffer, MAX_INPUT_SIZE+1, &object->buf.rem_bytes, NULL);
324 if (object->buf.rem_bytes > MAX_INPUT_SIZE)
326 FIXME("File size > %d not supported yet\n", MAX_INPUT_SIZE);
327 HeapFree(GetProcessHeap(), 0, object->buf.buffer);
328 hr = DXFILEERR_PARSEERROR;
334 object->buf.buffer = ((LPBYTE)lpdxflm->lpMemory) + 16;
335 object->buf.rem_bytes = lpdxflm->dSize;
338 TRACE("Read %d bytes\n", object->buf.rem_bytes);
340 *ppEnumObj = (LPDIRECTXFILEENUMOBJECT)object;
342 while (object->buf.rem_bytes && (check_TOKEN(&object->buf) == TOKEN_TEMPLATE))
344 if (!parse_template(&object->buf))
346 TRACE("Template is not correct\n");
347 hr = DXFILEERR_BADVALUE;
352 TRACE("Template successfully parsed:\n");
353 if (TRACE_ON(d3dxof))
354 dump_template(This->xtemplates, &This->xtemplates[This->nb_xtemplates - 1]);
358 if (TRACE_ON(d3dxof))
361 TRACE("Registered templates (%d):\n", This->nb_xtemplates);
362 for (i = 0; i < This->nb_xtemplates; i++)
363 DPRINTF("%s - %s\n", This->xtemplates[i].name, debugstr_guid(&This->xtemplates[i].class_id));
369 if (hFile != INVALID_HANDLE_VALUE)
376 static HRESULT WINAPI IDirectXFileImpl_CreateSaveObject(IDirectXFile* iface, LPCSTR szFileName, DXFILEFORMAT dwFileFormat, LPDIRECTXFILESAVEOBJECT* ppSaveObj)
378 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
380 FIXME("(%p/%p)->(%s,%x,%p) stub!\n", This, iface, szFileName, dwFileFormat, ppSaveObj);
382 return DXFILEERR_BADVALUE;
385 static BOOL read_bytes(parse_buffer * buf, LPVOID data, DWORD size)
387 if (buf->rem_bytes < size)
389 memcpy(data, buf->buffer, size);
391 buf->rem_bytes -= size;
395 static void dump_TOKEN(WORD token)
397 #define DUMP_TOKEN(t) case t: TRACE(#t "\n"); break
400 DUMP_TOKEN(TOKEN_NAME);
401 DUMP_TOKEN(TOKEN_STRING);
402 DUMP_TOKEN(TOKEN_INTEGER);
403 DUMP_TOKEN(TOKEN_GUID);
404 DUMP_TOKEN(TOKEN_INTEGER_LIST);
405 DUMP_TOKEN(TOKEN_FLOAT_LIST);
406 DUMP_TOKEN(TOKEN_OBRACE);
407 DUMP_TOKEN(TOKEN_CBRACE);
408 DUMP_TOKEN(TOKEN_OPAREN);
409 DUMP_TOKEN(TOKEN_CPAREN);
410 DUMP_TOKEN(TOKEN_OBRACKET);
411 DUMP_TOKEN(TOKEN_CBRACKET);
412 DUMP_TOKEN(TOKEN_OANGLE);
413 DUMP_TOKEN(TOKEN_CANGLE);
414 DUMP_TOKEN(TOKEN_DOT);
415 DUMP_TOKEN(TOKEN_COMMA);
416 DUMP_TOKEN(TOKEN_SEMICOLON);
417 DUMP_TOKEN(TOKEN_TEMPLATE);
418 DUMP_TOKEN(TOKEN_WORD);
419 DUMP_TOKEN(TOKEN_DWORD);
420 DUMP_TOKEN(TOKEN_FLOAT);
421 DUMP_TOKEN(TOKEN_DOUBLE);
422 DUMP_TOKEN(TOKEN_CHAR);
423 DUMP_TOKEN(TOKEN_UCHAR);
424 DUMP_TOKEN(TOKEN_SWORD);
425 DUMP_TOKEN(TOKEN_SDWORD);
426 DUMP_TOKEN(TOKEN_VOID);
427 DUMP_TOKEN(TOKEN_LPSTR);
428 DUMP_TOKEN(TOKEN_UNICODE);
429 DUMP_TOKEN(TOKEN_CSTRING);
430 DUMP_TOKEN(TOKEN_ARRAY);
433 TRACE("Unknown token %d\n", token);
439 static BOOL is_space(char c)
453 static BOOL is_operator(char c)
472 static inline BOOL is_separator(char c)
474 return is_space(c) || is_operator(c);
477 static WORD get_operator_token(char c)
486 return TOKEN_OBRACKET;
488 return TOKEN_CBRACKET;
500 return TOKEN_SEMICOLON;
505 static BOOL is_keyword(parse_buffer* buf, const char* keyword)
507 DWORD len = strlen(keyword);
508 if (!strncasecmp((char*)buf->buffer, keyword,len) && is_separator(*(buf->buffer+len)))
511 buf->rem_bytes -= len;
517 static WORD get_keyword_token(parse_buffer* buf)
519 if (is_keyword(buf, "template"))
520 return TOKEN_TEMPLATE;
521 if (is_keyword(buf, "WORD"))
523 if (is_keyword(buf, "DWORD"))
525 if (is_keyword(buf, "FLOAT"))
527 if (is_keyword(buf, "DOUBLE"))
529 if (is_keyword(buf, "CHAR"))
531 if (is_keyword(buf, "UCHAR"))
533 if (is_keyword(buf, "SWORD"))
535 if (is_keyword(buf, "SDWORD"))
537 if (is_keyword(buf, "VOID"))
539 if (is_keyword(buf, "STRING"))
541 if (is_keyword(buf, "UNICODE"))
542 return TOKEN_UNICODE;
543 if (is_keyword(buf, "CSTRING"))
544 return TOKEN_CSTRING;
545 if (is_keyword(buf, "array"))
551 static BOOL is_guid(parse_buffer* buf)
559 if (*buf->buffer != '<')
562 while (*(buf->buffer+pos) != '>')
564 tmp[pos] = *(buf->buffer+pos);
569 if (pos != 38 /* <+36+> */)
571 TRACE("Wrong guid %s (%d)\n", tmp, pos);
575 buf->rem_bytes -= pos;
577 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);
580 TRACE("Wrong guid %s (%d)\n", tmp, pos);
583 TRACE("Found guid %s (%d)\n", tmp, pos);
585 class_id.Data2 = tab[0];
586 class_id.Data3 = tab[1];
587 class_id.Data4[0] = tab[2];
588 class_id.Data4[1] = tab[3];
589 class_id.Data4[2] = tab[4];
590 class_id.Data4[3] = tab[5];
591 class_id.Data4[4] = tab[6];
592 class_id.Data4[5] = tab[7];
593 class_id.Data4[6] = tab[8];
594 class_id.Data4[7] = tab[9];
596 *(GUID*)buf->value = class_id;
601 static BOOL is_name(parse_buffer* buf)
607 while (!is_separator(c = *(buf->buffer+pos)))
609 if (!(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9')) || (c == '_') || (c == '-')))
617 TRACE("Wrong name %s\n", tmp);
622 buf->rem_bytes -= pos;
624 TRACE("Found name %s\n", tmp);
625 strcpy((char*)buf->value, tmp);
630 static BOOL is_float(parse_buffer* buf)
638 while (!is_separator(c = *(buf->buffer+pos)))
640 if (!((!pos && (c == '-')) || ((c >= '0') && (c <= '9')) || (!dot && (c == '.'))))
649 buf->rem_bytes -= pos;
651 sscanf(tmp, "%f", &decimal);
653 TRACE("Found float %s - %f\n", tmp, decimal);
655 *(float*)buf->value = decimal;
660 static BOOL is_integer(parse_buffer* buf)
667 while (!is_separator(c = *(buf->buffer+pos)))
669 if (!((c >= '0') && (c <= '9')))
676 buf->rem_bytes -= pos;
678 sscanf(tmp, "%d", &integer);
680 TRACE("Found integer %s - %d\n", tmp, integer);
682 *(DWORD*)buf->value = integer;
687 static BOOL is_string(parse_buffer* buf)
694 if (*buf->buffer != '"')
697 while (!is_separator(c = *(buf->buffer+pos+1)) && (pos < 31))
710 TRACE("Wrong string %s\n", tmp);
714 buf->buffer += pos + 2;
715 buf->rem_bytes -= pos + 2;
717 TRACE("Found string %s\n", tmp);
718 strcpy((char*)buf->value, tmp);
723 static WORD parse_TOKEN(parse_buffer * buf)
732 if (!read_bytes(buf, &c, 1))
734 /*TRACE("char = '%c'\n", is_space(c) ? ' ' : c);*/
735 if ((c == '#') || (c == '/'))
737 /* Handle comment (# or //) */
740 if (!read_bytes(buf, &c, 1))
748 if (!read_bytes(buf, &c, 1))
755 if (is_operator(c) && (c != '<'))
757 token = get_operator_token(c);
770 if ((token = get_keyword_token(buf)))
780 token = TOKEN_INTEGER;
799 FIXME("Unrecognize element\n");
811 if (!read_bytes(buf, &token, 2))
814 /* Convert integer and float list into separate elements */
815 if (token == TOKEN_INTEGER_LIST)
817 if (!read_bytes(buf, &nb_elem, 4))
819 token = TOKEN_INTEGER;
821 TRACE("Integer list (TOKEN_INTEGER_LIST) of size %d\n", nb_elem);
823 else if (token == TOKEN_FLOAT_LIST)
825 if (!read_bytes(buf, &nb_elem, 4))
829 TRACE("Float list (TOKEN_FLOAT_LIST) of size %d\n", nb_elem);
835 token = is_float ? TOKEN_FLOAT : TOKEN_INTEGER;
840 if (!read_bytes(buf, &integer, 4))
843 *(DWORD*)buf->value = integer;
856 if (!read_bytes(buf, &count, 4))
858 if (!read_bytes(buf, strname, count))
861 /*TRACE("name = %s\n", strname);*/
863 strcpy((char*)buf->value, strname);
870 if (!read_bytes(buf, &integer, 4))
872 /*TRACE("integer = %ld\n", integer);*/
874 *(DWORD*)buf->value = integer;
882 if (!read_bytes(buf, &class_id, 16))
884 sprintf(strguid, CLSIDFMT, class_id.Data1, class_id.Data2, class_id.Data3, class_id.Data4[0],
885 class_id.Data4[1], class_id.Data4[2], class_id.Data4[3], class_id.Data4[4], class_id.Data4[5],
886 class_id.Data4[6], class_id.Data4[7]);
887 /*TRACE("guid = {%s}\n", strguid);*/
889 *(GUID*)buf->value = class_id;
897 if (!read_bytes(buf, &count, 4))
899 if (!read_bytes(buf, strname, count))
902 if (!read_bytes(buf, &tmp_token, 2))
904 if ((tmp_token != TOKEN_COMMA) && (tmp_token != TOKEN_SEMICOLON))
905 ERR("No comma or semicolon (got %d)\n", tmp_token);
906 /*TRACE("name = %s\n", strname);*/
908 strcpy((char*)buf->value, strname);
922 case TOKEN_SEMICOLON:
948 static const char* get_primitive_string(WORD token)
982 static WORD get_TOKEN(parse_buffer * buf)
984 if (buf->token_present)
986 buf->token_present = FALSE;
987 return buf->current_token;
990 buf->current_token = parse_TOKEN(buf);
992 return buf->current_token;
995 static WORD check_TOKEN(parse_buffer * buf)
997 if (buf->token_present)
998 return buf->current_token;
1000 buf->current_token = parse_TOKEN(buf);
1001 buf->token_present = TRUE;
1003 return buf->current_token;
1006 static inline BOOL is_primitive_type(WORD token)
1031 static BOOL parse_template_option_info(parse_buffer * buf)
1033 xtemplate* cur_template = &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates];
1035 if (check_TOKEN(buf) == TOKEN_DOT)
1038 if (get_TOKEN(buf) != TOKEN_DOT)
1040 if (get_TOKEN(buf) != TOKEN_DOT)
1042 cur_template->open = TRUE;
1048 if (get_TOKEN(buf) != TOKEN_NAME)
1050 strcpy(cur_template->childs[cur_template->nb_childs], (char*)buf->value);
1051 if (check_TOKEN(buf) == TOKEN_GUID)
1053 cur_template->nb_childs++;
1054 if (check_TOKEN(buf) != TOKEN_COMMA)
1058 cur_template->open = FALSE;
1064 static BOOL parse_template_members_list(parse_buffer * buf)
1073 cur_member = &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[idx_member];
1075 if (check_TOKEN(buf) == TOKEN_ARRAY)
1081 if (check_TOKEN(buf) == TOKEN_NAME)
1083 cur_member->type = get_TOKEN(buf);
1084 cur_member->idx_template = 0;
1085 while (cur_member->idx_template < buf->pdxf->nb_xtemplates)
1087 if (!strcmp((char*)buf->value, buf->pdxf->xtemplates[cur_member->idx_template].name))
1089 cur_member->idx_template++;
1091 if (cur_member->idx_template == buf->pdxf->nb_xtemplates)
1093 TRACE("Reference to a nonexistent template '%s'\n", (char*)buf->value);
1097 else if (is_primitive_type(check_TOKEN(buf)))
1098 cur_member->type = get_TOKEN(buf);
1102 if (get_TOKEN(buf) != TOKEN_NAME)
1104 strcpy(cur_member->name, (char*)buf->value);
1108 while (check_TOKEN(buf) == TOKEN_OBRACKET)
1110 if (nb_dims >= MAX_ARRAY_DIM)
1112 FIXME("Too many dimensions (%d) for multi-dimensional array\n", nb_dims + 1);
1116 if (check_TOKEN(buf) == TOKEN_INTEGER)
1119 cur_member->dim_fixed[nb_dims] = TRUE;
1120 cur_member->dim_value[nb_dims] = *(DWORD*)buf->value;
1125 if (get_TOKEN(buf) != TOKEN_NAME)
1127 for (i = 0; i < idx_member; i++)
1129 if (!strcmp((char*)buf->value, buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[i].name))
1131 if (buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[i].nb_dims)
1133 ERR("Array cannot be used to specify variable array size\n");
1136 if (buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[i].type != TOKEN_DWORD)
1138 FIXME("Only DWORD supported to specify variable array size\n");
1144 if (i == idx_member)
1146 ERR("Reference to unknown member %s\n", (char*)buf->value);
1149 cur_member->dim_fixed[nb_dims] = FALSE;
1150 cur_member->dim_value[nb_dims] = i;
1152 if (get_TOKEN(buf) != TOKEN_CBRACKET)
1158 cur_member->nb_dims = nb_dims;
1160 if (get_TOKEN(buf) != TOKEN_SEMICOLON)
1166 buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].nb_members = idx_member;
1171 static BOOL parse_template_parts(parse_buffer * buf)
1173 if (!parse_template_members_list(buf))
1175 if (check_TOKEN(buf) == TOKEN_OBRACKET)
1178 if (!parse_template_option_info(buf))
1180 if (get_TOKEN(buf) != TOKEN_CBRACKET)
1187 static void go_to_next_definition(parse_buffer * buf)
1189 while (buf->rem_bytes)
1191 char c = *buf->buffer;
1192 if ((c == '#') || (c == '/'))
1194 read_bytes(buf, &c, 1);
1195 /* Handle comment (# or //) */
1198 if (!read_bytes(buf, &c, 1))
1206 if (!read_bytes(buf, &c, 1))
1211 else if (is_space(*buf->buffer))
1221 static BOOL parse_template(parse_buffer * buf)
1223 if (get_TOKEN(buf) != TOKEN_TEMPLATE)
1225 if (get_TOKEN(buf) != TOKEN_NAME)
1227 strcpy(buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].name, (char*)buf->value);
1228 if (get_TOKEN(buf) != TOKEN_OBRACE)
1230 if (get_TOKEN(buf) != TOKEN_GUID)
1232 buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].class_id = *(GUID*)buf->value;
1233 if (!parse_template_parts(buf))
1235 if (get_TOKEN(buf) != TOKEN_CBRACE)
1239 /* Go to the next template */
1240 go_to_next_definition(buf);
1243 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));
1244 buf->pdxf->nb_xtemplates++;
1249 static HRESULT WINAPI IDirectXFileImpl_RegisterTemplates(IDirectXFile* iface, LPVOID pvData, DWORD cbSize)
1251 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
1255 buf.buffer = (LPBYTE)pvData;
1256 buf.rem_bytes = cbSize;
1258 buf.token_present = FALSE;
1261 TRACE("(%p/%p)->(%p,%d)\n", This, iface, pvData, cbSize);
1264 return DXFILEERR_BADVALUE;
1267 return DXFILEERR_BADFILETYPE;
1269 if (TRACE_ON(d3dxof))
1272 memcpy(string, pvData, 16);
1274 TRACE("header = '%s'\n", string);
1277 read_bytes(&buf, &token_header, 4);
1279 if (token_header != XOFFILE_FORMAT_MAGIC)
1280 return DXFILEERR_BADFILETYPE;
1282 read_bytes(&buf, &token_header, 4);
1284 if ((token_header != XOFFILE_FORMAT_VERSION_302) && (token_header != XOFFILE_FORMAT_VERSION_303))
1285 return DXFILEERR_BADFILEVERSION;
1287 read_bytes(&buf, &token_header, 4);
1289 if ((token_header != XOFFILE_FORMAT_BINARY) && (token_header != XOFFILE_FORMAT_TEXT) && (token_header != XOFFILE_FORMAT_COMPRESSED))
1290 return DXFILEERR_BADFILETYPE;
1292 if (token_header == XOFFILE_FORMAT_TEXT)
1297 if (token_header == XOFFILE_FORMAT_COMPRESSED)
1299 FIXME("Compressed formats not supported yet\n");
1300 return DXFILEERR_BADVALUE;
1303 read_bytes(&buf, &token_header, 4);
1305 if ((token_header != XOFFILE_FORMAT_FLOAT_BITS_32) && (token_header != XOFFILE_FORMAT_FLOAT_BITS_64))
1306 return DXFILEERR_BADFILEFLOATSIZE;
1308 TRACE("Header is correct\n");
1310 while (buf.rem_bytes)
1312 if (!parse_template(&buf))
1314 TRACE("Template is not correct\n");
1315 return DXFILEERR_BADVALUE;
1319 TRACE("Template successfully parsed:\n");
1320 if (TRACE_ON(d3dxof))
1321 dump_template(This->xtemplates, &This->xtemplates[This->nb_xtemplates - 1]);
1325 if (TRACE_ON(d3dxof))
1328 TRACE("Registered templates (%d):\n", This->nb_xtemplates);
1329 for (i = 0; i < This->nb_xtemplates; i++)
1330 DPRINTF("%s - %s\n", This->xtemplates[i].name, debugstr_guid(&This->xtemplates[i].class_id));
1336 static const IDirectXFileVtbl IDirectXFile_Vtbl =
1338 IDirectXFileImpl_QueryInterface,
1339 IDirectXFileImpl_AddRef,
1340 IDirectXFileImpl_Release,
1341 IDirectXFileImpl_CreateEnumObject,
1342 IDirectXFileImpl_CreateSaveObject,
1343 IDirectXFileImpl_RegisterTemplates
1346 /*** IUnknown methods ***/
1347 static HRESULT WINAPI IDirectXFileBinaryImpl_QueryInterface(IDirectXFileBinary* iface, REFIID riid, void** ppvObject)
1349 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1351 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1353 if (IsEqualGUID(riid, &IID_IUnknown)
1354 || IsEqualGUID(riid, &IID_IDirectXFileObject)
1355 || IsEqualGUID(riid, &IID_IDirectXFileBinary))
1357 IClassFactory_AddRef(iface);
1362 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
1363 if (!IsEqualGUID(riid, &IID_IDirectXFileData)
1364 && !IsEqualGUID(riid, &IID_IDirectXFileDataReference))
1365 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1367 return E_NOINTERFACE;
1370 static ULONG WINAPI IDirectXFileBinaryImpl_AddRef(IDirectXFileBinary* iface)
1372 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1373 ULONG ref = InterlockedIncrement(&This->ref);
1375 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1380 static ULONG WINAPI IDirectXFileBinaryImpl_Release(IDirectXFileBinary* iface)
1382 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1383 ULONG ref = InterlockedDecrement(&This->ref);
1385 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1388 HeapFree(GetProcessHeap(), 0, This);
1393 /*** IDirectXFileObject methods ***/
1394 static HRESULT WINAPI IDirectXFileBinaryImpl_GetName(IDirectXFileBinary* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
1397 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1399 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pstrNameBuf, pdwBufLen);
1401 return DXFILEERR_BADVALUE;
1404 static HRESULT WINAPI IDirectXFileBinaryImpl_GetId(IDirectXFileBinary* iface, LPGUID pGuid)
1406 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1408 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pGuid);
1410 return DXFILEERR_BADVALUE;
1413 /*** IDirectXFileBinary methods ***/
1414 static HRESULT WINAPI IDirectXFileBinaryImpl_GetSize(IDirectXFileBinary* iface, DWORD* pcbSize)
1416 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1418 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pcbSize);
1420 return DXFILEERR_BADVALUE;
1423 static HRESULT WINAPI IDirectXFileBinaryImpl_GetMimeType(IDirectXFileBinary* iface, LPCSTR* pszMimeType)
1425 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1427 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pszMimeType);
1429 return DXFILEERR_BADVALUE;
1432 static HRESULT WINAPI IDirectXFileBinaryImpl_Read(IDirectXFileBinary* iface, LPVOID pvData, DWORD cbSize, LPDWORD pcbRead)
1434 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1436 FIXME("(%p/%p)->(%p, %d, %p) stub!\n", This, iface, pvData, cbSize, pcbRead);
1438 return DXFILEERR_BADVALUE;
1441 static const IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl =
1443 IDirectXFileBinaryImpl_QueryInterface,
1444 IDirectXFileBinaryImpl_AddRef,
1445 IDirectXFileBinaryImpl_Release,
1446 IDirectXFileBinaryImpl_GetName,
1447 IDirectXFileBinaryImpl_GetId,
1448 IDirectXFileBinaryImpl_GetSize,
1449 IDirectXFileBinaryImpl_GetMimeType,
1450 IDirectXFileBinaryImpl_Read
1453 static HRESULT IDirectXFileDataImpl_Create(IDirectXFileDataImpl** ppObj)
1455 IDirectXFileDataImpl* object;
1457 TRACE("(%p)\n", ppObj);
1459 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileDataImpl));
1462 ERR("Out of memory\n");
1463 return DXFILEERR_BADALLOC;
1466 object->lpVtbl.lpVtbl = &IDirectXFileData_Vtbl;
1474 /*** IUnknown methods ***/
1475 static HRESULT WINAPI IDirectXFileDataImpl_QueryInterface(IDirectXFileData* iface, REFIID riid, void** ppvObject)
1477 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1479 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1481 if (IsEqualGUID(riid, &IID_IUnknown)
1482 || IsEqualGUID(riid, &IID_IDirectXFileObject)
1483 || IsEqualGUID(riid, &IID_IDirectXFileData))
1485 IClassFactory_AddRef(iface);
1490 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
1491 if (!IsEqualGUID(riid, &IID_IDirectXFileBinary)
1492 && !IsEqualGUID(riid, &IID_IDirectXFileDataReference))
1493 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1495 return E_NOINTERFACE;
1498 static ULONG WINAPI IDirectXFileDataImpl_AddRef(IDirectXFileData* iface)
1500 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1501 ULONG ref = InterlockedIncrement(&This->ref);
1503 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1508 static ULONG WINAPI IDirectXFileDataImpl_Release(IDirectXFileData* iface)
1510 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1511 ULONG ref = InterlockedDecrement(&This->ref);
1513 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1516 HeapFree(GetProcessHeap(), 0, This);
1521 /*** IDirectXFileObject methods ***/
1522 static HRESULT WINAPI IDirectXFileDataImpl_GetName(IDirectXFileData* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
1525 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1527 TRACE("(%p/%p)->(%p,%p)\n", This, iface, pstrNameBuf, pdwBufLen);
1530 return DXFILEERR_BADVALUE;
1532 strcpy(pstrNameBuf, This->pobj->name);
1537 static HRESULT WINAPI IDirectXFileDataImpl_GetId(IDirectXFileData* iface, LPGUID pGuid)
1539 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1541 TRACE("(%p/%p)->(%p)\n", This, iface, pGuid);
1544 return DXFILEERR_BADVALUE;
1546 memcpy(pGuid, &This->pobj->class_id, 16);
1551 /*** IDirectXFileData methods ***/
1552 static HRESULT WINAPI IDirectXFileDataImpl_GetData(IDirectXFileData* iface, LPCSTR szMember, DWORD* pcbSize, void** ppvData)
1554 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1556 TRACE("(%p/%p)->(%s,%p,%p)\n", This, iface, szMember, pcbSize, ppvData);
1558 if (!pcbSize || !ppvData)
1559 return DXFILEERR_BADVALUE;
1563 FIXME("Specifying a member is not supported yet!\n");
1564 return DXFILEERR_BADVALUE;
1567 *pcbSize = This->pobj->size;
1568 *ppvData = This->pobj->pdata;
1573 static HRESULT WINAPI IDirectXFileDataImpl_GetType(IDirectXFileData* iface, const GUID** pguid)
1575 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1578 TRACE("(%p/%p)->(%p)\n", This, iface, pguid);
1581 return DXFILEERR_BADVALUE;
1583 memcpy(&guid, &This->pobj->type, 16);
1589 static HRESULT WINAPI IDirectXFileDataImpl_GetNextObject(IDirectXFileData* iface, LPDIRECTXFILEOBJECT* ppChildObj)
1592 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1594 TRACE("(%p/%p)->(%p)\n", This, iface, ppChildObj);
1596 if (This->cur_enum_object >= This->pobj->nb_childs)
1597 return DXFILEERR_NOMOREOBJECTS;
1599 if (This->from_ref && (This->level >= 1))
1601 /* Only 2 levels can enumerated if the object is obtained from a reference */
1602 return DXFILEERR_NOMOREOBJECTS;
1605 if (This->pobj->childs[This->cur_enum_object]->ptarget)
1607 IDirectXFileDataReferenceImpl *object;
1609 hr = IDirectXFileDataReferenceImpl_Create(&object);
1613 object->ptarget = This->pobj->childs[This->cur_enum_object++]->ptarget;
1615 *ppChildObj = (LPDIRECTXFILEOBJECT)object;
1619 IDirectXFileDataImpl *object;
1621 hr = IDirectXFileDataImpl_Create(&object);
1625 object->pobj = This->pobj->childs[This->cur_enum_object++];
1626 object->cur_enum_object = 0;
1627 object->from_ref = This->from_ref;
1628 object->level = This->level + 1;
1630 *ppChildObj = (LPDIRECTXFILEOBJECT)object;
1636 static HRESULT WINAPI IDirectXFileDataImpl_AddDataObject(IDirectXFileData* iface, LPDIRECTXFILEDATA pDataObj)
1638 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1640 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDataObj);
1642 return DXFILEERR_BADVALUE;
1645 static HRESULT WINAPI IDirectXFileDataImpl_AddDataReference(IDirectXFileData* iface, LPCSTR szRef, const GUID* pguidRef)
1647 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1649 FIXME("(%p/%p)->(%s,%p) stub!\n", This, iface, szRef, pguidRef);
1651 return DXFILEERR_BADVALUE;
1654 static HRESULT WINAPI IDirectXFileDataImpl_AddBinaryObject(IDirectXFileData* iface, LPCSTR szName, const GUID* pguid, LPCSTR szMimeType, LPVOID pvData, DWORD cbSize)
1656 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1658 FIXME("(%p/%p)->(%s,%p,%s,%p,%d) stub!\n", This, iface, szName, pguid, szMimeType, pvData, cbSize);
1660 return DXFILEERR_BADVALUE;
1663 static const IDirectXFileDataVtbl IDirectXFileData_Vtbl =
1665 IDirectXFileDataImpl_QueryInterface,
1666 IDirectXFileDataImpl_AddRef,
1667 IDirectXFileDataImpl_Release,
1668 IDirectXFileDataImpl_GetName,
1669 IDirectXFileDataImpl_GetId,
1670 IDirectXFileDataImpl_GetData,
1671 IDirectXFileDataImpl_GetType,
1672 IDirectXFileDataImpl_GetNextObject,
1673 IDirectXFileDataImpl_AddDataObject,
1674 IDirectXFileDataImpl_AddDataReference,
1675 IDirectXFileDataImpl_AddBinaryObject
1678 static HRESULT IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImpl** ppObj)
1680 IDirectXFileDataReferenceImpl* object;
1682 TRACE("(%p)\n", ppObj);
1684 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileDataReferenceImpl));
1687 ERR("Out of memory\n");
1688 return DXFILEERR_BADALLOC;
1691 object->lpVtbl.lpVtbl = &IDirectXFileDataReference_Vtbl;
1699 /*** IUnknown methods ***/
1700 static HRESULT WINAPI IDirectXFileDataReferenceImpl_QueryInterface(IDirectXFileDataReference* iface, REFIID riid, void** ppvObject)
1702 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1704 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1706 if (IsEqualGUID(riid, &IID_IUnknown)
1707 || IsEqualGUID(riid, &IID_IDirectXFileObject)
1708 || IsEqualGUID(riid, &IID_IDirectXFileDataReference))
1710 IClassFactory_AddRef(iface);
1715 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
1716 if (!IsEqualGUID(riid, &IID_IDirectXFileData)
1717 && !IsEqualGUID(riid, &IID_IDirectXFileBinary))
1718 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1720 return E_NOINTERFACE;
1723 static ULONG WINAPI IDirectXFileDataReferenceImpl_AddRef(IDirectXFileDataReference* iface)
1725 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1726 ULONG ref = InterlockedIncrement(&This->ref);
1728 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1733 static ULONG WINAPI IDirectXFileDataReferenceImpl_Release(IDirectXFileDataReference* iface)
1735 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1736 ULONG ref = InterlockedDecrement(&This->ref);
1738 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1741 HeapFree(GetProcessHeap(), 0, This);
1746 /*** IDirectXFileObject methods ***/
1747 static HRESULT WINAPI IDirectXFileDataReferenceImpl_GetName(IDirectXFileDataReference* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
1749 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1751 TRACE("(%p/%p)->(%p,%p)\n", This, iface, pstrNameBuf, pdwBufLen);
1754 return DXFILEERR_BADVALUE;
1756 strcpy(pstrNameBuf, This->ptarget->name);
1758 return DXFILEERR_BADVALUE;
1761 static HRESULT WINAPI IDirectXFileDataReferenceImpl_GetId(IDirectXFileDataReference* iface, LPGUID pGuid)
1763 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1765 TRACE("(%p/%p)->(%p)\n", This, iface, pGuid);
1768 return DXFILEERR_BADVALUE;
1770 memcpy(pGuid, &This->ptarget->class_id, 16);
1775 /*** IDirectXFileDataReference ***/
1776 static HRESULT WINAPI IDirectXFileDataReferenceImpl_Resolve(IDirectXFileDataReference* iface, LPDIRECTXFILEDATA* ppDataObj)
1778 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1779 IDirectXFileDataImpl *object;
1782 TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj);
1785 return DXFILEERR_BADVALUE;
1787 hr = IDirectXFileDataImpl_Create(&object);
1791 object->pobj = This->ptarget;
1792 object->cur_enum_object = 0;
1794 object->from_ref = TRUE;
1796 *ppDataObj = (LPDIRECTXFILEDATA)object;
1801 static const IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl =
1803 IDirectXFileDataReferenceImpl_QueryInterface,
1804 IDirectXFileDataReferenceImpl_AddRef,
1805 IDirectXFileDataReferenceImpl_Release,
1806 IDirectXFileDataReferenceImpl_GetName,
1807 IDirectXFileDataReferenceImpl_GetId,
1808 IDirectXFileDataReferenceImpl_Resolve
1811 static HRESULT IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl** ppObj)
1813 IDirectXFileEnumObjectImpl* object;
1815 TRACE("(%p)\n", ppObj);
1817 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileEnumObjectImpl));
1820 ERR("Out of memory\n");
1821 return DXFILEERR_BADALLOC;
1824 object->lpVtbl.lpVtbl = &IDirectXFileEnumObject_Vtbl;
1832 /*** IUnknown methods ***/
1833 static HRESULT WINAPI IDirectXFileEnumObjectImpl_QueryInterface(IDirectXFileEnumObject* iface, REFIID riid, void** ppvObject)
1835 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
1837 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1839 if (IsEqualGUID(riid, &IID_IUnknown)
1840 || IsEqualGUID(riid, &IID_IDirectXFileEnumObject))
1842 IClassFactory_AddRef(iface);
1847 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1848 return E_NOINTERFACE;
1851 static ULONG WINAPI IDirectXFileEnumObjectImpl_AddRef(IDirectXFileEnumObject* iface)
1853 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
1854 ULONG ref = InterlockedIncrement(&This->ref);
1856 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1861 static ULONG WINAPI IDirectXFileEnumObjectImpl_Release(IDirectXFileEnumObject* iface)
1863 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
1864 ULONG ref = InterlockedDecrement(&This->ref);
1866 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1870 CloseHandle(This->hFile);
1871 HeapFree(GetProcessHeap(), 0, This);
1877 static BOOL parse_object_members_list(parse_buffer * buf)
1881 xtemplate* pt = buf->pxt[buf->level];
1882 DWORD last_dword = 0;
1884 for (i = 0; i < pt->nb_members; i++)
1889 buf->pxo->members[i].start = buf->cur_pdata;
1891 for (k = 0; k < pt->members[i].nb_dims; k++)
1893 if (pt->members[i].dim_fixed[k])
1894 nb_elems *= pt->members[i].dim_value[k];
1896 nb_elems *= *(DWORD*)buf->pxo->members[pt->members[i].dim_value[k]].start;
1899 TRACE("Elements to consider: %d\n", nb_elems);
1901 for (k = 0; k < nb_elems; k++)
1905 token = check_TOKEN(buf);
1906 if (token == TOKEN_COMMA)
1912 /* Allow comma omission */
1913 if (!((token == TOKEN_FLOAT) || (token == TOKEN_INTEGER)))
1918 if (pt->members[i].type == TOKEN_NAME)
1922 TRACE("Found sub-object %s\n", buf->pdxf->xtemplates[pt->members[i].idx_template].name);
1924 /* To do template lookup */
1925 for (j = 0; j < buf->pdxf->nb_xtemplates; j++)
1927 if (!strcmp(buf->pdxf->xtemplates[pt->members[i].idx_template].name, buf->pdxf->xtemplates[j].name))
1929 buf->pxt[buf->level] = &buf->pdxf->xtemplates[j];
1933 if (j == buf->pdxf->nb_xtemplates)
1935 FIXME("Unknown template %s\n", (char*)buf->value);
1939 TRACE("Enter %s\n", buf->pdxf->xtemplates[pt->members[i].idx_template].name);
1940 if (!parse_object_parts(buf, FALSE))
1949 token = check_TOKEN(buf);
1950 if (token == TOKEN_INTEGER)
1953 last_dword = *(DWORD*)buf->value;
1954 TRACE("%s = %d\n", pt->members[i].name, *(DWORD*)buf->value);
1955 /* Assume larger size */
1956 if ((buf->cur_pdata - buf->pdata + 4) > MAX_DATA_SIZE)
1958 FIXME("Buffer too small\n");
1961 if (pt->members[i].type == TOKEN_WORD)
1963 *(((WORD*)(buf->cur_pdata))) = (WORD)(*(DWORD*)buf->value);
1964 buf->cur_pdata += 2;
1966 else if (pt->members[i].type == TOKEN_DWORD)
1968 *(((DWORD*)(buf->cur_pdata))) = (DWORD)(*(DWORD*)buf->value);
1969 buf->cur_pdata += 4;
1973 FIXME("Token %d not supported\n", pt->members[i].type);
1977 else if (token == TOKEN_FLOAT)
1980 TRACE("%s = %f\n", pt->members[i].name, *(float*)buf->value);
1981 /* Assume larger size */
1982 if ((buf->cur_pdata - buf->pdata + 4) > MAX_DATA_SIZE)
1984 FIXME("Buffer too small\n");
1987 if (pt->members[i].type == TOKEN_FLOAT)
1989 *(((float*)(buf->cur_pdata))) = (float)(*(float*)buf->value);
1990 buf->cur_pdata += 4;
1994 FIXME("Token %d not supported\n", pt->members[i].type);
1998 else if (token == TOKEN_LPSTR)
2001 TRACE("%s = %s\n", pt->members[i].name, (char*)buf->value);
2002 /* Assume larger size */
2003 if ((buf->cur_pdata - buf->pdata + 4) > MAX_DATA_SIZE)
2005 FIXME("Buffer too small\n");
2008 if (pt->members[i].type == TOKEN_LPSTR)
2010 int len = strlen((char*)buf->value) + 1;
2011 if ((buf->cur_pstrings - buf->pstrings + len) > MAX_STRINGS_BUFFER)
2013 FIXME("Buffer too small %p %p %d\n", buf->cur_pstrings, buf->pstrings, len);
2016 strcpy((char*)buf->cur_pstrings, (char*)buf->value);
2017 *(((LPCSTR*)(buf->cur_pdata))) = (char*)buf->cur_pstrings;
2018 buf->cur_pstrings += len;
2019 buf->cur_pdata += 4;
2023 FIXME("Token %d not supported\n", pt->members[i].type);
2029 FIXME("Unexpected token %d\n", token);
2035 if (buf->txt && (check_TOKEN(buf) != TOKEN_CBRACE))
2037 token = get_TOKEN(buf);
2038 if ((token != TOKEN_SEMICOLON) && (token != TOKEN_COMMA))
2040 /* Allow comma instead of semicolon in some specific cases */
2041 if (!((token == TOKEN_COMMA) && ((i+1) < pt->nb_members) && (pt->members[i].type == pt->members[i+1].type)
2042 && (!pt->members[i].nb_dims) && (!pt->members[i+1].nb_dims)))
2051 static BOOL parse_object_parts(parse_buffer * buf, BOOL allow_optional)
2053 if (!parse_object_members_list(buf))
2058 buf->pxo->size = buf->cur_pdata - buf->pxo->pdata;
2060 /* Skip trailing semicolon */
2061 while (check_TOKEN(buf) == TOKEN_SEMICOLON)
2066 if (check_TOKEN(buf) == TOKEN_OBRACE)
2070 if (get_TOKEN(buf) != TOKEN_NAME)
2072 if (get_TOKEN(buf) != TOKEN_CBRACE)
2074 TRACE("Found optional reference %s\n", (char*)buf->value);
2075 for (i = 0; i < buf->nb_pxo_globals; i++)
2077 for (j = 0; j < buf->pxo_globals[i*MAX_SUBOBJECTS].nb_subobjects; j++)
2079 if (!strcmp(buf->pxo_globals[i*MAX_SUBOBJECTS+j].name, (char*)buf->value))
2084 if (i == buf->nb_pxo_globals)
2086 ERR("Reference to unknown object %s\n", (char*)buf->value);
2089 buf->pxo->childs[buf->pxo->nb_childs] = &buf->pxo_tab[buf->cur_subobject++];
2090 buf->pxo->childs[buf->pxo->nb_childs]->ptarget = &buf->pxo_globals[i*MAX_SUBOBJECTS+j];
2091 buf->pxo->nb_childs++;
2093 else if (check_TOKEN(buf) == TOKEN_NAME)
2095 xobject* pxo = buf->pxo;
2096 buf->pxo = buf->pxo->childs[buf->pxo->nb_childs] = &buf->pxo_tab[buf->cur_subobject++];
2098 TRACE("Enter optional %s\n", (char*)buf->value);
2100 if (!parse_object(buf))
2107 buf->pxo->nb_childs++;
2114 if (buf->pxo->nb_childs > MAX_CHILDS)
2116 FIXME("Too many childs %d\n", buf->pxo->nb_childs);
2123 static BOOL parse_object(parse_buffer * buf)
2127 buf->pxo->pdata = buf->cur_pdata;
2128 buf->pxo->ptarget = NULL;
2130 if (get_TOKEN(buf) != TOKEN_NAME)
2133 /* To do template lookup */
2134 for (i = 0; i < buf->pdxf->nb_xtemplates; i++)
2136 if (!strcmp((char*)buf->value, buf->pdxf->xtemplates[i].name))
2138 buf->pxt[buf->level] = &buf->pdxf->xtemplates[i];
2139 memcpy(&buf->pxo->type, &buf->pdxf->xtemplates[i].class_id, 16);
2143 if (i == buf->pdxf->nb_xtemplates)
2145 FIXME("Unknown template %s\n", (char*)buf->value);
2149 if (check_TOKEN(buf) == TOKEN_NAME)
2152 strcpy(buf->pxo->name, (char*)buf->value);
2155 buf->pxo->name[0] = 0;
2157 if (get_TOKEN(buf) != TOKEN_OBRACE)
2159 if (check_TOKEN(buf) == TOKEN_GUID)
2162 memcpy(&buf->pxo->class_id, buf->value, 16);
2165 memset(&buf->pxo->class_id, 0, 16);
2167 if (!parse_object_parts(buf, TRUE))
2169 if (get_TOKEN(buf) != TOKEN_CBRACE)
2174 /* Go to the next object */
2175 go_to_next_definition(buf);
2181 /*** IDirectXFileEnumObject methods ***/
2182 static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileEnumObject* iface, LPDIRECTXFILEDATA* ppDataObj)
2184 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
2185 IDirectXFileDataImpl* object;
2190 TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj);
2192 if (This->nb_xobjects >= MAX_OBJECTS)
2194 ERR("Too many objects\n");
2195 return DXFILEERR_NOMOREOBJECTS;
2198 if (!This->buf.rem_bytes)
2199 return DXFILEERR_NOMOREOBJECTS;
2201 hr = IDirectXFileDataImpl_Create(&object);
2205 This->buf.pxo_globals = &This->xobjects[0][0];
2206 This->buf.nb_pxo_globals = This->nb_xobjects;
2207 This->buf.pxo_tab = &This->xobjects[This->nb_xobjects][0];
2208 This->buf.cur_subobject = 0;
2209 This->buf.pxo = &This->buf.pxo_tab[This->buf.cur_subobject++];
2210 This->buf.level = 0;
2212 pdata = HeapAlloc(GetProcessHeap(), 0, MAX_DATA_SIZE);
2215 ERR("Out of memory\n");
2216 return DXFILEERR_BADALLOC;
2218 This->buf.cur_pdata = This->buf.pdata = pdata;
2220 pstrings = HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER);
2223 ERR("Out of memory\n");
2224 HeapFree(GetProcessHeap(), 0, This->buf.pxo->pdata);
2225 return DXFILEERR_BADALLOC;
2227 This->buf.cur_pstrings = This->buf.pstrings = pstrings;
2229 if (!parse_object(&This->buf))
2231 TRACE("Object is not correct\n");
2232 HeapFree(GetProcessHeap(), 0, This->buf.pxo->pdata);
2233 HeapFree(GetProcessHeap(), 0, This->buf.pstrings);
2234 return DXFILEERR_PARSEERROR;
2237 This->buf.pxo->nb_subobjects = This->buf.cur_subobject;
2238 if (This->buf.cur_subobject > MAX_SUBOBJECTS)
2240 FIXME("Too many suobjects %d\n", This->buf.cur_subobject);
2241 return DXFILEERR_BADALLOC;
2244 object->pstrings = pstrings;
2245 object->pobj = This->buf.pxo;
2246 object->cur_enum_object = 0;
2248 object->from_ref = FALSE;
2250 *ppDataObj = (LPDIRECTXFILEDATA)object;
2252 This->nb_xobjects++;
2257 static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetDataObjectById(IDirectXFileEnumObject* iface, REFGUID rguid, LPDIRECTXFILEDATA* ppDataObj)
2259 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
2261 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, rguid, ppDataObj);
2263 return DXFILEERR_BADVALUE;
2266 static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetDataObjectByName(IDirectXFileEnumObject* iface, LPCSTR szName, LPDIRECTXFILEDATA* ppDataObj)
2268 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
2270 FIXME("(%p/%p)->(%s,%p) stub!\n", This, iface, szName, ppDataObj);
2272 return DXFILEERR_BADVALUE;
2275 static const IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl =
2277 IDirectXFileEnumObjectImpl_QueryInterface,
2278 IDirectXFileEnumObjectImpl_AddRef,
2279 IDirectXFileEnumObjectImpl_Release,
2280 IDirectXFileEnumObjectImpl_GetNextDataObject,
2281 IDirectXFileEnumObjectImpl_GetDataObjectById,
2282 IDirectXFileEnumObjectImpl_GetDataObjectByName
2285 /*** IUnknown methods ***/
2286 static HRESULT WINAPI IDirectXFileObjectImpl_QueryInterface(IDirectXFileObject* iface, REFIID riid, void** ppvObject)
2288 IDirectXFileObjectImpl *This = (IDirectXFileObjectImpl *)iface;
2290 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
2292 if (IsEqualGUID(riid, &IID_IUnknown)
2293 || IsEqualGUID(riid, &IID_IDirectXFileObject))
2295 IClassFactory_AddRef(iface);
2300 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
2301 return E_NOINTERFACE;
2304 static ULONG WINAPI IDirectXFileObjectImpl_AddRef(IDirectXFileObject* iface)
2306 IDirectXFileObjectImpl *This = (IDirectXFileObjectImpl *)iface;
2307 ULONG ref = InterlockedIncrement(&This->ref);
2309 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
2314 static ULONG WINAPI IDirectXFileObjectImpl_Release(IDirectXFileObject* iface)
2316 IDirectXFileObjectImpl *This = (IDirectXFileObjectImpl *)iface;
2317 ULONG ref = InterlockedDecrement(&This->ref);
2319 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
2322 HeapFree(GetProcessHeap(), 0, This);
2327 /*** IDirectXFileObject methods ***/
2328 static HRESULT WINAPI IDirectXFileObjectImpl_GetName(IDirectXFileObject* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
2330 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
2332 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pstrNameBuf, pdwBufLen);
2334 return DXFILEERR_BADVALUE;
2337 static HRESULT WINAPI IDirectXFileObjectImpl_GetId(IDirectXFileObject* iface, LPGUID pGuid)
2339 IDirectXFileObjectImpl *This = (IDirectXFileObjectImpl *)iface;
2341 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pGuid);
2343 return DXFILEERR_BADVALUE;
2346 static const IDirectXFileObjectVtbl IDirectXFileObject_Vtbl =
2348 IDirectXFileObjectImpl_QueryInterface,
2349 IDirectXFileObjectImpl_AddRef,
2350 IDirectXFileObjectImpl_Release,
2351 IDirectXFileObjectImpl_GetName,
2352 IDirectXFileObjectImpl_GetId
2355 /*** IUnknown methods ***/
2356 static HRESULT WINAPI IDirectXFileSaveObjectImpl_QueryInterface(IDirectXFileSaveObject* iface, REFIID riid, void** ppvObject)
2358 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2360 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
2362 if (IsEqualGUID(riid, &IID_IUnknown)
2363 || IsEqualGUID(riid, &IID_IDirectXFileSaveObject))
2365 IClassFactory_AddRef(iface);
2370 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
2371 return E_NOINTERFACE;
2374 static ULONG WINAPI IDirectXFileSaveObjectImpl_AddRef(IDirectXFileSaveObject* iface)
2376 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2377 ULONG ref = InterlockedIncrement(&This->ref);
2379 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
2384 static ULONG WINAPI IDirectXFileSaveObjectImpl_Release(IDirectXFileSaveObject* iface)
2386 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2387 ULONG ref = InterlockedDecrement(&This->ref);
2389 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
2392 HeapFree(GetProcessHeap(), 0, This);
2397 static HRESULT WINAPI IDirectXFileSaveObjectImpl_SaveTemplates(IDirectXFileSaveObject* iface, DWORD cTemplates, const GUID** ppguidTemplates)
2399 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2401 FIXME("(%p/%p)->(%d,%p) stub!\n", This, iface, cTemplates, ppguidTemplates);
2403 return DXFILEERR_BADVALUE;
2406 static HRESULT WINAPI IDirectXFileSaveObjectImpl_CreateDataObject(IDirectXFileSaveObject* iface, REFGUID rguidTemplate, LPCSTR szName, const GUID* pguid, DWORD cbSize, LPVOID pvData, LPDIRECTXFILEDATA* ppDataObj)
2408 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2410 FIXME("(%p/%p)->(%p,%s,%p,%d,%p,%p) stub!\n", This, iface, rguidTemplate, szName, pguid, cbSize, pvData, ppDataObj);
2412 return DXFILEERR_BADVALUE;
2415 static HRESULT WINAPI IDirectXFileSaveObjectImpl_SaveData(IDirectXFileSaveObject* iface, LPDIRECTXFILEDATA ppDataObj)
2417 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2419 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppDataObj);
2421 return DXFILEERR_BADVALUE;
2424 static const IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl =
2426 IDirectXFileSaveObjectImpl_QueryInterface,
2427 IDirectXFileSaveObjectImpl_AddRef,
2428 IDirectXFileSaveObjectImpl_Release,
2429 IDirectXFileSaveObjectImpl_SaveTemplates,
2430 IDirectXFileSaveObjectImpl_CreateDataObject,
2431 IDirectXFileSaveObjectImpl_SaveData