winhttp/tests: Make sure proxy settings are restored.
[wine] / dlls / 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 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26
27 #define COBJMACROS
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "shlobj.h"
33 #include "shell32_main.h"
34
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
38
39 /***********************************************************************
40  * IFileSystemBindData implementation
41  */
42 typedef struct
43 {
44     IFileSystemBindData IFileSystemBindData_iface;
45     LONG ref;
46     WIN32_FIND_DATAW findFile;
47 } FileSystemBindData;
48
49 static inline FileSystemBindData *impl_from_IFileSystemBindData(IFileSystemBindData *iface)
50 {
51     return CONTAINING_RECORD(iface, FileSystemBindData, IFileSystemBindData_iface);
52 }
53
54 static HRESULT WINAPI FileSystemBindData_QueryInterface(
55                 IFileSystemBindData *iface, REFIID riid, LPVOID *ppV)
56 {
57     FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
58
59     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppV);
60
61     *ppV = NULL;
62
63     if (IsEqualIID(riid, &IID_IUnknown) ||
64         IsEqualIID(riid, &IID_IFileSystemBindData))
65     {
66         *ppV = &This->IFileSystemBindData_iface;
67     }
68
69     if (*ppV)
70     {
71         IFileSystemBindData_AddRef(iface);
72         TRACE("-- Interface: (%p)->(%p)\n", ppV, *ppV);
73         return S_OK;
74     }
75     TRACE("-- Interface: E_NOINTERFACE\n");
76     return E_NOINTERFACE;
77 }
78
79 static ULONG WINAPI FileSystemBindData_AddRef(IFileSystemBindData *iface)
80 {
81     FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
82     ULONG ref = InterlockedIncrement(&This->ref);
83     TRACE("(%p)->(%u)\n", This, ref);
84     return ref;
85 }
86
87 static ULONG WINAPI FileSystemBindData_Release(IFileSystemBindData *iface)
88 {
89     FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
90     ULONG ref = InterlockedDecrement(&This->ref);
91
92     TRACE("(%p)->(%u)\n", This, ref);
93
94     if (!ref)
95         HeapFree(GetProcessHeap(), 0, This);
96
97     return ref;
98 }
99
100 static HRESULT WINAPI FileSystemBindData_GetFindData(IFileSystemBindData *iface, WIN32_FIND_DATAW *pfd)
101 {
102     FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
103
104     TRACE("(%p)->(%p)\n", This, pfd);
105
106     if (!pfd)
107         return E_INVALIDARG;
108
109     *pfd = This->findFile;
110     return S_OK;
111 }
112
113 static HRESULT WINAPI FileSystemBindData_SetFindData(IFileSystemBindData *iface, const WIN32_FIND_DATAW *pfd)
114 {
115     FileSystemBindData *This = impl_from_IFileSystemBindData(iface);
116
117     TRACE("(%p)->(%p)\n", This, pfd);
118
119     if (pfd)
120         This->findFile = *pfd;
121     else
122         memset(&This->findFile, 0, sizeof(WIN32_FIND_DATAW));
123     return S_OK;
124 }
125
126 static const IFileSystemBindDataVtbl FileSystemBindDataVtbl = {
127     FileSystemBindData_QueryInterface,
128     FileSystemBindData_AddRef,
129     FileSystemBindData_Release,
130     FileSystemBindData_SetFindData,
131     FileSystemBindData_GetFindData,
132 };
133
134 HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *find_data, LPBC *ppV)
135 {
136     FileSystemBindData *This;
137     HRESULT ret;
138
139     TRACE("(%p %p)\n", find_data, ppV);
140
141     if (!ppV)
142        return E_INVALIDARG;
143
144     *ppV = NULL;
145
146     This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
147     if (!This) return E_OUTOFMEMORY;
148
149     This->IFileSystemBindData_iface.lpVtbl = &FileSystemBindDataVtbl;
150     This->ref = 1;
151     IFileSystemBindData_SetFindData(&This->IFileSystemBindData_iface, find_data);
152
153     ret = CreateBindCtx(0, ppV);
154     if (SUCCEEDED(ret))
155     {
156         static const WCHAR nameW[] = {
157             'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d',' ','D','a','t','a',0};
158         BIND_OPTS bindOpts;
159
160         bindOpts.cbStruct = sizeof(BIND_OPTS);
161         bindOpts.grfFlags = 0;
162         bindOpts.grfMode = STGM_CREATE;
163         bindOpts.dwTickCountDeadline = 0;
164         IBindCtx_SetBindOptions(*ppV, &bindOpts);
165         IBindCtx_RegisterObjectParam(*ppV, (WCHAR*)nameW, (IUnknown*)&This->IFileSystemBindData_iface);
166
167         IFileSystemBindData_Release(&This->IFileSystemBindData_iface);
168     }
169     else
170         HeapFree(GetProcessHeap(), 0, This);
171     return ret;
172 }