2002-07-16 03:21:52 +02:00
|
|
|
/*
|
|
|
|
* SHLWAPI IStream functions
|
|
|
|
*
|
|
|
|
* Copyright 2002 Jon Griffiths
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-07-16 03:21:52 +02:00
|
|
|
*/
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-07-16 03:21:52 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2004-10-07 05:06:48 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-07-16 03:21:52 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#define NO_SHLWAPI_REG
|
|
|
|
#define NO_SHLWAPI_PATH
|
|
|
|
#include "shlwapi.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
|
|
|
|
2005-06-16 11:46:05 +02:00
|
|
|
#define STGM_ACCESS_MODE(stgm) ((stgm)&0x0000f)
|
|
|
|
#define STGM_SHARE_MODE(stgm) ((stgm)&0x000f0)
|
|
|
|
#define STGM_CREATE_MODE(stgm) ((stgm)&0x0f000)
|
|
|
|
|
2002-07-16 03:21:52 +02:00
|
|
|
/* Layout of ISHFileStream object */
|
|
|
|
typedef struct
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
IStream IStream_iface;
|
2005-07-29 16:15:31 +02:00
|
|
|
LONG ref;
|
2002-07-16 03:21:52 +02:00
|
|
|
HANDLE hFile;
|
|
|
|
DWORD dwMode;
|
|
|
|
LPOLESTR lpszPath;
|
|
|
|
DWORD type;
|
|
|
|
DWORD grfStateBits;
|
|
|
|
} ISHFileStream;
|
|
|
|
|
2010-11-30 00:03:34 +01:00
|
|
|
static inline ISHFileStream *impl_from_IStream(IStream *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ISHFileStream, IStream_iface);
|
|
|
|
}
|
|
|
|
|
2002-07-16 03:21:52 +02:00
|
|
|
static HRESULT WINAPI IStream_fnCommit(IStream*,DWORD);
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnQueryInterface
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppvObj);
|
|
|
|
|
|
|
|
*ppvObj = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IStream))
|
|
|
|
{
|
|
|
|
*ppvObj = This;
|
2005-06-16 11:46:05 +02:00
|
|
|
IStream_AddRef(iface);
|
2002-07-16 03:21:52 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnAddRef
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI IStream_fnAddRef(IStream *iface)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2005-01-12 20:29:43 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
2005-01-12 20:29:43 +01:00
|
|
|
return refCount;
|
2002-07-16 03:21:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnRelease
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI IStream_fnRelease(IStream *iface)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2005-01-12 20:29:43 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->ref);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
|
2005-01-12 20:29:43 +01:00
|
|
|
|
|
|
|
if (!refCount)
|
2002-07-16 03:21:52 +02:00
|
|
|
{
|
|
|
|
IStream_fnCommit(iface, 0); /* If ever buffered, this will be needed */
|
2008-11-05 23:04:51 +01:00
|
|
|
LocalFree(This->lpszPath);
|
2002-07-16 03:21:52 +02:00
|
|
|
CloseHandle(This->hFile);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
2005-01-12 20:29:43 +01:00
|
|
|
|
|
|
|
return refCount;
|
2002-07-16 03:21:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnRead
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnRead(IStream *iface, void* pv, ULONG cb, ULONG* pcbRead)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2002-07-16 03:21:52 +02:00
|
|
|
DWORD dwRead = 0;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%p,0x%08x,%p)\n", This, pv, cb, pcbRead);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
2005-06-16 11:46:05 +02:00
|
|
|
if (!ReadFile(This->hFile, pv, cb, &dwRead, NULL))
|
2002-07-16 03:21:52 +02:00
|
|
|
{
|
2008-04-15 22:16:03 +02:00
|
|
|
WARN("error %d reading file\n", GetLastError());
|
|
|
|
return S_FALSE;
|
2002-07-16 03:21:52 +02:00
|
|
|
}
|
|
|
|
if (pcbRead)
|
|
|
|
*pcbRead = dwRead;
|
2005-06-16 11:46:05 +02:00
|
|
|
return S_OK;
|
2002-07-16 03:21:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnWrite
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnWrite(IStream *iface, const void* pv, ULONG cb, ULONG* pcbWritten)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2002-07-16 03:21:52 +02:00
|
|
|
DWORD dwWritten = 0;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%p,0x%08x,%p)\n", This, pv, cb, pcbWritten);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
2005-06-16 11:46:05 +02:00
|
|
|
switch (STGM_ACCESS_MODE(This->dwMode))
|
2002-07-16 03:21:52 +02:00
|
|
|
{
|
2005-06-16 11:46:05 +02:00
|
|
|
case STGM_WRITE:
|
|
|
|
case STGM_READWRITE:
|
|
|
|
break;
|
|
|
|
default:
|
2008-04-15 22:16:03 +02:00
|
|
|
return STG_E_ACCESSDENIED;
|
2002-07-16 03:21:52 +02:00
|
|
|
}
|
2005-06-16 11:46:05 +02:00
|
|
|
|
|
|
|
if (!WriteFile(This->hFile, pv, cb, &dwWritten, NULL))
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
|
2002-07-16 03:21:52 +02:00
|
|
|
if (pcbWritten)
|
|
|
|
*pcbWritten = dwWritten;
|
2005-06-16 11:46:05 +02:00
|
|
|
return S_OK;
|
2002-07-16 03:21:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnSeek
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnSeek(IStream *iface, LARGE_INTEGER dlibMove,
|
|
|
|
DWORD dwOrigin, ULARGE_INTEGER* pNewPos)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2002-07-16 03:21:52 +02:00
|
|
|
DWORD dwPos;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%d,%d,%p)\n", This, dlibMove.u.LowPart, dwOrigin, pNewPos);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
IStream_fnCommit(iface, 0); /* If ever buffered, this will be needed */
|
2004-01-23 02:51:33 +01:00
|
|
|
dwPos = SetFilePointer(This->hFile, dlibMove.u.LowPart, NULL, dwOrigin);
|
2005-06-16 11:46:05 +02:00
|
|
|
if( dwPos == INVALID_SET_FILE_POINTER )
|
2008-04-15 22:16:03 +02:00
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
if (pNewPos)
|
|
|
|
{
|
2004-01-23 02:51:33 +01:00
|
|
|
pNewPos->u.HighPart = 0;
|
|
|
|
pNewPos->u.LowPart = dwPos;
|
2002-07-16 03:21:52 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnSetSize
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnSetSize(IStream *iface, ULARGE_INTEGER libNewSize)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%d)\n", This, libNewSize.u.LowPart);
|
2005-06-16 11:46:05 +02:00
|
|
|
|
2002-07-16 03:21:52 +02:00
|
|
|
IStream_fnCommit(iface, 0); /* If ever buffered, this will be needed */
|
2005-06-16 11:46:05 +02:00
|
|
|
if( ! SetFilePointer( This->hFile, libNewSize.QuadPart, NULL, FILE_BEGIN ) )
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
if( ! SetEndOfFile( This->hFile ) )
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
return S_OK;
|
2002-07-16 03:21:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnCopyTo
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnCopyTo(IStream *iface, IStream* pstm, ULARGE_INTEGER cb,
|
|
|
|
ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2002-07-16 03:21:52 +02:00
|
|
|
char copyBuff[1024];
|
|
|
|
ULONGLONG ulSize;
|
|
|
|
HRESULT hRet = S_OK;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%p,%d,%p,%p)\n", This, pstm, cb.u.LowPart, pcbRead, pcbWritten);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
if (pcbRead)
|
|
|
|
pcbRead->QuadPart = 0;
|
|
|
|
if (pcbWritten)
|
|
|
|
pcbWritten->QuadPart = 0;
|
|
|
|
|
|
|
|
if (!pstm)
|
2008-04-15 22:16:03 +02:00
|
|
|
return S_OK;
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
IStream_fnCommit(iface, 0); /* If ever buffered, this will be needed */
|
|
|
|
|
|
|
|
/* Copy data */
|
|
|
|
ulSize = cb.QuadPart;
|
|
|
|
while (ulSize)
|
|
|
|
{
|
2013-10-29 15:00:53 +01:00
|
|
|
ULONG ulLeft, ulRead, ulWritten;
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
ulLeft = ulSize > sizeof(copyBuff) ? sizeof(copyBuff) : ulSize;
|
|
|
|
|
|
|
|
/* Read */
|
2013-10-29 15:00:53 +01:00
|
|
|
hRet = IStream_fnRead(iface, copyBuff, ulLeft, &ulRead);
|
|
|
|
if (FAILED(hRet) || ulRead == 0)
|
2002-07-16 03:21:52 +02:00
|
|
|
break;
|
2013-10-29 15:00:53 +01:00
|
|
|
if (pcbRead)
|
|
|
|
pcbRead->QuadPart += ulRead;
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
/* Write */
|
2013-10-29 15:00:53 +01:00
|
|
|
hRet = IStream_fnWrite(pstm, copyBuff, ulRead, &ulWritten);
|
2002-07-16 03:21:52 +02:00
|
|
|
if (pcbWritten)
|
2013-10-29 15:00:53 +01:00
|
|
|
pcbWritten->QuadPart += ulWritten;
|
|
|
|
if (FAILED(hRet) || ulWritten != ulLeft)
|
2002-07-16 03:21:52 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
ulSize -= ulLeft;
|
|
|
|
}
|
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnCommit
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnCommit(IStream *iface, DWORD grfCommitFlags)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%d)\n", This, grfCommitFlags);
|
2002-07-16 03:21:52 +02:00
|
|
|
/* Currently unbuffered: This function is not needed */
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnRevert
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnRevert(IStream *iface)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnLockUnlockRegion
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnLockUnlockRegion(IStream *iface, ULARGE_INTEGER libOffset,
|
|
|
|
ULARGE_INTEGER cb, DWORD dwLockType)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%d,%d,%d)\n", This, libOffset.u.LowPart, cb.u.LowPart, dwLockType);
|
2002-07-16 03:21:52 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* IStream_fnStat
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnStat(IStream *iface, STATSTG* lpStat,
|
|
|
|
DWORD grfStatFlag)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2002-07-16 03:21:52 +02:00
|
|
|
BY_HANDLE_FILE_INFORMATION fi;
|
|
|
|
HRESULT hRet = S_OK;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%p,%d)\n", This, lpStat, grfStatFlag);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
if (!grfStatFlag)
|
|
|
|
hRet = STG_E_INVALIDPOINTER;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset(&fi, 0, sizeof(fi));
|
|
|
|
GetFileInformationByHandle(This->hFile, &fi);
|
|
|
|
|
|
|
|
if (grfStatFlag & STATFLAG_NONAME)
|
|
|
|
lpStat->pwcsName = NULL;
|
|
|
|
else
|
|
|
|
lpStat->pwcsName = StrDupW(This->lpszPath);
|
|
|
|
lpStat->type = This->type;
|
2004-01-23 02:51:33 +01:00
|
|
|
lpStat->cbSize.u.LowPart = fi.nFileSizeLow;
|
|
|
|
lpStat->cbSize.u.HighPart = fi.nFileSizeHigh;
|
2002-07-16 03:21:52 +02:00
|
|
|
lpStat->mtime = fi.ftLastWriteTime;
|
|
|
|
lpStat->ctime = fi.ftCreationTime;
|
|
|
|
lpStat->atime = fi.ftLastAccessTime;
|
|
|
|
lpStat->grfMode = This->dwMode;
|
|
|
|
lpStat->grfLocksSupported = 0;
|
|
|
|
memcpy(&lpStat->clsid, &IID_IStream, sizeof(CLSID));
|
|
|
|
lpStat->grfStateBits = This->grfStateBits;
|
|
|
|
lpStat->reserved = 0;
|
|
|
|
}
|
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* IStream_fnClone
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnClone(IStream *iface, IStream** ppstm)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
ISHFileStream *This = impl_from_IStream(iface);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n",This);
|
|
|
|
if (ppstm)
|
|
|
|
*ppstm = NULL;
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IStreamVtbl SHLWAPI_fsVTable =
|
2002-07-16 03:21:52 +02:00
|
|
|
{
|
|
|
|
IStream_fnQueryInterface,
|
|
|
|
IStream_fnAddRef,
|
|
|
|
IStream_fnRelease,
|
|
|
|
IStream_fnRead,
|
|
|
|
IStream_fnWrite,
|
|
|
|
IStream_fnSeek,
|
|
|
|
IStream_fnSetSize,
|
|
|
|
IStream_fnCopyTo,
|
|
|
|
IStream_fnCommit,
|
|
|
|
IStream_fnRevert,
|
|
|
|
IStream_fnLockUnlockRegion,
|
|
|
|
IStream_fnLockUnlockRegion,
|
|
|
|
IStream_fnStat,
|
|
|
|
IStream_fnClone
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_Create
|
|
|
|
*
|
|
|
|
* Internal helper: Create and initialise a new file stream object.
|
|
|
|
*/
|
|
|
|
static IStream *IStream_Create(LPCWSTR lpszPath, HANDLE hFile, DWORD dwMode)
|
|
|
|
{
|
|
|
|
ISHFileStream* fileStream;
|
|
|
|
|
2005-03-24 22:01:35 +01:00
|
|
|
fileStream = HeapAlloc(GetProcessHeap(), 0, sizeof(ISHFileStream));
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
if (fileStream)
|
|
|
|
{
|
2010-11-30 00:03:34 +01:00
|
|
|
fileStream->IStream_iface.lpVtbl = &SHLWAPI_fsVTable;
|
2002-07-16 03:21:52 +02:00
|
|
|
fileStream->ref = 1;
|
|
|
|
fileStream->hFile = hFile;
|
|
|
|
fileStream->dwMode = dwMode;
|
|
|
|
fileStream->lpszPath = StrDupW(lpszPath);
|
|
|
|
fileStream->type = 0; /* FIXME */
|
|
|
|
fileStream->grfStateBits = 0; /* FIXME */
|
|
|
|
}
|
|
|
|
TRACE ("Returning %p\n", fileStream);
|
2010-11-30 00:03:34 +01:00
|
|
|
return &fileStream->IStream_iface;
|
2002-07-16 03:21:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHCreateStreamOnFileEx [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Create a stream on a file.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path of file to create stream on
|
|
|
|
* dwMode [I] Mode to create stream in
|
|
|
|
* dwAttributes [I] Attributes of the file
|
|
|
|
* bCreate [I] Whether to create the file if it doesn't exist
|
|
|
|
* lpTemplate [I] Reserved, must be NULL
|
|
|
|
* lppStream [O] Destination for created stream
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. lppStream contains the new stream object
|
|
|
|
* Failure: E_INVALIDARG if any parameter is invalid, or an HRESULT error code
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function is available in Unicode only.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI SHCreateStreamOnFileEx(LPCWSTR lpszPath, DWORD dwMode,
|
|
|
|
DWORD dwAttributes, BOOL bCreate,
|
|
|
|
IStream *lpTemplate, IStream **lppStream)
|
|
|
|
{
|
|
|
|
DWORD dwAccess, dwShare, dwCreate;
|
|
|
|
HANDLE hFile;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%d,0x%08X,%d,%p,%p)\n", debugstr_w(lpszPath), dwMode,
|
2002-07-16 03:21:52 +02:00
|
|
|
dwAttributes, bCreate, lpTemplate, lppStream);
|
|
|
|
|
|
|
|
if (!lpszPath || !lppStream || lpTemplate)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*lppStream = NULL;
|
|
|
|
|
|
|
|
/* Access */
|
2005-06-16 11:46:05 +02:00
|
|
|
switch (STGM_ACCESS_MODE(dwMode))
|
2002-07-16 03:21:52 +02:00
|
|
|
{
|
2013-09-16 10:27:08 +02:00
|
|
|
case STGM_WRITE:
|
2002-07-16 03:21:52 +02:00
|
|
|
case STGM_READWRITE:
|
|
|
|
dwAccess = GENERIC_READ|GENERIC_WRITE;
|
|
|
|
break;
|
2005-06-16 11:46:05 +02:00
|
|
|
case STGM_READ:
|
2002-07-16 03:21:52 +02:00
|
|
|
dwAccess = GENERIC_READ;
|
|
|
|
break;
|
2005-06-16 11:46:05 +02:00
|
|
|
default:
|
|
|
|
return E_INVALIDARG;
|
2002-07-16 03:21:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sharing */
|
2005-06-16 11:46:05 +02:00
|
|
|
switch (STGM_SHARE_MODE(dwMode))
|
2002-07-16 03:21:52 +02:00
|
|
|
{
|
2008-04-15 22:16:03 +02:00
|
|
|
case 0:
|
2013-09-13 06:51:56 +02:00
|
|
|
case STGM_SHARE_DENY_NONE:
|
2008-04-15 22:16:03 +02:00
|
|
|
dwShare = FILE_SHARE_READ|FILE_SHARE_WRITE;
|
|
|
|
break;
|
2002-07-16 03:21:52 +02:00
|
|
|
case STGM_SHARE_DENY_READ:
|
|
|
|
dwShare = FILE_SHARE_WRITE;
|
|
|
|
break;
|
|
|
|
case STGM_SHARE_DENY_WRITE:
|
|
|
|
dwShare = FILE_SHARE_READ;
|
|
|
|
break;
|
|
|
|
case STGM_SHARE_EXCLUSIVE:
|
|
|
|
dwShare = 0;
|
|
|
|
break;
|
2005-06-16 11:46:05 +02:00
|
|
|
default:
|
|
|
|
return E_INVALIDARG;
|
2002-07-16 03:21:52 +02:00
|
|
|
}
|
|
|
|
|
2005-06-16 11:46:05 +02:00
|
|
|
switch(STGM_CREATE_MODE(dwMode))
|
|
|
|
{
|
|
|
|
case STGM_FAILIFTHERE:
|
2008-04-15 22:16:03 +02:00
|
|
|
dwCreate = bCreate ? CREATE_NEW : OPEN_EXISTING;
|
2005-06-16 11:46:05 +02:00
|
|
|
break;
|
|
|
|
case STGM_CREATE:
|
2002-07-16 03:21:52 +02:00
|
|
|
dwCreate = CREATE_ALWAYS;
|
2005-06-16 11:46:05 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
/* Open HANDLE to file */
|
|
|
|
hFile = CreateFileW(lpszPath, dwAccess, dwShare, NULL, dwCreate,
|
2003-01-15 00:43:41 +01:00
|
|
|
dwAttributes, 0);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
if(hFile == INVALID_HANDLE_VALUE)
|
2008-04-15 22:16:03 +02:00
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
*lppStream = IStream_Create(lpszPath, hFile, dwMode);
|
|
|
|
|
|
|
|
if(!*lppStream)
|
|
|
|
{
|
|
|
|
CloseHandle(hFile);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHCreateStreamOnFileW [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* See SHCreateStreamOnFileA.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI SHCreateStreamOnFileW(LPCWSTR lpszPath, DWORD dwMode,
|
|
|
|
IStream **lppStream)
|
|
|
|
{
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%d,%p)\n", debugstr_w(lpszPath), dwMode, lppStream);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
if (!lpszPath || !lppStream)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-04-15 22:16:03 +02:00
|
|
|
if ((dwMode & (STGM_CONVERT|STGM_DELETEONRELEASE|STGM_TRANSACTED)) != 0)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2005-06-16 11:46:05 +02:00
|
|
|
return SHCreateStreamOnFileEx(lpszPath, dwMode, 0, FALSE, NULL, lppStream);
|
2002-07-16 03:21:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHCreateStreamOnFileA [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Create a stream on a file.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszPath [I] Path of file to create stream on
|
|
|
|
* dwMode [I] Mode to create stream in
|
2003-03-15 20:41:19 +01:00
|
|
|
* lppStream [O] Destination for created IStream object
|
2002-07-16 03:21:52 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
2003-03-15 20:41:19 +01:00
|
|
|
* Success: S_OK. lppStream contains the new IStream object
|
2002-07-16 03:21:52 +02:00
|
|
|
* Failure: E_INVALIDARG if any parameter is invalid, or an HRESULT error code
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI SHCreateStreamOnFileA(LPCSTR lpszPath, DWORD dwMode,
|
|
|
|
IStream **lppStream)
|
|
|
|
{
|
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%s,%d,%p)\n", debugstr_a(lpszPath), dwMode, lppStream);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
if (!lpszPath)
|
2008-04-15 22:16:03 +02:00
|
|
|
return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
|
|
|
|
|
2012-09-24 13:04:26 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, szPath, MAX_PATH);
|
2002-07-16 03:21:52 +02:00
|
|
|
return SHCreateStreamOnFileW(szPath, dwMode, lppStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.184]
|
|
|
|
*
|
2003-03-15 20:41:19 +01:00
|
|
|
* Call IStream_Read() on a stream.
|
2002-07-16 03:21:52 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpStream [I] IStream object
|
|
|
|
* lpvDest [O] Destination for data read
|
|
|
|
* ulSize [I] Size of data to read
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. ulSize bytes have been read from the stream into lpvDest.
|
|
|
|
* Failure: An HRESULT error code, or E_FAIL if the read succeeded but the
|
|
|
|
* number of bytes read does not match.
|
|
|
|
*/
|
2007-10-26 11:31:55 +02:00
|
|
|
HRESULT WINAPI SHIStream_Read(IStream *lpStream, LPVOID lpvDest, ULONG ulSize)
|
2002-07-16 03:21:52 +02:00
|
|
|
{
|
|
|
|
ULONG ulRead;
|
|
|
|
HRESULT hRet;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%p,%d)\n", lpStream, lpvDest, ulSize);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
hRet = IStream_Read(lpStream, lpvDest, ulSize, &ulRead);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hRet) && ulRead != ulSize)
|
|
|
|
hRet = E_FAIL;
|
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.166]
|
|
|
|
*
|
|
|
|
* Determine if a stream has 0 length.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpStream [I] IStream object
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE: If the stream has 0 length
|
|
|
|
* FALSE: Otherwise.
|
|
|
|
*/
|
2003-09-11 04:56:15 +02:00
|
|
|
BOOL WINAPI SHIsEmptyStream(IStream *lpStream)
|
2002-07-16 03:21:52 +02:00
|
|
|
{
|
|
|
|
STATSTG statstg;
|
|
|
|
BOOL bRet = TRUE;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", lpStream);
|
|
|
|
|
|
|
|
memset(&statstg, 0, sizeof(statstg));
|
|
|
|
|
|
|
|
if(SUCCEEDED(IStream_Stat(lpStream, &statstg, 1)))
|
|
|
|
{
|
|
|
|
if(statstg.cbSize.QuadPart)
|
|
|
|
bRet = FALSE; /* Non-Zero */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD dwDummy;
|
|
|
|
|
|
|
|
/* Try to read from the stream */
|
2007-10-26 11:31:55 +02:00
|
|
|
if(SUCCEEDED(SHIStream_Read(lpStream, &dwDummy, sizeof(dwDummy))))
|
2002-07-16 03:21:52 +02:00
|
|
|
{
|
|
|
|
LARGE_INTEGER zero;
|
|
|
|
zero.QuadPart = 0;
|
|
|
|
|
|
|
|
IStream_Seek(lpStream, zero, 0, NULL);
|
|
|
|
bRet = FALSE; /* Non-Zero */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.212]
|
|
|
|
*
|
2003-03-15 20:41:19 +01:00
|
|
|
* Call IStream_Write() on a stream.
|
2002-07-16 03:21:52 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpStream [I] IStream object
|
|
|
|
* lpvSrc [I] Source for data to write
|
|
|
|
* ulSize [I] Size of data
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. ulSize bytes have been written to the stream from lpvSrc.
|
|
|
|
* Failure: An HRESULT error code, or E_FAIL if the write succeeded but the
|
|
|
|
* number of bytes written does not match.
|
|
|
|
*/
|
2007-10-26 11:31:55 +02:00
|
|
|
HRESULT WINAPI SHIStream_Write(IStream *lpStream, LPCVOID lpvSrc, ULONG ulSize)
|
2002-07-16 03:21:52 +02:00
|
|
|
{
|
|
|
|
ULONG ulWritten;
|
|
|
|
HRESULT hRet;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p,%p,%d)\n", lpStream, lpvSrc, ulSize);
|
2002-07-16 03:21:52 +02:00
|
|
|
|
|
|
|
hRet = IStream_Write(lpStream, lpvSrc, ulSize, &ulWritten);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hRet) && ulWritten != ulSize)
|
|
|
|
hRet = E_FAIL;
|
|
|
|
|
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.213]
|
|
|
|
*
|
|
|
|
* Seek to the start of a stream.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpStream [I] IStream object
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. The current position within the stream is updated
|
|
|
|
* Failure: An HRESULT error code.
|
|
|
|
*/
|
2003-09-11 04:56:15 +02:00
|
|
|
HRESULT WINAPI IStream_Reset(IStream *lpStream)
|
2002-07-16 03:21:52 +02:00
|
|
|
{
|
|
|
|
LARGE_INTEGER zero;
|
|
|
|
TRACE("(%p)\n", lpStream);
|
|
|
|
zero.QuadPart = 0;
|
|
|
|
return IStream_Seek(lpStream, zero, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* @ [SHLWAPI.214]
|
|
|
|
*
|
2003-03-15 20:41:19 +01:00
|
|
|
* Get the size of a stream.
|
2002-07-16 03:21:52 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpStream [I] IStream object
|
|
|
|
* lpulSize [O] Destination for size
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. lpulSize contains the size of the stream.
|
|
|
|
* Failure: An HRESULT error code.
|
|
|
|
*/
|
2003-09-11 04:56:15 +02:00
|
|
|
HRESULT WINAPI IStream_Size(IStream *lpStream, ULARGE_INTEGER* lpulSize)
|
2002-07-16 03:21:52 +02:00
|
|
|
{
|
|
|
|
STATSTG statstg;
|
|
|
|
HRESULT hRet;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", lpStream, lpulSize);
|
|
|
|
|
|
|
|
memset(&statstg, 0, sizeof(statstg));
|
|
|
|
|
|
|
|
hRet = IStream_Stat(lpStream, &statstg, 1);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hRet) && lpulSize)
|
|
|
|
*lpulSize = statstg.cbSize;
|
|
|
|
return hRet;
|
|
|
|
}
|