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