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 const IAssemblyCacheVtbl *lpIAssemblyCacheVtbl;
129 } IAssemblyCacheImpl;
131 static HRESULT WINAPI IAssemblyCacheImpl_QueryInterface(IAssemblyCache *iface,
132 REFIID riid, LPVOID *ppobj)
134 IAssemblyCacheImpl *This = (IAssemblyCacheImpl *)iface;
136 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
140 if (IsEqualIID(riid, &IID_IUnknown) ||
141 IsEqualIID(riid, &IID_IAssemblyCache))
143 IUnknown_AddRef(iface);
148 WARN("(%p, %s, %p): not found\n", This, debugstr_guid(riid), ppobj);
149 return E_NOINTERFACE;
152 static ULONG WINAPI IAssemblyCacheImpl_AddRef(IAssemblyCache *iface)
154 IAssemblyCacheImpl *This = (IAssemblyCacheImpl *)iface;
155 ULONG refCount = InterlockedIncrement(&This->ref);
157 TRACE("(%p)->(ref before = %u)\n", This, refCount - 1);
162 static ULONG WINAPI IAssemblyCacheImpl_Release(IAssemblyCache *iface)
164 IAssemblyCacheImpl *This = (IAssemblyCacheImpl *)iface;
165 ULONG refCount = InterlockedDecrement(&This->ref);
167 TRACE("(%p)->(ref before = %u)\n", This, refCount + 1);
170 HeapFree(GetProcessHeap(), 0, This);
175 static HRESULT WINAPI IAssemblyCacheImpl_UninstallAssembly(IAssemblyCache *iface,
177 LPCWSTR pszAssemblyName,
178 LPCFUSION_INSTALL_REFERENCE pRefData,
179 ULONG *pulDisposition)
181 FIXME("(%p, %d, %s, %p, %p) stub!\n", iface, dwFlags,
182 debugstr_w(pszAssemblyName), pRefData, pulDisposition);
187 static HRESULT WINAPI IAssemblyCacheImpl_QueryAssemblyInfo(IAssemblyCache *iface,
189 LPCWSTR pszAssemblyName,
190 ASSEMBLY_INFO *pAsmInfo)
192 IAssemblyName *asmname, *next = NULL;
193 IAssemblyEnum *asmenum = NULL;
196 TRACE("(%p, %d, %s, %p)\n", iface, dwFlags,
197 debugstr_w(pszAssemblyName), pAsmInfo);
201 if (pAsmInfo->cbAssemblyInfo == 0)
202 pAsmInfo->cbAssemblyInfo = sizeof(ASSEMBLY_INFO);
203 else if (pAsmInfo->cbAssemblyInfo != sizeof(ASSEMBLY_INFO))
207 hr = CreateAssemblyNameObject(&asmname, pszAssemblyName,
208 CANOF_PARSE_DISPLAY_NAME, NULL);
212 hr = CreateAssemblyEnum(&asmenum, NULL, asmname, ASM_CACHE_GAC, NULL);
216 hr = IAssemblyEnum_GetNextAssembly(asmenum, NULL, &next, 0);
219 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
226 hr = IAssemblyName_GetPath(next, pAsmInfo->pszCurrentAssemblyPathBuf, &pAsmInfo->cchBuf);
228 pAsmInfo->dwAssemblyFlags = ASSEMBLYINFO_FLAG_INSTALLED;
231 IAssemblyName_Release(asmname);
232 if (next) IAssemblyName_Release(next);
233 if (asmenum) IAssemblyEnum_Release(asmenum);
238 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyCacheItem(IAssemblyCache *iface,
241 IAssemblyCacheItem **ppAsmItem,
242 LPCWSTR pszAssemblyName)
244 FIXME("(%p, %d, %p, %p, %s) stub!\n", iface, dwFlags, pvReserved,
245 ppAsmItem, debugstr_w(pszAssemblyName));
250 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyScavenger(IAssemblyCache *iface,
251 IUnknown **ppUnkReserved)
253 FIXME("(%p, %p) stub!\n", iface, ppUnkReserved);
257 static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface,
259 LPCWSTR pszManifestFilePath,
260 LPCFUSION_INSTALL_REFERENCE pRefData)
262 static const WCHAR format[] =
263 {'%','s','\\','%','s','\\','%','s','_','_','%','s','\\',0};
269 LPWSTR version = NULL;
270 LPWSTR asmpath = NULL;
271 WCHAR path[MAX_PATH];
272 WCHAR asmdir[MAX_PATH];
276 static const WCHAR ext_exe[] = {'.','e','x','e',0};
277 static const WCHAR ext_dll[] = {'.','d','l','l',0};
279 TRACE("(%p, %d, %s, %p)\n", iface, dwFlags,
280 debugstr_w(pszManifestFilePath), pRefData);
282 if (!pszManifestFilePath || !*pszManifestFilePath)
285 if (!(ext = strrchrW(pszManifestFilePath, '.')))
286 return HRESULT_FROM_WIN32(ERROR_INVALID_NAME);
288 if (lstrcmpiW(ext, ext_exe) && lstrcmpiW(ext, ext_dll))
289 return HRESULT_FROM_WIN32(ERROR_INVALID_NAME);
291 if (GetFileAttributesW(pszManifestFilePath) == INVALID_FILE_ATTRIBUTES)
292 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
294 hr = assembly_create(&assembly, pszManifestFilePath);
297 hr = COR_E_ASSEMBLYEXPECTED;
301 hr = assembly_get_name(assembly, &name);
305 hr = assembly_get_pubkey_token(assembly, &token);
309 hr = assembly_get_version(assembly, &version);
313 get_assembly_directory(asmdir, MAX_PATH, assembly_get_architecture(assembly));
315 sprintfW(path, format, asmdir, name, version, token);
317 create_full_path(path);
319 hr = assembly_get_path(assembly, &asmpath);
323 filename = PathFindFileNameW(asmpath);
325 strcatW(path, filename);
326 if (!CopyFileW(asmpath, path, FALSE))
327 hr = HRESULT_FROM_WIN32(GetLastError());
330 HeapFree(GetProcessHeap(), 0, name);
331 HeapFree(GetProcessHeap(), 0, token);
332 HeapFree(GetProcessHeap(), 0, version);
333 HeapFree(GetProcessHeap(), 0, asmpath);
334 assembly_release(assembly);
338 static const IAssemblyCacheVtbl AssemblyCacheVtbl = {
339 IAssemblyCacheImpl_QueryInterface,
340 IAssemblyCacheImpl_AddRef,
341 IAssemblyCacheImpl_Release,
342 IAssemblyCacheImpl_UninstallAssembly,
343 IAssemblyCacheImpl_QueryAssemblyInfo,
344 IAssemblyCacheImpl_CreateAssemblyCacheItem,
345 IAssemblyCacheImpl_CreateAssemblyScavenger,
346 IAssemblyCacheImpl_InstallAssembly
349 /******************************************************************
350 * CreateAssemblyCache (FUSION.@)
352 HRESULT WINAPI CreateAssemblyCache(IAssemblyCache **ppAsmCache, DWORD dwReserved)
354 IAssemblyCacheImpl *cache;
356 TRACE("(%p, %d)\n", ppAsmCache, dwReserved);
363 cache = HeapAlloc(GetProcessHeap(), 0, sizeof(IAssemblyCacheImpl));
365 return E_OUTOFMEMORY;
367 cache->lpIAssemblyCacheVtbl = &AssemblyCacheVtbl;
370 *ppAsmCache = (IAssemblyCache *)cache;
375 /* IAssemblyCacheItem */
378 const IAssemblyCacheItemVtbl *lpIAssemblyCacheItemVtbl;
381 } IAssemblyCacheItemImpl;
383 static HRESULT WINAPI IAssemblyCacheItemImpl_QueryInterface(IAssemblyCacheItem *iface,
384 REFIID riid, LPVOID *ppobj)
386 IAssemblyCacheItemImpl *This = (IAssemblyCacheItemImpl *)iface;
388 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
392 if (IsEqualIID(riid, &IID_IUnknown) ||
393 IsEqualIID(riid, &IID_IAssemblyCacheItem))
395 IUnknown_AddRef(iface);
400 WARN("(%p, %s, %p): not found\n", This, debugstr_guid(riid), ppobj);
401 return E_NOINTERFACE;
404 static ULONG WINAPI IAssemblyCacheItemImpl_AddRef(IAssemblyCacheItem *iface)
406 IAssemblyCacheItemImpl *This = (IAssemblyCacheItemImpl *)iface;
407 ULONG refCount = InterlockedIncrement(&This->ref);
409 TRACE("(%p)->(ref before = %u)\n", This, refCount - 1);
414 static ULONG WINAPI IAssemblyCacheItemImpl_Release(IAssemblyCacheItem *iface)
416 IAssemblyCacheItemImpl *This = (IAssemblyCacheItemImpl *)iface;
417 ULONG refCount = InterlockedDecrement(&This->ref);
419 TRACE("(%p)->(ref before = %u)\n", This, refCount + 1);
422 HeapFree(GetProcessHeap(), 0, This);
427 static HRESULT WINAPI IAssemblyCacheItemImpl_CreateStream(IAssemblyCacheItem *iface,
429 LPCWSTR pszStreamName,
433 ULARGE_INTEGER *puliMaxSize)
435 FIXME("(%p, %d, %s, %d, %d, %p, %p) stub!\n", iface, dwFlags,
436 debugstr_w(pszStreamName), dwFormat, dwFormatFlags, ppIStream, puliMaxSize);
441 static HRESULT WINAPI IAssemblyCacheItemImpl_Commit(IAssemblyCacheItem *iface,
443 ULONG *pulDisposition)
445 FIXME("(%p, %d, %p) stub!\n", iface, dwFlags, pulDisposition);
449 static HRESULT WINAPI IAssemblyCacheItemImpl_AbortItem(IAssemblyCacheItem *iface)
451 FIXME("(%p) stub!\n", iface);
455 static const IAssemblyCacheItemVtbl AssemblyCacheItemVtbl = {
456 IAssemblyCacheItemImpl_QueryInterface,
457 IAssemblyCacheItemImpl_AddRef,
458 IAssemblyCacheItemImpl_Release,
459 IAssemblyCacheItemImpl_CreateStream,
460 IAssemblyCacheItemImpl_Commit,
461 IAssemblyCacheItemImpl_AbortItem