msvcrt: Stop at trylevel for ControlPc on target frame for non-consolidate unwinds.
[wine.git] / dlls / dmscript / script.c
blob98b9759c2705e0301b3bc87dfff49b5885938c24
1 /* IDirectMusicScript
3 * Copyright (C) 2003-2004 Rok Mandeljc
4 * Copyright (C) 2003-2004 Raphael Junqueira
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #ifdef HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
28 #include "dmscript_private.h"
29 #include "dmobject.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(dmscript);
32 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
35 /*****************************************************************************
36 * IDirectMusicScriptImpl implementation
38 typedef struct IDirectMusicScriptImpl {
39 IDirectMusicScript IDirectMusicScript_iface;
40 struct dmobject dmobj;
41 LONG ref;
42 IDirectMusicPerformance *pPerformance;
43 DMUS_IO_SCRIPT_HEADER *pHeader;
44 DMUS_IO_VERSION *pVersion;
45 WCHAR *pwzLanguage;
46 WCHAR *pwzSource;
47 } IDirectMusicScriptImpl;
49 static inline IDirectMusicScriptImpl *impl_from_IDirectMusicScript(IDirectMusicScript *iface)
51 return CONTAINING_RECORD(iface, IDirectMusicScriptImpl, IDirectMusicScript_iface);
54 static HRESULT WINAPI IDirectMusicScriptImpl_QueryInterface(IDirectMusicScript *iface, REFIID riid,
55 void **ret_iface)
57 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
59 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface);
61 *ret_iface = NULL;
63 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDirectMusicScript))
64 *ret_iface = iface;
65 else if (IsEqualIID(riid, &IID_IDirectMusicObject))
66 *ret_iface = &This->dmobj.IDirectMusicObject_iface;
67 else if (IsEqualIID(riid, &IID_IPersistStream))
68 *ret_iface = &This->dmobj.IPersistStream_iface;
69 else {
70 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface);
71 return E_NOINTERFACE;
74 IUnknown_AddRef((IUnknown*)*ret_iface);
75 return S_OK;
78 static ULONG WINAPI IDirectMusicScriptImpl_AddRef(IDirectMusicScript *iface)
80 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
81 LONG ref = InterlockedIncrement(&This->ref);
83 TRACE("(%p) ref=%d\n", This, ref);
85 return ref;
88 static ULONG WINAPI IDirectMusicScriptImpl_Release(IDirectMusicScript *iface)
90 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
91 LONG ref = InterlockedDecrement(&This->ref);
93 TRACE("(%p) ref=%d\n", This, ref);
95 if (!ref) {
96 HeapFree(GetProcessHeap(), 0, This->pHeader);
97 HeapFree(GetProcessHeap(), 0, This->pVersion);
98 HeapFree(GetProcessHeap(), 0, This->pwzLanguage);
99 HeapFree(GetProcessHeap(), 0, This->pwzSource);
100 HeapFree(GetProcessHeap(), 0, This);
101 DMSCRIPT_UnlockModule();
104 return ref;
107 static HRESULT WINAPI IDirectMusicScriptImpl_Init(IDirectMusicScript *iface,
108 IDirectMusicPerformance *pPerformance, DMUS_SCRIPT_ERRORINFO *pErrorInfo)
110 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
111 FIXME("(%p, %p, %p): stub\n", This, pPerformance, pErrorInfo);
112 This->pPerformance = pPerformance;
113 return S_OK;
116 static HRESULT WINAPI IDirectMusicScriptImpl_CallRoutine(IDirectMusicScript *iface,
117 WCHAR *pwszRoutineName, DMUS_SCRIPT_ERRORINFO *pErrorInfo)
119 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
120 FIXME("(%p, %s, %p): stub\n", This, debugstr_w(pwszRoutineName), pErrorInfo);
121 /*return E_NOTIMPL;*/
122 return S_OK;
123 /*return E_FAIL;*/
126 static HRESULT WINAPI IDirectMusicScriptImpl_SetVariableVariant(IDirectMusicScript *iface,
127 WCHAR *pwszVariableName, VARIANT varValue, BOOL fSetRef, DMUS_SCRIPT_ERRORINFO *pErrorInfo)
129 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
130 FIXME("(%p, %s, FIXME, %d, %p): stub\n", This, debugstr_w(pwszVariableName),/* varValue,*/ fSetRef, pErrorInfo);
131 return S_OK;
134 static HRESULT WINAPI IDirectMusicScriptImpl_GetVariableVariant(IDirectMusicScript *iface,
135 WCHAR *pwszVariableName, VARIANT *pvarValue, DMUS_SCRIPT_ERRORINFO *pErrorInfo)
137 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
138 FIXME("(%p, %s, %p, %p): stub\n", This, debugstr_w(pwszVariableName), pvarValue, pErrorInfo);
139 return S_OK;
142 static HRESULT WINAPI IDirectMusicScriptImpl_SetVariableNumber(IDirectMusicScript *iface,
143 WCHAR *pwszVariableName, LONG lValue, DMUS_SCRIPT_ERRORINFO *pErrorInfo)
145 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
146 FIXME("(%p, %s, %i, %p): stub\n", This, debugstr_w(pwszVariableName), lValue, pErrorInfo);
147 return S_OK;
150 static HRESULT WINAPI IDirectMusicScriptImpl_GetVariableNumber(IDirectMusicScript *iface,
151 WCHAR *pwszVariableName, LONG *plValue, DMUS_SCRIPT_ERRORINFO *pErrorInfo)
153 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
154 FIXME("(%p, %s, %p, %p): stub\n", This, debugstr_w(pwszVariableName), plValue, pErrorInfo);
155 return S_OK;
158 static HRESULT WINAPI IDirectMusicScriptImpl_SetVariableObject(IDirectMusicScript *iface,
159 WCHAR *pwszVariableName, IUnknown *punkValue, DMUS_SCRIPT_ERRORINFO *pErrorInfo)
161 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
162 FIXME("(%p, %s, %p, %p): stub\n", This, debugstr_w(pwszVariableName), punkValue, pErrorInfo);
163 return S_OK;
166 static HRESULT WINAPI IDirectMusicScriptImpl_GetVariableObject(IDirectMusicScript *iface,
167 WCHAR *pwszVariableName, REFIID riid, void **ppv, DMUS_SCRIPT_ERRORINFO *pErrorInfo)
169 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
170 FIXME("(%p, %s, %s, %p, %p): stub\n", This, debugstr_w(pwszVariableName), debugstr_dmguid(riid), ppv, pErrorInfo);
171 return S_OK;
174 static HRESULT WINAPI IDirectMusicScriptImpl_EnumRoutine(IDirectMusicScript *iface, DWORD dwIndex,
175 WCHAR *pwszName)
177 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
178 FIXME("(%p, %d, %p): stub\n", This, dwIndex, pwszName);
179 return S_OK;
182 static HRESULT WINAPI IDirectMusicScriptImpl_EnumVariable(IDirectMusicScript *iface, DWORD dwIndex,
183 WCHAR *pwszName)
185 IDirectMusicScriptImpl *This = impl_from_IDirectMusicScript(iface);
186 FIXME("(%p, %d, %p): stub\n", This, dwIndex, pwszName);
187 return S_OK;
190 static const IDirectMusicScriptVtbl dmscript_vtbl = {
191 IDirectMusicScriptImpl_QueryInterface,
192 IDirectMusicScriptImpl_AddRef,
193 IDirectMusicScriptImpl_Release,
194 IDirectMusicScriptImpl_Init,
195 IDirectMusicScriptImpl_CallRoutine,
196 IDirectMusicScriptImpl_SetVariableVariant,
197 IDirectMusicScriptImpl_GetVariableVariant,
198 IDirectMusicScriptImpl_SetVariableNumber,
199 IDirectMusicScriptImpl_GetVariableNumber,
200 IDirectMusicScriptImpl_SetVariableObject,
201 IDirectMusicScriptImpl_GetVariableObject,
202 IDirectMusicScriptImpl_EnumRoutine,
203 IDirectMusicScriptImpl_EnumVariable
206 /* IDirectMusicScriptImpl IDirectMusicObject part: */
207 static inline IDirectMusicScriptImpl *impl_from_IDirectMusicObject(IDirectMusicObject *iface)
209 return CONTAINING_RECORD(iface, IDirectMusicScriptImpl, dmobj.IDirectMusicObject_iface);
212 static HRESULT WINAPI IDirectMusicObjectImpl_ParseDescriptor(IDirectMusicObject *iface,
213 IStream *pStream, DMUS_OBJECTDESC *pDesc)
215 IDirectMusicScriptImpl *This = impl_from_IDirectMusicObject(iface);
216 DMUS_PRIVATE_CHUNK Chunk;
217 DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
218 LARGE_INTEGER liMove; /* used when skipping chunks */
220 TRACE("(%p, %p, %p)\n", This, pStream, pDesc);
222 /* FIXME: should this be determined from stream? */
223 pDesc->dwValidData |= DMUS_OBJ_CLASS;
224 pDesc->guidClass = CLSID_DirectMusicScript;
226 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
227 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
228 switch (Chunk.fccID) {
229 case FOURCC_RIFF: {
230 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
231 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
232 StreamSize = Chunk.dwSize - sizeof(FOURCC);
233 StreamCount = 0;
234 if (Chunk.fccID == DMUS_FOURCC_SCRIPT_FORM) {
235 TRACE_(dmfile)(": script form\n");
236 do {
237 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
238 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
239 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
240 switch (Chunk.fccID) {
241 case DMUS_FOURCC_GUID_CHUNK: {
242 TRACE_(dmfile)(": GUID chunk\n");
243 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
244 IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
245 break;
247 case DMUS_FOURCC_VERSION_CHUNK: {
248 TRACE_(dmfile)(": version chunk\n");
249 pDesc->dwValidData |= DMUS_OBJ_VERSION;
250 IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
251 break;
253 case DMUS_FOURCC_CATEGORY_CHUNK: {
254 TRACE_(dmfile)(": category chunk\n");
255 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
256 IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
257 break;
259 case FOURCC_LIST: {
260 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
261 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
262 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
263 ListCount[0] = 0;
264 switch (Chunk.fccID) {
265 /* evil M$ UNFO list, which can (!?) contain INFO elements */
266 case DMUS_FOURCC_UNFO_LIST: {
267 TRACE_(dmfile)(": UNFO list\n");
268 do {
269 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
270 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
271 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
272 switch (Chunk.fccID) {
273 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
274 (though strings seem to be valid unicode) */
275 case mmioFOURCC('I','N','A','M'):
276 case DMUS_FOURCC_UNAM_CHUNK: {
277 TRACE_(dmfile)(": name chunk\n");
278 pDesc->dwValidData |= DMUS_OBJ_NAME;
279 IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
280 break;
282 case mmioFOURCC('I','A','R','T'):
283 case DMUS_FOURCC_UART_CHUNK: {
284 TRACE_(dmfile)(": artist chunk (ignored)\n");
285 liMove.QuadPart = Chunk.dwSize;
286 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
287 break;
289 case mmioFOURCC('I','C','O','P'):
290 case DMUS_FOURCC_UCOP_CHUNK: {
291 TRACE_(dmfile)(": copyright chunk (ignored)\n");
292 liMove.QuadPart = Chunk.dwSize;
293 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
294 break;
296 case mmioFOURCC('I','S','B','J'):
297 case DMUS_FOURCC_USBJ_CHUNK: {
298 TRACE_(dmfile)(": subject chunk (ignored)\n");
299 liMove.QuadPart = Chunk.dwSize;
300 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
301 break;
303 case mmioFOURCC('I','C','M','T'):
304 case DMUS_FOURCC_UCMT_CHUNK: {
305 TRACE_(dmfile)(": comment chunk (ignored)\n");
306 liMove.QuadPart = Chunk.dwSize;
307 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
308 break;
310 default: {
311 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
312 liMove.QuadPart = Chunk.dwSize;
313 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
314 break;
317 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
318 } while (ListCount[0] < ListSize[0]);
319 break;
321 default: {
322 TRACE_(dmfile)(": unknown (skipping)\n");
323 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
324 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
325 break;
328 break;
330 default: {
331 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
332 liMove.QuadPart = Chunk.dwSize;
333 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
334 break;
337 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
338 } while (StreamCount < StreamSize);
339 } else {
340 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
341 liMove.QuadPart = StreamSize;
342 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
343 return E_FAIL;
346 TRACE_(dmfile)(": reading finished\n");
347 break;
349 default: {
350 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
351 liMove.QuadPart = Chunk.dwSize;
352 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
353 return DMUS_E_INVALIDFILE;
357 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
359 return S_OK;
362 static const IDirectMusicObjectVtbl dmobject_vtbl = {
363 dmobj_IDirectMusicObject_QueryInterface,
364 dmobj_IDirectMusicObject_AddRef,
365 dmobj_IDirectMusicObject_Release,
366 dmobj_IDirectMusicObject_GetDescriptor,
367 dmobj_IDirectMusicObject_SetDescriptor,
368 IDirectMusicObjectImpl_ParseDescriptor
371 /* IDirectMusicScriptImpl IPersistStream part: */
372 static inline IDirectMusicScriptImpl *impl_from_IPersistStream(IPersistStream *iface)
374 return CONTAINING_RECORD(iface, IDirectMusicScriptImpl, dmobj.IPersistStream_iface);
377 static HRESULT WINAPI IPersistStreamImpl_Load(IPersistStream *iface, IStream *pStm)
379 IDirectMusicScriptImpl *This = impl_from_IPersistStream(iface);
380 DMUS_PRIVATE_CHUNK Chunk;
381 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
382 LARGE_INTEGER liMove; /* used when skipping chunks */
383 LPDIRECTMUSICGETLOADER pGetLoader = NULL;
384 LPDIRECTMUSICLOADER pLoader = NULL;
386 FIXME("(%p, %p): Loading not implemented yet\n", This, pStm);
387 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
388 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
389 switch (Chunk.fccID) {
390 case FOURCC_RIFF: {
391 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
392 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
393 StreamSize = Chunk.dwSize - sizeof(FOURCC);
394 StreamCount = 0;
395 switch (Chunk.fccID) {
396 case DMUS_FOURCC_SCRIPT_FORM: {
397 TRACE_(dmfile)(": script form\n");
398 do {
399 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
400 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
401 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
402 switch (Chunk.fccID) {
403 case DMUS_FOURCC_SCRIPT_CHUNK: {
404 TRACE_(dmfile)(": script header chunk\n");
405 This->pHeader = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize);
406 IStream_Read (pStm, This->pHeader, Chunk.dwSize, NULL);
407 break;
409 case DMUS_FOURCC_SCRIPTVERSION_CHUNK: {
410 TRACE_(dmfile)(": script version chunk\n");
411 This->pVersion = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize);
412 IStream_Read (pStm, This->pVersion, Chunk.dwSize, NULL);
413 TRACE_(dmfile)("version: 0x%08x.0x%08x\n", This->pVersion->dwVersionMS, This->pVersion->dwVersionLS);
414 break;
416 case DMUS_FOURCC_SCRIPTLANGUAGE_CHUNK: {
417 TRACE_(dmfile)(": script language chunk\n");
418 This->pwzLanguage = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize);
419 IStream_Read (pStm, This->pwzLanguage, Chunk.dwSize, NULL);
420 TRACE_(dmfile)("using language: %s\n", debugstr_w(This->pwzLanguage));
421 break;
423 case DMUS_FOURCC_SCRIPTSOURCE_CHUNK: {
424 TRACE_(dmfile)(": script source chunk\n");
425 This->pwzSource = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize);
426 IStream_Read (pStm, This->pwzSource, Chunk.dwSize, NULL);
427 if (TRACE_ON(dmscript)) {
428 int count = WideCharToMultiByte(CP_ACP, 0, This->pwzSource, -1, NULL, 0, NULL, NULL);
429 LPSTR str = HeapAlloc(GetProcessHeap (), 0, count);
430 WideCharToMultiByte(CP_ACP, 0, This->pwzSource, -1, str, count, NULL, NULL);
431 str[count-1] = '\n';
432 TRACE("source:\n");
433 write( 2, str, count );
434 HeapFree(GetProcessHeap(), 0, str);
436 break;
438 case DMUS_FOURCC_GUID_CHUNK: {
439 TRACE_(dmfile)(": GUID chunk\n");
440 This->dmobj.desc.dwValidData |= DMUS_OBJ_OBJECT;
441 IStream_Read (pStm, &This->dmobj.desc.guidObject, Chunk.dwSize, NULL);
442 break;
444 case DMUS_FOURCC_VERSION_CHUNK: {
445 TRACE_(dmfile)(": version chunk\n");
446 This->dmobj.desc.dwValidData |= DMUS_OBJ_VERSION;
447 IStream_Read (pStm, &This->dmobj.desc.vVersion, Chunk.dwSize, NULL);
448 break;
450 case DMUS_FOURCC_CATEGORY_CHUNK: {
451 TRACE_(dmfile)(": category chunk\n");
452 This->dmobj.desc.dwValidData |= DMUS_OBJ_CATEGORY;
453 IStream_Read (pStm, This->dmobj.desc.wszCategory, Chunk.dwSize, NULL);
454 break;
456 case FOURCC_RIFF: {
457 IDirectMusicObject* pObject = NULL;
458 DMUS_OBJECTDESC desc;
460 ZeroMemory (&desc, sizeof(DMUS_OBJECTDESC));
461 desc.dwSize = sizeof(DMUS_OBJECTDESC);
462 desc.dwValidData = DMUS_OBJ_STREAM | DMUS_OBJ_CLASS;
463 desc.guidClass = CLSID_DirectMusicContainer;
464 desc.pStream = NULL;
465 IStream_Clone (pStm, &desc.pStream);
467 liMove.QuadPart = 0;
468 liMove.QuadPart -= (sizeof(FOURCC) + sizeof(DWORD));
469 IStream_Seek (desc.pStream, liMove, STREAM_SEEK_CUR, NULL);
471 IStream_QueryInterface (pStm, &IID_IDirectMusicGetLoader, (LPVOID*)&pGetLoader);
472 IDirectMusicGetLoader_GetLoader (pGetLoader, &pLoader);
473 IDirectMusicGetLoader_Release (pGetLoader);
475 if (SUCCEEDED(IDirectMusicLoader_GetObject (pLoader, &desc, &IID_IDirectMusicObject, (LPVOID*) &pObject))) {
476 IDirectMusicObject_Release (pObject);
477 } else {
478 ERR_(dmfile)("Error on GetObject while trying to load Scrip SubContainer\n");
481 IDirectMusicLoader_Release (pLoader); pLoader = NULL; /* release loader */
482 IStream_Release(desc.pStream); desc.pStream = NULL; /* release cloned stream */
484 liMove.QuadPart = Chunk.dwSize;
485 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
487 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
488 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
489 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
490 ListCount[0] = 0;
492 switch (Chunk.fccID) {
493 default: {
494 TRACE_(dmfile)(": unknown (skipping)\n");
495 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
496 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
497 break;
501 break;
503 case FOURCC_LIST: {
504 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
505 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
506 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
507 ListCount[0] = 0;
508 switch (Chunk.fccID) {
509 case DMUS_FOURCC_UNFO_LIST: {
510 TRACE_(dmfile)(": UNFO list\n");
511 do {
512 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
513 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
514 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
515 switch (Chunk.fccID) {
516 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
517 (though strings seem to be valid unicode) */
518 case mmioFOURCC('I','N','A','M'):
519 case DMUS_FOURCC_UNAM_CHUNK: {
520 TRACE_(dmfile)(": name chunk\n");
521 This->dmobj.desc.dwValidData |= DMUS_OBJ_NAME;
522 IStream_Read (pStm, This->dmobj.desc.wszName, Chunk.dwSize, NULL);
523 break;
525 case mmioFOURCC('I','A','R','T'):
526 case DMUS_FOURCC_UART_CHUNK: {
527 TRACE_(dmfile)(": artist chunk (ignored)\n");
528 liMove.QuadPart = Chunk.dwSize;
529 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
530 break;
532 case mmioFOURCC('I','C','O','P'):
533 case DMUS_FOURCC_UCOP_CHUNK: {
534 TRACE_(dmfile)(": copyright chunk (ignored)\n");
535 liMove.QuadPart = Chunk.dwSize;
536 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
537 break;
539 case mmioFOURCC('I','S','B','J'):
540 case DMUS_FOURCC_USBJ_CHUNK: {
541 TRACE_(dmfile)(": subject chunk (ignored)\n");
542 liMove.QuadPart = Chunk.dwSize;
543 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
544 break;
546 case mmioFOURCC('I','C','M','T'):
547 case DMUS_FOURCC_UCMT_CHUNK: {
548 TRACE_(dmfile)(": comment chunk (ignored)\n");
549 liMove.QuadPart = Chunk.dwSize;
550 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
551 break;
553 default: {
554 TRACE_(dmfile)(": unknown sub-chunk (irrelevant & skipping)\n");
555 liMove.QuadPart = Chunk.dwSize;
556 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
557 break;
560 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
561 } while (ListCount[0] < ListSize[0]);
562 break;
564 default: {
565 TRACE_(dmfile)(": unknown (skipping)\n");
566 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
567 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
568 break;
571 break;
573 default: {
574 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
575 liMove.QuadPart = Chunk.dwSize;
576 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
577 break;
580 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
581 } while (StreamCount < StreamSize);
582 break;
584 default: {
585 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
586 liMove.QuadPart = StreamSize;
587 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
588 return E_FAIL;
591 TRACE_(dmfile)(": reading finished\n");
592 break;
594 default: {
595 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
596 liMove.QuadPart = Chunk.dwSize;
597 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
598 return E_FAIL;
602 return S_OK;
605 static const IPersistStreamVtbl persiststream_vtbl = {
606 dmobj_IPersistStream_QueryInterface,
607 dmobj_IPersistStream_AddRef,
608 dmobj_IPersistStream_Release,
609 unimpl_IPersistStream_GetClassID,
610 unimpl_IPersistStream_IsDirty,
611 IPersistStreamImpl_Load,
612 unimpl_IPersistStream_Save,
613 unimpl_IPersistStream_GetSizeMax
616 /* for ClassFactory */
617 HRESULT WINAPI DMUSIC_CreateDirectMusicScriptImpl(REFIID lpcGUID, void **ppobj, IUnknown *pUnkOuter)
619 IDirectMusicScriptImpl *obj;
620 HRESULT hr;
622 *ppobj = NULL;
624 if (pUnkOuter)
625 return CLASS_E_NOAGGREGATION;
627 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicScriptImpl));
628 if (!obj)
629 return E_OUTOFMEMORY;
631 obj->IDirectMusicScript_iface.lpVtbl = &dmscript_vtbl;
632 obj->ref = 1;
633 dmobject_init(&obj->dmobj, &CLSID_DirectMusicScript, (IUnknown*)&obj->IDirectMusicScript_iface);
634 obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl;
635 obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
637 DMSCRIPT_LockModule();
638 hr = IDirectMusicScript_QueryInterface(&obj->IDirectMusicScript_iface, lpcGUID, ppobj);
639 IDirectMusicScript_Release(&obj->IDirectMusicScript_iface);
641 return hr;