| 1 | /* $Id: memorystream.cpp,v 1.4 2000-03-26 16:34:42 cbratschi Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 SHELL32 for OS/2
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
|
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 8 | *
|
|---|
| 9 | * this class implements a pure IStream object
|
|---|
| 10 | * and can be used for many purposes
|
|---|
| 11 | *
|
|---|
| 12 | * the main reason for implementing this was
|
|---|
| 13 | * a cleaner implementation of IShellLink which
|
|---|
| 14 | * needs to be able to load lnk's from a IStream
|
|---|
| 15 | * interface so it was obvious to capsule the file
|
|---|
| 16 | * access in a IStream to.
|
|---|
| 17 | *
|
|---|
| 18 | * Corel WINE 20000324 level
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | /*****************************************************************************
|
|---|
| 23 | * Includes *
|
|---|
| 24 | *****************************************************************************/
|
|---|
| 25 |
|
|---|
| 26 | #include <odin.h>
|
|---|
| 27 | #include <odinwrap.h>
|
|---|
| 28 | #include <os2sel.h>
|
|---|
| 29 |
|
|---|
| 30 | #include <string.h>
|
|---|
| 31 |
|
|---|
| 32 | #define ICOM_CINTERFACE 1
|
|---|
| 33 | #define CINTERFACE 1
|
|---|
| 34 |
|
|---|
| 35 | #include "wine/obj_storage.h"
|
|---|
| 36 | #include "heap.h"
|
|---|
| 37 | #include "winerror.h"
|
|---|
| 38 | #include "debugtools.h"
|
|---|
| 39 | #include "shell32_main.h"
|
|---|
| 40 |
|
|---|
| 41 | #include <misc.h>
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 | ODINDEBUGCHANNEL(SHELL32-MEMORYSTREAM)
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | /*****************************************************************************
|
|---|
| 48 | * Local Prototypes *
|
|---|
| 49 | *****************************************************************************/
|
|---|
| 50 |
|
|---|
| 51 | static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj);
|
|---|
| 52 | static ULONG WINAPI IStream_fnAddRef(IStream *iface);
|
|---|
| 53 | static ULONG WINAPI IStream_fnRelease(IStream *iface);
|
|---|
| 54 | static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead);
|
|---|
| 55 | static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten);
|
|---|
| 56 | static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition);
|
|---|
| 57 | static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize);
|
|---|
| 58 | static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten);
|
|---|
| 59 | static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags);
|
|---|
| 60 | static HRESULT WINAPI IStream_fnRevert (IStream * iface);
|
|---|
| 61 | static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
|
|---|
| 62 | static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
|
|---|
| 63 | static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag);
|
|---|
| 64 | static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm);
|
|---|
| 65 |
|
|---|
| 66 | static ICOM_VTABLE(IStream) stvt =
|
|---|
| 67 | {
|
|---|
| 68 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|---|
| 69 | IStream_fnQueryInterface,
|
|---|
| 70 | IStream_fnAddRef,
|
|---|
| 71 | IStream_fnRelease,
|
|---|
| 72 | IStream_fnRead,
|
|---|
| 73 | IStream_fnWrite,
|
|---|
| 74 | IStream_fnSeek,
|
|---|
| 75 | IStream_fnSetSize,
|
|---|
| 76 | IStream_fnCopyTo,
|
|---|
| 77 | IStream_fnCommit,
|
|---|
| 78 | IStream_fnRevert,
|
|---|
| 79 | IStream_fnLockRegion,
|
|---|
| 80 | IStream_fnUnlockRegion,
|
|---|
| 81 | IStream_fnStat,
|
|---|
| 82 | IStream_fnClone
|
|---|
| 83 |
|
|---|
| 84 | };
|
|---|
| 85 |
|
|---|
| 86 | typedef struct
|
|---|
| 87 | { ICOM_VTABLE(IStream) *lpvtst;
|
|---|
| 88 | DWORD ref;
|
|---|
| 89 | LPBYTE pImage;
|
|---|
| 90 | HANDLE hMapping;
|
|---|
| 91 | DWORD dwLength;
|
|---|
| 92 | DWORD dwPos;
|
|---|
| 93 | } ISHFileStream;
|
|---|
| 94 |
|
|---|
| 95 | /**************************************************************************
|
|---|
| 96 | * CreateStreamOnFile()
|
|---|
| 97 | *
|
|---|
| 98 | * similar to CreateStreamOnHGlobal
|
|---|
| 99 | */
|
|---|
| 100 | HRESULT CreateStreamOnFile (LPCSTR pszFilename, IStream ** ppstm)
|
|---|
| 101 | {
|
|---|
| 102 | ISHFileStream* fstr;
|
|---|
| 103 | OFSTRUCT ofs;
|
|---|
| 104 | HFILE hFile = OpenFile( pszFilename, &ofs, OF_READ );
|
|---|
| 105 | HRESULT ret = E_FAIL;
|
|---|
| 106 |
|
|---|
| 107 | dprintf(("SHELL32:MemoryStream CreateStreamOnFile(%s,%08xh)\n",
|
|---|
| 108 | pszFilename,
|
|---|
| 109 | ppstm));
|
|---|
| 110 |
|
|---|
| 111 | fstr = (ISHFileStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHFileStream));
|
|---|
| 112 | fstr->lpvtst=&stvt;
|
|---|
| 113 | fstr->ref = 1;
|
|---|
| 114 | fstr->dwLength = GetFileSize (hFile, NULL);
|
|---|
| 115 |
|
|---|
| 116 | shell32_ObjCount++;
|
|---|
| 117 |
|
|---|
| 118 | if (!(fstr->hMapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL)))
|
|---|
| 119 | {
|
|---|
| 120 | dprintf(("failed to create filemap.\n"));
|
|---|
| 121 | goto end_2;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | if (!(fstr->pImage = (BYTE*)MapViewOfFile(fstr->hMapping,FILE_MAP_READ,0,0,0)))
|
|---|
| 125 | {
|
|---|
| 126 | dprintf(("failed to mmap filemap.\n"));
|
|---|
| 127 | goto end_3;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | ret = S_OK;
|
|---|
| 131 | goto end_1;
|
|---|
| 132 |
|
|---|
| 133 | end_3: CloseHandle(fstr->hMapping);
|
|---|
| 134 | end_2: HeapFree(GetProcessHeap(), 0, fstr);
|
|---|
| 135 | fstr = NULL;
|
|---|
| 136 |
|
|---|
| 137 | end_1: _lclose(hFile);
|
|---|
| 138 | (*ppstm) = (IStream*)fstr;
|
|---|
| 139 | return ret;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | /**************************************************************************
|
|---|
| 143 | * IStream_fnQueryInterface
|
|---|
| 144 | */
|
|---|
| 145 | static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
|
|---|
| 146 | {
|
|---|
| 147 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 148 |
|
|---|
| 149 | char xriid[50];
|
|---|
| 150 | WINE_StringFromCLSID((LPCLSID)riid,xriid);
|
|---|
| 151 |
|
|---|
| 152 | dprintf(("SHELL32:MemoryStream IStream_fnQueryInterface(%p)->(\n\tIID:\t%s,%p)\n",
|
|---|
| 153 | This,xriid,ppvObj));
|
|---|
| 154 |
|
|---|
| 155 | *ppvObj = NULL;
|
|---|
| 156 |
|
|---|
| 157 | if(IsEqualIID(riid, &IID_IUnknown) ||
|
|---|
| 158 | IsEqualIID(riid, &IID_IStream))
|
|---|
| 159 | {
|
|---|
| 160 | *ppvObj = This;
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | if(*ppvObj)
|
|---|
| 164 | {
|
|---|
| 165 | IStream_AddRef((IStream*)*ppvObj);
|
|---|
| 166 | dprintf(("Interface: (%p)->(%p)\n",ppvObj,*ppvObj));
|
|---|
| 167 | return S_OK;
|
|---|
| 168 | }
|
|---|
| 169 | dprintf(("-- Interface: E_NOINTERFACE\n"));
|
|---|
| 170 | return E_NOINTERFACE;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | /**************************************************************************
|
|---|
| 174 | * IStream_fnAddRef
|
|---|
| 175 | */
|
|---|
| 176 | static ULONG WINAPI IStream_fnAddRef(IStream *iface)
|
|---|
| 177 | {
|
|---|
| 178 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 179 |
|
|---|
| 180 | dprintf(("SHELL32:MemoryStream IStream_fnAddRef (%p)->(count=%lu)\n",
|
|---|
| 181 | This, This->ref));
|
|---|
| 182 |
|
|---|
| 183 | shell32_ObjCount++;
|
|---|
| 184 | return ++(This->ref);
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | /**************************************************************************
|
|---|
| 188 | * IStream_fnRelease
|
|---|
| 189 | */
|
|---|
| 190 | static ULONG WINAPI IStream_fnRelease(IStream *iface)
|
|---|
| 191 | {
|
|---|
| 192 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 193 |
|
|---|
| 194 | dprintf(("SHELL32:MemoryStream IStream_fnRelease(%p)->()\n",
|
|---|
| 195 | This));
|
|---|
| 196 |
|
|---|
| 197 | shell32_ObjCount--;
|
|---|
| 198 |
|
|---|
| 199 | if (!--(This->ref))
|
|---|
| 200 | { dprintf((" destroying SHFileStream (%p)\n",This));
|
|---|
| 201 |
|
|---|
| 202 | UnmapViewOfFile(This->pImage);
|
|---|
| 203 | CloseHandle(This->hMapping);
|
|---|
| 204 |
|
|---|
| 205 | HeapFree(GetProcessHeap(),0,This);
|
|---|
| 206 | return 0;
|
|---|
| 207 | }
|
|---|
| 208 | return This->ref;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
|
|---|
| 212 | {
|
|---|
| 213 | DWORD dwBytesToRead, dwBytesLeft;
|
|---|
| 214 |
|
|---|
| 215 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 216 |
|
|---|
| 217 | dprintf(("SHELL32:MemoryStream IStream_fnRead(%p)->(%p,%p,%p)\n",
|
|---|
| 218 | This, pv, cb, pcbRead));
|
|---|
| 219 |
|
|---|
| 220 | if ( !pv )
|
|---|
| 221 | return STG_E_INVALIDPOINTER;
|
|---|
| 222 |
|
|---|
| 223 | dwBytesLeft = This->dwLength - This->dwPos;
|
|---|
| 224 |
|
|---|
| 225 | if ( 0 >= dwBytesLeft ) /* end of buffer */
|
|---|
| 226 | return S_FALSE;
|
|---|
| 227 |
|
|---|
| 228 | dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
|
|---|
| 229 |
|
|---|
| 230 | memmove ( pv, (This->pImage) + (This->dwPos), dwBytesToRead);
|
|---|
| 231 |
|
|---|
| 232 | This->dwPos += dwBytesToRead; /* adjust pointer */
|
|---|
| 233 |
|
|---|
| 234 | if (pcbRead)
|
|---|
| 235 | *pcbRead = dwBytesToRead;
|
|---|
| 236 |
|
|---|
| 237 | return S_OK;
|
|---|
| 238 | }
|
|---|
| 239 | static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
|
|---|
| 240 | {
|
|---|
| 241 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 242 |
|
|---|
| 243 | dprintf(("SHELL32:MemoryStream IStream_fnWrite (%p) not implemented\n",This));
|
|---|
| 244 |
|
|---|
| 245 | return E_NOTIMPL;
|
|---|
| 246 | }
|
|---|
| 247 | static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
|
|---|
| 248 | {
|
|---|
| 249 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 250 |
|
|---|
| 251 | dprintf(("SHELL32:MemoryStream IStream_fnSeek (%p) not implemented\n",This));
|
|---|
| 252 |
|
|---|
| 253 | return E_NOTIMPL;
|
|---|
| 254 | }
|
|---|
| 255 | static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
|
|---|
| 256 | {
|
|---|
| 257 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 258 |
|
|---|
| 259 | dprintf(("SHELL32:MemoryStream IStream_fnSetSize (%p) not implemented\n",This));
|
|---|
| 260 |
|
|---|
| 261 | return E_NOTIMPL;
|
|---|
| 262 | }
|
|---|
| 263 | static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
|
|---|
| 264 | {
|
|---|
| 265 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 266 |
|
|---|
| 267 | dprintf(("SHELL32:MemoryStream IStream_fnCopyTo (%p) not implemented\n",This));
|
|---|
| 268 |
|
|---|
| 269 | return E_NOTIMPL;
|
|---|
| 270 | }
|
|---|
| 271 | static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
|
|---|
| 272 | {
|
|---|
| 273 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 274 |
|
|---|
| 275 | dprintf(("SHELL32:MemoryStream IStream_fnCommit (%p) not implemented\n",This));
|
|---|
| 276 |
|
|---|
| 277 | return E_NOTIMPL;
|
|---|
| 278 | }
|
|---|
| 279 | static HRESULT WINAPI IStream_fnRevert (IStream * iface)
|
|---|
| 280 | {
|
|---|
| 281 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 282 |
|
|---|
| 283 | dprintf(("SHELL32:MemoryStream IStream_fnRevert (%p) not implemented\n",This));
|
|---|
| 284 |
|
|---|
| 285 | return E_NOTIMPL;
|
|---|
| 286 | }
|
|---|
| 287 | static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
|
|---|
| 288 | {
|
|---|
| 289 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 290 |
|
|---|
| 291 | dprintf(("SHELL32:MemoryStream IStream_fnLockRegion (%p) not implemented\n",This));
|
|---|
| 292 |
|
|---|
| 293 | return E_NOTIMPL;
|
|---|
| 294 | }
|
|---|
| 295 | static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
|
|---|
| 296 | {
|
|---|
| 297 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 298 |
|
|---|
| 299 | dprintf(("SHELL32:MemoryStream IStream_fnUnlockRegoin (%p) not implemented.\n",This));
|
|---|
| 300 |
|
|---|
| 301 | return E_NOTIMPL;
|
|---|
| 302 | }
|
|---|
| 303 | static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
|
|---|
| 304 | {
|
|---|
| 305 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 306 |
|
|---|
| 307 | dprintf(("SHELL32:MemoryStream IStream_fnStat (%p) not implemented.\n",This));
|
|---|
| 308 |
|
|---|
| 309 | return E_NOTIMPL;
|
|---|
| 310 | }
|
|---|
| 311 | static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
|
|---|
| 312 | {
|
|---|
| 313 | ICOM_THIS(ISHFileStream, iface);
|
|---|
| 314 |
|
|---|
| 315 | dprintf(("SHELL32:MemoryStream IStream_fnClone (%p) not implemented.\n",This));
|
|---|
| 316 |
|
|---|
| 317 | return E_NOTIMPL;
|
|---|
| 318 | }
|
|---|