Commit 1ffc47b5 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dmloader: Use a simpler file stream implementation.

parent 9e0487c4
...@@ -59,26 +59,9 @@ typedef struct IDirectMusicLoaderGenericStream IDirectMusicLoaderGenericStream; ...@@ -59,26 +59,9 @@ typedef struct IDirectMusicLoaderGenericStream IDirectMusicLoaderGenericStream;
*/ */
extern HRESULT create_dmloader(REFIID riid, void **ret_iface); extern HRESULT create_dmloader(REFIID riid, void **ret_iface);
extern HRESULT create_dmcontainer(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_CreateDirectMusicLoaderResourceStream(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);
/*****************************************************************************
* IDirectMusicLoaderResourceStream implementation structure * IDirectMusicLoaderResourceStream implementation structure
*/ */
struct IDirectMusicLoaderResourceStream { struct IDirectMusicLoaderResourceStream {
...@@ -98,6 +81,7 @@ extern HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach(LPSTREAM iface, LP ...@@ -98,6 +81,7 @@ extern HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach(LPSTREAM iface, LP
LONGLONG llMemLength, LONGLONG llPos); LONGLONG llMemLength, LONGLONG llPos);
extern HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, IStream **ret_iface); extern HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, IStream **ret_iface);
extern HRESULT file_stream_create(const WCHAR *path, IStream **ret_iface);
#include "debug.h" #include "debug.h"
......
...@@ -305,39 +305,28 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE ...@@ -305,39 +305,28 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE
TRACE(": no cache/alias entry found for requested object\n"); TRACE(": no cache/alias entry found for requested object\n");
} }
if (pDesc->dwValidData & DMUS_OBJ_URL) { if (pDesc->dwValidData & DMUS_OBJ_URL)
{
TRACE(": loading from URLs not supported yet\n"); TRACE(": loading from URLs not supported yet\n");
return DMUS_E_LOADER_FORMATNOTSUPPORTED; return DMUS_E_LOADER_FORMATNOTSUPPORTED;
} }
else if (pDesc->dwValidData & DMUS_OBJ_FILENAME) { else if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
/* load object from file */ {
/* generate filename; if it's full path, don't add search WCHAR file_name[MAX_PATH];
directory path, otherwise do */
WCHAR wszFileName[MAX_PATH];
if (pDesc->dwValidData & DMUS_OBJ_FULLPATH) { if (pDesc->dwValidData & DMUS_OBJ_FULLPATH)
lstrcpyW(wszFileName, pDesc->wszFileName); lstrcpyW(file_name, pDesc->wszFileName);
} else { else
{
WCHAR *p; WCHAR *p;
get_search_path(This, &pDesc->guidClass, wszFileName); get_search_path(This, &pDesc->guidClass, file_name);
p = wszFileName + lstrlenW(wszFileName); p = file_name + lstrlenW(file_name);
if (p > wszFileName && p[-1] != '\\') *p++ = '\\'; if (p > file_name && p[-1] != '\\') *p++ = '\\';
lstrcpyW(p, pDesc->wszFileName); lstrcpyW(p, pDesc->wszFileName);
} }
TRACE(": loading from file (%s)\n", debugstr_w(wszFileName));
/* create stream and associate it with file */ TRACE(": loading from file (%s)\n", debugstr_w(file_name));
result = DMUSIC_CreateDirectMusicLoaderFileStream ((LPVOID*)&pStream); if (FAILED(hr = file_stream_create(file_name, &pStream))) return hr;
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;
}
} }
else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) { else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
/* load object from resource */ /* load object from resource */
...@@ -363,9 +352,8 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE ...@@ -363,9 +352,8 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE
} }
else else
{ {
/* nowhere to load from */
FIXME(": unknown/unsupported way of loading\n"); 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))) if (FAILED(hr = loader_stream_create((IDirectMusicLoader *)iface, pStream, &loader_stream)))
...@@ -459,35 +447,22 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE ...@@ -459,35 +447,22 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE
if (TRACE_ON(dmloader)) if (TRACE_ON(dmloader))
dump_DMUS_OBJECTDESC(pDesc); dump_DMUS_OBJECTDESC(pDesc);
/* create stream and load additional info from it */ if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
if (pDesc->dwValidData & DMUS_OBJ_FILENAME) { {
/* generate filename; if it's full path, don't add search WCHAR file_name[MAX_PATH];
directory path, otherwise do */
WCHAR wszFileName[MAX_PATH];
if (pDesc->dwValidData & DMUS_OBJ_FULLPATH) { if (pDesc->dwValidData & DMUS_OBJ_FULLPATH)
lstrcpyW(wszFileName, pDesc->wszFileName); lstrcpyW(file_name, pDesc->wszFileName);
} else { else
{
WCHAR *p; WCHAR *p;
get_search_path(This, &pDesc->guidClass, wszFileName); get_search_path(This, &pDesc->guidClass, file_name);
p = wszFileName + lstrlenW(wszFileName); p = file_name + lstrlenW(file_name);
if (p > wszFileName && p[-1] != '\\') *p++ = '\\'; if (p > file_name && p[-1] != '\\') *p++ = '\\';
lstrcpyW(p, pDesc->wszFileName); lstrcpyW(p, pDesc->wszFileName);
} }
/* create stream */
hr = DMUSIC_CreateDirectMusicLoaderFileStream ((LPVOID*)&pStream); if (FAILED(hr = file_stream_create(file_name, &pStream))) return hr;
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;
}
} }
else if (pDesc->dwValidData & DMUS_OBJ_STREAM) else if (pDesc->dwValidData & DMUS_OBJ_STREAM)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment