| 1 | /* $Id: regstream.cpp,v 1.2 2000-03-26 16:34:43 cbratschi Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 SHELL32 for OS/2
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1997 Marcus Meissner
|
|---|
| 7 | * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
|
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 9 | *
|
|---|
| 10 | * Corel WINE 20000324 level
|
|---|
| 11 | */
|
|---|
| 12 |
|
|---|
| 13 | /*
|
|---|
| 14 | * SHRegOpenStream
|
|---|
| 15 | */
|
|---|
| 16 |
|
|---|
| 17 | /*****************************************************************************
|
|---|
| 18 | * Includes *
|
|---|
| 19 | *****************************************************************************/
|
|---|
| 20 |
|
|---|
| 21 | #include <string.h>
|
|---|
| 22 | #include <odin.h>
|
|---|
| 23 | #include <odinwrap.h>
|
|---|
| 24 | #include <os2sel.h>
|
|---|
| 25 |
|
|---|
| 26 | #define ICOM_CINTERFACE 1
|
|---|
| 27 | #define CINTERFACE 1
|
|---|
| 28 |
|
|---|
| 29 | #include "wine/obj_storage.h"
|
|---|
| 30 |
|
|---|
| 31 | #include "debugtools.h"
|
|---|
| 32 | #include "heap.h"
|
|---|
| 33 | #include "winerror.h"
|
|---|
| 34 | #include "winreg.h"
|
|---|
| 35 |
|
|---|
| 36 | #include "shell32_main.h"
|
|---|
| 37 |
|
|---|
| 38 | #include <heapstring.h>
|
|---|
| 39 | #include <misc.h>
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | ODINDEBUGCHANNEL(SHELL32-REGSTREAM)
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | /*****************************************************************************
|
|---|
| 46 | * Implementation *
|
|---|
| 47 | *****************************************************************************/
|
|---|
| 48 |
|
|---|
| 49 | typedef struct
|
|---|
| 50 | { ICOM_VTABLE(IStream)* lpvtbl;
|
|---|
| 51 | DWORD ref;
|
|---|
| 52 | HKEY hKey;
|
|---|
| 53 | LPSTR pszSubKey;
|
|---|
| 54 | LPSTR pszValue;
|
|---|
| 55 | LPBYTE pbBuffer;
|
|---|
| 56 | DWORD dwLength;
|
|---|
| 57 | DWORD dwPos;
|
|---|
| 58 | } ISHRegStream;
|
|---|
| 59 |
|
|---|
| 60 | //static struct ICOM_VTABLE(IStream) rstvt;
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | /**************************************************************************
|
|---|
| 64 | * IStream_fnQueryInterface
|
|---|
| 65 | */
|
|---|
| 66 | static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
|
|---|
| 67 | {
|
|---|
| 68 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 69 |
|
|---|
| 70 | char xriid[50];
|
|---|
| 71 | WINE_StringFromCLSID((LPCLSID)riid,xriid);
|
|---|
| 72 |
|
|---|
| 73 | dprintf(("SHELL32:regstream IStream_fnQueryInterface (%p)->(\n\tIID:\t%s,%p)\n",
|
|---|
| 74 | This,
|
|---|
| 75 | xriid,
|
|---|
| 76 | ppvObj));
|
|---|
| 77 |
|
|---|
| 78 | *ppvObj = NULL;
|
|---|
| 79 |
|
|---|
| 80 | if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
|
|---|
| 81 | { *ppvObj = This;
|
|---|
| 82 | }
|
|---|
| 83 | else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
|
|---|
| 84 | { *ppvObj = This;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | if(*ppvObj)
|
|---|
| 88 | {
|
|---|
| 89 | IStream_AddRef((IStream*)*ppvObj);
|
|---|
| 90 | dprintf(("SHELL32:regstream IStream_fnQueryInterface -- Interface: (%p)->(%p)\n",
|
|---|
| 91 | ppvObj,
|
|---|
| 92 | *ppvObj));
|
|---|
| 93 | return S_OK;
|
|---|
| 94 | }
|
|---|
| 95 | dprintf(("SHELL32:regstream IStream_fnQueryInterface-- Interface: E_NOINTERFACE\n"));
|
|---|
| 96 | return E_NOINTERFACE;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | /**************************************************************************
|
|---|
| 100 | * IStream_fnAddRef
|
|---|
| 101 | */
|
|---|
| 102 | static ULONG WINAPI IStream_fnAddRef(IStream *iface)
|
|---|
| 103 | {
|
|---|
| 104 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 105 |
|
|---|
| 106 | dprintf(("SHELL32:regstream IStream_fnAddRef (%p)->(count=%lu)\n",
|
|---|
| 107 | This,
|
|---|
| 108 | This->ref));
|
|---|
| 109 |
|
|---|
| 110 | shell32_ObjCount++;
|
|---|
| 111 | return ++(This->ref);
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | /**************************************************************************
|
|---|
| 115 | * IStream_fnRelease
|
|---|
| 116 | */
|
|---|
| 117 | static ULONG WINAPI IStream_fnRelease(IStream *iface)
|
|---|
| 118 | {
|
|---|
| 119 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 120 |
|
|---|
| 121 | dprintf(("SHELL32:regstream IStream_fnRelease(%p)->()\n",
|
|---|
| 122 | This));
|
|---|
| 123 |
|
|---|
| 124 | shell32_ObjCount--;
|
|---|
| 125 |
|
|---|
| 126 | if (!--(This->ref))
|
|---|
| 127 | { dprintf(("SHELL32:regstream IStream_fnRelease destroying SHReg IStream (%p)\n",
|
|---|
| 128 | This));
|
|---|
| 129 |
|
|---|
| 130 | if (This->pszSubKey)
|
|---|
| 131 | HeapFree(GetProcessHeap(),0,This->pszSubKey);
|
|---|
| 132 |
|
|---|
| 133 | if (This->pszValue)
|
|---|
| 134 | HeapFree(GetProcessHeap(),0,This->pszValue);
|
|---|
| 135 |
|
|---|
| 136 | if (This->pbBuffer)
|
|---|
| 137 | HeapFree(GetProcessHeap(),0,This->pbBuffer);
|
|---|
| 138 |
|
|---|
| 139 | if (This->hKey)
|
|---|
| 140 | RegCloseKey(This->hKey);
|
|---|
| 141 |
|
|---|
| 142 | HeapFree(GetProcessHeap(),0,This);
|
|---|
| 143 | return 0;
|
|---|
| 144 | }
|
|---|
| 145 | return This->ref;
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
|
|---|
| 149 | {
|
|---|
| 150 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 151 |
|
|---|
| 152 | DWORD dwBytesToRead, dwBytesLeft;
|
|---|
| 153 |
|
|---|
| 154 | dprintf(("SHELL32:regstream IStream_fnRead(%p)->(%p,0x%08lx,%p)\n",
|
|---|
| 155 | This,
|
|---|
| 156 | pv,
|
|---|
| 157 | cb,
|
|---|
| 158 | pcbRead));
|
|---|
| 159 |
|
|---|
| 160 | if ( !pv )
|
|---|
| 161 | return STG_E_INVALIDPOINTER;
|
|---|
| 162 |
|
|---|
| 163 | dwBytesLeft = This->dwLength - This->dwPos;
|
|---|
| 164 |
|
|---|
| 165 | if ( 0 >= dwBytesLeft ) /* end of buffer */
|
|---|
| 166 | return S_FALSE;
|
|---|
| 167 |
|
|---|
| 168 | dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
|
|---|
| 169 |
|
|---|
| 170 | memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
|
|---|
| 171 |
|
|---|
| 172 | This->dwPos += dwBytesToRead; /* adjust pointer */
|
|---|
| 173 |
|
|---|
| 174 | if (pcbRead)
|
|---|
| 175 | *pcbRead = dwBytesToRead;
|
|---|
| 176 |
|
|---|
| 177 | return S_OK;
|
|---|
| 178 | }
|
|---|
| 179 | HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
|
|---|
| 180 | {
|
|---|
| 181 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 182 |
|
|---|
| 183 | dprintf(("SHELL32:regstream IStream_fnWrite(%p)\n",
|
|---|
| 184 | This));
|
|---|
| 185 |
|
|---|
| 186 | return E_NOTIMPL;
|
|---|
| 187 | }
|
|---|
| 188 | HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
|
|---|
| 189 | {
|
|---|
| 190 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 191 |
|
|---|
| 192 | dprintf(("SHELL32:regstream IStream_fnSeek(%p)\n",
|
|---|
| 193 | This));
|
|---|
| 194 |
|
|---|
| 195 | return E_NOTIMPL;
|
|---|
| 196 | }
|
|---|
| 197 | HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
|
|---|
| 198 | {
|
|---|
| 199 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 200 |
|
|---|
| 201 | dprintf(("SHELL32:regstream IStream_fnSetSize(%p)\n",
|
|---|
| 202 | This));
|
|---|
| 203 |
|
|---|
| 204 | return E_NOTIMPL;
|
|---|
| 205 | }
|
|---|
| 206 | HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
|
|---|
| 207 | {
|
|---|
| 208 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 209 |
|
|---|
| 210 | dprintf(("SHELL32:regstream IStream_fnCopyTo(%p)\n",
|
|---|
| 211 | This));
|
|---|
| 212 |
|
|---|
| 213 | return E_NOTIMPL;
|
|---|
| 214 | }
|
|---|
| 215 | HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
|
|---|
| 216 | {
|
|---|
| 217 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 218 |
|
|---|
| 219 | dprintf(("SHELL32:regstream IStream_fnCommit(%p)\n",
|
|---|
| 220 | This));
|
|---|
| 221 |
|
|---|
| 222 | return E_NOTIMPL;
|
|---|
| 223 | }
|
|---|
| 224 | HRESULT WINAPI IStream_fnRevert (IStream * iface)
|
|---|
| 225 | {
|
|---|
| 226 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 227 |
|
|---|
| 228 | dprintf(("SHELL32:regstream IStream_fnRevert(%p)\n",
|
|---|
| 229 | This));
|
|---|
| 230 |
|
|---|
| 231 | return E_NOTIMPL;
|
|---|
| 232 | }
|
|---|
| 233 | HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
|
|---|
| 234 | {
|
|---|
| 235 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 236 |
|
|---|
| 237 | dprintf(("SHELL32:regstream IStream_fnLockRegion(%p)\n",
|
|---|
| 238 | This));
|
|---|
| 239 |
|
|---|
| 240 | return E_NOTIMPL;
|
|---|
| 241 | }
|
|---|
| 242 | HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
|
|---|
| 243 | {
|
|---|
| 244 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 245 |
|
|---|
| 246 | dprintf(("SHELL32:regstream IStream_fnUnlockRegion(%p)\n",
|
|---|
| 247 | This));
|
|---|
| 248 |
|
|---|
| 249 | return E_NOTIMPL;
|
|---|
| 250 | }
|
|---|
| 251 | HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
|
|---|
| 252 | {
|
|---|
| 253 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 254 |
|
|---|
| 255 | dprintf(("SHELL32:regstream IStream_fnStat(%p)\n",
|
|---|
| 256 | This));
|
|---|
| 257 |
|
|---|
| 258 | return E_NOTIMPL;
|
|---|
| 259 | }
|
|---|
| 260 | HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
|
|---|
| 261 | {
|
|---|
| 262 | ICOM_THIS(ISHRegStream, iface);
|
|---|
| 263 |
|
|---|
| 264 | dprintf(("SHELL32:regstream IStream_fnClone(%p)\n",
|
|---|
| 265 | This));
|
|---|
| 266 |
|
|---|
| 267 | return E_NOTIMPL;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | static struct ICOM_VTABLE(IStream) rstvt =
|
|---|
| 271 | {
|
|---|
| 272 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|---|
| 273 | IStream_fnQueryInterface,
|
|---|
| 274 | IStream_fnAddRef,
|
|---|
| 275 | IStream_fnRelease,
|
|---|
| 276 | IStream_fnRead,
|
|---|
| 277 | IStream_fnWrite,
|
|---|
| 278 | IStream_fnSeek,
|
|---|
| 279 | IStream_fnSetSize,
|
|---|
| 280 | IStream_fnCopyTo,
|
|---|
| 281 | IStream_fnCommit,
|
|---|
| 282 | IStream_fnRevert,
|
|---|
| 283 | IStream_fnLockRegion,
|
|---|
| 284 | IStream_fnUnlockRegion,
|
|---|
| 285 | IStream_fnStat,
|
|---|
| 286 | IStream_fnClone
|
|---|
| 287 |
|
|---|
| 288 | };
|
|---|
| 289 |
|
|---|
| 290 | /**************************************************************************
|
|---|
| 291 | * IStream_Constructor()
|
|---|
| 292 | */
|
|---|
| 293 | IStream *IStream_Constructor(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode)
|
|---|
| 294 | { ISHRegStream* rstr;
|
|---|
| 295 | DWORD dwType;
|
|---|
| 296 |
|
|---|
| 297 | rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
|
|---|
| 298 | rstr->lpvtbl=&rstvt;
|
|---|
| 299 | rstr->ref = 1;
|
|---|
| 300 |
|
|---|
| 301 | dprintf(("SHELL32:regstream IStream_Constructor(%08xh,%ls,%ls,%08xh)\n",
|
|---|
| 302 | hKey,
|
|---|
| 303 | pszSubKey,
|
|---|
| 304 | pszValue,
|
|---|
| 305 | grfMode));
|
|---|
| 306 |
|
|---|
| 307 | if ( ERROR_SUCCESS == RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey)))
|
|---|
| 308 | { if ( ERROR_SUCCESS == RegQueryValueExA(rstr->hKey, (LPSTR)pszValue,0,0,0,&(rstr->dwLength)))
|
|---|
| 309 | {
|
|---|
| 310 | /* read the binary data into the buffer */
|
|---|
| 311 | rstr->pbBuffer = (BYTE*)HeapAlloc(GetProcessHeap(),0,rstr->dwLength);
|
|---|
| 312 | if (rstr->pbBuffer)
|
|---|
| 313 | { if ( ERROR_SUCCESS == RegQueryValueExA(rstr->hKey, (LPSTR)pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength)))
|
|---|
| 314 | { if (dwType == REG_BINARY )
|
|---|
| 315 | { rstr->pszSubKey = HEAP_strdupA (GetProcessHeap(),0, pszSubKey);
|
|---|
| 316 | rstr->pszValue = HEAP_strdupA (GetProcessHeap(),0, pszValue);
|
|---|
| 317 | dprintf(("SHELL32:regstream IStream_Constructor(%p)->0x%08x,%s,%s,0x%08lx\n", rstr, hKey, pszSubKey, pszValue, grfMode));
|
|---|
| 318 | shell32_ObjCount++;
|
|---|
| 319 | return (IStream*)rstr;
|
|---|
| 320 | }
|
|---|
| 321 | }
|
|---|
| 322 | HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
|
|---|
| 323 | }
|
|---|
| 324 | }
|
|---|
| 325 | RegCloseKey(rstr->hKey);
|
|---|
| 326 |
|
|---|
| 327 | }
|
|---|
| 328 | HeapFree (GetProcessHeap(),0,rstr);
|
|---|
| 329 | return NULL;
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 | /*************************************************************************
|
|---|
| 334 | * OpenRegStream [SHELL32.85]
|
|---|
| 335 | *
|
|---|
| 336 | * NOTES
|
|---|
| 337 | * exported by ordinal
|
|---|
| 338 | */
|
|---|
| 339 | IStream * WINAPI OpenRegStream(HKEY hkey, LPCSTR pszSubkey, LPCSTR pszValue, DWORD grfMode)
|
|---|
| 340 | {
|
|---|
| 341 | dprintf(("SHELL32:regstream OpenRegStream(0x%08x,%s,%s,0x%08lx)\n",
|
|---|
| 342 | hkey,
|
|---|
| 343 | pszSubkey,
|
|---|
| 344 | pszValue,
|
|---|
| 345 | grfMode));
|
|---|
| 346 | return IStream_Constructor(hkey, pszSubkey, pszValue, grfMode);
|
|---|
| 347 | }
|
|---|