advapi32: Create MachineGuid value if it doesn't exist.
[wine] / dlls / fusion / asmcache.c
1 /*
2  * IAssemblyCache implementation
3  *
4  * Copyright 2008 James Hawkins
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
29 #include "fusion.h"
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(fusion);
33
34 /* IAssemblyCache */
35
36 typedef struct {
37     const IAssemblyCacheVtbl *lpIAssemblyCacheVtbl;
38
39     LONG ref;
40 } IAssemblyCacheImpl;
41
42 static HRESULT WINAPI IAssemblyCacheImpl_QueryInterface(IAssemblyCache *iface,
43                                                         REFIID riid, LPVOID *ppobj)
44 {
45     IAssemblyCacheImpl *This = (IAssemblyCacheImpl *)iface;
46
47     TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
48
49     *ppobj = NULL;
50
51     if (IsEqualIID(riid, &IID_IUnknown) ||
52         IsEqualIID(riid, &IID_IAssemblyCache))
53     {
54         IUnknown_AddRef(iface);
55         *ppobj = This;
56         return S_OK;
57     }
58
59     WARN("(%p, %s, %p): not found\n", This, debugstr_guid(riid), ppobj);
60     return E_NOINTERFACE;
61 }
62
63 static ULONG WINAPI IAssemblyCacheImpl_AddRef(IAssemblyCache *iface)
64 {
65     IAssemblyCacheImpl *This = (IAssemblyCacheImpl *)iface;
66     ULONG refCount = InterlockedIncrement(&This->ref);
67
68     TRACE("(%p)->(ref before = %u)\n", This, refCount - 1);
69
70     return refCount;
71 }
72
73 static ULONG WINAPI IAssemblyCacheImpl_Release(IAssemblyCache *iface)
74 {
75     IAssemblyCacheImpl *This = (IAssemblyCacheImpl *)iface;
76     ULONG refCount = InterlockedDecrement(&This->ref);
77
78     TRACE("(%p)->(ref before = %u)\n", This, refCount + 1);
79
80     if (!refCount)
81         HeapFree(GetProcessHeap(), 0, This);
82
83     return refCount;
84 }
85
86 static HRESULT WINAPI IAssemblyCacheImpl_UninstallAssembly(IAssemblyCache *iface,
87                                                            DWORD dwFlags,
88                                                            LPCWSTR pszAssemblyName,
89                                                            LPCFUSION_INSTALL_REFERENCE pRefData,
90                                                            ULONG *pulDisposition)
91 {
92     FIXME("(%p, %d, %s, %p, %p) stub!\n", iface, dwFlags,
93           debugstr_w(pszAssemblyName), pRefData, pulDisposition);
94
95     return E_NOTIMPL;
96 }
97
98 static HRESULT WINAPI IAssemblyCacheImpl_QueryAssemblyInfo(IAssemblyCache *iface,
99                                                            DWORD dwFlags,
100                                                            LPCWSTR pszAssemblyName,
101                                                            ASSEMBLY_INFO *pAsmInfo)
102 {
103     FIXME("(%p, %d, %s, %p) stub!\n", iface, dwFlags,
104           debugstr_w(pszAssemblyName), pAsmInfo);
105
106     return E_NOTIMPL;
107 }
108
109 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyCacheItem(IAssemblyCache *iface,
110                                                                  DWORD dwFlags,
111                                                                  PVOID pvReserved,
112                                                                  IAssemblyCacheItem **ppAsmItem,
113                                                                  LPCWSTR pszAssemblyName)
114 {
115     FIXME("(%p, %d, %p, %p, %s) stub!\n", iface, dwFlags, pvReserved,
116           ppAsmItem, debugstr_w(pszAssemblyName));
117
118     return E_NOTIMPL;
119 }
120
121 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyScavenger(IAssemblyCache *iface,
122                                                                  IUnknown **ppUnkReserved)
123 {
124     FIXME("(%p, %p) stub!\n", iface, ppUnkReserved);
125     return E_NOTIMPL;
126 }
127
128 static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface,
129                                                          DWORD dwFlags,
130                                                          LPCWSTR pszManifestFilePath,
131                                                          LPCFUSION_INSTALL_REFERENCE pRefData)
132 {
133     FIXME("(%p, %d, %s, %p) stub!\n", iface, dwFlags,
134           debugstr_w(pszManifestFilePath), pRefData);
135
136     return E_NOTIMPL;
137 }
138
139 static const IAssemblyCacheVtbl AssemblyCacheVtbl = {
140     IAssemblyCacheImpl_QueryInterface,
141     IAssemblyCacheImpl_AddRef,
142     IAssemblyCacheImpl_Release,
143     IAssemblyCacheImpl_UninstallAssembly,
144     IAssemblyCacheImpl_QueryAssemblyInfo,
145     IAssemblyCacheImpl_CreateAssemblyCacheItem,
146     IAssemblyCacheImpl_CreateAssemblyScavenger,
147     IAssemblyCacheImpl_InstallAssembly
148 };
149
150 /******************************************************************
151  *  CreateAssemblyCache   (FUSION.@)
152  */
153 HRESULT WINAPI CreateAssemblyCache(IAssemblyCache **ppAsmCache, DWORD dwReserved)
154 {
155     IAssemblyCacheImpl *cache;
156
157     TRACE("(%p, %d)\n", ppAsmCache, dwReserved);
158
159     if (!ppAsmCache)
160         return E_INVALIDARG;
161
162     *ppAsmCache = NULL;
163
164     cache = HeapAlloc(GetProcessHeap(), 0, sizeof(IAssemblyCacheImpl));
165     if (!cache)
166         return E_OUTOFMEMORY;
167
168     cache->lpIAssemblyCacheVtbl = &AssemblyCacheVtbl;
169     cache->ref = 1;
170
171     *ppAsmCache = (IAssemblyCache *)cache;
172
173     return S_OK;
174 }
175
176 /* IAssemblyCacheItem */
177
178 typedef struct {
179     const IAssemblyCacheItemVtbl *lpIAssemblyCacheItemVtbl;
180
181     LONG ref;
182 } IAssemblyCacheItemImpl;
183
184 static HRESULT WINAPI IAssemblyCacheItemImpl_QueryInterface(IAssemblyCacheItem *iface,
185                                                             REFIID riid, LPVOID *ppobj)
186 {
187     IAssemblyCacheItemImpl *This = (IAssemblyCacheItemImpl *)iface;
188
189     TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
190
191     *ppobj = NULL;
192
193     if (IsEqualIID(riid, &IID_IUnknown) ||
194         IsEqualIID(riid, &IID_IAssemblyCacheItem))
195     {
196         IUnknown_AddRef(iface);
197         *ppobj = This;
198         return S_OK;
199     }
200
201     WARN("(%p, %s, %p): not found\n", This, debugstr_guid(riid), ppobj);
202     return E_NOINTERFACE;
203 }
204
205 static ULONG WINAPI IAssemblyCacheItemImpl_AddRef(IAssemblyCacheItem *iface)
206 {
207     IAssemblyCacheItemImpl *This = (IAssemblyCacheItemImpl *)iface;
208     ULONG refCount = InterlockedIncrement(&This->ref);
209
210     TRACE("(%p)->(ref before = %u)\n", This, refCount - 1);
211
212     return refCount;
213 }
214
215 static ULONG WINAPI IAssemblyCacheItemImpl_Release(IAssemblyCacheItem *iface)
216 {
217     IAssemblyCacheItemImpl *This = (IAssemblyCacheItemImpl *)iface;
218     ULONG refCount = InterlockedDecrement(&This->ref);
219
220     TRACE("(%p)->(ref before = %u)\n", This, refCount + 1);
221
222     if (!refCount)
223         HeapFree(GetProcessHeap(), 0, This);
224
225     return refCount;
226 }
227
228 static HRESULT WINAPI IAssemblyCacheItemImpl_CreateStream(IAssemblyCacheItem *iface,
229                                                         DWORD dwFlags,
230                                                         LPCWSTR pszStreamName,
231                                                         DWORD dwFormat,
232                                                         DWORD dwFormatFlags,
233                                                         IStream **ppIStream,
234                                                         ULARGE_INTEGER *puliMaxSize)
235 {
236     FIXME("(%p, %d, %s, %d, %d, %p, %p) stub!\n", iface, dwFlags,
237           debugstr_w(pszStreamName), dwFormat, dwFormatFlags, ppIStream, puliMaxSize);
238
239     return E_NOTIMPL;
240 }
241
242 static HRESULT WINAPI IAssemblyCacheItemImpl_Commit(IAssemblyCacheItem *iface,
243                                                   DWORD dwFlags,
244                                                   ULONG *pulDisposition)
245 {
246     FIXME("(%p, %d, %p) stub!\n", iface, dwFlags, pulDisposition);
247     return E_NOTIMPL;
248 }
249
250 static HRESULT WINAPI IAssemblyCacheItemImpl_AbortItem(IAssemblyCacheItem *iface)
251 {
252     FIXME("(%p) stub!\n", iface);
253     return E_NOTIMPL;
254 }
255
256 static const IAssemblyCacheItemVtbl AssemblyCacheItemVtbl = {
257     IAssemblyCacheItemImpl_QueryInterface,
258     IAssemblyCacheItemImpl_AddRef,
259     IAssemblyCacheItemImpl_Release,
260     IAssemblyCacheItemImpl_CreateStream,
261     IAssemblyCacheItemImpl_Commit,
262     IAssemblyCacheItemImpl_AbortItem
263 };
264
265 /* IAssemblyEnum */
266
267 typedef struct {
268     const IAssemblyEnumVtbl *lpIAssemblyEnumVtbl;
269
270     LONG ref;
271 } IAssemblyEnumImpl;
272
273 static HRESULT WINAPI IAssemblyEnumImpl_QueryInterface(IAssemblyEnum *iface,
274                                                        REFIID riid, LPVOID *ppobj)
275 {
276     IAssemblyEnumImpl *This = (IAssemblyEnumImpl *)iface;
277
278     TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
279
280     *ppobj = NULL;
281
282     if (IsEqualIID(riid, &IID_IUnknown) ||
283         IsEqualIID(riid, &IID_IAssemblyEnum))
284     {
285         IUnknown_AddRef(iface);
286         *ppobj = This;
287         return S_OK;
288     }
289
290     WARN("(%p, %s, %p): not found\n", This, debugstr_guid(riid), ppobj);
291     return E_NOINTERFACE;
292 }
293
294 static ULONG WINAPI IAssemblyEnumImpl_AddRef(IAssemblyEnum *iface)
295 {
296     IAssemblyEnumImpl *This = (IAssemblyEnumImpl *)iface;
297     ULONG refCount = InterlockedIncrement(&This->ref);
298
299     TRACE("(%p)->(ref before = %u)\n", This, refCount - 1);
300
301     return refCount;
302 }
303
304 static ULONG WINAPI IAssemblyEnumImpl_Release(IAssemblyEnum *iface)
305 {
306     IAssemblyEnumImpl *This = (IAssemblyEnumImpl *)iface;
307     ULONG refCount = InterlockedDecrement(&This->ref);
308
309     TRACE("(%p)->(ref before = %u)\n", This, refCount + 1);
310
311     if (!refCount)
312         HeapFree(GetProcessHeap(), 0, This);
313
314     return refCount;
315 }
316
317 static HRESULT WINAPI IAssemblyEnumImpl_GetNextAssembly(IAssemblyEnum *iface,
318                                                         LPVOID pvReserved,
319                                                         IAssemblyName **ppName,
320                                                         DWORD dwFlags)
321 {
322     FIXME("(%p, %p, %p, %d) stub!\n", iface, pvReserved, ppName, dwFlags);
323     return E_NOTIMPL;
324 }
325
326 static HRESULT WINAPI IAssemblyEnumImpl_Reset(IAssemblyEnum *iface)
327 {
328     FIXME("(%p) stub!\n", iface);
329     return E_NOTIMPL;
330 }
331
332 static HRESULT WINAPI IAssemblyEnumImpl_Clone(IAssemblyEnum *iface,
333                                                IAssemblyEnum **ppEnum)
334 {
335     FIXME("(%p, %p) stub!\n", iface, ppEnum);
336     return E_NOTIMPL;
337 }
338
339 static const IAssemblyEnumVtbl AssemblyEnumVtbl = {
340     IAssemblyEnumImpl_QueryInterface,
341     IAssemblyEnumImpl_AddRef,
342     IAssemblyEnumImpl_Release,
343     IAssemblyEnumImpl_GetNextAssembly,
344     IAssemblyEnumImpl_Reset,
345     IAssemblyEnumImpl_Clone
346 };