From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmloader/loader.c | 72 ++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 38 deletions(-)
diff --git a/dlls/dmloader/loader.c b/dlls/dmloader/loader.c index 7b1fb8d04a5..c5801ed32fd 100644 --- a/dlls/dmloader/loader.c +++ b/dlls/dmloader/loader.c @@ -111,12 +111,7 @@ static HRESULT DMUSIC_CopyDescriptor(DMUS_OBJECTDESC *pDst, DMUS_OBJECTDESC *pSr return S_OK; }
-/***************************************************************************** - * IDirectMusicLoaderImpl implementation - */ -/* IUnknown/IDirectMusicLoader(8) part: */ - -static HRESULT WINAPI IDirectMusicLoaderImpl_QueryInterface(IDirectMusicLoader8 *iface, REFIID riid, void **ppobj) +static HRESULT WINAPI loader_QueryInterface(IDirectMusicLoader8 *iface, REFIID riid, void **ppobj) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface);
@@ -133,7 +128,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_QueryInterface(IDirectMusicLoader8 return E_NOINTERFACE; }
-static ULONG WINAPI IDirectMusicLoaderImpl_AddRef(IDirectMusicLoader8 *iface) +static ULONG WINAPI loader_AddRef(IDirectMusicLoader8 *iface) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); ULONG ref = InterlockedIncrement(&This->ref); @@ -143,7 +138,7 @@ static ULONG WINAPI IDirectMusicLoaderImpl_AddRef(IDirectMusicLoader8 *iface) return ref; }
-static ULONG WINAPI IDirectMusicLoaderImpl_Release(IDirectMusicLoader8 *iface) +static ULONG WINAPI loader_Release(IDirectMusicLoader8 *iface) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); ULONG ref = InterlockedDecrement(&This->ref); @@ -251,7 +246,7 @@ static struct cache_entry *find_cache_object(IDirectMusicLoaderImpl *This, DMUS_ return NULL; }
-static HRESULT WINAPI IDirectMusicLoaderImpl_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDESC *pDesc, REFIID riid, void **ppv) +static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDESC *pDesc, REFIID riid, void **ppv) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); HRESULT result = S_OK; @@ -451,7 +446,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_GetObject(IDirectMusicLoader8 *ifac return result; }
-static HRESULT WINAPI IDirectMusicLoaderImpl_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDESC *pDesc) +static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDESC *pDesc) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); LPSTREAM pStream; @@ -575,7 +570,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_SetObject(IDirectMusicLoader8 *ifac return S_OK; }
-static HRESULT WINAPI IDirectMusicLoaderImpl_SetSearchDirectory(IDirectMusicLoader8 *iface, +static HRESULT WINAPI loader_SetSearchDirectory(IDirectMusicLoader8 *iface, REFGUID class, WCHAR *path, BOOL clear) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); @@ -610,7 +605,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_SetSearchDirectory(IDirectMusicLoad return S_OK; }
-static HRESULT WINAPI IDirectMusicLoaderImpl_ScanDirectory(IDirectMusicLoader8 *iface, REFGUID rguidClass, WCHAR *pwzFileExtension, WCHAR *pwzScanFileName) +static HRESULT WINAPI loader_ScanDirectory(IDirectMusicLoader8 *iface, REFGUID rguidClass, WCHAR *pwzFileExtension, WCHAR *pwzScanFileName) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); WIN32_FIND_DATAW FileData; @@ -669,7 +664,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_ScanDirectory(IDirectMusicLoader8 * } while (1); }
-static HRESULT WINAPI IDirectMusicLoaderImpl_CacheObject(IDirectMusicLoader8 *iface, +static HRESULT WINAPI loader_CacheObject(IDirectMusicLoader8 *iface, IDirectMusicObject *object) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); @@ -699,7 +694,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_CacheObject(IDirectMusicLoader8 *if return DMUS_E_LOADER_OBJECTNOTFOUND; }
-static HRESULT WINAPI IDirectMusicLoaderImpl_ReleaseObject(IDirectMusicLoader8 *iface, +static HRESULT WINAPI loader_ReleaseObject(IDirectMusicLoader8 *iface, IDirectMusicObject *object) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); @@ -730,7 +725,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_ReleaseObject(IDirectMusicLoader8 * return S_FALSE; }
-static HRESULT WINAPI IDirectMusicLoaderImpl_ClearCache(IDirectMusicLoader8 *iface, REFGUID class) +static HRESULT WINAPI loader_ClearCache(IDirectMusicLoader8 *iface, REFGUID class) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); struct cache_entry *obj, *obj2; @@ -750,7 +745,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_ClearCache(IDirectMusicLoader8 *ifa return S_OK; }
-static HRESULT WINAPI IDirectMusicLoaderImpl_EnableCache(IDirectMusicLoader8 *iface, REFGUID class, +static HRESULT WINAPI loader_EnableCache(IDirectMusicLoader8 *iface, REFGUID class, BOOL enable) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); @@ -780,7 +775,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_EnableCache(IDirectMusicLoader8 *if return S_OK; }
-static HRESULT WINAPI IDirectMusicLoaderImpl_EnumObject(IDirectMusicLoader8 *iface, REFGUID rguidClass, DWORD dwIndex, DMUS_OBJECTDESC *pDesc) +static HRESULT WINAPI loader_EnumObject(IDirectMusicLoader8 *iface, REFGUID rguidClass, DWORD dwIndex, DMUS_OBJECTDESC *pDesc) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); DWORD dwCount = 0; @@ -808,12 +803,12 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_EnumObject(IDirectMusicLoader8 *ifa return S_FALSE; }
-static void WINAPI IDirectMusicLoaderImpl_CollectGarbage(IDirectMusicLoader8 *iface) +static void WINAPI loader_CollectGarbage(IDirectMusicLoader8 *iface) { FIXME("(%p)->(): stub\n", iface); }
-static HRESULT WINAPI IDirectMusicLoaderImpl_ReleaseObjectByUnknown(IDirectMusicLoader8 *iface, IUnknown *pObject) +static HRESULT WINAPI loader_ReleaseObjectByUnknown(IDirectMusicLoader8 *iface, IUnknown *pObject) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); HRESULT result; @@ -835,13 +830,13 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_ReleaseObjectByUnknown(IDirectMusic return result; }
-static HRESULT WINAPI IDirectMusicLoaderImpl_LoadObjectFromFile(IDirectMusicLoader8 *iface, REFGUID rguidClassID, REFIID iidInterfaceID, WCHAR *pwzFilePath, void **ppObject) +static HRESULT WINAPI loader_LoadObjectFromFile(IDirectMusicLoader8 *iface, REFGUID rguidClassID, REFIID iidInterfaceID, WCHAR *pwzFilePath, void **ppObject) { IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); DMUS_OBJECTDESC ObjDesc; WCHAR wszLoaderSearchPath[MAX_PATH];
- TRACE("(%p, %s, %s, %s, %p): wrapping to IDirectMusicLoaderImpl_GetObject\n", This, debugstr_dmguid(rguidClassID), debugstr_dmguid(iidInterfaceID), debugstr_w(pwzFilePath), ppObject); + TRACE("(%p, %s, %s, %s, %p): wrapping to loader_GetObject\n", This, debugstr_dmguid(rguidClassID), debugstr_dmguid(iidInterfaceID), debugstr_w(pwzFilePath), ppObject);
DM_STRUCT_INIT(&ObjDesc); ObjDesc.dwValidData = DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH | DMUS_OBJ_CLASS; /* I believe I've read somewhere in MSDN that this function requires either full path or relative path */ @@ -866,22 +861,23 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_LoadObjectFromFile(IDirectMusicLoad return IDirectMusicLoader_GetObject(iface, &ObjDesc, iidInterfaceID, ppObject); }
-static const IDirectMusicLoader8Vtbl DirectMusicLoader_Loader_Vtbl = { - IDirectMusicLoaderImpl_QueryInterface, - IDirectMusicLoaderImpl_AddRef, - IDirectMusicLoaderImpl_Release, - IDirectMusicLoaderImpl_GetObject, - IDirectMusicLoaderImpl_SetObject, - IDirectMusicLoaderImpl_SetSearchDirectory, - IDirectMusicLoaderImpl_ScanDirectory, - IDirectMusicLoaderImpl_CacheObject, - IDirectMusicLoaderImpl_ReleaseObject, - IDirectMusicLoaderImpl_ClearCache, - IDirectMusicLoaderImpl_EnableCache, - IDirectMusicLoaderImpl_EnumObject, - IDirectMusicLoaderImpl_CollectGarbage, - IDirectMusicLoaderImpl_ReleaseObjectByUnknown, - IDirectMusicLoaderImpl_LoadObjectFromFile +static const IDirectMusicLoader8Vtbl loader_vtbl = +{ + loader_QueryInterface, + loader_AddRef, + loader_Release, + loader_GetObject, + loader_SetObject, + loader_SetSearchDirectory, + loader_ScanDirectory, + loader_CacheObject, + loader_ReleaseObject, + loader_ClearCache, + loader_EnableCache, + loader_EnumObject, + loader_CollectGarbage, + loader_ReleaseObjectByUnknown, + loader_LoadObjectFromFile, };
/* help function for DMUSIC_SetDefaultDLS */ @@ -912,7 +908,7 @@ HRESULT create_dmloader(REFIID lpcGUID, void **ppobj) TRACE("(%s, %p)\n", debugstr_dmguid(lpcGUID), ppobj); *ppobj = NULL; if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; - obj->IDirectMusicLoader8_iface.lpVtbl = &DirectMusicLoader_Loader_Vtbl; + obj->IDirectMusicLoader8_iface.lpVtbl = &loader_vtbl; obj->ref = 0; /* Will be inited with QueryInterface */ list_init(&obj->cache); /* Caching is enabled by default for all classes */
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmloader/loader.c | 48 ++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/dlls/dmloader/loader.c b/dlls/dmloader/loader.c index c5801ed32fd..9c3a73e9612 100644 --- a/dlls/dmloader/loader.c +++ b/dlls/dmloader/loader.c @@ -1,6 +1,4 @@ /* - * IDirectMusicLoaderImpl - * * Copyright (C) 2003-2004 Rok Mandeljc * * This program is free software; you can redistribute it and/or @@ -45,18 +43,18 @@ struct cache_entry { BOOL bInvalidDefaultDLS; /* workaround for enabling caching of "faulty" default dls collection */ };
-typedef struct IDirectMusicLoaderImpl { +struct loader +{ IDirectMusicLoader8 IDirectMusicLoader8_iface; LONG ref; WCHAR *search_paths[ARRAY_SIZE(classes)]; unsigned int cache_class; struct list cache; -} IDirectMusicLoaderImpl; - +};
-static inline IDirectMusicLoaderImpl* impl_from_IDirectMusicLoader8(IDirectMusicLoader8 *iface) +static inline struct loader *impl_from_IDirectMusicLoader8(IDirectMusicLoader8 *iface) { - return CONTAINING_RECORD(iface, IDirectMusicLoaderImpl, IDirectMusicLoader8_iface); + return CONTAINING_RECORD(iface, struct loader, IDirectMusicLoader8_iface); }
static int index_from_class(REFCLSID class) @@ -70,12 +68,12 @@ static int index_from_class(REFCLSID class) return -1; }
-static inline BOOL is_cache_enabled(IDirectMusicLoaderImpl *This, REFCLSID class) +static inline BOOL is_cache_enabled(struct loader *This, REFCLSID class) { return !!(This->cache_class & 1 << index_from_class(class)); }
-static void get_search_path(IDirectMusicLoaderImpl *This, REFGUID class, WCHAR *path) +static void get_search_path(struct loader *This, REFGUID class, WCHAR *path) { int index = index_from_class(class);
@@ -113,7 +111,7 @@ static HRESULT DMUSIC_CopyDescriptor(DMUS_OBJECTDESC *pDst, DMUS_OBJECTDESC *pSr
static HRESULT WINAPI loader_QueryInterface(IDirectMusicLoader8 *iface, REFIID riid, void **ppobj) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface);
TRACE("(%p, %s, %p)\n",This, debugstr_dmguid(riid), ppobj); if (IsEqualIID (riid, &IID_IUnknown) || @@ -130,7 +128,7 @@ static HRESULT WINAPI loader_QueryInterface(IDirectMusicLoader8 *iface, REFIID r
static ULONG WINAPI loader_AddRef(IDirectMusicLoader8 *iface) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p)->(): new ref = %lu\n", iface, ref); @@ -140,7 +138,7 @@ static ULONG WINAPI loader_AddRef(IDirectMusicLoader8 *iface)
static ULONG WINAPI loader_Release(IDirectMusicLoader8 *iface) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p)->(): new ref = %lu\n", iface, ref); @@ -157,7 +155,7 @@ static ULONG WINAPI loader_Release(IDirectMusicLoader8 *iface) return ref; }
-static struct cache_entry *find_cache_object(IDirectMusicLoaderImpl *This, DMUS_OBJECTDESC *desc) +static struct cache_entry *find_cache_object(struct loader *This, DMUS_OBJECTDESC *desc) { struct cache_entry *existing;
@@ -248,7 +246,7 @@ static struct cache_entry *find_cache_object(IDirectMusicLoaderImpl *This, DMUS_
static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDESC *pDesc, REFIID riid, void **ppv) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); HRESULT result = S_OK; HRESULT ret = S_OK; /* used at the end of function, to determine whether everything went OK */ struct cache_entry *pExistingEntry, *pObjectEntry = NULL; @@ -448,7 +446,7 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE
static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDESC *pDesc) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); LPSTREAM pStream; LPDIRECTMUSICOBJECT pObject; DMUS_OBJECTDESC Desc; @@ -573,7 +571,7 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE static HRESULT WINAPI loader_SetSearchDirectory(IDirectMusicLoader8 *iface, REFGUID class, WCHAR *path, BOOL clear) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); int index = index_from_class(class); DWORD attr;
@@ -607,7 +605,7 @@ static HRESULT WINAPI loader_SetSearchDirectory(IDirectMusicLoader8 *iface,
static HRESULT WINAPI loader_ScanDirectory(IDirectMusicLoader8 *iface, REFGUID rguidClass, WCHAR *pwzFileExtension, WCHAR *pwzScanFileName) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); WIN32_FIND_DATAW FileData; HANDLE hSearch; WCHAR wszSearchString[MAX_PATH]; @@ -667,7 +665,7 @@ static HRESULT WINAPI loader_ScanDirectory(IDirectMusicLoader8 *iface, REFGUID r static HRESULT WINAPI loader_CacheObject(IDirectMusicLoader8 *iface, IDirectMusicObject *object) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); DMUS_OBJECTDESC desc; struct cache_entry *entry;
@@ -697,7 +695,7 @@ static HRESULT WINAPI loader_CacheObject(IDirectMusicLoader8 *iface, static HRESULT WINAPI loader_ReleaseObject(IDirectMusicLoader8 *iface, IDirectMusicObject *object) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); DMUS_OBJECTDESC desc; struct cache_entry *entry;
@@ -727,7 +725,7 @@ static HRESULT WINAPI loader_ReleaseObject(IDirectMusicLoader8 *iface,
static HRESULT WINAPI loader_ClearCache(IDirectMusicLoader8 *iface, REFGUID class) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); struct cache_entry *obj, *obj2;
TRACE("(%p, %s)\n", This, debugstr_dmguid(class)); @@ -748,7 +746,7 @@ static HRESULT WINAPI loader_ClearCache(IDirectMusicLoader8 *iface, REFGUID clas static HRESULT WINAPI loader_EnableCache(IDirectMusicLoader8 *iface, REFGUID class, BOOL enable) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); BOOL current;
TRACE("(%p, %s, %d)\n", This, debugstr_dmguid(class), enable); @@ -777,7 +775,7 @@ static HRESULT WINAPI loader_EnableCache(IDirectMusicLoader8 *iface, REFGUID cla
static HRESULT WINAPI loader_EnumObject(IDirectMusicLoader8 *iface, REFGUID rguidClass, DWORD dwIndex, DMUS_OBJECTDESC *pDesc) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); DWORD dwCount = 0; struct cache_entry *pObjectEntry; TRACE("(%p, %s, %ld, %p)\n", This, debugstr_dmguid(rguidClass), dwIndex, pDesc); @@ -810,7 +808,7 @@ static void WINAPI loader_CollectGarbage(IDirectMusicLoader8 *iface)
static HRESULT WINAPI loader_ReleaseObjectByUnknown(IDirectMusicLoader8 *iface, IUnknown *pObject) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); HRESULT result; LPDIRECTMUSICOBJECT pObjectInterface; @@ -832,7 +830,7 @@ static HRESULT WINAPI loader_ReleaseObjectByUnknown(IDirectMusicLoader8 *iface,
static HRESULT WINAPI loader_LoadObjectFromFile(IDirectMusicLoader8 *iface, REFGUID rguidClassID, REFIID iidInterfaceID, WCHAR *pwzFilePath, void **ppObject) { - IDirectMusicLoaderImpl *This = impl_from_IDirectMusicLoader8(iface); + struct loader *This = impl_from_IDirectMusicLoader8(iface); DMUS_OBJECTDESC ObjDesc; WCHAR wszLoaderSearchPath[MAX_PATH];
@@ -900,7 +898,7 @@ static HRESULT DMUSIC_GetDefaultGMPath (WCHAR wszPath[MAX_PATH]) { /* for ClassFactory */ HRESULT create_dmloader(REFIID lpcGUID, void **ppobj) { - IDirectMusicLoaderImpl *obj; + struct loader *obj; DMUS_OBJECTDESC Desc; struct cache_entry *dls; struct list *pEntry;
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmloader/loader.c | 70 ++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 33 deletions(-)
diff --git a/dlls/dmloader/loader.c b/dlls/dmloader/loader.c index 9c3a73e9612..3d51b65c335 100644 --- a/dlls/dmloader/loader.c +++ b/dlls/dmloader/loader.c @@ -898,37 +898,41 @@ static HRESULT DMUSIC_GetDefaultGMPath (WCHAR wszPath[MAX_PATH]) { /* for ClassFactory */ HRESULT create_dmloader(REFIID lpcGUID, void **ppobj) { - struct loader *obj; - DMUS_OBJECTDESC Desc; - struct cache_entry *dls; - struct list *pEntry; - - TRACE("(%s, %p)\n", debugstr_dmguid(lpcGUID), ppobj); - *ppobj = NULL; - if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; - obj->IDirectMusicLoader8_iface.lpVtbl = &loader_vtbl; - obj->ref = 0; /* Will be inited with QueryInterface */ - list_init(&obj->cache); - /* Caching is enabled by default for all classes */ - obj->cache_class = ~0; - - /* set default DLS collection (via SetObject... so that loading via DMUS_OBJ_OBJECT is possible) */ - DM_STRUCT_INIT(&Desc); - Desc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH | DMUS_OBJ_OBJECT; - Desc.guidClass = CLSID_DirectMusicCollection; - Desc.guidObject = GUID_DefaultGMCollection; - DMUSIC_GetDefaultGMPath (Desc.wszFileName); - IDirectMusicLoader_SetObject(&obj->IDirectMusicLoader8_iface, &Desc); - /* and now the workaroundTM for "invalid" default DLS; basically, - my tests showed that if GUID chunk is present in default DLS - collection, loader treats it as "invalid" and returns - DMUS_E_LOADER_NOFILENAME for all requests for it; basically, we check - if out input guidObject was overwritten */ - pEntry = list_head(&obj->cache); - dls = LIST_ENTRY(pEntry, struct cache_entry, entry); - if (!IsEqualGUID(&Desc.guidObject, &GUID_DefaultGMCollection)) { - dls->bInvalidDefaultDLS = TRUE; - } - - return IDirectMusicLoader_QueryInterface(&obj->IDirectMusicLoader8_iface, lpcGUID, ppobj); + struct loader *obj; + DMUS_OBJECTDESC Desc; + struct cache_entry *dls; + struct list *pEntry; + HRESULT hr; + + TRACE("(%s, %p)\n", debugstr_dmguid(lpcGUID), ppobj); + + *ppobj = NULL; + if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; + obj->IDirectMusicLoader8_iface.lpVtbl = &loader_vtbl; + obj->ref = 1; + list_init(&obj->cache); + /* Caching is enabled by default for all classes */ + obj->cache_class = ~0; + + /* set default DLS collection (via SetObject... so that loading via DMUS_OBJ_OBJECT is possible) */ + DM_STRUCT_INIT(&Desc); + Desc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH | DMUS_OBJ_OBJECT; + Desc.guidClass = CLSID_DirectMusicCollection; + Desc.guidObject = GUID_DefaultGMCollection; + DMUSIC_GetDefaultGMPath(Desc.wszFileName); + IDirectMusicLoader_SetObject(&obj->IDirectMusicLoader8_iface, &Desc); + + /* and now the workaroundTM for "invalid" default DLS; basically, + my tests showed that if GUID chunk is present in default DLS + collection, loader treats it as "invalid" and returns + DMUS_E_LOADER_NOFILENAME for all requests for it; basically, we check + if out input guidObject was overwritten */ + pEntry = list_head(&obj->cache); + dls = LIST_ENTRY(pEntry, struct cache_entry, entry); + if (!IsEqualGUID(&Desc.guidObject, &GUID_DefaultGMCollection)) + dls->bInvalidDefaultDLS = TRUE; + + hr = IDirectMusicLoader_QueryInterface(&obj->IDirectMusicLoader8_iface, lpcGUID, ppobj); + IDirectMusicLoader_Release(&obj->IDirectMusicLoader8_iface); + return hr; }
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmloader/dmloader_private.h | 18 +- dlls/dmloader/loader.c | 51 ++-- dlls/dmloader/loaderstream.c | 383 ++++++++++++++++++++----------- 3 files changed, 289 insertions(+), 163 deletions(-)
diff --git a/dlls/dmloader/dmloader_private.h b/dlls/dmloader/dmloader_private.h index 0aea1ba8499..bd5777f54f1 100644 --- a/dlls/dmloader/dmloader_private.h +++ b/dlls/dmloader/dmloader_private.h @@ -69,18 +69,15 @@ extern HRESULT DMUSIC_CreateDirectMusicLoaderGenericStream(void **ppobj); struct IDirectMusicLoaderFileStream { /* VTABLEs */ const IStreamVtbl *StreamVtbl; - const IDirectMusicGetLoaderVtbl *GetLoaderVtbl; /* reference counter */ LONG dwRef; /* file */ WCHAR wzFileName[MAX_PATH]; /* for clone */ HANDLE hFile; - /* loader */ - LPDIRECTMUSICLOADER8 pLoader; };
/* Custom: */ -extern HRESULT WINAPI IDirectMusicLoaderFileStream_Attach (LPSTREAM iface, LPCWSTR wzFile, LPDIRECTMUSICLOADER8 pLoader); +extern HRESULT WINAPI IDirectMusicLoaderFileStream_Attach(LPSTREAM iface, LPCWSTR wzFile);
/***************************************************************************** * IDirectMusicLoaderResourceStream implementation structure @@ -88,7 +85,6 @@ extern HRESULT WINAPI IDirectMusicLoaderFileStream_Attach (LPSTREAM iface, LPCWS struct IDirectMusicLoaderResourceStream { /* IUnknown fields */ const IStreamVtbl *StreamVtbl; - const IDirectMusicGetLoaderVtbl *GetLoaderVtbl; /* reference counter */ LONG dwRef; /* data */ @@ -96,12 +92,11 @@ struct IDirectMusicLoaderResourceStream { LONGLONG llMemLength; /* current position */ LONGLONG llPos; - /* loader */ - LPDIRECTMUSICLOADER8 pLoader; };
/* Custom: */ -extern HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach (LPSTREAM iface, LPBYTE pbMemData, LONGLONG llMemLength, LONGLONG llPos, LPDIRECTMUSICLOADER8 pLoader); +extern HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach(LPSTREAM iface, LPBYTE pbMemData, + LONGLONG llMemLength, LONGLONG llPos);
/***************************************************************************** * IDirectMusicLoaderGenericStream implementation structure @@ -109,17 +104,16 @@ extern HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach (LPSTREAM iface, L struct IDirectMusicLoaderGenericStream { /* IUnknown fields */ const IStreamVtbl *StreamVtbl; - const IDirectMusicGetLoaderVtbl *GetLoaderVtbl; /* reference counter */ LONG dwRef; /* stream */ LPSTREAM pStream; - /* loader */ - LPDIRECTMUSICLOADER8 pLoader; };
/* Custom: */ -extern HRESULT WINAPI IDirectMusicLoaderGenericStream_Attach (LPSTREAM iface, LPSTREAM pStream, LPDIRECTMUSICLOADER8 pLoader); +extern HRESULT WINAPI IDirectMusicLoaderGenericStream_Attach(LPSTREAM iface, LPSTREAM pStream); + +extern HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, IStream **ret_iface);
#include "debug.h"
diff --git a/dlls/dmloader/loader.c b/dlls/dmloader/loader.c index 3d51b65c335..a0683307f8f 100644 --- a/dlls/dmloader/loader.c +++ b/dlls/dmloader/loader.c @@ -256,8 +256,10 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE LPDIRECTMUSICOBJECT pObject; DMUS_OBJECTDESC GotDesc; BOOL bCache; + IStream *loader_stream; + HRESULT hr;
- TRACE("(%p)->(%p, %s, %p)\n", This, pDesc, debugstr_dmguid(riid), ppv); + TRACE("(%p)->(%p, %s, %p)\n", This, pDesc, debugstr_dmguid(riid), ppv);
if (TRACE_ON(dmloader)) dump_DMUS_OBJECTDESC(pDesc); @@ -329,8 +331,9 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE ERR(": could not create file stream\n"); return result; } - result = IDirectMusicLoaderFileStream_Attach (pStream, wszFileName, iface); - if (FAILED(result)) { + result = IDirectMusicLoaderFileStream_Attach(pStream, wszFileName); + if (FAILED(result)) + { ERR(": could not attach stream to file\n"); IStream_Release (pStream); return result; @@ -345,8 +348,9 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE ERR(": could not create resource stream\n"); return result; } - result = IDirectMusicLoaderResourceStream_Attach (pStream, pDesc->pbMemData, pDesc->llMemLength, 0, iface); - if (FAILED(result)) { + result = IDirectMusicLoaderResourceStream_Attach(pStream, pDesc->pbMemData, pDesc->llMemLength, 0); + if (FAILED(result)) + { ERR(": could not attach stream to resource\n"); IStream_Release (pStream); return result; @@ -361,8 +365,9 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE ERR(": could not create generic stream\n"); return result; } - result = IDirectMusicLoaderGenericStream_Attach (pStream, pDesc->pStream, iface); - if (FAILED(result)) { + result = IDirectMusicLoaderGenericStream_Attach(pStream, pDesc->pStream); + if (FAILED(result)) + { ERR(": failed to attach stream\n"); IStream_Release (pStream); return result; @@ -373,7 +378,12 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE return DMUS_E_LOADER_NOFILENAME; /* test shows this is returned */ }
- /* create object */ + if (FAILED(hr = loader_stream_create((IDirectMusicLoader *)iface, pStream, &loader_stream))) + return hr; + IStream_Release(pStream); + pStream = loader_stream; + + /* create object */ result = CoCreateInstance (&pDesc->guidClass, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicObject, (LPVOID*)&pObject); if (FAILED(result)) { IStream_Release(pStream); @@ -451,7 +461,8 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE LPDIRECTMUSICOBJECT pObject; DMUS_OBJECTDESC Desc; struct cache_entry *pObjectEntry, *pNewEntry; - HRESULT hr; + IStream *loader_stream; + HRESULT hr;
TRACE("(%p)->(%p)\n", This, pDesc);
@@ -480,8 +491,9 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE return DMUS_E_LOADER_FAILEDOPEN; } /* attach stream */ - hr = IDirectMusicLoaderFileStream_Attach (pStream, wszFileName, iface); - if (FAILED(hr)) { + hr = IDirectMusicLoaderFileStream_Attach(pStream, wszFileName); + if (FAILED(hr)) + { ERR(": could not attach stream to file %s, make sure it exists\n", debugstr_w(wszFileName)); IStream_Release (pStream); return DMUS_E_LOADER_FAILEDOPEN; @@ -495,8 +507,9 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE return DMUS_E_LOADER_FAILEDOPEN; } /* attach stream */ - hr = IDirectMusicLoaderGenericStream_Attach (pStream, pDesc->pStream, iface); - if (FAILED(hr)) { + hr = IDirectMusicLoaderGenericStream_Attach(pStream, pDesc->pStream); + if (FAILED(hr)) + { ERR(": could not attach stream\n"); IStream_Release (pStream); return DMUS_E_LOADER_FAILEDOPEN; @@ -510,8 +523,9 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE return DMUS_E_LOADER_FAILEDOPEN; } /* attach stream */ - hr = IDirectMusicLoaderResourceStream_Attach (pStream, pDesc->pbMemData, pDesc->llMemLength, 0, iface); - if (FAILED(hr)) { + hr = IDirectMusicLoaderResourceStream_Attach(pStream, pDesc->pbMemData, pDesc->llMemLength, 0); + if (FAILED(hr)) + { ERR(": could not attach stream to resource\n"); IStream_Release (pStream); return DMUS_E_LOADER_FAILEDOPEN; @@ -522,7 +536,12 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE return DMUS_E_LOADER_FAILEDOPEN; }
- /* create object */ + if (FAILED(hr = loader_stream_create((IDirectMusicLoader *)iface, pStream, &loader_stream))) + return hr; + IStream_Release(pStream); + pStream = loader_stream; + + /* create object */ hr = CoCreateInstance (&pDesc->guidClass, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicObject, (LPVOID*)&pObject); if (FAILED(hr)) { IStream_Release(pStream); diff --git a/dlls/dmloader/loaderstream.c b/dlls/dmloader/loaderstream.c index 5d6c5ad3e25..3e01d423483 100644 --- a/dlls/dmloader/loaderstream.c +++ b/dlls/dmloader/loaderstream.c @@ -49,12 +49,244 @@ WINE_DEFAULT_DEBUG_CHANNEL(dmloader); WINE_DECLARE_DEBUG_CHANNEL(dmfileraw);
+struct loader_stream +{ + IStream IStream_iface; + IDirectMusicGetLoader IDirectMusicGetLoader_iface; + LONG ref; + + IStream *stream; + IDirectMusicLoader *loader; +}; + +static struct loader_stream *impl_from_IStream(IStream *iface) +{ + return CONTAINING_RECORD(iface, struct loader_stream, IStream_iface); +} + +static HRESULT WINAPI loader_stream_QueryInterface(IStream *iface, REFIID riid, void **ret_iface) +{ + struct loader_stream *This = impl_from_IStream(iface); + + TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface); + + if (IsEqualGUID(riid, &IID_IUnknown) + || IsEqualGUID(riid, &IID_IStream)) + { + IStream_AddRef(&This->IStream_iface); + *ret_iface = &This->IStream_iface; + return S_OK; + } + + if (IsEqualGUID(riid, &IID_IDirectMusicGetLoader)) + { + IDirectMusicGetLoader_AddRef(&This->IDirectMusicGetLoader_iface); + *ret_iface = &This->IDirectMusicGetLoader_iface; + return S_OK; + } + + WARN("(%p, %s, %p): not found\n", iface, debugstr_dmguid(riid), ret_iface); + *ret_iface = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI loader_stream_AddRef(IStream *iface) +{ + struct loader_stream *This = impl_from_IStream(iface); + ULONG ref = InterlockedIncrement(&This->ref); + TRACE("(%p): new ref = %lu\n", This, ref); + return ref; +} + +static ULONG WINAPI loader_stream_Release(IStream *iface) +{ + struct loader_stream *This = impl_from_IStream(iface); + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p): new ref = %lu\n", This, ref); + + if (!ref) + { + IDirectMusicLoader_Release(This->loader); + IStream_Release(This->stream); + free(This); + } + + return ref; +} + +static HRESULT WINAPI loader_stream_Read(IStream *iface, void *data, ULONG size, ULONG *ret_size) +{ + struct loader_stream *This = impl_from_IStream(iface); + TRACE("(%p, %p, %#lx, %p)\n", This, data, size, ret_size); + return IStream_Read(This->stream, data, size, ret_size); +} + +static HRESULT WINAPI loader_stream_Write(IStream *iface, const void *data, ULONG size, ULONG *ret_size) +{ + struct loader_stream *This = impl_from_IStream(iface); + FIXME("(%p): stub\n", This); + return E_NOTIMPL; +} + +static HRESULT WINAPI loader_stream_Seek(IStream *iface, LARGE_INTEGER offset, DWORD method, ULARGE_INTEGER *ret_offset) +{ + struct loader_stream *This = impl_from_IStream(iface); + TRACE("(%p, %I64d, %#lx, %p)\n", This, offset.QuadPart, method, ret_offset); + return IStream_Seek(This->stream, offset, method, ret_offset); +} + +static HRESULT WINAPI loader_stream_SetSize(IStream *iface, ULARGE_INTEGER size) +{ + struct loader_stream *This = impl_from_IStream(iface); + FIXME("(%p): stub\n", This); + return E_NOTIMPL; +} + +static HRESULT WINAPI loader_stream_CopyTo(IStream *iface, IStream *dest, ULARGE_INTEGER size, + ULARGE_INTEGER *read_size, ULARGE_INTEGER *write_size) +{ + struct loader_stream *This = impl_from_IStream(iface); + FIXME("(%p): stub\n", This); + return E_NOTIMPL; +} + +static HRESULT WINAPI loader_stream_Commit(IStream *iface, DWORD flags) +{ + struct loader_stream *This = impl_from_IStream(iface); + FIXME("(%p): stub\n", This); + return E_NOTIMPL; +} + +static HRESULT WINAPI loader_stream_Revert(IStream *iface) +{ + struct loader_stream *This = impl_from_IStream(iface); + FIXME("(%p): stub\n", This); + return E_NOTIMPL; +} + +static HRESULT WINAPI loader_stream_LockRegion(IStream *iface, ULARGE_INTEGER offset, ULARGE_INTEGER size, DWORD type) +{ + struct loader_stream *This = impl_from_IStream(iface); + FIXME("(%p): stub\n", This); + return E_NOTIMPL; +} + +static HRESULT WINAPI loader_stream_UnlockRegion(IStream *iface, ULARGE_INTEGER offset, + ULARGE_INTEGER size, DWORD type) +{ + struct loader_stream *This = impl_from_IStream(iface); + FIXME("(%p): stub\n", This); + return E_NOTIMPL; +} + +static HRESULT WINAPI loader_stream_Stat(IStream *iface, STATSTG *stat, DWORD flags) +{ + struct loader_stream *This = impl_from_IStream(iface); + FIXME("(%p): stub\n", This); + return E_NOTIMPL; +} + +static HRESULT WINAPI loader_stream_Clone(IStream *iface, IStream **ret_iface) +{ + struct loader_stream *This = impl_from_IStream(iface); + IStream *stream; + HRESULT hr; + + TRACE("(%p, %p)\n", This, ret_iface); + + if (SUCCEEDED(hr = IStream_Clone(This->stream, &stream))) + { + hr = loader_stream_create(This->loader, stream, ret_iface); + IStream_Release(stream); + } + + return hr; +} + +static const IStreamVtbl loader_stream_vtbl = +{ + loader_stream_QueryInterface, + loader_stream_AddRef, + loader_stream_Release, + loader_stream_Read, + loader_stream_Write, + loader_stream_Seek, + loader_stream_SetSize, + loader_stream_CopyTo, + loader_stream_Commit, + loader_stream_Revert, + loader_stream_LockRegion, + loader_stream_UnlockRegion, + loader_stream_Stat, + loader_stream_Clone, +}; + +static struct loader_stream *impl_from_IDirectMusicGetLoader(IDirectMusicGetLoader *iface) +{ + return CONTAINING_RECORD(iface, struct loader_stream, IDirectMusicGetLoader_iface); +} + +static HRESULT WINAPI loader_stream_getter_QueryInterface(IDirectMusicGetLoader *iface, REFIID iid, void **out) +{ + struct loader_stream *This = impl_from_IDirectMusicGetLoader(iface); + return IStream_QueryInterface(&This->IStream_iface, iid, out); +} + +static ULONG WINAPI loader_stream_getter_AddRef(IDirectMusicGetLoader *iface) +{ + struct loader_stream *This = impl_from_IDirectMusicGetLoader(iface); + return IStream_AddRef(&This->IStream_iface); +} + +static ULONG WINAPI loader_stream_getter_Release(IDirectMusicGetLoader *iface) +{ + struct loader_stream *This = impl_from_IDirectMusicGetLoader(iface); + return IStream_Release(&This->IStream_iface); +} + +static HRESULT WINAPI loader_stream_getter_GetLoader(IDirectMusicGetLoader *iface, IDirectMusicLoader **ret_loader) +{ + struct loader_stream *This = impl_from_IDirectMusicGetLoader(iface); + + TRACE("(%p, %p)\n", This, ret_loader); + + *ret_loader = This->loader; + IDirectMusicLoader_AddRef(This->loader); + return S_OK; +} + +static const IDirectMusicGetLoaderVtbl loader_stream_getter_vtbl = +{ + loader_stream_getter_QueryInterface, + loader_stream_getter_AddRef, + loader_stream_getter_Release, + loader_stream_getter_GetLoader, +}; + +HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, + IStream **ret_iface) +{ + struct loader_stream *obj; + + *ret_iface = NULL; + if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; + obj->IStream_iface.lpVtbl = &loader_stream_vtbl; + obj->IDirectMusicGetLoader_iface.lpVtbl = &loader_stream_getter_vtbl; + obj->ref = 1; + + obj->stream = stream; + IStream_AddRef(stream); + obj->loader = loader; + IDirectMusicLoader_AddRef(loader); + + *ret_iface = &obj->IStream_iface; + return S_OK; +} + static ULONG WINAPI IDirectMusicLoaderFileStream_IStream_AddRef (LPSTREAM iface); -static ULONG WINAPI IDirectMusicLoaderFileStream_IDirectMusicGetLoader_AddRef (LPDIRECTMUSICGETLOADER iface); -static ULONG WINAPI IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_AddRef (LPDIRECTMUSICGETLOADER iface); static ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_AddRef (LPSTREAM iface); static ULONG WINAPI IDirectMusicLoaderGenericStream_IStream_AddRef (LPSTREAM iface); -static ULONG WINAPI IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_AddRef (LPDIRECTMUSICGETLOADER iface);
/***************************************************************************** @@ -69,9 +301,10 @@ static void IDirectMusicLoaderFileStream_Detach (LPSTREAM iface) { This->wzFileName[0] = '\0'; }
-HRESULT WINAPI IDirectMusicLoaderFileStream_Attach (LPSTREAM iface, LPCWSTR wzFile, LPDIRECTMUSICLOADER8 pLoader) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface); - TRACE("(%p, %s, %p)\n", This, debugstr_w(wzFile), pLoader); +HRESULT WINAPI IDirectMusicLoaderFileStream_Attach(LPSTREAM iface, LPCWSTR wzFile) +{ + ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface); + TRACE("(%p, %s)\n", This, debugstr_w(wzFile)); IDirectMusicLoaderFileStream_Detach (iface); This->hFile = CreateFileW (wzFile, (GENERIC_READ | GENERIC_WRITE), (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (This->hFile == INVALID_HANDLE_VALUE) { @@ -79,7 +312,6 @@ HRESULT WINAPI IDirectMusicLoaderFileStream_Attach (LPSTREAM iface, LPCWSTR wzFi return DMUS_E_LOADER_FAILEDOPEN; } /* create IDirectMusicGetLoader */ - This->pLoader = pLoader; lstrcpynW (This->wzFileName, wzFile, MAX_PATH); TRACE(": succeeded\n"); return S_OK; @@ -96,10 +328,6 @@ static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_QueryInterface (LPSTR *ppobj = &This->StreamVtbl; IDirectMusicLoaderFileStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl); return S_OK; - } else if (IsEqualIID (riid, &IID_IDirectMusicGetLoader)) { - *ppobj = &This->GetLoaderVtbl; - IDirectMusicLoaderFileStream_IDirectMusicGetLoader_AddRef ((LPDIRECTMUSICGETLOADER)&This->GetLoaderVtbl); - return S_OK; }
WARN(": not found\n"); @@ -166,8 +394,9 @@ static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Clone (LPSTREAM iface if (FAILED(result)) return result; if (This->hFile != INVALID_HANDLE_VALUE) { ULARGE_INTEGER ullCurrentPosition; - result = IDirectMusicLoaderFileStream_Attach (pOther, This->wzFileName, This->pLoader); - if (SUCCEEDED(result)) { + result = IDirectMusicLoaderFileStream_Attach(pOther, This->wzFileName); + if (SUCCEEDED(result)) + { LARGE_INTEGER liZero; liZero.QuadPart = 0; result = IDirectMusicLoaderFileStream_IStream_Seek (iface, liZero, STREAM_SEEK_CUR, &ullCurrentPosition); /* get current position in current stream */ @@ -253,39 +482,6 @@ static const IStreamVtbl DirectMusicLoaderFileStream_Stream_Vtbl = { IDirectMusicLoaderFileStream_IStream_Clone };
-/* IDirectMusicGetLoader part: */ -static HRESULT WINAPI IDirectMusicLoaderFileStream_IDirectMusicGetLoader_QueryInterface (LPDIRECTMUSICGETLOADER iface, REFIID riid, void** ppobj) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, GetLoaderVtbl, iface); - return IDirectMusicLoaderFileStream_IStream_QueryInterface ((LPSTREAM)&This->StreamVtbl, riid, ppobj); -} - -static ULONG WINAPI IDirectMusicLoaderFileStream_IDirectMusicGetLoader_AddRef (LPDIRECTMUSICGETLOADER iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, GetLoaderVtbl, iface); - return IDirectMusicLoaderFileStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl); -} - -static ULONG WINAPI IDirectMusicLoaderFileStream_IDirectMusicGetLoader_Release (LPDIRECTMUSICGETLOADER iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, GetLoaderVtbl, iface); - return IDirectMusicLoaderFileStream_IStream_Release ((LPSTREAM)&This->StreamVtbl); -} - -static HRESULT WINAPI IDirectMusicLoaderFileStream_IDirectMusicGetLoader_GetLoader (LPDIRECTMUSICGETLOADER iface, IDirectMusicLoader **ppLoader) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, GetLoaderVtbl, iface); - - TRACE("(%p, %p)\n", This, ppLoader); - *ppLoader = (LPDIRECTMUSICLOADER)This->pLoader; - IDirectMusicLoader8_AddRef ((LPDIRECTMUSICLOADER8)*ppLoader); - - return S_OK; -} - -static const IDirectMusicGetLoaderVtbl DirectMusicLoaderFileStream_GetLoader_Vtbl = { - IDirectMusicLoaderFileStream_IDirectMusicGetLoader_QueryInterface, - IDirectMusicLoaderFileStream_IDirectMusicGetLoader_AddRef, - IDirectMusicLoaderFileStream_IDirectMusicGetLoader_Release, - IDirectMusicLoaderFileStream_IDirectMusicGetLoader_GetLoader -}; - HRESULT DMUSIC_CreateDirectMusicLoaderFileStream (void** ppobj) { IDirectMusicLoaderFileStream *obj;
@@ -294,7 +490,6 @@ HRESULT DMUSIC_CreateDirectMusicLoaderFileStream (void** ppobj) { *ppobj = NULL; if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; obj->StreamVtbl = &DirectMusicLoaderFileStream_Stream_Vtbl; - obj->GetLoaderVtbl = &DirectMusicLoaderFileStream_GetLoader_Vtbl; obj->dwRef = 0; /* will be inited with QueryInterface */
return IDirectMusicLoaderFileStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj); @@ -314,10 +509,10 @@ static void IDirectMusicLoaderResourceStream_Detach (LPSTREAM iface) { This->llMemLength = 0; }
-HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach (LPSTREAM iface, LPBYTE pbMemData, LONGLONG llMemLength, LONGLONG llPos, LPDIRECTMUSICLOADER8 pLoader) { +HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach (LPSTREAM iface, LPBYTE pbMemData, LONGLONG llMemLength, LONGLONG llPos) { ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface);
- TRACE("(%p, %p, %s, %s, %p)\n", This, pbMemData, wine_dbgstr_longlong(llMemLength), wine_dbgstr_longlong(llPos), pLoader); + TRACE("(%p, %p, %s, %s)\n", This, pbMemData, wine_dbgstr_longlong(llMemLength), wine_dbgstr_longlong(llPos)); if (!pbMemData || !llMemLength) { WARN(": invalid pbMemData or llMemLength\n"); return E_FAIL; @@ -326,7 +521,6 @@ HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach (LPSTREAM iface, LPBYTE p This->pbMemData = pbMemData; This->llMemLength = llMemLength; This->llPos = llPos; - This->pLoader = pLoader; return S_OK; } @@ -342,10 +536,6 @@ static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_QueryInterface (L *ppobj = &This->StreamVtbl; IDirectMusicLoaderResourceStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl); return S_OK; - } else if (IsEqualIID (riid, &IID_IDirectMusicGetLoader)) { - *ppobj = &This->GetLoaderVtbl; - IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_AddRef ((LPDIRECTMUSICGETLOADER)&This->GetLoaderVtbl); - return S_OK; }
WARN(": not found\n"); @@ -444,7 +634,7 @@ static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Clone (LPSTREAM i result = DMUSIC_CreateDirectMusicLoaderResourceStream ((LPVOID*)&pOther); if (FAILED(result)) return result; - IDirectMusicLoaderResourceStream_Attach (pOther, This->pbMemData, This->llMemLength, This->llPos, This->pLoader); + IDirectMusicLoaderResourceStream_Attach (pOther, This->pbMemData, This->llMemLength, This->llPos);
TRACE(": succeeded\n"); *ppstm = pOther; @@ -508,39 +698,6 @@ static const IStreamVtbl DirectMusicLoaderResourceStream_Stream_Vtbl = { IDirectMusicLoaderResourceStream_IStream_Clone };
-/* IDirectMusicGetLoader part: */ -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_QueryInterface (LPDIRECTMUSICGETLOADER iface, REFIID riid, void** ppobj) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, GetLoaderVtbl, iface); - return IDirectMusicLoaderResourceStream_IStream_QueryInterface ((LPSTREAM)&This->StreamVtbl, riid, ppobj); -} - -static ULONG WINAPI IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_AddRef (LPDIRECTMUSICGETLOADER iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, GetLoaderVtbl, iface); - return IDirectMusicLoaderResourceStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl); -} - -static ULONG WINAPI IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_Release (LPDIRECTMUSICGETLOADER iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, GetLoaderVtbl, iface); - return IDirectMusicLoaderResourceStream_IStream_Release ((LPSTREAM)&This->StreamVtbl); -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_GetLoader (LPDIRECTMUSICGETLOADER iface, IDirectMusicLoader **ppLoader) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, GetLoaderVtbl, iface); - - TRACE("(%p, %p)\n", This, ppLoader); - *ppLoader = (LPDIRECTMUSICLOADER)This->pLoader; - IDirectMusicLoader8_AddRef ((LPDIRECTMUSICLOADER8)*ppLoader); - - return S_OK; -} - -static const IDirectMusicGetLoaderVtbl DirectMusicLoaderResourceStream_GetLoader_Vtbl = { - IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_QueryInterface, - IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_AddRef, - IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_Release, - IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_GetLoader -}; - HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream (void** ppobj) { IDirectMusicLoaderResourceStream *obj;
@@ -549,7 +706,6 @@ HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream (void** ppobj) { *ppobj = NULL; if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; obj->StreamVtbl = &DirectMusicLoaderResourceStream_Stream_Vtbl; - obj->GetLoaderVtbl = &DirectMusicLoaderResourceStream_GetLoader_Vtbl; obj->dwRef = 0; /* will be inited with QueryInterface */
return IDirectMusicLoaderResourceStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj); @@ -569,22 +725,17 @@ static void IDirectMusicLoaderGenericStream_Detach (LPSTREAM iface) { This->pStream = NULL; }
-HRESULT WINAPI IDirectMusicLoaderGenericStream_Attach (LPSTREAM iface, LPSTREAM pStream, LPDIRECTMUSICLOADER8 pLoader) { +HRESULT WINAPI IDirectMusicLoaderGenericStream_Attach (LPSTREAM iface, LPSTREAM pStream) { ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
- TRACE("(%p, %p, %p)\n", This, pStream, pLoader); + TRACE("(%p, %p)\n", This, pStream); if (!pStream) { WARN(": invalid pStream\n"); return E_FAIL; } - if (!pLoader) { - WARN(": invalid pLoader\n"); - return E_FAIL; - } IDirectMusicLoaderGenericStream_Detach (iface); IStream_Clone (pStream, &This->pStream); - This->pLoader = pLoader; return S_OK; } @@ -600,10 +751,6 @@ static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_QueryInterface (LP *ppobj = &This->StreamVtbl; IDirectMusicLoaderGenericStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl); return S_OK; - } else if (IsEqualIID (riid, &IID_IDirectMusicGetLoader)) { - *ppobj = &This->GetLoaderVtbl; - IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_AddRef ((LPDIRECTMUSICGETLOADER)&This->GetLoaderVtbl); - return S_OK; }
WARN(": not found\n"); @@ -662,7 +809,7 @@ static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Clone (LPSTREAM if IStream_Release(pOther); return E_FAIL; } - IDirectMusicLoaderGenericStream_Attach (pOther, pLowLevel, This->pLoader); + IDirectMusicLoaderGenericStream_Attach (pOther, pLowLevel);
TRACE(": succeeded\n"); *ppstm = pOther; @@ -758,39 +905,6 @@ static const IStreamVtbl DirectMusicLoaderGenericStream_Stream_Vtbl = { IDirectMusicLoaderGenericStream_IStream_Clone };
-/* IDirectMusicGetLoader part: */ -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_QueryInterface (LPDIRECTMUSICGETLOADER iface, REFIID riid, void** ppobj) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, GetLoaderVtbl, iface); - return IDirectMusicLoaderGenericStream_IStream_QueryInterface ((LPSTREAM)&This->StreamVtbl, riid, ppobj); -} - -static ULONG WINAPI IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_AddRef (LPDIRECTMUSICGETLOADER iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, GetLoaderVtbl, iface); - return IDirectMusicLoaderGenericStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl); -} - -static ULONG WINAPI IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_Release (LPDIRECTMUSICGETLOADER iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, GetLoaderVtbl, iface); - return IDirectMusicLoaderGenericStream_IStream_Release ((LPSTREAM)&This->StreamVtbl); -} - -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_GetLoader (LPDIRECTMUSICGETLOADER iface, IDirectMusicLoader **ppLoader) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, GetLoaderVtbl, iface); - - TRACE("(%p, %p)\n", This, ppLoader); - *ppLoader = (LPDIRECTMUSICLOADER)This->pLoader; - IDirectMusicLoader8_AddRef ((LPDIRECTMUSICLOADER8)*ppLoader); - - return S_OK; -} - -static const IDirectMusicGetLoaderVtbl DirectMusicLoaderGenericStream_GetLoader_Vtbl = { - IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_QueryInterface, - IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_AddRef, - IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_Release, - IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_GetLoader -}; - HRESULT DMUSIC_CreateDirectMusicLoaderGenericStream (void** ppobj) { IDirectMusicLoaderGenericStream *obj;
@@ -799,7 +913,6 @@ HRESULT DMUSIC_CreateDirectMusicLoaderGenericStream (void** ppobj) { *ppobj = NULL; if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; obj->StreamVtbl = &DirectMusicLoaderGenericStream_Stream_Vtbl; - obj->GetLoaderVtbl = &DirectMusicLoaderGenericStream_GetLoader_Vtbl; obj->dwRef = 0; /* will be inited with QueryInterface */
return IDirectMusicLoaderGenericStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj);
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmloader/dmloader_private.h | 16 --- dlls/dmloader/loader.c | 53 +++----- dlls/dmloader/loaderstream.c | 208 ------------------------------- 3 files changed, 16 insertions(+), 261 deletions(-)
diff --git a/dlls/dmloader/dmloader_private.h b/dlls/dmloader/dmloader_private.h index bd5777f54f1..87fcf087bc0 100644 --- a/dlls/dmloader/dmloader_private.h +++ b/dlls/dmloader/dmloader_private.h @@ -61,7 +61,6 @@ extern HRESULT create_dmloader(REFIID riid, void **ret_iface); extern HRESULT create_dmcontainer(REFIID riid, void **ret_iface); extern HRESULT DMUSIC_CreateDirectMusicLoaderFileStream(void **ppobj); extern HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream(void **ppobj); -extern HRESULT DMUSIC_CreateDirectMusicLoaderGenericStream(void **ppobj);
/***************************************************************************** * IDirectMusicLoaderFileStream implementation structure @@ -98,21 +97,6 @@ struct IDirectMusicLoaderResourceStream { extern HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach(LPSTREAM iface, LPBYTE pbMemData, LONGLONG llMemLength, LONGLONG llPos);
-/***************************************************************************** - * IDirectMusicLoaderGenericStream implementation structure - */ -struct IDirectMusicLoaderGenericStream { - /* IUnknown fields */ - const IStreamVtbl *StreamVtbl; - /* reference counter */ - LONG dwRef; - /* stream */ - LPSTREAM pStream; -}; - -/* Custom: */ -extern HRESULT WINAPI IDirectMusicLoaderGenericStream_Attach(LPSTREAM iface, LPSTREAM pStream); - extern HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, IStream **ret_iface);
#include "debug.h" diff --git a/dlls/dmloader/loader.c b/dlls/dmloader/loader.c index a0683307f8f..ef1a8c3dfe0 100644 --- a/dlls/dmloader/loader.c +++ b/dlls/dmloader/loader.c @@ -356,27 +356,17 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE return result; } } - else if (pDesc->dwValidData & DMUS_OBJ_STREAM) { - /* load object from stream */ - TRACE(": loading from stream\n"); - /* create universal stream and associate it with given one */ - result = DMUSIC_CreateDirectMusicLoaderGenericStream ((LPVOID*)&pStream); - if (FAILED(result)) { - ERR(": could not create generic stream\n"); - return result; - } - result = IDirectMusicLoaderGenericStream_Attach(pStream, pDesc->pStream); - if (FAILED(result)) - { - ERR(": failed to attach stream\n"); - IStream_Release (pStream); - return result; - } - } else { - /* nowhere to load from */ - FIXME(": unknown/unsupported way of loading\n"); - return DMUS_E_LOADER_NOFILENAME; /* test shows this is returned */ - } + else if (pDesc->dwValidData & DMUS_OBJ_STREAM) + { + pStream = pDesc->pStream; + IStream_AddRef(pStream); + } + else + { + /* nowhere to load from */ + FIXME(": unknown/unsupported way of loading\n"); + return DMUS_E_LOADER_NOFILENAME; /* test shows this is returned */ + }
if (FAILED(hr = loader_stream_create((IDirectMusicLoader *)iface, pStream, &loader_stream))) return hr; @@ -499,22 +489,11 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE return DMUS_E_LOADER_FAILEDOPEN; } } - else if (pDesc->dwValidData & DMUS_OBJ_STREAM) { - /* create stream */ - hr = DMUSIC_CreateDirectMusicLoaderGenericStream ((LPVOID*)&pStream); - if (FAILED(hr)) { - ERR(": could not create generic stream\n"); - return DMUS_E_LOADER_FAILEDOPEN; - } - /* attach stream */ - hr = IDirectMusicLoaderGenericStream_Attach(pStream, pDesc->pStream); - if (FAILED(hr)) - { - ERR(": could not attach stream\n"); - IStream_Release (pStream); - return DMUS_E_LOADER_FAILEDOPEN; - } - } + else if (pDesc->dwValidData & DMUS_OBJ_STREAM) + { + pStream = pDesc->pStream; + IStream_AddRef(pStream); + } else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) { /* create stream */ hr = DMUSIC_CreateDirectMusicLoaderResourceStream ((LPVOID*)&pStream); diff --git a/dlls/dmloader/loaderstream.c b/dlls/dmloader/loaderstream.c index 3e01d423483..5b7862c16f8 100644 --- a/dlls/dmloader/loaderstream.c +++ b/dlls/dmloader/loaderstream.c @@ -286,7 +286,6 @@ HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream,
static ULONG WINAPI IDirectMusicLoaderFileStream_IStream_AddRef (LPSTREAM iface); static ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_AddRef (LPSTREAM iface); -static ULONG WINAPI IDirectMusicLoaderGenericStream_IStream_AddRef (LPSTREAM iface);
/***************************************************************************** @@ -710,210 +709,3 @@ HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream (void** ppobj) {
return IDirectMusicLoaderResourceStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj); } - - -/***************************************************************************** - * IDirectMusicLoaderGenericStream implementation - */ -/* Custom : */ - -static void IDirectMusicLoaderGenericStream_Detach (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - - if (This->pStream) - IStream_Release (This->pStream); - This->pStream = NULL; -} - -HRESULT WINAPI IDirectMusicLoaderGenericStream_Attach (LPSTREAM iface, LPSTREAM pStream) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - - TRACE("(%p, %p)\n", This, pStream); - if (!pStream) { - WARN(": invalid pStream\n"); - return E_FAIL; - } - - IDirectMusicLoaderGenericStream_Detach (iface); - IStream_Clone (pStream, &This->pStream); - - return S_OK; -} - - -/* IUnknown/IStream part: */ -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_QueryInterface (LPSTREAM iface, REFIID riid, void** ppobj) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - - TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj); - if (IsEqualIID (riid, &IID_IUnknown) || - IsEqualIID (riid, &IID_IStream)) { - *ppobj = &This->StreamVtbl; - IDirectMusicLoaderGenericStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl); - return S_OK; - } - - WARN(": not found\n"); - return E_NOINTERFACE; -} - -static ULONG WINAPI IDirectMusicLoaderGenericStream_IStream_AddRef (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - TRACE("(%p): AddRef from %ld\n", This, This->dwRef); - return InterlockedIncrement (&This->dwRef); -} - -static ULONG WINAPI IDirectMusicLoaderGenericStream_IStream_Release (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - - DWORD dwRef = InterlockedDecrement (&This->dwRef); - TRACE("(%p): ReleaseRef to %ld\n", This, dwRef); - if (dwRef == 0) { - IDirectMusicLoaderGenericStream_Detach (iface); - HeapFree (GetProcessHeap(), 0, This); - } - - return dwRef; -} - -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Read (LPSTREAM iface, void* pv, ULONG cb, ULONG* pcbRead) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - - TRACE_(dmfileraw)("(%p, %p, %#lx, %p): redirecting to low-level stream\n", This, pv, cb, pcbRead); - if (!This->pStream) - return E_FAIL; - - return IStream_Read (This->pStream, pv, cb, pcbRead); -} - -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Seek (LPSTREAM iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - TRACE_(dmfileraw)("(%p, %s, %s, %p): redirecting to low-level stream\n", This, wine_dbgstr_longlong(dlibMove.QuadPart), resolve_STREAM_SEEK(dwOrigin), plibNewPosition); - if (!This->pStream) - return E_FAIL; - - return IStream_Seek (This->pStream, dlibMove, dwOrigin, plibNewPosition); -} - -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Clone (LPSTREAM iface, IStream** ppstm) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - LPSTREAM pOther = NULL; - LPSTREAM pLowLevel = NULL; - HRESULT result; - - TRACE("(%p, %p)\n", iface, ppstm); - result = DMUSIC_CreateDirectMusicLoaderGenericStream ((LPVOID*)&pOther); - if (FAILED(result)) return result; - - if (FAILED(IStream_Clone (This->pStream, &pLowLevel))) { - IStream_Release(pOther); - return E_FAIL; - } - IDirectMusicLoaderGenericStream_Attach (pOther, pLowLevel); - - TRACE(": succeeded\n"); - *ppstm = pOther; - return S_OK; -} - -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Write (LPSTREAM iface, const void* pv, ULONG cb, ULONG* pcbWritten) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - TRACE_(dmfileraw)("(%p, %p, %#lx, %p): redirecting to low-level stream\n", This, pv, cb, pcbWritten); - if (!This->pStream) - return E_FAIL; - - return IStream_Write (This->pStream, pv, cb, pcbWritten); -} - -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_SetSize (LPSTREAM iface, ULARGE_INTEGER libNewSize) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - TRACE("(%p, %s): redirecting to low-level stream\n", This, wine_dbgstr_longlong(libNewSize.QuadPart)); - if (!This->pStream) - return E_FAIL; - - return IStream_SetSize (This->pStream, libNewSize); -} - -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_CopyTo (LPSTREAM iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - TRACE("(%p, %p, %s, %p, %p): redirecting to low-level stream\n", This, pstm, wine_dbgstr_longlong(cb.QuadPart), pcbRead, pcbWritten); - if (!This->pStream) - return E_FAIL; - - return IStream_CopyTo (This->pStream, pstm, cb, pcbRead, pcbWritten); -} - -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Commit (LPSTREAM iface, DWORD grfCommitFlags) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - TRACE("(%p, %#lx): redirecting to low-level stream\n", This, grfCommitFlags); - if (!This->pStream) - return E_FAIL; - - return IStream_Commit (This->pStream, grfCommitFlags); -} - -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Revert (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - TRACE("(%p): redirecting to low-level stream\n", This); - if (!This->pStream) - return E_FAIL; - - return IStream_Revert (This->pStream); -} - -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_LockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - TRACE("(%p, %s, %s, %#lx): redirecting to low-level stream\n", This, wine_dbgstr_longlong(libOffset.QuadPart), wine_dbgstr_longlong(cb.QuadPart), dwLockType); - if (!This->pStream) - return E_FAIL; - - return IStream_LockRegion (This->pStream, libOffset, cb, dwLockType); -} - -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_UnlockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - TRACE("(%p, %s, %s, %#lx): redirecting to low-level stream\n", This, wine_dbgstr_longlong(libOffset.QuadPart), wine_dbgstr_longlong(cb.QuadPart), dwLockType); - if (!This->pStream) - return E_FAIL; - - return IStream_UnlockRegion (This->pStream, libOffset, cb, dwLockType); -} - -static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Stat (LPSTREAM iface, STATSTG* pstatstg, DWORD grfStatFlag) { - ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); - TRACE("(%p, %p, %#lx): redirecting to low-level stream\n", This, pstatstg, grfStatFlag); - if (!This->pStream) - return E_FAIL; - - return IStream_Stat (This->pStream, pstatstg, grfStatFlag); -} - -static const IStreamVtbl DirectMusicLoaderGenericStream_Stream_Vtbl = { - IDirectMusicLoaderGenericStream_IStream_QueryInterface, - IDirectMusicLoaderGenericStream_IStream_AddRef, - IDirectMusicLoaderGenericStream_IStream_Release, - IDirectMusicLoaderGenericStream_IStream_Read, - IDirectMusicLoaderGenericStream_IStream_Write, - IDirectMusicLoaderGenericStream_IStream_Seek, - IDirectMusicLoaderGenericStream_IStream_SetSize, - IDirectMusicLoaderGenericStream_IStream_CopyTo, - IDirectMusicLoaderGenericStream_IStream_Commit, - IDirectMusicLoaderGenericStream_IStream_Revert, - IDirectMusicLoaderGenericStream_IStream_LockRegion, - IDirectMusicLoaderGenericStream_IStream_UnlockRegion, - IDirectMusicLoaderGenericStream_IStream_Stat, - IDirectMusicLoaderGenericStream_IStream_Clone -}; - -HRESULT DMUSIC_CreateDirectMusicLoaderGenericStream (void** ppobj) { - IDirectMusicLoaderGenericStream *obj; - - TRACE("(%p)\n", ppobj); - - *ppobj = NULL; - if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; - obj->StreamVtbl = &DirectMusicLoaderGenericStream_Stream_Vtbl; - obj->dwRef = 0; /* will be inited with QueryInterface */ - - return IDirectMusicLoaderGenericStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj); -}
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmloader/Makefile.in | 2 +- dlls/dmloader/dmloader_private.h | 20 --- dlls/dmloader/loader.c | 54 +++----- dlls/dmloader/loaderstream.c | 217 ------------------------------- 4 files changed, 18 insertions(+), 275 deletions(-)
diff --git a/dlls/dmloader/Makefile.in b/dlls/dmloader/Makefile.in index a8d3698ab6c..51f171b6286 100644 --- a/dlls/dmloader/Makefile.in +++ b/dlls/dmloader/Makefile.in @@ -1,5 +1,5 @@ MODULE = dmloader.dll -IMPORTS = dxguid uuid ole32 advapi32 +IMPORTS = dxguid uuid ole32 advapi32 shcore PARENTSRC = ../dmusic
C_SRCS = \ diff --git a/dlls/dmloader/dmloader_private.h b/dlls/dmloader/dmloader_private.h index 87fcf087bc0..2b3603dc94b 100644 --- a/dlls/dmloader/dmloader_private.h +++ b/dlls/dmloader/dmloader_private.h @@ -60,7 +60,6 @@ typedef struct IDirectMusicLoaderGenericStream IDirectMusicLoaderGenericStream; extern HRESULT create_dmloader(REFIID riid, void **ret_iface); extern HRESULT create_dmcontainer(REFIID riid, void **ret_iface); extern HRESULT DMUSIC_CreateDirectMusicLoaderFileStream(void **ppobj); -extern HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream(void **ppobj);
/***************************************************************************** * IDirectMusicLoaderFileStream implementation structure @@ -78,25 +77,6 @@ struct IDirectMusicLoaderFileStream { /* Custom: */ extern HRESULT WINAPI IDirectMusicLoaderFileStream_Attach(LPSTREAM iface, LPCWSTR wzFile);
-/***************************************************************************** - * IDirectMusicLoaderResourceStream implementation structure - */ -struct IDirectMusicLoaderResourceStream { - /* IUnknown fields */ - const IStreamVtbl *StreamVtbl; - /* reference counter */ - LONG dwRef; - /* data */ - LPBYTE pbMemData; - LONGLONG llMemLength; - /* current position */ - LONGLONG llPos; -}; - -/* Custom: */ -extern HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach(LPSTREAM iface, LPBYTE pbMemData, - LONGLONG llMemLength, LONGLONG llPos); - extern HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, IStream **ret_iface);
#include "debug.h" diff --git a/dlls/dmloader/loader.c b/dlls/dmloader/loader.c index ef1a8c3dfe0..7d5132a34a6 100644 --- a/dlls/dmloader/loader.c +++ b/dlls/dmloader/loader.c @@ -18,6 +18,8 @@
#include "dmloader_private.h"
+#include "shlwapi.h" + WINE_DEFAULT_DEBUG_CHANNEL(dmloader);
static const GUID *classes[] = { @@ -339,23 +341,11 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE return result; } } - else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) { - /* load object from resource */ - TRACE(": loading from resource\n"); - /* create stream and associate it with given resource */ - result = DMUSIC_CreateDirectMusicLoaderResourceStream ((LPVOID*)&pStream); - if (FAILED(result)) { - ERR(": could not create resource stream\n"); - return result; - } - result = IDirectMusicLoaderResourceStream_Attach(pStream, pDesc->pbMemData, pDesc->llMemLength, 0); - if (FAILED(result)) - { - ERR(": could not attach stream to resource\n"); - IStream_Release (pStream); - return result; - } - } + else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) + { + pStream = SHCreateMemStream(pDesc->pbMemData, pDesc->llMemLength); + if (!pStream) return E_OUTOFMEMORY; + } else if (pDesc->dwValidData & DMUS_OBJ_STREAM) { pStream = pDesc->pStream; @@ -494,26 +484,16 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE pStream = pDesc->pStream; IStream_AddRef(pStream); } - else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) { - /* create stream */ - hr = DMUSIC_CreateDirectMusicLoaderResourceStream ((LPVOID*)&pStream); - if (FAILED(hr)) { - ERR(": could not create resource stream\n"); - return DMUS_E_LOADER_FAILEDOPEN; - } - /* attach stream */ - hr = IDirectMusicLoaderResourceStream_Attach(pStream, pDesc->pbMemData, pDesc->llMemLength, 0); - if (FAILED(hr)) - { - ERR(": could not attach stream to resource\n"); - IStream_Release (pStream); - return DMUS_E_LOADER_FAILEDOPEN; - } - } - else { - ERR(": no way to get additional info\n"); - return DMUS_E_LOADER_FAILEDOPEN; - } + else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) + { + pStream = SHCreateMemStream(pDesc->pbMemData, pDesc->llMemLength); + if (!pStream) return E_OUTOFMEMORY; + } + else + { + ERR(": no way to get additional info\n"); + return DMUS_E_LOADER_FAILEDOPEN; + }
if (FAILED(hr = loader_stream_create((IDirectMusicLoader *)iface, pStream, &loader_stream))) return hr; diff --git a/dlls/dmloader/loaderstream.c b/dlls/dmloader/loaderstream.c index 5b7862c16f8..b7130065e32 100644 --- a/dlls/dmloader/loaderstream.c +++ b/dlls/dmloader/loaderstream.c @@ -285,7 +285,6 @@ HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, }
static ULONG WINAPI IDirectMusicLoaderFileStream_IStream_AddRef (LPSTREAM iface); -static ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_AddRef (LPSTREAM iface);
/***************************************************************************** @@ -493,219 +492,3 @@ HRESULT DMUSIC_CreateDirectMusicLoaderFileStream (void** ppobj) {
return IDirectMusicLoaderFileStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj); } - - -/***************************************************************************** - * IDirectMusicLoaderResourceStream implementation - */ -/* Custom : */ - -static void IDirectMusicLoaderResourceStream_Detach (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - TRACE("(%p)\n", This); - - This->pbMemData = NULL; - This->llMemLength = 0; -} - -HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach (LPSTREAM iface, LPBYTE pbMemData, LONGLONG llMemLength, LONGLONG llPos) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - - TRACE("(%p, %p, %s, %s)\n", This, pbMemData, wine_dbgstr_longlong(llMemLength), wine_dbgstr_longlong(llPos)); - if (!pbMemData || !llMemLength) { - WARN(": invalid pbMemData or llMemLength\n"); - return E_FAIL; - } - IDirectMusicLoaderResourceStream_Detach (iface); - This->pbMemData = pbMemData; - This->llMemLength = llMemLength; - This->llPos = llPos; - - return S_OK; -} - - -/* IUnknown/IStream part: */ -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_QueryInterface (LPSTREAM iface, REFIID riid, void** ppobj) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - - TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj); - if (IsEqualIID (riid, &IID_IUnknown) || - IsEqualIID (riid, &IID_IStream)) { - *ppobj = &This->StreamVtbl; - IDirectMusicLoaderResourceStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl); - return S_OK; - } - - WARN(": not found\n"); - return E_NOINTERFACE; -} - -static ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_AddRef (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - TRACE("(%p): AddRef from %ld\n", This, This->dwRef); - return InterlockedIncrement (&This->dwRef); -} - -static ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_Release (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - - DWORD dwRef = InterlockedDecrement (&This->dwRef); - TRACE("(%p): ReleaseRef to %ld\n", This, dwRef); - if (dwRef == 0) { - IDirectMusicLoaderResourceStream_Detach (iface); - free(This); - } - - return dwRef; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Read (LPSTREAM iface, void* pv, ULONG cb, ULONG* pcbRead) { - LPBYTE pByte; - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - - TRACE_(dmfileraw)("(%p, %p, %#lx, %p)\n", This, pv, cb, pcbRead); - if ((This->llPos + cb) > This->llMemLength) { - WARN_(dmfileraw)(": requested size out of range\n"); - return E_FAIL; - } - - pByte = &This->pbMemData[This->llPos]; - memcpy (pv, pByte, cb); - This->llPos += cb; /* move pointer */ - /* FIXME: error checking would be nice */ - if (pcbRead) *pcbRead = cb; - - TRACE_(dmfileraw)(": data (size = %#lx): %s\n", cb, debugstr_an(pv, cb)); - return S_OK; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Seek (LPSTREAM iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - TRACE_(dmfileraw)("(%p, %s, %s, %p)\n", This, wine_dbgstr_longlong(dlibMove.QuadPart), resolve_STREAM_SEEK(dwOrigin), plibNewPosition); - - switch (dwOrigin) { - case STREAM_SEEK_CUR: { - if ((This->llPos + dlibMove.QuadPart) > This->llMemLength) { - WARN_(dmfileraw)(": requested offset out of range\n"); - return E_FAIL; - } - break; - } - case STREAM_SEEK_SET: { - if (dlibMove.QuadPart > This->llMemLength) { - WARN_(dmfileraw)(": requested offset out of range\n"); - return E_FAIL; - } - /* set to the beginning of the stream */ - This->llPos = 0; - break; - } - case STREAM_SEEK_END: { - /* TODO: check if this is true... I do think offset should be negative in this case */ - if (dlibMove.QuadPart > 0) { - WARN_(dmfileraw)(": requested offset out of range\n"); - return E_FAIL; - } - /* set to the end of the stream */ - This->llPos = This->llMemLength; - break; - } - default: { - ERR_(dmfileraw)(": invalid dwOrigin\n"); - return E_FAIL; - } - } - /* now simply add */ - This->llPos += dlibMove.QuadPart; - - if (plibNewPosition) plibNewPosition->QuadPart = This->llPos; - - return S_OK; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Clone (LPSTREAM iface, IStream** ppstm) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - LPSTREAM pOther = NULL; - HRESULT result; - - TRACE("(%p, %p)\n", iface, ppstm); - result = DMUSIC_CreateDirectMusicLoaderResourceStream ((LPVOID*)&pOther); - if (FAILED(result)) return result; - - IDirectMusicLoaderResourceStream_Attach (pOther, This->pbMemData, This->llMemLength, This->llPos); - - TRACE(": succeeded\n"); - *ppstm = pOther; - return S_OK; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Write (LPSTREAM iface, const void* pv, ULONG cb, ULONG* pcbWritten) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_SetSize (LPSTREAM iface, ULARGE_INTEGER libNewSize) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_CopyTo (LPSTREAM iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Commit (LPSTREAM iface, DWORD grfCommitFlags) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Revert (LPSTREAM iface) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_LockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_UnlockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Stat (LPSTREAM iface, STATSTG* pstatstg, DWORD grfStatFlag) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static const IStreamVtbl DirectMusicLoaderResourceStream_Stream_Vtbl = { - IDirectMusicLoaderResourceStream_IStream_QueryInterface, - IDirectMusicLoaderResourceStream_IStream_AddRef, - IDirectMusicLoaderResourceStream_IStream_Release, - IDirectMusicLoaderResourceStream_IStream_Read, - IDirectMusicLoaderResourceStream_IStream_Write, - IDirectMusicLoaderResourceStream_IStream_Seek, - IDirectMusicLoaderResourceStream_IStream_SetSize, - IDirectMusicLoaderResourceStream_IStream_CopyTo, - IDirectMusicLoaderResourceStream_IStream_Commit, - IDirectMusicLoaderResourceStream_IStream_Revert, - IDirectMusicLoaderResourceStream_IStream_LockRegion, - IDirectMusicLoaderResourceStream_IStream_UnlockRegion, - IDirectMusicLoaderResourceStream_IStream_Stat, - IDirectMusicLoaderResourceStream_IStream_Clone -}; - -HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream (void** ppobj) { - IDirectMusicLoaderResourceStream *obj; - - TRACE("(%p)\n", ppobj); - - *ppobj = NULL; - if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; - obj->StreamVtbl = &DirectMusicLoaderResourceStream_Stream_Vtbl; - obj->dwRef = 0; /* will be inited with QueryInterface */ - - return IDirectMusicLoaderResourceStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj); -}
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmloader/dmloader_private.h | 17 --- dlls/dmloader/loader.c | 105 +++++--------- dlls/dmloader/loaderstream.c | 241 +------------------------------ 3 files changed, 42 insertions(+), 321 deletions(-)
diff --git a/dlls/dmloader/dmloader_private.h b/dlls/dmloader/dmloader_private.h index 2b3603dc94b..8992f25585e 100644 --- a/dlls/dmloader/dmloader_private.h +++ b/dlls/dmloader/dmloader_private.h @@ -59,23 +59,6 @@ typedef struct IDirectMusicLoaderGenericStream IDirectMusicLoaderGenericStream; */ extern HRESULT create_dmloader(REFIID riid, void **ret_iface); extern HRESULT create_dmcontainer(REFIID riid, void **ret_iface); -extern HRESULT DMUSIC_CreateDirectMusicLoaderFileStream(void **ppobj); - -/***************************************************************************** - * IDirectMusicLoaderFileStream implementation structure - */ -struct IDirectMusicLoaderFileStream { - /* VTABLEs */ - const IStreamVtbl *StreamVtbl; - /* reference counter */ - LONG dwRef; - /* file */ - WCHAR wzFileName[MAX_PATH]; /* for clone */ - HANDLE hFile; -}; - -/* Custom: */ -extern HRESULT WINAPI IDirectMusicLoaderFileStream_Attach(LPSTREAM iface, LPCWSTR wzFile);
extern HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, IStream **ret_iface);
diff --git a/dlls/dmloader/loader.c b/dlls/dmloader/loader.c index 7d5132a34a6..9a0882c4d00 100644 --- a/dlls/dmloader/loader.c +++ b/dlls/dmloader/loader.c @@ -307,40 +307,29 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE TRACE(": no cache/alias entry found for requested object\n"); } - if (pDesc->dwValidData & DMUS_OBJ_URL) { - TRACE(": loading from URLs not supported yet\n"); - return DMUS_E_LOADER_FORMATNOTSUPPORTED; - } - else if (pDesc->dwValidData & DMUS_OBJ_FILENAME) { - /* load object from file */ - /* generate filename; if it's full path, don't add search - directory path, otherwise do */ - WCHAR wszFileName[MAX_PATH]; - - if (pDesc->dwValidData & DMUS_OBJ_FULLPATH) { - lstrcpyW(wszFileName, pDesc->wszFileName); - } else { - WCHAR *p; - get_search_path(This, &pDesc->guidClass, wszFileName); - p = wszFileName + lstrlenW(wszFileName); - if (p > wszFileName && p[-1] != '\') *p++ = '\'; - lstrcpyW(p, pDesc->wszFileName); - } - TRACE(": loading from file (%s)\n", debugstr_w(wszFileName)); - /* create stream and associate it with file */ - result = DMUSIC_CreateDirectMusicLoaderFileStream ((LPVOID*)&pStream); - if (FAILED(result)) { - ERR(": could not create file stream\n"); - return result; - } - result = IDirectMusicLoaderFileStream_Attach(pStream, wszFileName); - if (FAILED(result)) - { - ERR(": could not attach stream to file\n"); - IStream_Release (pStream); - return result; - } - } + if (pDesc->dwValidData & DMUS_OBJ_URL) + { + TRACE(": loading from URLs not supported yet\n"); + return DMUS_E_LOADER_FORMATNOTSUPPORTED; + } + else if (pDesc->dwValidData & DMUS_OBJ_FILENAME) + { + WCHAR file_name[MAX_PATH]; + + if (pDesc->dwValidData & DMUS_OBJ_FULLPATH) + lstrcpyW(file_name, pDesc->wszFileName); + else + { + WCHAR *p; + get_search_path(This, &pDesc->guidClass, file_name); + p = file_name + lstrlenW(file_name); + if (p > file_name && p[-1] != '\') *p++ = '\'; + lstrcpyW(p, pDesc->wszFileName); + } + + TRACE(": loading from file (%s)\n", debugstr_w(file_name)); + if (FAILED(hr = SHCreateStreamOnFileW(file_name, STGM_READ, &pStream))) return hr; + } else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) { pStream = SHCreateMemStream(pDesc->pbMemData, pDesc->llMemLength); @@ -353,9 +342,8 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE } else { - /* nowhere to load from */ FIXME(": unknown/unsupported way of loading\n"); - return DMUS_E_LOADER_NOFILENAME; /* test shows this is returned */ + return DMUS_E_LOADER_NOFILENAME; }
if (FAILED(hr = loader_stream_create((IDirectMusicLoader *)iface, pStream, &loader_stream))) @@ -449,36 +437,23 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE if (TRACE_ON(dmloader)) dump_DMUS_OBJECTDESC(pDesc);
- /* create stream and load additional info from it */ - if (pDesc->dwValidData & DMUS_OBJ_FILENAME) { - /* generate filename; if it's full path, don't add search - directory path, otherwise do */ - WCHAR wszFileName[MAX_PATH]; + if (pDesc->dwValidData & DMUS_OBJ_FILENAME) + { + WCHAR file_name[MAX_PATH];
- if (pDesc->dwValidData & DMUS_OBJ_FULLPATH) { - lstrcpyW(wszFileName, pDesc->wszFileName); - } else { - WCHAR *p; - get_search_path(This, &pDesc->guidClass, wszFileName); - p = wszFileName + lstrlenW(wszFileName); - if (p > wszFileName && p[-1] != '\') *p++ = '\'; - lstrcpyW(p, pDesc->wszFileName); - } - /* create stream */ - hr = DMUSIC_CreateDirectMusicLoaderFileStream ((LPVOID*)&pStream); - if (FAILED(hr)) { - ERR(": could not create file stream\n"); - return DMUS_E_LOADER_FAILEDOPEN; - } - /* attach stream */ - hr = IDirectMusicLoaderFileStream_Attach(pStream, wszFileName); - if (FAILED(hr)) - { - ERR(": could not attach stream to file %s, make sure it exists\n", debugstr_w(wszFileName)); - IStream_Release (pStream); - return DMUS_E_LOADER_FAILEDOPEN; - } - } + if (pDesc->dwValidData & DMUS_OBJ_FULLPATH) + lstrcpyW(file_name, pDesc->wszFileName); + else + { + WCHAR *p; + get_search_path(This, &pDesc->guidClass, file_name); + p = file_name + lstrlenW(file_name); + if (p > file_name && p[-1] != '\') *p++ = '\'; + lstrcpyW(p, pDesc->wszFileName); + } + + if (FAILED(hr = SHCreateStreamOnFileW(file_name, STGM_READ, &pStream))) return hr; + } else if (pDesc->dwValidData & DMUS_OBJ_STREAM) { pStream = pDesc->pStream; diff --git a/dlls/dmloader/loaderstream.c b/dlls/dmloader/loaderstream.c index b7130065e32..eecf92dcca1 100644 --- a/dlls/dmloader/loaderstream.c +++ b/dlls/dmloader/loaderstream.c @@ -1,8 +1,6 @@ -/* IDirectMusicLoaderFileStream - * IDirectMusicLoaderResourceStream - * IDirectMusicLoaderGenericStream - * +/* * Copyright (C) 2003-2004 Rok Mandeljc + * Copyright 2023 Rémi Bernon for CodeWeavers * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,35 +17,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
- -/* SIDE NOTES: - * After extensive testing and structure dumping I came to a conclusion that - * DirectMusic as in present state implements three types of streams: - * 1. IDirectMusicLoaderFileStream: stream that was most obvious, since - * it's used for loading from files; it is sort of wrapper around - * CreateFile, ReadFile, WriteFile and SetFilePointer and it supports - * both read and write - * 2. IDirectMusicLoaderResourceStream: a stream that had to exist, since - * according to MSDN, IDirectMusicLoader supports loading from resource - * as well; in this case, data is represented as a big chunk of bytes, - * from which we "read" (copy) data and keep the trace of our position; - * it supports read only - * 3. IDirectMusicLoaderGenericStream: this one was the most problematic, - * since I thought it was URL-related; besides, there's no obvious need - * for it, since input streams can simply be cloned, lest loading from - * stream is requested; but if one really thinks about it, input stream - * could be none of 1. or 2.; in this case, a wrapper that offers - * IDirectMusicGetLoader interface would be nice, and this is what this - * stream is; as such, all functions are supported, as long as underlying - * ("low-level") stream supports them - * - * - Rok Mandeljc; 24. April, 2004 -*/ - #include "dmloader_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmloader); -WINE_DECLARE_DEBUG_CHANNEL(dmfileraw);
struct loader_stream { @@ -283,212 +255,3 @@ HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, *ret_iface = &obj->IStream_iface; return S_OK; } - -static ULONG WINAPI IDirectMusicLoaderFileStream_IStream_AddRef (LPSTREAM iface); - - -/***************************************************************************** - * IDirectMusicLoaderFileStream implementation - */ -/* Custom : */ - -static void IDirectMusicLoaderFileStream_Detach (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface); - TRACE("(%p)\n", This); - if (This->hFile != INVALID_HANDLE_VALUE) CloseHandle(This->hFile); - This->wzFileName[0] = '\0'; -} - -HRESULT WINAPI IDirectMusicLoaderFileStream_Attach(LPSTREAM iface, LPCWSTR wzFile) -{ - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface); - TRACE("(%p, %s)\n", This, debugstr_w(wzFile)); - IDirectMusicLoaderFileStream_Detach (iface); - This->hFile = CreateFileW (wzFile, (GENERIC_READ | GENERIC_WRITE), (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (This->hFile == INVALID_HANDLE_VALUE) { - WARN(": failed\n"); - return DMUS_E_LOADER_FAILEDOPEN; - } - /* create IDirectMusicGetLoader */ - lstrcpynW (This->wzFileName, wzFile, MAX_PATH); - TRACE(": succeeded\n"); - return S_OK; -} - - -/* IUnknown/IStream part: */ -static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_QueryInterface (LPSTREAM iface, REFIID riid, void** ppobj) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface); - - TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj); - if (IsEqualIID (riid, &IID_IUnknown) || - IsEqualIID (riid, &IID_IStream)) { - *ppobj = &This->StreamVtbl; - IDirectMusicLoaderFileStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl); - return S_OK; - } - - WARN(": not found\n"); - return E_NOINTERFACE; -} - -static ULONG WINAPI IDirectMusicLoaderFileStream_IStream_AddRef (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface); - TRACE("(%p): AddRef from %ld\n", This, This->dwRef); - return InterlockedIncrement (&This->dwRef); -} - -static ULONG WINAPI IDirectMusicLoaderFileStream_IStream_Release (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface); - - DWORD dwRef = InterlockedDecrement (&This->dwRef); - TRACE("(%p): ReleaseRef to %ld\n", This, dwRef); - if (dwRef == 0) { - if (This->hFile) - IDirectMusicLoaderFileStream_Detach (iface); - free(This); - } - - return dwRef; -} - -static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Read (LPSTREAM iface, void* pv, ULONG cb, ULONG* pcbRead) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface); - ULONG cbRead; - - TRACE_(dmfileraw)("(%p, %p, %#lx, %p)\n", This, pv, cb, pcbRead); - if (This->hFile == INVALID_HANDLE_VALUE) return E_FAIL; - if (pcbRead == NULL) pcbRead = &cbRead; - if (!ReadFile (This->hFile, pv, cb, pcbRead, NULL) || *pcbRead != cb) return E_FAIL; - - TRACE_(dmfileraw)(": data (size = %#lx): %s\n", *pcbRead, debugstr_an(pv, *pcbRead)); - return S_OK; -} - -static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Seek (LPSTREAM iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface); - LARGE_INTEGER liNewPos; - - TRACE_(dmfileraw)("(%p, %s, %s, %p)\n", This, wine_dbgstr_longlong(dlibMove.QuadPart), resolve_STREAM_SEEK(dwOrigin), plibNewPosition); - - if (This->hFile == INVALID_HANDLE_VALUE) return E_FAIL; - - liNewPos.HighPart = dlibMove.HighPart; - liNewPos.LowPart = SetFilePointer (This->hFile, dlibMove.LowPart, &liNewPos.HighPart, dwOrigin); - - if (liNewPos.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) return E_FAIL; - if (plibNewPosition) plibNewPosition->QuadPart = liNewPos.QuadPart; - - return S_OK; -} - -static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Clone (LPSTREAM iface, IStream** ppstm) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface); - LPSTREAM pOther = NULL; - HRESULT result; - - TRACE("(%p, %p)\n", iface, ppstm); - result = DMUSIC_CreateDirectMusicLoaderFileStream ((LPVOID*)&pOther); - if (FAILED(result)) return result; - if (This->hFile != INVALID_HANDLE_VALUE) { - ULARGE_INTEGER ullCurrentPosition; - result = IDirectMusicLoaderFileStream_Attach(pOther, This->wzFileName); - if (SUCCEEDED(result)) - { - LARGE_INTEGER liZero; - liZero.QuadPart = 0; - result = IDirectMusicLoaderFileStream_IStream_Seek (iface, liZero, STREAM_SEEK_CUR, &ullCurrentPosition); /* get current position in current stream */ - } - if (SUCCEEDED(result)) { - LARGE_INTEGER liNewPosition; - liNewPosition.QuadPart = ullCurrentPosition.QuadPart; - result = IDirectMusicLoaderFileStream_IStream_Seek (pOther, liNewPosition, STREAM_SEEK_SET, &ullCurrentPosition); - } - if (FAILED(result)) { - TRACE(": failed\n"); - IDirectMusicLoaderFileStream_IStream_Release (pOther); - return result; - } - } - TRACE(": succeeded\n"); - *ppstm = pOther; - return S_OK; -} - -static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Write (LPSTREAM iface, const void* pv, ULONG cb, ULONG* pcbWritten) { - ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface); - ULONG cbWrite; - - TRACE_(dmfileraw)("(%p, %p, %#lx, %p)\n", This, pv, cb, pcbWritten); - if (This->hFile == INVALID_HANDLE_VALUE) return E_FAIL; - if (pcbWritten == NULL) pcbWritten = &cbWrite; - if (!WriteFile (This->hFile, pv, cb, pcbWritten, NULL) || *pcbWritten != cb) return E_FAIL; - - TRACE_(dmfileraw)(": data (size = %#lx): %s\n", *pcbWritten, debugstr_an(pv, *pcbWritten)); - return S_OK; -} - -static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_SetSize (LPSTREAM iface, ULARGE_INTEGER libNewSize) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_CopyTo (LPSTREAM iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Commit (LPSTREAM iface, DWORD grfCommitFlags) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Revert (LPSTREAM iface) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_LockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_UnlockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Stat (LPSTREAM iface, STATSTG* pstatstg, DWORD grfStatFlag) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static const IStreamVtbl DirectMusicLoaderFileStream_Stream_Vtbl = { - IDirectMusicLoaderFileStream_IStream_QueryInterface, - IDirectMusicLoaderFileStream_IStream_AddRef, - IDirectMusicLoaderFileStream_IStream_Release, - IDirectMusicLoaderFileStream_IStream_Read, - IDirectMusicLoaderFileStream_IStream_Write, - IDirectMusicLoaderFileStream_IStream_Seek, - IDirectMusicLoaderFileStream_IStream_SetSize, - IDirectMusicLoaderFileStream_IStream_CopyTo, - IDirectMusicLoaderFileStream_IStream_Commit, - IDirectMusicLoaderFileStream_IStream_Revert, - IDirectMusicLoaderFileStream_IStream_LockRegion, - IDirectMusicLoaderFileStream_IStream_UnlockRegion, - IDirectMusicLoaderFileStream_IStream_Stat, - IDirectMusicLoaderFileStream_IStream_Clone -}; - -HRESULT DMUSIC_CreateDirectMusicLoaderFileStream (void** ppobj) { - IDirectMusicLoaderFileStream *obj; - - TRACE("(%p)\n", ppobj); - - *ppobj = NULL; - if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; - obj->StreamVtbl = &DirectMusicLoaderFileStream_Stream_Vtbl; - obj->dwRef = 0; /* will be inited with QueryInterface */ - - return IDirectMusicLoaderFileStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj); -}
Actually this breaks Clone, as shcore streams don't implement it. I'm not sure it's so important to have but at least I found that it breaks the current segment track parsing code.