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(LPCSTR path)
50 new_path = HeapAlloc(GetProcessHeap(), 0, lstrlenA(path) + 1);
54 lstrcpyA(new_path, path);
56 while ((len = lstrlenA(new_path)) && new_path[len - 1] == '\\')
57 new_path[len - 1] = 0;
59 while (!CreateDirectoryA(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 = strrchr(new_path, '\\')))
79 len = slash - new_path;
81 if(!create_full_path(new_path))
90 HeapFree(GetProcessHeap(), 0, new_path);
97 const IAssemblyCacheVtbl *lpIAssemblyCacheVtbl;
100 } IAssemblyCacheImpl;
102 static HRESULT WINAPI IAssemblyCacheImpl_QueryInterface(IAssemblyCache *iface,
103 REFIID riid, LPVOID *ppobj)
105 IAssemblyCacheImpl *This = (IAssemblyCacheImpl *)iface;
107 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
111 if (IsEqualIID(riid, &IID_IUnknown) ||
112 IsEqualIID(riid, &IID_IAssemblyCache))
114 IUnknown_AddRef(iface);
119 WARN("(%p, %s, %p): not found\n", This, debugstr_guid(riid), ppobj);
120 return E_NOINTERFACE;
123 static ULONG WINAPI IAssemblyCacheImpl_AddRef(IAssemblyCache *iface)
125 IAssemblyCacheImpl *This = (IAssemblyCacheImpl *)iface;
126 ULONG refCount = InterlockedIncrement(&This->ref);
128 TRACE("(%p)->(ref before = %u)\n", This, refCount - 1);
133 static ULONG WINAPI IAssemblyCacheImpl_Release(IAssemblyCache *iface)
135 IAssemblyCacheImpl *This = (IAssemblyCacheImpl *)iface;
136 ULONG refCount = InterlockedDecrement(&This->ref);
138 TRACE("(%p)->(ref before = %u)\n", This, refCount + 1);
141 HeapFree(GetProcessHeap(), 0, This);
146 static HRESULT WINAPI IAssemblyCacheImpl_UninstallAssembly(IAssemblyCache *iface,
148 LPCWSTR pszAssemblyName,
149 LPCFUSION_INSTALL_REFERENCE pRefData,
150 ULONG *pulDisposition)
152 FIXME("(%p, %d, %s, %p, %p) stub!\n", iface, dwFlags,
153 debugstr_w(pszAssemblyName), pRefData, pulDisposition);
158 static HRESULT WINAPI IAssemblyCacheImpl_QueryAssemblyInfo(IAssemblyCache *iface,
160 LPCWSTR pszAssemblyName,
161 ASSEMBLY_INFO *pAsmInfo)
163 IAssemblyName *asmname, *next = NULL;
164 IAssemblyEnum *asmenum = NULL;
167 TRACE("(%p, %d, %s, %p)\n", iface, dwFlags,
168 debugstr_w(pszAssemblyName), pAsmInfo);
172 if (pAsmInfo->cbAssemblyInfo == 0)
173 pAsmInfo->cbAssemblyInfo = sizeof(ASSEMBLY_INFO);
174 else if (pAsmInfo->cbAssemblyInfo != sizeof(ASSEMBLY_INFO))
178 hr = CreateAssemblyNameObject(&asmname, pszAssemblyName,
179 CANOF_PARSE_DISPLAY_NAME, NULL);
183 hr = CreateAssemblyEnum(&asmenum, NULL, asmname, ASM_CACHE_GAC, NULL);
187 hr = IAssemblyEnum_GetNextAssembly(asmenum, NULL, &next, 0);
190 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
197 pAsmInfo->dwAssemblyFlags = ASSEMBLYINFO_FLAG_INSTALLED;
200 IAssemblyName_Release(asmname);
201 if (next) IAssemblyName_Release(next);
202 if (asmenum) IAssemblyEnum_Release(asmenum);
207 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyCacheItem(IAssemblyCache *iface,
210 IAssemblyCacheItem **ppAsmItem,
211 LPCWSTR pszAssemblyName)
213 FIXME("(%p, %d, %p, %p, %s) stub!\n", iface, dwFlags, pvReserved,
214 ppAsmItem, debugstr_w(pszAssemblyName));
219 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyScavenger(IAssemblyCache *iface,
220 IUnknown **ppUnkReserved)
222 FIXME("(%p, %p) stub!\n", iface, ppUnkReserved);
226 static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface,
228 LPCWSTR pszManifestFilePath,
229 LPCFUSION_INSTALL_REFERENCE pRefData)
235 LPSTR version = NULL;
236 LPSTR asmpath = NULL;
238 CHAR windir[MAX_PATH];
242 static const WCHAR ext_exe[] = {'.','e','x','e',0};
243 static const WCHAR ext_dll[] = {'.','d','l','l',0};
245 TRACE("(%p, %d, %s, %p)\n", iface, dwFlags,
246 debugstr_w(pszManifestFilePath), pRefData);
248 if (!pszManifestFilePath || !*pszManifestFilePath)
251 if (!(ext = strrchrW(pszManifestFilePath, '.')))
252 return HRESULT_FROM_WIN32(ERROR_INVALID_NAME);
254 if (lstrcmpiW(ext, ext_exe) && lstrcmpiW(ext, ext_dll))
255 return HRESULT_FROM_WIN32(ERROR_INVALID_NAME);
257 if (GetFileAttributesW(pszManifestFilePath) == INVALID_FILE_ATTRIBUTES)
258 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
260 hr = assembly_create(&assembly, pszManifestFilePath);
263 hr = COR_E_ASSEMBLYEXPECTED;
267 hr = assembly_get_name(assembly, &name);
271 hr = assembly_get_pubkey_token(assembly, &token);
275 hr = assembly_get_version(assembly, &version);
279 GetWindowsDirectoryA(windir, MAX_PATH);
281 FIXME("Ignoring assembly architecture!\n");
283 sprintf(path, "%s\\assembly\\GAC_MSIL\\%s\\%s__%s\\", windir, name,
286 create_full_path(path);
288 hr = assembly_get_path(assembly, &asmpath);
292 filename = PathFindFileNameA(asmpath);
294 lstrcatA(path, filename);
295 if (!CopyFileA(asmpath, path, FALSE))
296 hr = HRESULT_FROM_WIN32(GetLastError());
299 HeapFree(GetProcessHeap(), 0, name);
300 HeapFree(GetProcessHeap(), 0, token);
301 HeapFree(GetProcessHeap(), 0, version);
302 HeapFree(GetProcessHeap(), 0, asmpath);
303 assembly_release(assembly);
307 static const IAssemblyCacheVtbl AssemblyCacheVtbl = {
308 IAssemblyCacheImpl_QueryInterface,
309 IAssemblyCacheImpl_AddRef,
310 IAssemblyCacheImpl_Release,
311 IAssemblyCacheImpl_UninstallAssembly,
312 IAssemblyCacheImpl_QueryAssemblyInfo,
313 IAssemblyCacheImpl_CreateAssemblyCacheItem,
314 IAssemblyCacheImpl_CreateAssemblyScavenger,
315 IAssemblyCacheImpl_InstallAssembly
318 /******************************************************************
319 * CreateAssemblyCache (FUSION.@)
321 HRESULT WINAPI CreateAssemblyCache(IAssemblyCache **ppAsmCache, DWORD dwReserved)
323 IAssemblyCacheImpl *cache;
325 TRACE("(%p, %d)\n", ppAsmCache, dwReserved);
332 cache = HeapAlloc(GetProcessHeap(), 0, sizeof(IAssemblyCacheImpl));
334 return E_OUTOFMEMORY;
336 cache->lpIAssemblyCacheVtbl = &AssemblyCacheVtbl;
339 *ppAsmCache = (IAssemblyCache *)cache;
344 /* IAssemblyCacheItem */
347 const IAssemblyCacheItemVtbl *lpIAssemblyCacheItemVtbl;
350 } IAssemblyCacheItemImpl;
352 static HRESULT WINAPI IAssemblyCacheItemImpl_QueryInterface(IAssemblyCacheItem *iface,
353 REFIID riid, LPVOID *ppobj)
355 IAssemblyCacheItemImpl *This = (IAssemblyCacheItemImpl *)iface;
357 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
361 if (IsEqualIID(riid, &IID_IUnknown) ||
362 IsEqualIID(riid, &IID_IAssemblyCacheItem))
364 IUnknown_AddRef(iface);
369 WARN("(%p, %s, %p): not found\n", This, debugstr_guid(riid), ppobj);
370 return E_NOINTERFACE;
373 static ULONG WINAPI IAssemblyCacheItemImpl_AddRef(IAssemblyCacheItem *iface)
375 IAssemblyCacheItemImpl *This = (IAssemblyCacheItemImpl *)iface;
376 ULONG refCount = InterlockedIncrement(&This->ref);
378 TRACE("(%p)->(ref before = %u)\n", This, refCount - 1);
383 static ULONG WINAPI IAssemblyCacheItemImpl_Release(IAssemblyCacheItem *iface)
385 IAssemblyCacheItemImpl *This = (IAssemblyCacheItemImpl *)iface;
386 ULONG refCount = InterlockedDecrement(&This->ref);
388 TRACE("(%p)->(ref before = %u)\n", This, refCount + 1);
391 HeapFree(GetProcessHeap(), 0, This);
396 static HRESULT WINAPI IAssemblyCacheItemImpl_CreateStream(IAssemblyCacheItem *iface,
398 LPCWSTR pszStreamName,
402 ULARGE_INTEGER *puliMaxSize)
404 FIXME("(%p, %d, %s, %d, %d, %p, %p) stub!\n", iface, dwFlags,
405 debugstr_w(pszStreamName), dwFormat, dwFormatFlags, ppIStream, puliMaxSize);
410 static HRESULT WINAPI IAssemblyCacheItemImpl_Commit(IAssemblyCacheItem *iface,
412 ULONG *pulDisposition)
414 FIXME("(%p, %d, %p) stub!\n", iface, dwFlags, pulDisposition);
418 static HRESULT WINAPI IAssemblyCacheItemImpl_AbortItem(IAssemblyCacheItem *iface)
420 FIXME("(%p) stub!\n", iface);
424 static const IAssemblyCacheItemVtbl AssemblyCacheItemVtbl = {
425 IAssemblyCacheItemImpl_QueryInterface,
426 IAssemblyCacheItemImpl_AddRef,
427 IAssemblyCacheItemImpl_Release,
428 IAssemblyCacheItemImpl_CreateStream,
429 IAssemblyCacheItemImpl_Commit,
430 IAssemblyCacheItemImpl_AbortItem