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
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)
50 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) * sizeof(WCHAR));
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))
62 DWORD last_error = GetLastError();
64 if(last_error == ERROR_ALREADY_EXISTS)
67 if(last_error != ERROR_PATH_NOT_FOUND)
73 if(!(slash = strrchrW(new_path, '\\')))
79 len = slash - new_path;
81 if(!create_full_path(new_path))
90 HeapFree(GetProcessHeap(), 0, new_path);
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);
105 switch (architecture)
126 IAssemblyCache IAssemblyCache_iface;
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);
145 if (IsEqualIID(riid, &IID_IUnknown) ||
146 IsEqualIID(riid, &IID_IAssemblyCache))
148 IUnknown_AddRef(iface);
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);
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);
175 HeapFree(GetProcessHeap(), 0, This);
180 static HRESULT WINAPI IAssemblyCacheImpl_UninstallAssembly(IAssemblyCache *iface,
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);
192 static HRESULT WINAPI IAssemblyCacheImpl_QueryAssemblyInfo(IAssemblyCache *iface,
194 LPCWSTR pszAssemblyName,
195 ASSEMBLY_INFO *pAsmInfo)
197 IAssemblyName *asmname, *next = NULL;
198 IAssemblyEnum *asmenum = NULL;
201 TRACE("(%p, %d, %s, %p)\n", iface, dwFlags,
202 debugstr_w(pszAssemblyName), pAsmInfo);
206 if (pAsmInfo->cbAssemblyInfo == 0)
207 pAsmInfo->cbAssemblyInfo = sizeof(ASSEMBLY_INFO);
208 else if (pAsmInfo->cbAssemblyInfo != sizeof(ASSEMBLY_INFO))
212 hr = CreateAssemblyNameObject(&asmname, pszAssemblyName,
213 CANOF_PARSE_DISPLAY_NAME, NULL);
217 hr = CreateAssemblyEnum(&asmenum, NULL, asmname, ASM_CACHE_GAC, NULL);
221 hr = IAssemblyEnum_GetNextAssembly(asmenum, NULL, &next, 0);
224 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
231 hr = IAssemblyName_GetPath(next, pAsmInfo->pszCurrentAssemblyPathBuf, &pAsmInfo->cchBuf);
233 pAsmInfo->dwAssemblyFlags = ASSEMBLYINFO_FLAG_INSTALLED;
236 IAssemblyName_Release(asmname);
237 if (next) IAssemblyName_Release(next);
238 if (asmenum) IAssemblyEnum_Release(asmenum);
243 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyCacheItem(IAssemblyCache *iface,
246 IAssemblyCacheItem **ppAsmItem,
247 LPCWSTR pszAssemblyName)
249 FIXME("(%p, %d, %p, %p, %s) stub!\n", iface, dwFlags, pvReserved,
250 ppAsmItem, debugstr_w(pszAssemblyName));
255 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyScavenger(IAssemblyCache *iface,
256 IUnknown **ppUnkReserved)
258 FIXME("(%p, %p) stub!\n", iface, ppUnkReserved);
262 static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface,
264 LPCWSTR pszManifestFilePath,
265 LPCFUSION_INSTALL_REFERENCE pRefData)
267 static const WCHAR format[] =
268 {'%','s','\\','%','s','\\','%','s','_','_','%','s','\\',0};
274 LPWSTR version = NULL;
275 LPWSTR asmpath = NULL;
276 WCHAR path[MAX_PATH];
277 WCHAR asmdir[MAX_PATH];
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)
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);
302 hr = COR_E_ASSEMBLYEXPECTED;
306 hr = assembly_get_name(assembly, &name);
310 hr = assembly_get_pubkey_token(assembly, &token);
314 hr = assembly_get_version(assembly, &version);
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);
328 filename = PathFindFileNameW(asmpath);
330 strcatW(path, filename);
331 if (!CopyFileW(asmpath, path, FALSE))
332 hr = HRESULT_FROM_WIN32(GetLastError());
335 HeapFree(GetProcessHeap(), 0, name);
336 HeapFree(GetProcessHeap(), 0, token);
337 HeapFree(GetProcessHeap(), 0, version);
338 HeapFree(GetProcessHeap(), 0, asmpath);
339 assembly_release(assembly);
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);
368 cache = HeapAlloc(GetProcessHeap(), 0, sizeof(IAssemblyCacheImpl));
370 return E_OUTOFMEMORY;
372 cache->IAssemblyCache_iface.lpVtbl = &AssemblyCacheVtbl;
375 *ppAsmCache = &cache->IAssemblyCache_iface;
380 /* IAssemblyCacheItem */
383 IAssemblyCacheItem IAssemblyCacheItem_iface;
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);
402 if (IsEqualIID(riid, &IID_IUnknown) ||
403 IsEqualIID(riid, &IID_IAssemblyCacheItem))
405 IUnknown_AddRef(iface);
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);
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);
432 HeapFree(GetProcessHeap(), 0, This);
437 static HRESULT WINAPI IAssemblyCacheItemImpl_CreateStream(IAssemblyCacheItem *iface,
439 LPCWSTR pszStreamName,
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);
451 static HRESULT WINAPI IAssemblyCacheItemImpl_Commit(IAssemblyCacheItem *iface,
453 ULONG *pulDisposition)
455 FIXME("(%p, %d, %p) stub!\n", iface, dwFlags, pulDisposition);
459 static HRESULT WINAPI IAssemblyCacheItemImpl_AbortItem(IAssemblyCacheItem *iface)
461 FIXME("(%p) stub!\n", iface);
465 static const IAssemblyCacheItemVtbl AssemblyCacheItemVtbl = {
466 IAssemblyCacheItemImpl_QueryInterface,
467 IAssemblyCacheItemImpl_AddRef,
468 IAssemblyCacheItemImpl_Release,
469 IAssemblyCacheItemImpl_CreateStream,
470 IAssemblyCacheItemImpl_Commit,
471 IAssemblyCacheItemImpl_AbortItem