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 MAKEFOUR('0','3','0','2')
42 #define XOFFILE_FORMAT_BINARY MAKEFOUR('b','i','n',' ')
43 #define XOFFILE_FORMAT_TEXT MAKEFOUR('t','x','t',' ')
44 #define XOFFILE_FORMAT_COMPRESSED MAKEFOUR('c','m','p',' ')
45 #define XOFFILE_FORMAT_FLOAT_BITS_32 MAKEFOUR('0','0','3','2')
46 #define XOFFILE_FORMAT_FLOAT_BITS_64 MAKEFOUR('0','0','6','4')
49 #define TOKEN_STRING 2
50 #define TOKEN_INTEGER 3
52 #define TOKEN_INTEGER_LIST 6
53 #define TOKEN_FLOAT_LIST 7
54 #define TOKEN_OBRACE 10
55 #define TOKEN_CBRACE 11
56 #define TOKEN_OPAREN 12
57 #define TOKEN_CPAREN 13
58 #define TOKEN_OBRACKET 14
59 #define TOKEN_CBRACKET 15
60 #define TOKEN_OANGLE 16
61 #define TOKEN_CANGLE 17
63 #define TOKEN_COMMA 19
64 #define TOKEN_SEMICOLON 20
65 #define TOKEN_TEMPLATE 31
67 #define TOKEN_DWORD 41
68 #define TOKEN_FLOAT 42
69 #define TOKEN_DOUBLE 43
71 #define TOKEN_UCHAR 45
72 #define TOKEN_SWORD 46
73 #define TOKEN_SDWORD 47
75 #define TOKEN_LPSTR 49
76 #define TOKEN_UNICODE 50
77 #define TOKEN_CSTRING 51
78 #define TOKEN_ARRAY 52
80 #define CLSIDFMT "<%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X>"
82 #define MAX_INPUT_SIZE 1000000
83 #define MAX_DATA_SIZE 100000
85 static const struct IDirectXFileVtbl IDirectXFile_Vtbl;
86 static const struct IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl;
87 static const struct IDirectXFileDataVtbl IDirectXFileData_Vtbl;
88 static const struct IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl;
89 static const struct IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl;
90 static const struct IDirectXFileObjectVtbl IDirectXFileObject_Vtbl;
91 static const struct IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl;
93 static BOOL parse_object_parts(parse_buffer * buf, BOOL allow_optional);
94 static BOOL parse_object(parse_buffer * buf);
96 HRESULT IDirectXFileImpl_Create(IUnknown* pUnkOuter, LPVOID* ppObj)
98 IDirectXFileImpl* object;
100 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
102 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileImpl));
104 object->lpVtbl.lpVtbl = &IDirectXFile_Vtbl;
112 /*** IUnknown methods ***/
113 static HRESULT WINAPI IDirectXFileImpl_QueryInterface(IDirectXFile* iface, REFIID riid, void** ppvObject)
115 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
117 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
119 if (IsEqualGUID(riid, &IID_IUnknown)
120 || IsEqualGUID(riid, &IID_IDirectXFile))
122 IClassFactory_AddRef(iface);
127 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
128 return E_NOINTERFACE;
131 static ULONG WINAPI IDirectXFileImpl_AddRef(IDirectXFile* iface)
133 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
134 ULONG ref = InterlockedIncrement(&This->ref);
136 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
141 static ULONG WINAPI IDirectXFileImpl_Release(IDirectXFile* iface)
143 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
144 ULONG ref = InterlockedDecrement(&This->ref);
146 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
149 HeapFree(GetProcessHeap(), 0, This);
154 /*** IDirectXFile methods ***/
155 static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPVOID pvSource, DXFILELOADOPTIONS dwLoadOptions, LPDIRECTXFILEENUMOBJECT* ppEnumObj)
157 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
158 IDirectXFileEnumObjectImpl* object;
162 HANDLE hFile = INVALID_HANDLE_VALUE;
164 TRACE("(%p/%p)->(%p,%x,%p)\n", This, iface, pvSource, dwLoadOptions, ppEnumObj);
167 return DXFILEERR_BADVALUE;
169 if (dwLoadOptions == DXFILELOAD_FROMFILE)
171 TRACE("Open source file '%s'\n", (char*)pvSource);
173 hFile = CreateFileA((char*)pvSource, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
174 if (hFile == INVALID_HANDLE_VALUE)
176 TRACE("File '%s' not found\n", (char*)pvSource);
177 return DXFILEERR_FILENOTFOUND;
180 if (!ReadFile(hFile, header, 16, &size, NULL))
182 hr = DXFILEERR_BADVALUE;
188 hr = DXFILEERR_BADFILETYPE;
192 if (TRACE_ON(d3dxof))
195 memcpy(string, header, 16);
197 TRACE("header = '%s'\n", string);
202 FIXME("Source type %d is not handled yet\n", dwLoadOptions);
203 hr = DXFILEERR_NOTDONEYET;
207 if (header[0] != XOFFILE_FORMAT_MAGIC)
209 hr = DXFILEERR_BADFILETYPE;
213 if (header[1] != XOFFILE_FORMAT_VERSION)
215 hr = DXFILEERR_BADFILEVERSION;
219 if ((header[2] != XOFFILE_FORMAT_BINARY) && (header[2] != XOFFILE_FORMAT_TEXT) && (header[2] != XOFFILE_FORMAT_COMPRESSED))
221 hr = DXFILEERR_BADFILETYPE;
225 if (header[2] == XOFFILE_FORMAT_BINARY)
227 FIXME("Binary format not supported yet\n");
228 hr = DXFILEERR_NOTDONEYET;
232 if (header[2] == XOFFILE_FORMAT_COMPRESSED)
234 FIXME("Compressed formats not supported yet\n");
235 hr = DXFILEERR_BADVALUE;
239 if ((header[3] != XOFFILE_FORMAT_FLOAT_BITS_32) && (header[3] != XOFFILE_FORMAT_FLOAT_BITS_64))
241 hr = DXFILEERR_BADFILEFLOATSIZE;
245 TRACE("Header is correct\n");
247 hr = IDirectXFileEnumObjectImpl_Create(&object);
251 object->source = dwLoadOptions;
252 object->hFile = hFile;
253 object->pDirectXFile = This;
254 object->buf.pdxf = This;
255 object->buf.txt = TRUE;
256 object->buf.token_present = FALSE;
257 object->buf.cur_subobject = 0;
259 object->buf.buffer = HeapAlloc(GetProcessHeap(), 0, MAX_INPUT_SIZE+1);
260 if (!object->buf.buffer)
262 WARN("Out of memory\n");
263 hr = DXFILEERR_BADALLOC;
267 ReadFile(hFile, object->buf.buffer, MAX_INPUT_SIZE+1, &object->buf.rem_bytes, NULL);
268 if (object->buf.rem_bytes > MAX_INPUT_SIZE)
270 FIXME("File size > %d not supported yet\n", MAX_INPUT_SIZE);
271 HeapFree(GetProcessHeap(), 0, object->buf.buffer);
272 hr = DXFILEERR_PARSEERROR;
275 TRACE("Read %d bytes\n", object->buf.rem_bytes);
277 *ppEnumObj = (LPDIRECTXFILEENUMOBJECT)object;
282 if (hFile != INVALID_HANDLE_VALUE)
289 static HRESULT WINAPI IDirectXFileImpl_CreateSaveObject(IDirectXFile* iface, LPCSTR szFileName, DXFILEFORMAT dwFileFormat, LPDIRECTXFILESAVEOBJECT* ppSaveObj)
291 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
293 FIXME("(%p/%p)->(%s,%x,%p) stub!\n", This, iface, szFileName, dwFileFormat, ppSaveObj);
295 return DXFILEERR_BADVALUE;
298 static BOOL read_bytes(parse_buffer * buf, LPVOID data, DWORD size)
300 if (buf->rem_bytes < size)
302 memcpy(data, buf->buffer, size);
304 buf->rem_bytes -= size;
308 static void dump_TOKEN(WORD token)
310 #define DUMP_TOKEN(t) case t: TRACE(#t "\n"); break
313 DUMP_TOKEN(TOKEN_NAME);
314 DUMP_TOKEN(TOKEN_STRING);
315 DUMP_TOKEN(TOKEN_INTEGER);
316 DUMP_TOKEN(TOKEN_GUID);
317 DUMP_TOKEN(TOKEN_INTEGER_LIST);
318 DUMP_TOKEN(TOKEN_FLOAT_LIST);
319 DUMP_TOKEN(TOKEN_OBRACE);
320 DUMP_TOKEN(TOKEN_CBRACE);
321 DUMP_TOKEN(TOKEN_OPAREN);
322 DUMP_TOKEN(TOKEN_CPAREN);
323 DUMP_TOKEN(TOKEN_OBRACKET);
324 DUMP_TOKEN(TOKEN_CBRACKET);
325 DUMP_TOKEN(TOKEN_OANGLE);
326 DUMP_TOKEN(TOKEN_CANGLE);
327 DUMP_TOKEN(TOKEN_DOT);
328 DUMP_TOKEN(TOKEN_COMMA);
329 DUMP_TOKEN(TOKEN_SEMICOLON);
330 DUMP_TOKEN(TOKEN_TEMPLATE);
331 DUMP_TOKEN(TOKEN_WORD);
332 DUMP_TOKEN(TOKEN_DWORD);
333 DUMP_TOKEN(TOKEN_FLOAT);
334 DUMP_TOKEN(TOKEN_DOUBLE);
335 DUMP_TOKEN(TOKEN_CHAR);
336 DUMP_TOKEN(TOKEN_UCHAR);
337 DUMP_TOKEN(TOKEN_SWORD);
338 DUMP_TOKEN(TOKEN_SDWORD);
339 DUMP_TOKEN(TOKEN_VOID);
340 DUMP_TOKEN(TOKEN_LPSTR);
341 DUMP_TOKEN(TOKEN_UNICODE);
342 DUMP_TOKEN(TOKEN_CSTRING);
343 DUMP_TOKEN(TOKEN_ARRAY);
346 TRACE("Unknown token %d\n", token);
352 static BOOL is_space(char c)
366 static BOOL is_operator(char c)
385 static inline BOOL is_separator(char c)
387 return is_space(c) || is_operator(c);
390 static WORD get_operator_token(char c)
399 return TOKEN_OBRACKET;
401 return TOKEN_CBRACKET;
413 return TOKEN_SEMICOLON;
418 static BOOL is_keyword(parse_buffer* buf, const char* keyword)
420 DWORD len = strlen(keyword);
421 if (!strncmp((char*)buf->buffer, keyword,len) && is_separator(*(buf->buffer+len)))
424 buf->rem_bytes -= len;
430 static WORD get_keyword_token(parse_buffer* buf)
432 if (is_keyword(buf, "template"))
433 return TOKEN_TEMPLATE;
434 if (is_keyword(buf, "WORD"))
436 if (is_keyword(buf, "DWORD"))
438 if (is_keyword(buf, "FLOAT"))
440 if (is_keyword(buf, "DOUBLE"))
442 if (is_keyword(buf, "CHAR"))
444 if (is_keyword(buf, "UCHAR"))
446 if (is_keyword(buf, "SWORD"))
448 if (is_keyword(buf, "SDWORD"))
450 if (is_keyword(buf, "VOID"))
452 if (is_keyword(buf, "STRING"))
454 if (is_keyword(buf, "UNICODE"))
455 return TOKEN_UNICODE;
456 if (is_keyword(buf, "CSTRING"))
457 return TOKEN_CSTRING;
458 if (is_keyword(buf, "array"))
464 static BOOL is_guid(parse_buffer* buf)
472 if (*buf->buffer != '<')
475 while (*(buf->buffer+pos) != '>')
477 tmp[pos] = *(buf->buffer+pos);
482 if (pos != 38 /* <+36+> */)
484 TRACE("Wrong guid %s (%d)\n", tmp, pos);
488 buf->rem_bytes -= pos;
490 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);
493 TRACE("Wrong guid %s (%d)\n", tmp, pos);
496 TRACE("Found guid %s (%d)\n", tmp, pos);
498 class_id.Data2 = tab[0];
499 class_id.Data3 = tab[1];
500 class_id.Data4[0] = tab[2];
501 class_id.Data4[1] = tab[3];
502 class_id.Data4[2] = tab[4];
503 class_id.Data4[3] = tab[5];
504 class_id.Data4[4] = tab[6];
505 class_id.Data4[5] = tab[7];
506 class_id.Data4[6] = tab[8];
507 class_id.Data4[7] = tab[9];
509 *(GUID*)buf->value = class_id;
514 static BOOL is_name(parse_buffer* buf)
520 while (!is_separator(c = *(buf->buffer+pos)))
522 if (!(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9')) || (c == '_')))
530 TRACE("Wrong name %s\n", tmp);
535 buf->rem_bytes -= pos;
537 TRACE("Found name %s\n", tmp);
538 strcpy((char*)buf->value, tmp);
543 static BOOL is_float(parse_buffer* buf)
551 while (!is_separator(c = *(buf->buffer+pos)))
553 if (!((!pos && (c == '-')) || ((c >= '0') && (c <= '9')) || (!dot && (c == '.'))))
562 buf->rem_bytes -= pos;
564 sscanf(tmp, "%f", &decimal);
566 TRACE("Found float %s - %f\n", tmp, decimal);
568 *(float*)buf->value = decimal;
573 static BOOL is_integer(parse_buffer* buf)
580 while (!is_separator(c = *(buf->buffer+pos)))
582 if (!((c >= '0') && (c <= '9')))
589 buf->rem_bytes -= pos;
591 sscanf(tmp, "%d", &integer);
593 TRACE("Found integer %s - %d\n", tmp, integer);
595 *(DWORD*)buf->value = integer;
600 static WORD parse_TOKEN(parse_buffer * buf)
609 if (!read_bytes(buf, &c, 1))
611 /*TRACE("char = '%c'\n", is_space(c) ? ' ' : c);*/
612 if ((c == '#') || (c == '/'))
614 /* Handle comment (# or //) */
617 if (!read_bytes(buf, &c, 1))
625 if (!read_bytes(buf, &c, 1))
632 if (is_operator(c) && (c != '<'))
634 token = get_operator_token(c);
647 if ((token = get_keyword_token(buf)))
657 token = TOKEN_INTEGER;
671 FIXME("Unrecognize element\n");
678 if (!read_bytes(buf, &token, 2))
688 if (!read_bytes(buf, &count, 4))
690 if (!read_bytes(buf, strname, count))
693 /*TRACE("name = %s\n", strname);*/
695 strcpy((char*)buf->value, strname);
702 if (!read_bytes(buf, &integer, 4))
704 /*TRACE("integer = %ld\n", integer);*/
706 *(DWORD*)buf->value = integer;
714 if (!read_bytes(buf, &class_id, 16))
716 sprintf(strguid, CLSIDFMT, class_id.Data1, class_id.Data2, class_id.Data3, class_id.Data4[0],
717 class_id.Data4[1], class_id.Data4[2], class_id.Data4[3], class_id.Data4[4], class_id.Data4[5],
718 class_id.Data4[6], class_id.Data4[7]);
719 /*TRACE("guid = {%s}\n", strguid);*/
721 *(GUID*)buf->value = class_id;
725 case TOKEN_INTEGER_LIST:
726 case TOKEN_FLOAT_LIST:
737 case TOKEN_SEMICOLON:
763 static const char* get_primitive_string(WORD token)
797 static WORD get_TOKEN(parse_buffer * buf)
799 if (buf->token_present)
801 buf->token_present = FALSE;
802 return buf->current_token;
805 buf->current_token = parse_TOKEN(buf);
807 return buf->current_token;
810 static WORD check_TOKEN(parse_buffer * buf)
812 if (buf->token_present)
813 return buf->current_token;
815 buf->current_token = parse_TOKEN(buf);
816 buf->token_present = TRUE;
818 return buf->current_token;
821 static inline BOOL is_primitive_type(WORD token)
846 static BOOL parse_template_option_info(parse_buffer * buf)
848 xtemplate* cur_template = &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates];
850 if (check_TOKEN(buf) == TOKEN_DOT)
853 if (get_TOKEN(buf) != TOKEN_DOT)
855 if (get_TOKEN(buf) != TOKEN_DOT)
857 cur_template->open = TRUE;
863 if (get_TOKEN(buf) != TOKEN_NAME)
865 strcpy(cur_template->childs[cur_template->nb_childs], (char*)buf->value);
866 if (check_TOKEN(buf) == TOKEN_GUID)
868 cur_template->nb_childs++;
869 if (check_TOKEN(buf) != TOKEN_COMMA)
873 cur_template->open = FALSE;
879 static BOOL parse_template_members_list(parse_buffer * buf)
888 cur_member = &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[idx_member];
890 if (check_TOKEN(buf) == TOKEN_ARRAY)
896 if (check_TOKEN(buf) == TOKEN_NAME)
898 cur_member->type = get_TOKEN(buf);
899 cur_member->idx_template = 0;
900 while (cur_member->idx_template < buf->pdxf->nb_xtemplates)
902 if (!strcmp((char*)buf->value, buf->pdxf->xtemplates[cur_member->idx_template].name))
904 cur_member->idx_template++;
906 if (cur_member->idx_template == buf->pdxf->nb_xtemplates)
908 TRACE("Reference to a nonexistent template '%s'\n", (char*)buf->value);
912 else if (is_primitive_type(check_TOKEN(buf)))
913 cur_member->type = get_TOKEN(buf);
917 if (get_TOKEN(buf) != TOKEN_NAME)
919 strcpy(cur_member->name, (char*)buf->value);
923 while (check_TOKEN(buf) == TOKEN_OBRACKET)
927 FIXME("No support for multi-dimensional array yet\n");
931 if (check_TOKEN(buf) == TOKEN_INTEGER)
934 cur_member->dim_fixed[nb_dims] = TRUE;
935 cur_member->dim_value[nb_dims] = *(DWORD*)buf->value;
939 if (get_TOKEN(buf) != TOKEN_NAME)
941 cur_member->dim_fixed[nb_dims] = FALSE;
942 /* Hack: Assume array size is specified in previous member */
943 cur_member->dim_value[nb_dims] = idx_member - 1;
945 if (get_TOKEN(buf) != TOKEN_CBRACKET)
951 cur_member->nb_dims = nb_dims;
953 if (get_TOKEN(buf) != TOKEN_SEMICOLON)
959 buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].nb_members = idx_member;
964 static BOOL parse_template_parts(parse_buffer * buf)
966 if (!parse_template_members_list(buf))
968 if (check_TOKEN(buf) == TOKEN_OBRACKET)
971 if (!parse_template_option_info(buf))
973 if (get_TOKEN(buf) != TOKEN_CBRACKET)
980 static BOOL parse_template(parse_buffer * buf)
982 if (get_TOKEN(buf) != TOKEN_TEMPLATE)
984 if (get_TOKEN(buf) != TOKEN_NAME)
986 strcpy(buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].name, (char*)buf->value);
987 if (get_TOKEN(buf) != TOKEN_OBRACE)
989 if (get_TOKEN(buf) != TOKEN_GUID)
991 buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].class_id = *(GUID*)buf->value;
992 if (!parse_template_parts(buf))
994 if (get_TOKEN(buf) != TOKEN_CBRACE)
998 /* Go to the next template */
999 while (buf->rem_bytes && is_space(*buf->buffer))
1006 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));
1007 buf->pdxf->nb_xtemplates++;
1012 static HRESULT WINAPI IDirectXFileImpl_RegisterTemplates(IDirectXFile* iface, LPVOID pvData, DWORD cbSize)
1014 IDirectXFileImpl *This = (IDirectXFileImpl *)iface;
1018 buf.buffer = (LPBYTE)pvData;
1019 buf.rem_bytes = cbSize;
1021 buf.token_present = FALSE;
1024 TRACE("(%p/%p)->(%p,%d)\n", This, iface, pvData, cbSize);
1027 return DXFILEERR_BADVALUE;
1030 return DXFILEERR_BADFILETYPE;
1032 if (TRACE_ON(d3dxof))
1035 memcpy(string, pvData, 16);
1037 TRACE("header = '%s'\n", string);
1040 read_bytes(&buf, &token_header, 4);
1042 if (token_header != XOFFILE_FORMAT_MAGIC)
1043 return DXFILEERR_BADFILETYPE;
1045 read_bytes(&buf, &token_header, 4);
1047 if (token_header != XOFFILE_FORMAT_VERSION)
1048 return DXFILEERR_BADFILEVERSION;
1050 read_bytes(&buf, &token_header, 4);
1052 if ((token_header != XOFFILE_FORMAT_BINARY) && (token_header != XOFFILE_FORMAT_TEXT) && (token_header != XOFFILE_FORMAT_COMPRESSED))
1053 return DXFILEERR_BADFILETYPE;
1055 if (token_header == XOFFILE_FORMAT_TEXT)
1060 if (token_header == XOFFILE_FORMAT_COMPRESSED)
1062 FIXME("Compressed formats not supported yet\n");
1063 return DXFILEERR_BADVALUE;
1066 read_bytes(&buf, &token_header, 4);
1068 if ((token_header != XOFFILE_FORMAT_FLOAT_BITS_32) && (token_header != XOFFILE_FORMAT_FLOAT_BITS_64))
1069 return DXFILEERR_BADFILEFLOATSIZE;
1071 TRACE("Header is correct\n");
1073 while (buf.rem_bytes)
1075 if (!parse_template(&buf))
1077 TRACE("Template is not correct\n");
1078 return DXFILEERR_BADVALUE;
1082 TRACE("Template successfully parsed:\n");
1083 if (TRACE_ON(d3dxof))
1088 i = This->nb_xtemplates - 1;
1089 clsid = &This->xtemplates[i].class_id;
1091 DPRINTF("template %s\n", This->xtemplates[i].name);
1093 DPRINTF(CLSIDFMT "\n", clsid->Data1, clsid->Data2, clsid->Data3, clsid->Data4[0],
1094 clsid->Data4[1], clsid->Data4[2], clsid->Data4[3], clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7]);
1095 for (j = 0; j < This->xtemplates[i].nb_members; j++)
1097 if (This->xtemplates[i].members[j].nb_dims)
1099 if (This->xtemplates[i].members[j].type == TOKEN_NAME)
1100 DPRINTF("%s ", This->xtemplates[This->xtemplates[i].members[j].idx_template].name);
1102 DPRINTF("%s ", get_primitive_string(This->xtemplates[i].members[j].type));
1103 DPRINTF("%s", This->xtemplates[i].members[j].name);
1104 for (k = 0; k < This->xtemplates[i].members[j].nb_dims; k++)
1106 if (This->xtemplates[i].members[j].dim_fixed[k])
1107 DPRINTF("[%d]", This->xtemplates[i].members[j].dim_value[k]);
1109 DPRINTF("[%s]", This->xtemplates[i].members[This->xtemplates[i].members[j].dim_value[k]].name);
1113 if (This->xtemplates[i].open)
1115 else if (This->xtemplates[i].nb_childs)
1117 DPRINTF("[%s", This->xtemplates[i].childs[0]);
1118 for (j = 1; j < This->xtemplates[i].nb_childs; j++)
1119 DPRINTF(",%s", This->xtemplates[i].childs[j]);
1127 if (TRACE_ON(d3dxof))
1130 TRACE("Registered templates (%d):\n", This->nb_xtemplates);
1131 for (i = 0; i < This->nb_xtemplates; i++)
1132 DPRINTF("%s - %s\n", This->xtemplates[i].name, debugstr_guid(&This->xtemplates[i].class_id));
1138 static const IDirectXFileVtbl IDirectXFile_Vtbl =
1140 IDirectXFileImpl_QueryInterface,
1141 IDirectXFileImpl_AddRef,
1142 IDirectXFileImpl_Release,
1143 IDirectXFileImpl_CreateEnumObject,
1144 IDirectXFileImpl_CreateSaveObject,
1145 IDirectXFileImpl_RegisterTemplates
1148 HRESULT IDirectXFileBinaryImpl_Create(IDirectXFileBinaryImpl** ppObj)
1150 IDirectXFileBinaryImpl* object;
1152 TRACE("(%p)\n", ppObj);
1154 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileBinaryImpl));
1156 object->lpVtbl.lpVtbl = &IDirectXFileBinary_Vtbl;
1164 /*** IUnknown methods ***/
1165 static HRESULT WINAPI IDirectXFileBinaryImpl_QueryInterface(IDirectXFileBinary* iface, REFIID riid, void** ppvObject)
1167 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1169 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1171 if (IsEqualGUID(riid, &IID_IUnknown)
1172 || IsEqualGUID(riid, &IID_IDirectXFileObject)
1173 || IsEqualGUID(riid, &IID_IDirectXFileBinary))
1175 IClassFactory_AddRef(iface);
1180 /* Do not print an error for interfaces that can be queried to retrieve the type of the object */
1181 if (!IsEqualGUID(riid, &IID_IDirectXFileData)
1182 && !IsEqualGUID(riid, &IID_IDirectXFileDataReference))
1183 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1185 return E_NOINTERFACE;
1188 static ULONG WINAPI IDirectXFileBinaryImpl_AddRef(IDirectXFileBinary* iface)
1190 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1191 ULONG ref = InterlockedIncrement(&This->ref);
1193 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1198 static ULONG WINAPI IDirectXFileBinaryImpl_Release(IDirectXFileBinary* iface)
1200 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1201 ULONG ref = InterlockedDecrement(&This->ref);
1203 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1206 HeapFree(GetProcessHeap(), 0, This);
1211 /*** IDirectXFileObject methods ***/
1212 static HRESULT WINAPI IDirectXFileBinaryImpl_GetName(IDirectXFileBinary* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
1215 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1217 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pstrNameBuf, pdwBufLen);
1219 return DXFILEERR_BADVALUE;
1222 static HRESULT WINAPI IDirectXFileBinaryImpl_GetId(IDirectXFileBinary* iface, LPGUID pGuid)
1224 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1226 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pGuid);
1228 return DXFILEERR_BADVALUE;
1231 /*** IDirectXFileBinary methods ***/
1232 static HRESULT WINAPI IDirectXFileBinaryImpl_GetSize(IDirectXFileBinary* iface, DWORD* pcbSize)
1234 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1236 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pcbSize);
1238 return DXFILEERR_BADVALUE;
1241 static HRESULT WINAPI IDirectXFileBinaryImpl_GetMimeType(IDirectXFileBinary* iface, LPCSTR* pszMimeType)
1243 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1245 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pszMimeType);
1247 return DXFILEERR_BADVALUE;
1250 static HRESULT WINAPI IDirectXFileBinaryImpl_Read(IDirectXFileBinary* iface, LPVOID pvData, DWORD cbSize, LPDWORD pcbRead)
1252 IDirectXFileBinaryImpl *This = (IDirectXFileBinaryImpl *)iface;
1254 FIXME("(%p/%p)->(%p, %d, %p) stub!\n", This, iface, pvData, cbSize, pcbRead);
1256 return DXFILEERR_BADVALUE;
1259 static const IDirectXFileBinaryVtbl IDirectXFileBinary_Vtbl =
1261 IDirectXFileBinaryImpl_QueryInterface,
1262 IDirectXFileBinaryImpl_AddRef,
1263 IDirectXFileBinaryImpl_Release,
1264 IDirectXFileBinaryImpl_GetName,
1265 IDirectXFileBinaryImpl_GetId,
1266 IDirectXFileBinaryImpl_GetSize,
1267 IDirectXFileBinaryImpl_GetMimeType,
1268 IDirectXFileBinaryImpl_Read
1271 HRESULT IDirectXFileDataImpl_Create(IDirectXFileDataImpl** ppObj)
1273 IDirectXFileDataImpl* object;
1275 TRACE("(%p)\n", ppObj);
1277 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileDataImpl));
1279 object->lpVtbl.lpVtbl = &IDirectXFileData_Vtbl;
1287 /*** IUnknown methods ***/
1288 static HRESULT WINAPI IDirectXFileDataImpl_QueryInterface(IDirectXFileData* iface, REFIID riid, void** ppvObject)
1290 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1292 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1294 if (IsEqualGUID(riid, &IID_IUnknown)
1295 || IsEqualGUID(riid, &IID_IDirectXFileObject)
1296 || IsEqualGUID(riid, &IID_IDirectXFileData))
1298 IClassFactory_AddRef(iface);
1303 /* Do not print an error for interfaces that can be queried to retreive the type of the object */
1304 if (!IsEqualGUID(riid, &IID_IDirectXFileBinary)
1305 && !IsEqualGUID(riid, &IID_IDirectXFileDataReference))
1306 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1308 return E_NOINTERFACE;
1311 static ULONG WINAPI IDirectXFileDataImpl_AddRef(IDirectXFileData* iface)
1313 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1314 ULONG ref = InterlockedIncrement(&This->ref);
1316 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1321 static ULONG WINAPI IDirectXFileDataImpl_Release(IDirectXFileData* iface)
1323 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1324 ULONG ref = InterlockedDecrement(&This->ref);
1326 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1329 HeapFree(GetProcessHeap(), 0, This);
1334 /*** IDirectXFileObject methods ***/
1335 static HRESULT WINAPI IDirectXFileDataImpl_GetName(IDirectXFileData* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
1338 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1340 TRACE("(%p/%p)->(%p,%p)\n", This, iface, pstrNameBuf, pdwBufLen);
1343 return DXFILEERR_BADVALUE;
1345 strcpy(pstrNameBuf, This->pobj->name);
1350 static HRESULT WINAPI IDirectXFileDataImpl_GetId(IDirectXFileData* iface, LPGUID pGuid)
1352 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1354 TRACE("(%p/%p)->(%p)\n", This, iface, pGuid);
1357 return DXFILEERR_BADVALUE;
1359 memcpy(pGuid, &This->pobj->class_id, 16);
1364 /*** IDirectXFileData methods ***/
1365 static HRESULT WINAPI IDirectXFileDataImpl_GetData(IDirectXFileData* iface, LPCSTR szMember, DWORD* pcbSize, void** ppvData)
1367 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1369 TRACE("(%p/%p)->(%s,%p,%p)\n", This, iface, szMember, pcbSize, ppvData);
1371 if (!pcbSize || !ppvData)
1372 return DXFILEERR_BADVALUE;
1376 FIXME("Specifying a member is not supported yet!\n");
1377 return DXFILEERR_BADVALUE;
1380 *pcbSize = This->pobj->size;
1381 *ppvData = This->pobj->pdata;
1386 static HRESULT WINAPI IDirectXFileDataImpl_GetType(IDirectXFileData* iface, const GUID** pguid)
1388 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1391 TRACE("(%p/%p)->(%p)\n", This, iface, pguid);
1394 return DXFILEERR_BADVALUE;
1396 memcpy(&guid, &This->pobj->type, 16);
1402 static HRESULT WINAPI IDirectXFileDataImpl_GetNextObject(IDirectXFileData* iface, LPDIRECTXFILEOBJECT* ppChildObj)
1405 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1407 TRACE("(%p/%p)->(%p)\n", This, iface, ppChildObj);
1409 if (This->cur_enum_object >= This->pobj->nb_childs)
1410 return DXFILEERR_NOMOREOBJECTS;
1412 if (This->pobj->childs[This->cur_enum_object]->ptarget)
1414 IDirectXFileDataReferenceImpl *object;
1416 hr = IDirectXFileDataReferenceImpl_Create(&object);
1418 return DXFILEERR_BADVALUE;
1420 object->ptarget = This->pobj->childs[This->cur_enum_object++]->ptarget;
1422 *ppChildObj = (LPDIRECTXFILEOBJECT)object;
1426 IDirectXFileDataImpl *object;
1428 hr = IDirectXFileDataImpl_Create(&object);
1430 return DXFILEERR_BADVALUE;
1432 object->pobj = This->pobj->childs[This->cur_enum_object++];
1433 object->cur_enum_object = 0;
1435 *ppChildObj = (LPDIRECTXFILEOBJECT)object;
1441 static HRESULT WINAPI IDirectXFileDataImpl_AddDataObject(IDirectXFileData* iface, LPDIRECTXFILEDATA pDataObj)
1443 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1445 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDataObj);
1447 return DXFILEERR_BADVALUE;
1450 static HRESULT WINAPI IDirectXFileDataImpl_AddDataReference(IDirectXFileData* iface, LPCSTR szRef, const GUID* pguidRef)
1452 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1454 FIXME("(%p/%p)->(%s,%p) stub!\n", This, iface, szRef, pguidRef);
1456 return DXFILEERR_BADVALUE;
1459 static HRESULT WINAPI IDirectXFileDataImpl_AddBinaryObject(IDirectXFileData* iface, LPCSTR szName, const GUID* pguid, LPCSTR szMimeType, LPVOID pvData, DWORD cbSize)
1461 IDirectXFileDataImpl *This = (IDirectXFileDataImpl *)iface;
1463 FIXME("(%p/%p)->(%s,%p,%s,%p,%d) stub!\n", This, iface, szName, pguid, szMimeType, pvData, cbSize);
1465 return DXFILEERR_BADVALUE;
1468 static const IDirectXFileDataVtbl IDirectXFileData_Vtbl =
1470 IDirectXFileDataImpl_QueryInterface,
1471 IDirectXFileDataImpl_AddRef,
1472 IDirectXFileDataImpl_Release,
1473 IDirectXFileDataImpl_GetName,
1474 IDirectXFileDataImpl_GetId,
1475 IDirectXFileDataImpl_GetData,
1476 IDirectXFileDataImpl_GetType,
1477 IDirectXFileDataImpl_GetNextObject,
1478 IDirectXFileDataImpl_AddDataObject,
1479 IDirectXFileDataImpl_AddDataReference,
1480 IDirectXFileDataImpl_AddBinaryObject
1483 HRESULT IDirectXFileDataReferenceImpl_Create(IDirectXFileDataReferenceImpl** ppObj)
1485 IDirectXFileDataReferenceImpl* object;
1487 TRACE("(%p)\n", ppObj);
1489 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileDataReferenceImpl));
1491 object->lpVtbl.lpVtbl = &IDirectXFileDataReference_Vtbl;
1499 /*** IUnknown methods ***/
1500 static HRESULT WINAPI IDirectXFileDataReferenceImpl_QueryInterface(IDirectXFileDataReference* iface, REFIID riid, void** ppvObject)
1502 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)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_IDirectXFileDataReference))
1510 IClassFactory_AddRef(iface);
1515 /* Do not print an error for interfaces that can be queried to retreive the type of the object */
1516 if (!IsEqualGUID(riid, &IID_IDirectXFileData)
1517 && !IsEqualGUID(riid, &IID_IDirectXFileBinary))
1518 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1520 return E_NOINTERFACE;
1523 static ULONG WINAPI IDirectXFileDataReferenceImpl_AddRef(IDirectXFileDataReference* iface)
1525 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1526 ULONG ref = InterlockedIncrement(&This->ref);
1528 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1533 static ULONG WINAPI IDirectXFileDataReferenceImpl_Release(IDirectXFileDataReference* iface)
1535 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)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 IDirectXFileDataReferenceImpl_GetName(IDirectXFileDataReference* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
1549 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1551 TRACE("(%p/%p)->(%p,%p)\n", This, iface, pstrNameBuf, pdwBufLen);
1554 return DXFILEERR_BADVALUE;
1556 strcpy(pstrNameBuf, This->ptarget->name);
1558 return DXFILEERR_BADVALUE;
1561 static HRESULT WINAPI IDirectXFileDataReferenceImpl_GetId(IDirectXFileDataReference* iface, LPGUID pGuid)
1563 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1565 TRACE("(%p/%p)->(%p)\n", This, iface, pGuid);
1568 return DXFILEERR_BADVALUE;
1570 memcpy(pGuid, &This->ptarget->class_id, 16);
1575 /*** IDirectXFileDataReference ***/
1576 static HRESULT WINAPI IDirectXFileDataReferenceImpl_Resolve(IDirectXFileDataReference* iface, LPDIRECTXFILEDATA* ppDataObj)
1578 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
1579 IDirectXFileDataImpl *object;
1582 TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj);
1585 return DXFILEERR_BADVALUE;
1587 hr = IDirectXFileDataImpl_Create(&object);
1589 return DXFILEERR_BADVALUE;
1591 object->pobj = This->ptarget;
1592 object->cur_enum_object = 0;
1594 *ppDataObj = (LPDIRECTXFILEDATA)object;
1599 static const IDirectXFileDataReferenceVtbl IDirectXFileDataReference_Vtbl =
1601 IDirectXFileDataReferenceImpl_QueryInterface,
1602 IDirectXFileDataReferenceImpl_AddRef,
1603 IDirectXFileDataReferenceImpl_Release,
1604 IDirectXFileDataReferenceImpl_GetName,
1605 IDirectXFileDataReferenceImpl_GetId,
1606 IDirectXFileDataReferenceImpl_Resolve
1609 HRESULT IDirectXFileEnumObjectImpl_Create(IDirectXFileEnumObjectImpl** ppObj)
1611 IDirectXFileEnumObjectImpl* object;
1613 TRACE("(%p)\n", ppObj);
1615 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileEnumObjectImpl));
1617 object->lpVtbl.lpVtbl = &IDirectXFileEnumObject_Vtbl;
1625 /*** IUnknown methods ***/
1626 static HRESULT WINAPI IDirectXFileEnumObjectImpl_QueryInterface(IDirectXFileEnumObject* iface, REFIID riid, void** ppvObject)
1628 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
1630 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
1632 if (IsEqualGUID(riid, &IID_IUnknown)
1633 || IsEqualGUID(riid, &IID_IDirectXFileEnumObject))
1635 IClassFactory_AddRef(iface);
1640 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
1641 return E_NOINTERFACE;
1644 static ULONG WINAPI IDirectXFileEnumObjectImpl_AddRef(IDirectXFileEnumObject* iface)
1646 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
1647 ULONG ref = InterlockedIncrement(&This->ref);
1649 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
1654 static ULONG WINAPI IDirectXFileEnumObjectImpl_Release(IDirectXFileEnumObject* iface)
1656 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
1657 ULONG ref = InterlockedDecrement(&This->ref);
1659 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
1662 HeapFree(GetProcessHeap(), 0, This);
1667 static BOOL parse_object_members_list(parse_buffer * buf)
1671 xtemplate* pt = buf->pxt[buf->level];
1672 DWORD last_dword = 0;
1674 for (i = 0; i < pt->nb_members; i++)
1678 if (pt->members[i].nb_dims > 1)
1680 FIXME("Arrays with dimension > 1 not yet supported\n");
1683 else if (pt->members[i].nb_dims)
1685 if (!pt->members[i].dim_fixed[0])
1689 FIXME("Array with variable must be preceded by the size\n");
1692 nb_elems = last_dword;
1693 /*FIXME("Arrays with variable size not yet supported\n");
1697 nb_elems = pt->members[i].dim_value[0];
1702 for (k = 0; k < nb_elems; k++)
1706 if (get_TOKEN(buf) != TOKEN_COMMA)
1710 if (pt->members[i].type == TOKEN_NAME)
1714 TRACE("Found suboject %s\n", buf->pdxf->xtemplates[pt->members[i].idx_template].name);
1716 /* To do template lookup */
1717 for (j = 0; j < buf->pdxf->nb_xtemplates; j++)
1719 if (!strcmp(buf->pdxf->xtemplates[pt->members[i].idx_template].name, buf->pdxf->xtemplates[j].name))
1721 buf->pxt[buf->level] = &buf->pdxf->xtemplates[j];
1725 if (j == buf->pdxf->nb_xtemplates)
1727 FIXME("Unknown template %s\n", (char*)buf->value);
1731 TRACE("Enter %s\n", buf->pdxf->xtemplates[pt->members[i].idx_template].name);
1732 if (!parse_object_parts(buf, FALSE))
1738 /*if (get_TOKEN(buf) != TOKEN_SEMICOLON)
1743 token = check_TOKEN(buf);
1744 if (token == TOKEN_INTEGER)
1747 last_dword = *(DWORD*)buf->value;
1748 TRACE("%s = %d\n", pt->members[i].name, *(DWORD*)buf->value);
1749 /* Assume larger size */
1750 if ((buf->cur_pdata - buf->pxo->pdata + 4) > MAX_DATA_SIZE)
1752 WARN("Buffer too small\n");
1755 if (pt->members[i].type == TOKEN_WORD)
1757 *(((WORD*)(buf->cur_pdata))) = (WORD)(*(DWORD*)buf->value);
1758 buf->cur_pdata += 2;
1760 else if (pt->members[i].type == TOKEN_DWORD)
1762 *(((DWORD*)(buf->cur_pdata))) = (DWORD)(*(DWORD*)buf->value);
1763 buf->cur_pdata += 4;
1767 FIXME("Token %d not supported\n", pt->members[i].type);
1771 else if (token == TOKEN_FLOAT)
1774 TRACE("%s = %f\n", pt->members[i].name, *(float*)buf->value);
1775 /* Assume larger size */
1776 if ((buf->cur_pdata - buf->pxo->pdata + 4) > MAX_DATA_SIZE)
1778 WARN("Buffer too small\n");
1781 if (pt->members[i].type == TOKEN_FLOAT)
1783 *(((float*)(buf->cur_pdata))) = (float)(*(float*)buf->value);
1784 buf->cur_pdata += 4;
1788 FIXME("Token %d not supported\n", pt->members[i].type);
1797 token = get_TOKEN(buf);
1798 if (token != TOKEN_SEMICOLON)
1800 /* Allow comma instead of semicolon in some specific cases */
1801 if (!((token == TOKEN_COMMA) && ((i+1) < pt->nb_members) && (pt->members[i].type == pt->members[i+1].type)
1802 && (!pt->members[i].nb_dims) && (!pt->members[i+1].nb_dims)))
1810 static BOOL parse_object_parts(parse_buffer * buf, BOOL allow_optional)
1812 if (!parse_object_members_list(buf))
1817 buf->pxo->size = buf->cur_pdata - buf->pxo->pdata;
1819 /* Skip trailing semicolon */
1820 while (check_TOKEN(buf) == TOKEN_SEMICOLON)
1825 if (check_TOKEN(buf) == TOKEN_OBRACE)
1829 if (get_TOKEN(buf) != TOKEN_NAME)
1831 if (get_TOKEN(buf) != TOKEN_CBRACE)
1833 TRACE("Found optional reference %s\n", (char*)buf->value);
1834 for (i = 0; i < buf->nb_pxo_globals; i++)
1836 if (!strcmp(buf->pxo_globals[i*MAX_SUBOBJECTS].name, (char*)buf->value))
1839 if (i == buf->nb_pxo_globals)
1841 ERR("Reference to unknown object %s\n", (char*)buf->value);
1844 buf->pxo->childs[buf->pxo->nb_childs] = &buf->pxo_tab[buf->cur_subobject++];
1845 buf->pxo->childs[buf->pxo->nb_childs]->ptarget = &buf->pxo_globals[i*MAX_SUBOBJECTS];
1846 buf->pxo->nb_childs++;
1848 else if (check_TOKEN(buf) == TOKEN_NAME)
1850 xobject* pxo = buf->pxo;
1851 buf->pxo = buf->pxo->childs[buf->pxo->nb_childs] = &buf->pxo_tab[buf->cur_subobject++];
1853 TRACE("Enter optional %s\n", (char*)buf->value);
1855 if (!parse_object(buf))
1862 buf->pxo->nb_childs++;
1872 static BOOL parse_object(parse_buffer * buf)
1876 buf->pxo->pdata = buf->cur_pdata;
1877 buf->pxo->ptarget = NULL;
1879 if (get_TOKEN(buf) != TOKEN_NAME)
1882 /* To do template lookup */
1883 for (i = 0; i < buf->pdxf->nb_xtemplates; i++)
1885 if (!strcmp((char*)buf->value, buf->pdxf->xtemplates[i].name))
1887 buf->pxt[buf->level] = &buf->pdxf->xtemplates[i];
1888 memcpy(&buf->pxo->type, &buf->pdxf->xtemplates[i].class_id, 16);
1892 if (i == buf->pdxf->nb_xtemplates)
1894 FIXME("Unknown template %s\n", (char*)buf->value);
1898 if (check_TOKEN(buf) == TOKEN_NAME)
1901 strcpy(buf->pxo->name, (char*)buf->value);
1904 buf->pxo->name[0] = 0;
1906 if (get_TOKEN(buf) != TOKEN_OBRACE)
1908 if (check_TOKEN(buf) == TOKEN_GUID)
1911 memcpy(&buf->pxo->class_id, buf->value, 16);
1914 memset(&buf->pxo->class_id, 0, 16);
1916 if (!parse_object_parts(buf, TRUE))
1918 if (get_TOKEN(buf) != TOKEN_CBRACE)
1923 /* Go to the next object */
1924 while (buf->rem_bytes && is_space(*buf->buffer))
1934 /*** IDirectXFileEnumObject methods ***/
1935 static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileEnumObject* iface, LPDIRECTXFILEDATA* ppDataObj)
1937 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
1938 IDirectXFileDataImpl* object;
1942 TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj);
1944 if (!This->buf.rem_bytes)
1945 return DXFILEERR_NOMOREOBJECTS;
1947 hr = IDirectXFileDataImpl_Create(&object);
1951 This->buf.pxo_globals = &This->xobjects[0][0];
1952 This->buf.nb_pxo_globals = This->nb_xobjects;
1953 This->buf.pxo_tab = &This->xobjects[This->nb_xobjects][0];
1954 This->buf.cur_subobject = 0;
1955 This->buf.pxo = &This->buf.pxo_tab[This->buf.cur_subobject++];
1957 pdata = HeapAlloc(GetProcessHeap(), 0, MAX_DATA_SIZE);
1960 WARN("Out of memory\n");
1961 return DXFILEERR_BADALLOC;
1963 This->buf.cur_pdata = pdata;
1964 This->buf.level = 0;
1966 if (!parse_object(&This->buf))
1968 TRACE("Object is not correct\n");
1969 HeapFree(GetProcessHeap(), 0, This->buf.pxo->pdata);
1970 return DXFILEERR_PARSEERROR;
1973 object->pobj = This->buf.pxo;
1974 object->cur_enum_object = 0;
1976 *ppDataObj = (LPDIRECTXFILEDATA)object;
1978 This->nb_xobjects++;
1983 static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetDataObjectById(IDirectXFileEnumObject* iface, REFGUID rguid, LPDIRECTXFILEDATA* ppDataObj)
1985 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
1987 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, rguid, ppDataObj);
1989 return DXFILEERR_BADVALUE;
1992 static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetDataObjectByName(IDirectXFileEnumObject* iface, LPCSTR szName, LPDIRECTXFILEDATA* ppDataObj)
1994 IDirectXFileEnumObjectImpl *This = (IDirectXFileEnumObjectImpl *)iface;
1996 FIXME("(%p/%p)->(%s,%p) stub!\n", This, iface, szName, ppDataObj);
1998 return DXFILEERR_BADVALUE;
2001 static const IDirectXFileEnumObjectVtbl IDirectXFileEnumObject_Vtbl =
2003 IDirectXFileEnumObjectImpl_QueryInterface,
2004 IDirectXFileEnumObjectImpl_AddRef,
2005 IDirectXFileEnumObjectImpl_Release,
2006 IDirectXFileEnumObjectImpl_GetNextDataObject,
2007 IDirectXFileEnumObjectImpl_GetDataObjectById,
2008 IDirectXFileEnumObjectImpl_GetDataObjectByName
2011 HRESULT IDirectXFileObjectImpl_Create(IDirectXFileObjectImpl** ppObj)
2013 IDirectXFileObjectImpl* object;
2015 TRACE("(%p)\n", ppObj);
2017 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileObjectImpl));
2019 object->lpVtbl.lpVtbl = &IDirectXFileObject_Vtbl;
2027 /*** IUnknown methods ***/
2028 static HRESULT WINAPI IDirectXFileObjectImpl_QueryInterface(IDirectXFileObject* iface, REFIID riid, void** ppvObject)
2030 IDirectXFileObjectImpl *This = (IDirectXFileObjectImpl *)iface;
2032 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
2034 if (IsEqualGUID(riid, &IID_IUnknown)
2035 || IsEqualGUID(riid, &IID_IDirectXFileObject))
2037 IClassFactory_AddRef(iface);
2042 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
2043 return E_NOINTERFACE;
2046 static ULONG WINAPI IDirectXFileObjectImpl_AddRef(IDirectXFileObject* iface)
2048 IDirectXFileObjectImpl *This = (IDirectXFileObjectImpl *)iface;
2049 ULONG ref = InterlockedIncrement(&This->ref);
2051 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
2056 static ULONG WINAPI IDirectXFileObjectImpl_Release(IDirectXFileObject* iface)
2058 IDirectXFileObjectImpl *This = (IDirectXFileObjectImpl *)iface;
2059 ULONG ref = InterlockedDecrement(&This->ref);
2061 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
2064 HeapFree(GetProcessHeap(), 0, This);
2069 /*** IDirectXFileObject methods ***/
2070 static HRESULT WINAPI IDirectXFileObjectImpl_GetName(IDirectXFileObject* iface, LPSTR pstrNameBuf, LPDWORD pdwBufLen)
2072 IDirectXFileDataReferenceImpl *This = (IDirectXFileDataReferenceImpl *)iface;
2074 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pstrNameBuf, pdwBufLen);
2076 return DXFILEERR_BADVALUE;
2079 static HRESULT WINAPI IDirectXFileObjectImpl_GetId(IDirectXFileObject* iface, LPGUID pGuid)
2081 IDirectXFileObjectImpl *This = (IDirectXFileObjectImpl *)iface;
2083 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pGuid);
2085 return DXFILEERR_BADVALUE;
2088 static const IDirectXFileObjectVtbl IDirectXFileObject_Vtbl =
2090 IDirectXFileObjectImpl_QueryInterface,
2091 IDirectXFileObjectImpl_AddRef,
2092 IDirectXFileObjectImpl_Release,
2093 IDirectXFileObjectImpl_GetName,
2094 IDirectXFileObjectImpl_GetId
2097 HRESULT IDirectXFileSaveObjectImpl_Create(IDirectXFileSaveObjectImpl** ppObj)
2099 IDirectXFileSaveObjectImpl* object;
2101 TRACE("(%p)\n", ppObj);
2103 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectXFileSaveObjectImpl));
2105 object->lpVtbl.lpVtbl = &IDirectXFileSaveObject_Vtbl;
2113 /*** IUnknown methods ***/
2114 static HRESULT WINAPI IDirectXFileSaveObjectImpl_QueryInterface(IDirectXFileSaveObject* iface, REFIID riid, void** ppvObject)
2116 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2118 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
2120 if (IsEqualGUID(riid, &IID_IUnknown)
2121 || IsEqualGUID(riid, &IID_IDirectXFileSaveObject))
2123 IClassFactory_AddRef(iface);
2128 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
2129 return E_NOINTERFACE;
2132 static ULONG WINAPI IDirectXFileSaveObjectImpl_AddRef(IDirectXFileSaveObject* iface)
2134 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2135 ULONG ref = InterlockedIncrement(&This->ref);
2137 TRACE("(%p/%p): AddRef from %d\n", iface, This, ref - 1);
2142 static ULONG WINAPI IDirectXFileSaveObjectImpl_Release(IDirectXFileSaveObject* iface)
2144 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2145 ULONG ref = InterlockedDecrement(&This->ref);
2147 TRACE("(%p/%p): ReleaseRef to %d\n", iface, This, ref);
2150 HeapFree(GetProcessHeap(), 0, This);
2155 static HRESULT WINAPI IDirectXFileSaveObjectImpl_SaveTemplates(IDirectXFileSaveObject* iface, DWORD cTemplates, const GUID** ppguidTemplates)
2157 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2159 FIXME("(%p/%p)->(%d,%p) stub!\n", This, iface, cTemplates, ppguidTemplates);
2161 return DXFILEERR_BADVALUE;
2164 static HRESULT WINAPI IDirectXFileSaveObjectImpl_CreateDataObject(IDirectXFileSaveObject* iface, REFGUID rguidTemplate, LPCSTR szName, const GUID* pguid, DWORD cbSize, LPVOID pvData, LPDIRECTXFILEDATA* ppDataObj)
2166 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2168 FIXME("(%p/%p)->(%p,%s,%p,%d,%p,%p) stub!\n", This, iface, rguidTemplate, szName, pguid, cbSize, pvData, ppDataObj);
2170 return DXFILEERR_BADVALUE;
2173 static HRESULT WINAPI IDirectXFileSaveObjectImpl_SaveData(IDirectXFileSaveObject* iface, LPDIRECTXFILEDATA ppDataObj)
2175 IDirectXFileSaveObjectImpl *This = (IDirectXFileSaveObjectImpl *)iface;
2177 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppDataObj);
2179 return DXFILEERR_BADVALUE;
2182 static const IDirectXFileSaveObjectVtbl IDirectXFileSaveObject_Vtbl =
2184 IDirectXFileSaveObjectImpl_QueryInterface,
2185 IDirectXFileSaveObjectImpl_AddRef,
2186 IDirectXFileSaveObjectImpl_Release,
2187 IDirectXFileSaveObjectImpl_SaveTemplates,
2188 IDirectXFileSaveObjectImpl_CreateDataObject,
2189 IDirectXFileSaveObjectImpl_SaveData