1999-07-10 13:53:24 +02:00
|
|
|
/*
|
|
|
|
* this class implements a pure IStream object
|
|
|
|
* and can be used for many purposes
|
|
|
|
*
|
|
|
|
* the main reason for implementing this was
|
|
|
|
* a cleaner implementation of IShellLink which
|
|
|
|
* needs to be able to load lnk's from a IStream
|
|
|
|
* interface so it was obvious to capsule the file
|
|
|
|
* access in a IStream to.
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* Copyright 1999 Juergen Schmied
|
2003-09-08 21:38:45 +02:00
|
|
|
* Copyright 2003 Mike McCormack for CodeWeavers
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-07-10 13:53:24 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
1999-07-10 13:53:24 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-09-26 02:00:55 +02:00
|
|
|
#include "winbase.h"
|
1999-07-10 13:53:24 +02:00
|
|
|
#include "winerror.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winuser.h"
|
|
|
|
#include "wingdi.h"
|
2000-09-26 02:00:55 +02:00
|
|
|
#include "shlobj.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-07-10 13:53:24 +02:00
|
|
|
#include "shell32_main.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
1999-07-10 13:53:24 +02:00
|
|
|
|
2004-11-19 19:14:47 +01:00
|
|
|
static const IStreamVtbl stvt;
|
1999-07-31 16:41:43 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
typedef struct
|
2004-11-19 19:14:47 +01:00
|
|
|
{
|
|
|
|
const IStreamVtbl *lpvtst;
|
1999-07-10 13:53:24 +02:00
|
|
|
DWORD ref;
|
2003-05-21 20:50:53 +02:00
|
|
|
HANDLE handle;
|
1999-07-10 13:53:24 +02:00
|
|
|
} ISHFileStream;
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* CreateStreamOnFile()
|
|
|
|
*
|
|
|
|
* similar to CreateStreamOnHGlobal
|
|
|
|
*/
|
2003-05-21 20:50:53 +02:00
|
|
|
HRESULT CreateStreamOnFile (LPCWSTR pszFilename, DWORD grfMode, IStream ** ppstm)
|
1999-07-10 13:53:24 +02:00
|
|
|
{
|
|
|
|
ISHFileStream* fstr;
|
2003-05-21 20:50:53 +02:00
|
|
|
HANDLE handle;
|
|
|
|
DWORD access = GENERIC_READ, creat;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
if( grfMode & STGM_TRANSACTED )
|
|
|
|
return E_INVALIDARG;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
if( grfMode & STGM_WRITE )
|
|
|
|
access |= GENERIC_WRITE;
|
|
|
|
if( grfMode & STGM_READWRITE )
|
|
|
|
access = GENERIC_WRITE | GENERIC_READ;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
if( grfMode & STGM_CREATE )
|
|
|
|
creat = CREATE_ALWAYS;
|
|
|
|
else
|
|
|
|
creat = OPEN_EXISTING;
|
|
|
|
|
|
|
|
TRACE("Opening %s\n", debugstr_w(pszFilename) );
|
1999-07-10 13:53:24 +02:00
|
|
|
|
2004-01-18 23:06:35 +01:00
|
|
|
handle = CreateFileW( pszFilename, access, FILE_SHARE_READ, NULL, creat, 0, NULL );
|
2003-05-21 20:50:53 +02:00
|
|
|
if( handle == INVALID_HANDLE_VALUE )
|
2004-11-19 19:14:47 +01:00
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
fstr = (ISHFileStream*)HeapAlloc(GetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,sizeof(ISHFileStream));
|
|
|
|
if( !fstr )
|
2004-11-19 19:14:47 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2003-05-21 20:50:53 +02:00
|
|
|
fstr->lpvtst=&stvt;
|
|
|
|
fstr->ref = 1;
|
|
|
|
fstr->handle = handle;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
(*ppstm) = (IStream*)fstr;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
return S_OK;
|
1999-07-10 13:53:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnQueryInterface
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
2000-01-18 06:09:49 +01:00
|
|
|
TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
*ppvObj = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IStream))
|
|
|
|
{
|
|
|
|
*ppvObj = This;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ppvObj)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
|
|
|
IStream_AddRef((IStream*)*ppvObj);
|
1999-07-10 13:53:24 +02:00
|
|
|
TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
TRACE("-- Interface: E_NOINTERFACE\n");
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnAddRef
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI IStream_fnAddRef(IStream *iface)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
1999-07-10 13:53:24 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
|
1999-07-10 13:53:24 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
1999-07-10 13:53:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnRelease
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI IStream_fnRelease(IStream *iface)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->ref);
|
1999-07-10 13:53:24 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
TRACE("(%p)->(count=%lu)\n", This, refCount + 1);
|
1999-07-10 13:53:24 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
if (!refCount)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
TRACE(" destroying SHFileStream (%p)\n",This);
|
|
|
|
CloseHandle(This->handle);
|
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
1999-07-10 13:53:24 +02:00
|
|
|
}
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
1999-07-10 13:53:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-07-10 13:53:24 +02:00
|
|
|
if ( !pv )
|
2003-05-21 20:50:53 +02:00
|
|
|
return STG_E_INVALIDPOINTER;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
if ( ! ReadFile( This->handle, pv, cb, pcbRead, NULL ) )
|
2004-11-19 19:14:47 +01:00
|
|
|
return S_FALSE;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
1999-07-10 13:53:24 +02:00
|
|
|
static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
|
|
|
|
{
|
2004-01-19 00:17:13 +01:00
|
|
|
DWORD dummy_count;
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
if( !pv )
|
|
|
|
return STG_E_INVALIDPOINTER;
|
|
|
|
|
2004-01-19 00:17:13 +01:00
|
|
|
/* WriteFile() doesn't allow to specify NULL as write count pointer */
|
|
|
|
if (!pcbWritten)
|
|
|
|
pcbWritten = &dummy_count;
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
if( ! WriteFile( This->handle, pv, cb, pcbWritten, NULL ) )
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
return S_OK;
|
1999-07-10 13:53:24 +02:00
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
1999-07-10 13:53:24 +02:00
|
|
|
static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
|
|
|
|
{
|
2003-05-21 20:50:53 +02:00
|
|
|
DWORD pos, newposlo, newposhi;
|
|
|
|
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
pos = dlibMove.QuadPart; /* FIXME: truncates */
|
|
|
|
newposhi = 0;
|
|
|
|
newposlo = SetFilePointer( This->handle, pos, &newposhi, dwOrigin );
|
|
|
|
if( newposlo == INVALID_SET_FILE_POINTER )
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
plibNewPosition->QuadPart = newposlo | ( (LONGLONG)newposhi<<32);
|
|
|
|
|
|
|
|
return S_OK;
|
1999-07-10 13:53:24 +02:00
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
1999-07-10 13:53:24 +02:00
|
|
|
static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
if( ! SetFilePointer( This->handle, libNewSize.QuadPart, NULL, FILE_BEGIN ) )
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
if( ! SetEndOfFile( This->handle ) )
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
return S_OK;
|
1999-07-10 13:53:24 +02:00
|
|
|
}
|
|
|
|
static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
static HRESULT WINAPI IStream_fnRevert (IStream * iface)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
ISHFileStream *This = (ISHFileStream *)iface;
|
1999-07-10 13:53:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2004-11-19 19:14:47 +01:00
|
|
|
|
|
|
|
static const IStreamVtbl stvt =
|
|
|
|
{
|
|
|
|
IStream_fnQueryInterface,
|
|
|
|
IStream_fnAddRef,
|
|
|
|
IStream_fnRelease,
|
|
|
|
IStream_fnRead,
|
|
|
|
IStream_fnWrite,
|
|
|
|
IStream_fnSeek,
|
|
|
|
IStream_fnSetSize,
|
|
|
|
IStream_fnCopyTo,
|
|
|
|
IStream_fnCommit,
|
|
|
|
IStream_fnRevert,
|
|
|
|
IStream_fnLockRegion,
|
|
|
|
IStream_fnUnlockRegion,
|
|
|
|
IStream_fnStat,
|
|
|
|
IStream_fnClone
|
|
|
|
|
|
|
|
};
|