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