gdi32: Don't set the bitmap owner when selecting a pattern brush.
[wine.git] / dlls / fusion / asmcache.c
blobfe4e12a49a925345bdf24b50789c56debfa691c0
1 /*
2 * IAssemblyCache implementation
4 * Copyright 2008 James Hawkins
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.
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.
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winver.h"
30 #include "wincrypt.h"
31 #include "winreg.h"
32 #include "shlwapi.h"
33 #include "dbghelp.h"
34 #include "ole2.h"
35 #include "fusion.h"
36 #include "corerror.h"
38 #include "fusionpriv.h"
39 #include "wine/debug.h"
40 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(fusion);
44 static BOOL create_full_path(LPCWSTR path)
46 LPWSTR new_path;
47 BOOL ret = TRUE;
48 int len;
50 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) * sizeof(WCHAR));
51 if (!new_path)
52 return FALSE;
54 strcpyW(new_path, path);
56 while ((len = strlenW(new_path)) && new_path[len - 1] == '\\')
57 new_path[len - 1] = 0;
59 while (!CreateDirectoryW(new_path, NULL))
61 LPWSTR slash;
62 DWORD last_error = GetLastError();
64 if(last_error == ERROR_ALREADY_EXISTS)
65 break;
67 if(last_error != ERROR_PATH_NOT_FOUND)
69 ret = FALSE;
70 break;
73 if(!(slash = strrchrW(new_path, '\\')))
75 ret = FALSE;
76 break;
79 len = slash - new_path;
80 new_path[len] = 0;
81 if(!create_full_path(new_path))
83 ret = FALSE;
84 break;
87 new_path[len] = '\\';
90 HeapFree(GetProcessHeap(), 0, new_path);
91 return ret;
94 static BOOL get_assembly_directory(LPWSTR dir, DWORD size, BYTE architecture)
96 static const WCHAR gac[] = {'\\','a','s','s','e','m','b','l','y','\\','G','A','C',0};
98 static const WCHAR msil[] = {'_','M','S','I','L',0};
99 static const WCHAR x86[] = {'_','3','2',0};
100 static const WCHAR amd64[] = {'_','6','4',0};
102 GetWindowsDirectoryW(dir, size);
103 strcatW(dir, gac);
105 switch (architecture)
107 case peMSIL:
108 strcatW(dir, msil);
109 break;
111 case peI386:
112 strcatW(dir, x86);
113 break;
115 case peAMD64:
116 strcatW(dir, amd64);
117 break;
120 return TRUE;
123 /* IAssemblyCache */
125 typedef struct {
126 IAssemblyCache IAssemblyCache_iface;
128 LONG ref;
129 } IAssemblyCacheImpl;
131 static inline IAssemblyCacheImpl *impl_from_IAssemblyCache(IAssemblyCache *iface)
133 return CONTAINING_RECORD(iface, IAssemblyCacheImpl, IAssemblyCache_iface);
136 static HRESULT WINAPI IAssemblyCacheImpl_QueryInterface(IAssemblyCache *iface,
137 REFIID riid, LPVOID *ppobj)
139 IAssemblyCacheImpl *This = impl_from_IAssemblyCache(iface);
141 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
143 *ppobj = NULL;
145 if (IsEqualIID(riid, &IID_IUnknown) ||
146 IsEqualIID(riid, &IID_IAssemblyCache))
148 IUnknown_AddRef(iface);
149 *ppobj = This;
150 return S_OK;
153 WARN("(%p, %s, %p): not found\n", This, debugstr_guid(riid), ppobj);
154 return E_NOINTERFACE;
157 static ULONG WINAPI IAssemblyCacheImpl_AddRef(IAssemblyCache *iface)
159 IAssemblyCacheImpl *This = impl_from_IAssemblyCache(iface);
160 ULONG refCount = InterlockedIncrement(&This->ref);
162 TRACE("(%p)->(ref before = %u)\n", This, refCount - 1);
164 return refCount;
167 static ULONG WINAPI IAssemblyCacheImpl_Release(IAssemblyCache *iface)
169 IAssemblyCacheImpl *This = impl_from_IAssemblyCache(iface);
170 ULONG refCount = InterlockedDecrement(&This->ref);
172 TRACE("(%p)->(ref before = %u)\n", This, refCount + 1);
174 if (!refCount)
175 HeapFree(GetProcessHeap(), 0, This);
177 return refCount;
180 static HRESULT WINAPI IAssemblyCacheImpl_UninstallAssembly(IAssemblyCache *iface,
181 DWORD dwFlags,
182 LPCWSTR pszAssemblyName,
183 LPCFUSION_INSTALL_REFERENCE pRefData,
184 ULONG *pulDisposition)
186 FIXME("(%p, %d, %s, %p, %p) stub!\n", iface, dwFlags,
187 debugstr_w(pszAssemblyName), pRefData, pulDisposition);
189 return E_NOTIMPL;
192 static HRESULT WINAPI IAssemblyCacheImpl_QueryAssemblyInfo(IAssemblyCache *iface,
193 DWORD dwFlags,
194 LPCWSTR pszAssemblyName,
195 ASSEMBLY_INFO *pAsmInfo)
197 IAssemblyName *asmname, *next = NULL;
198 IAssemblyEnum *asmenum = NULL;
199 HRESULT hr;
201 TRACE("(%p, %d, %s, %p)\n", iface, dwFlags,
202 debugstr_w(pszAssemblyName), pAsmInfo);
204 if (pAsmInfo)
206 if (pAsmInfo->cbAssemblyInfo == 0)
207 pAsmInfo->cbAssemblyInfo = sizeof(ASSEMBLY_INFO);
208 else if (pAsmInfo->cbAssemblyInfo != sizeof(ASSEMBLY_INFO))
209 return E_INVALIDARG;
212 hr = CreateAssemblyNameObject(&asmname, pszAssemblyName,
213 CANOF_PARSE_DISPLAY_NAME, NULL);
214 if (FAILED(hr))
215 return hr;
217 hr = CreateAssemblyEnum(&asmenum, NULL, asmname, ASM_CACHE_GAC, NULL);
218 if (FAILED(hr))
219 goto done;
221 hr = IAssemblyEnum_GetNextAssembly(asmenum, NULL, &next, 0);
222 if (hr == S_FALSE)
224 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
225 goto done;
228 if (!pAsmInfo)
229 goto done;
231 hr = IAssemblyName_GetPath(next, pAsmInfo->pszCurrentAssemblyPathBuf, &pAsmInfo->cchBuf);
233 pAsmInfo->dwAssemblyFlags = ASSEMBLYINFO_FLAG_INSTALLED;
235 done:
236 IAssemblyName_Release(asmname);
237 if (next) IAssemblyName_Release(next);
238 if (asmenum) IAssemblyEnum_Release(asmenum);
240 return hr;
243 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyCacheItem(IAssemblyCache *iface,
244 DWORD dwFlags,
245 PVOID pvReserved,
246 IAssemblyCacheItem **ppAsmItem,
247 LPCWSTR pszAssemblyName)
249 FIXME("(%p, %d, %p, %p, %s) stub!\n", iface, dwFlags, pvReserved,
250 ppAsmItem, debugstr_w(pszAssemblyName));
252 return E_NOTIMPL;
255 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyScavenger(IAssemblyCache *iface,
256 IUnknown **ppUnkReserved)
258 FIXME("(%p, %p) stub!\n", iface, ppUnkReserved);
259 return E_NOTIMPL;
262 static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface,
263 DWORD dwFlags,
264 LPCWSTR pszManifestFilePath,
265 LPCFUSION_INSTALL_REFERENCE pRefData)
267 static const WCHAR format[] =
268 {'%','s','\\','%','s','\\','%','s','_','_','%','s','\\',0};
270 ASSEMBLY *assembly;
271 LPWSTR filename;
272 LPWSTR name = NULL;
273 LPWSTR token = NULL;
274 LPWSTR version = NULL;
275 LPWSTR asmpath = NULL;
276 WCHAR path[MAX_PATH];
277 WCHAR asmdir[MAX_PATH];
278 LPWSTR ext;
279 HRESULT hr;
281 static const WCHAR ext_exe[] = {'.','e','x','e',0};
282 static const WCHAR ext_dll[] = {'.','d','l','l',0};
284 TRACE("(%p, %d, %s, %p)\n", iface, dwFlags,
285 debugstr_w(pszManifestFilePath), pRefData);
287 if (!pszManifestFilePath || !*pszManifestFilePath)
288 return E_INVALIDARG;
290 if (!(ext = strrchrW(pszManifestFilePath, '.')))
291 return HRESULT_FROM_WIN32(ERROR_INVALID_NAME);
293 if (lstrcmpiW(ext, ext_exe) && lstrcmpiW(ext, ext_dll))
294 return HRESULT_FROM_WIN32(ERROR_INVALID_NAME);
296 if (GetFileAttributesW(pszManifestFilePath) == INVALID_FILE_ATTRIBUTES)
297 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
299 hr = assembly_create(&assembly, pszManifestFilePath);
300 if (FAILED(hr))
302 hr = COR_E_ASSEMBLYEXPECTED;
303 goto done;
306 hr = assembly_get_name(assembly, &name);
307 if (FAILED(hr))
308 goto done;
310 hr = assembly_get_pubkey_token(assembly, &token);
311 if (FAILED(hr))
312 goto done;
314 hr = assembly_get_version(assembly, &version);
315 if (FAILED(hr))
316 goto done;
318 get_assembly_directory(asmdir, MAX_PATH, assembly_get_architecture(assembly));
320 sprintfW(path, format, asmdir, name, version, token);
322 create_full_path(path);
324 hr = assembly_get_path(assembly, &asmpath);
325 if (FAILED(hr))
326 goto done;
328 filename = PathFindFileNameW(asmpath);
330 strcatW(path, filename);
331 if (!CopyFileW(asmpath, path, FALSE))
332 hr = HRESULT_FROM_WIN32(GetLastError());
334 done:
335 HeapFree(GetProcessHeap(), 0, name);
336 HeapFree(GetProcessHeap(), 0, token);
337 HeapFree(GetProcessHeap(), 0, version);
338 HeapFree(GetProcessHeap(), 0, asmpath);
339 assembly_release(assembly);
340 return hr;
343 static const IAssemblyCacheVtbl AssemblyCacheVtbl = {
344 IAssemblyCacheImpl_QueryInterface,
345 IAssemblyCacheImpl_AddRef,
346 IAssemblyCacheImpl_Release,
347 IAssemblyCacheImpl_UninstallAssembly,
348 IAssemblyCacheImpl_QueryAssemblyInfo,
349 IAssemblyCacheImpl_CreateAssemblyCacheItem,
350 IAssemblyCacheImpl_CreateAssemblyScavenger,
351 IAssemblyCacheImpl_InstallAssembly
354 /******************************************************************
355 * CreateAssemblyCache (FUSION.@)
357 HRESULT WINAPI CreateAssemblyCache(IAssemblyCache **ppAsmCache, DWORD dwReserved)
359 IAssemblyCacheImpl *cache;
361 TRACE("(%p, %d)\n", ppAsmCache, dwReserved);
363 if (!ppAsmCache)
364 return E_INVALIDARG;
366 *ppAsmCache = NULL;
368 cache = HeapAlloc(GetProcessHeap(), 0, sizeof(IAssemblyCacheImpl));
369 if (!cache)
370 return E_OUTOFMEMORY;
372 cache->IAssemblyCache_iface.lpVtbl = &AssemblyCacheVtbl;
373 cache->ref = 1;
375 *ppAsmCache = &cache->IAssemblyCache_iface;
377 return S_OK;
380 /* IAssemblyCacheItem */
382 typedef struct {
383 IAssemblyCacheItem IAssemblyCacheItem_iface;
385 LONG ref;
386 } IAssemblyCacheItemImpl;
388 static inline IAssemblyCacheItemImpl *impl_from_IAssemblyCacheItem(IAssemblyCacheItem *iface)
390 return CONTAINING_RECORD(iface, IAssemblyCacheItemImpl, IAssemblyCacheItem_iface);
393 static HRESULT WINAPI IAssemblyCacheItemImpl_QueryInterface(IAssemblyCacheItem *iface,
394 REFIID riid, LPVOID *ppobj)
396 IAssemblyCacheItemImpl *This = impl_from_IAssemblyCacheItem(iface);
398 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
400 *ppobj = NULL;
402 if (IsEqualIID(riid, &IID_IUnknown) ||
403 IsEqualIID(riid, &IID_IAssemblyCacheItem))
405 IUnknown_AddRef(iface);
406 *ppobj = This;
407 return S_OK;
410 WARN("(%p, %s, %p): not found\n", This, debugstr_guid(riid), ppobj);
411 return E_NOINTERFACE;
414 static ULONG WINAPI IAssemblyCacheItemImpl_AddRef(IAssemblyCacheItem *iface)
416 IAssemblyCacheItemImpl *This = impl_from_IAssemblyCacheItem(iface);
417 ULONG refCount = InterlockedIncrement(&This->ref);
419 TRACE("(%p)->(ref before = %u)\n", This, refCount - 1);
421 return refCount;
424 static ULONG WINAPI IAssemblyCacheItemImpl_Release(IAssemblyCacheItem *iface)
426 IAssemblyCacheItemImpl *This = impl_from_IAssemblyCacheItem(iface);
427 ULONG refCount = InterlockedDecrement(&This->ref);
429 TRACE("(%p)->(ref before = %u)\n", This, refCount + 1);
431 if (!refCount)
432 HeapFree(GetProcessHeap(), 0, This);
434 return refCount;
437 static HRESULT WINAPI IAssemblyCacheItemImpl_CreateStream(IAssemblyCacheItem *iface,
438 DWORD dwFlags,
439 LPCWSTR pszStreamName,
440 DWORD dwFormat,
441 DWORD dwFormatFlags,
442 IStream **ppIStream,
443 ULARGE_INTEGER *puliMaxSize)
445 FIXME("(%p, %d, %s, %d, %d, %p, %p) stub!\n", iface, dwFlags,
446 debugstr_w(pszStreamName), dwFormat, dwFormatFlags, ppIStream, puliMaxSize);
448 return E_NOTIMPL;
451 static HRESULT WINAPI IAssemblyCacheItemImpl_Commit(IAssemblyCacheItem *iface,
452 DWORD dwFlags,
453 ULONG *pulDisposition)
455 FIXME("(%p, %d, %p) stub!\n", iface, dwFlags, pulDisposition);
456 return E_NOTIMPL;
459 static HRESULT WINAPI IAssemblyCacheItemImpl_AbortItem(IAssemblyCacheItem *iface)
461 FIXME("(%p) stub!\n", iface);
462 return E_NOTIMPL;
465 static const IAssemblyCacheItemVtbl AssemblyCacheItemVtbl = {
466 IAssemblyCacheItemImpl_QueryInterface,
467 IAssemblyCacheItemImpl_AddRef,
468 IAssemblyCacheItemImpl_Release,
469 IAssemblyCacheItemImpl_CreateStream,
470 IAssemblyCacheItemImpl_Commit,
471 IAssemblyCacheItemImpl_AbortItem