[SHELL32]
[reactos.git] / reactos / dll / win32 / shell32 / shlfsbind.c
1 /*
2 * File System Bind Data object to use as parameter for the bind context to
3 * IShellFolder_ParseDisplayName
4 *
5 * Copyright 2003 Rolf Kalbermatter
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 */
22
23 #include <precomp.h>
24
25 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
26
27 /***********************************************************************
28 * IFileSystemBindData implementation
29 */
30 typedef struct
31 {
32 const IFileSystemBindDataVtbl *lpVtbl;
33 LONG ref;
34 WIN32_FIND_DATAW findFile;
35 } IFileSystemBindDataImpl;
36
37 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(IFileSystemBindData *, REFIID, LPVOID*);
38 static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *);
39 static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *);
40 static HRESULT WINAPI IFileSystemBindData_fnGetFindData(IFileSystemBindData *, WIN32_FIND_DATAW *);
41 static HRESULT WINAPI IFileSystemBindData_fnSetFindData(IFileSystemBindData *, const WIN32_FIND_DATAW *);
42
43 static const IFileSystemBindDataVtbl sbvt =
44 {
45 IFileSystemBindData_fnQueryInterface,
46 IFileSystemBindData_fnAddRef,
47 IFileSystemBindData_fnRelease,
48 IFileSystemBindData_fnSetFindData,
49 IFileSystemBindData_fnGetFindData,
50 };
51
52 static const WCHAR wFileSystemBindData[] = {
53 'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d','D','a','t','a',0};
54
55 HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC *ppV)
56 {
57 IFileSystemBindDataImpl *sb;
58 HRESULT ret = E_OUTOFMEMORY;
59
60 TRACE("%p, %p\n", pfd, ppV);
61
62 if (!ppV)
63 return E_INVALIDARG;
64
65 *ppV = NULL;
66
67 sb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileSystemBindDataImpl));
68 if (!sb)
69 return ret;
70
71 sb->lpVtbl = &sbvt;
72 sb->ref = 1;
73 IFileSystemBindData_fnSetFindData((IFileSystemBindData*)sb, pfd);
74
75 ret = CreateBindCtx(0, ppV);
76 if (SUCCEEDED(ret))
77 {
78 BIND_OPTS bindOpts;
79
80 bindOpts.cbStruct = sizeof(BIND_OPTS);
81 bindOpts.grfFlags = 0;
82 bindOpts.grfMode = STGM_CREATE;
83 bindOpts.dwTickCountDeadline = 0;
84 IBindCtx_SetBindOptions(*ppV, &bindOpts);
85 IBindCtx_RegisterObjectParam(*ppV, (LPOLESTR)wFileSystemBindData, (LPUNKNOWN)sb);
86
87 IFileSystemBindData_Release((IFileSystemBindData*)sb);
88 }
89 else
90 HeapFree(GetProcessHeap(), 0, sb);
91 return ret;
92 }
93
94 HRESULT WINAPI FileSystemBindData_GetFindData(LPBC pbc, WIN32_FIND_DATAW *pfd)
95 {
96 LPUNKNOWN pUnk;
97 IFileSystemBindData *pfsbd = NULL;
98 HRESULT ret;
99
100 TRACE("%p, %p\n", pbc, pfd);
101
102 if (!pfd)
103 return E_INVALIDARG;
104
105 ret = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &pUnk);
106 if (SUCCEEDED(ret))
107 {
108 ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
109 if (SUCCEEDED(ret))
110 {
111 ret = IFileSystemBindData_GetFindData(pfsbd, pfd);
112 IFileSystemBindData_Release(pfsbd);
113 }
114 IUnknown_Release(pUnk);
115 }
116 return ret;
117 }
118
119 HRESULT WINAPI FileSystemBindData_SetFindData(LPBC pbc, const WIN32_FIND_DATAW *pfd)
120 {
121 LPUNKNOWN pUnk;
122 IFileSystemBindData *pfsbd = NULL;
123 HRESULT ret;
124
125 TRACE("%p, %p\n", pbc, pfd);
126
127 ret = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &pUnk);
128 if (SUCCEEDED(ret))
129 {
130 ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
131 if (SUCCEEDED(ret))
132 {
133 ret = IFileSystemBindData_SetFindData(pfsbd, pfd);
134 IFileSystemBindData_Release(pfsbd);
135 }
136 IUnknown_Release(pUnk);
137 }
138 return ret;
139 }
140
141 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(
142 IFileSystemBindData *iface, REFIID riid, LPVOID *ppV)
143 {
144 IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
145 TRACE("(%p)->(\n\tIID:\t%s, %p)\n", This, debugstr_guid(riid), ppV);
146
147 *ppV = NULL;
148
149 if (IsEqualIID(riid, &IID_IUnknown))
150 *ppV = This;
151 else if (IsEqualIID(riid, &IID_IFileSystemBindData))
152 *ppV = (IFileSystemBindData*)This;
153
154 if (*ppV)
155 {
156 IUnknown_AddRef((IUnknown*)(*ppV));
157 TRACE("-- Interface: (%p)->(%p)\n", ppV, *ppV);
158 return S_OK;
159 }
160 TRACE("-- Interface: E_NOINTERFACE\n");
161 return E_NOINTERFACE;
162 }
163
164 static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *iface)
165 {
166 IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
167 ULONG refCount = InterlockedIncrement(&This->ref);
168
169 TRACE("(%p)->(count=%i)\n", This, refCount - 1);
170
171 return refCount;
172 }
173
174 static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *iface)
175 {
176 IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
177 ULONG refCount = InterlockedDecrement(&This->ref);
178
179 TRACE("(%p)->(count=%i)\n", This, refCount + 1);
180
181 if (!refCount)
182 {
183 TRACE(" destroying ISFBindPidl(%p)\n",This);
184 HeapFree(GetProcessHeap(), 0, This);
185 }
186 return refCount;
187 }
188
189 static HRESULT WINAPI IFileSystemBindData_fnGetFindData(
190 IFileSystemBindData *iface, WIN32_FIND_DATAW *pfd)
191 {
192 IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
193 TRACE("(%p), %p\n", This, pfd);
194
195 if (!pfd)
196 return E_INVALIDARG;
197
198 memcpy(pfd, &This->findFile, sizeof(WIN32_FIND_DATAW));
199 return NOERROR;
200 }
201
202 static HRESULT WINAPI IFileSystemBindData_fnSetFindData(
203 IFileSystemBindData *iface, const WIN32_FIND_DATAW *pfd)
204 {
205 IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
206 TRACE("(%p), %p\n", This, pfd);
207
208 if (pfd)
209 memcpy(&This->findFile, pfd, sizeof(WIN32_FIND_DATAW));
210 else
211 memset(&This->findFile, 0, sizeof(WIN32_FIND_DATAW));
212 return NOERROR;
213 }