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