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