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 FIXME("(%p, %d, %s, %p) stub!\n", iface, dwFlags,
164 debugstr_w(pszAssemblyName), pAsmInfo);
169 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyCacheItem(IAssemblyCache *iface,
172 IAssemblyCacheItem **ppAsmItem,
173 LPCWSTR pszAssemblyName)
175 FIXME("(%p, %d, %p, %p, %s) stub!\n", iface, dwFlags, pvReserved,
176 ppAsmItem, debugstr_w(pszAssemblyName));
181 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyScavenger(IAssemblyCache *iface,
182 IUnknown **ppUnkReserved)
184 FIXME("(%p, %p) stub!\n", iface, ppUnkReserved);
188 static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface,
190 LPCWSTR pszManifestFilePath,
191 LPCFUSION_INSTALL_REFERENCE pRefData)
197 LPSTR version = NULL;
198 LPSTR asmpath = NULL;
200 CHAR windir[MAX_PATH];
204 static const WCHAR ext_exe[] = {'.','e','x','e',0};
205 static const WCHAR ext_dll[] = {'.','d','l','l',0};
207 TRACE("(%p, %d, %s, %p)\n", iface, dwFlags,
208 debugstr_w(pszManifestFilePath), pRefData);
210 if (!pszManifestFilePath || !*pszManifestFilePath)
213 if (!(ext = strrchrW(pszManifestFilePath, '.')))
214 return HRESULT_FROM_WIN32(ERROR_INVALID_NAME);
216 if (lstrcmpiW(ext, ext_exe) && lstrcmpiW(ext, ext_dll))
217 return HRESULT_FROM_WIN32(ERROR_INVALID_NAME);
219 if (GetFileAttributesW(pszManifestFilePath) == INVALID_FILE_ATTRIBUTES)
220 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
222 hr = assembly_create(&assembly, pszManifestFilePath);
225 hr = COR_E_ASSEMBLYEXPECTED;
229 hr = assembly_get_name(assembly, &name);
233 hr = assembly_get_pubkey_token(assembly, &token);
237 hr = assembly_get_version(assembly, &version);
241 GetWindowsDirectoryA(windir, MAX_PATH);
243 FIXME("Ignoring assembly architecture!\n");
245 sprintf(path, "%s\\assembly\\GAC_MSIL\\%s\\%s__%s\\", windir, name,
248 create_full_path(path);
250 hr = assembly_get_path(assembly, &asmpath);
254 filename = PathFindFileNameA(asmpath);
256 lstrcatA(path, filename);
257 if (!CopyFileA(asmpath, path, FALSE))
258 hr = HRESULT_FROM_WIN32(GetLastError());
261 HeapFree(GetProcessHeap(), 0, name);
262 HeapFree(GetProcessHeap(), 0, token);
263 HeapFree(GetProcessHeap(), 0, version);
264 HeapFree(GetProcessHeap(), 0, asmpath);
265 assembly_release(assembly);
269 static const IAssemblyCacheVtbl AssemblyCacheVtbl = {
270 IAssemblyCacheImpl_QueryInterface,
271 IAssemblyCacheImpl_AddRef,
272 IAssemblyCacheImpl_Release,
273 IAssemblyCacheImpl_UninstallAssembly,
274 IAssemblyCacheImpl_QueryAssemblyInfo,
275 IAssemblyCacheImpl_CreateAssemblyCacheItem,
276 IAssemblyCacheImpl_CreateAssemblyScavenger,
277 IAssemblyCacheImpl_InstallAssembly
280 /******************************************************************
281 * CreateAssemblyCache (FUSION.@)
283 HRESULT WINAPI CreateAssemblyCache(IAssemblyCache **ppAsmCache, DWORD dwReserved)
285 IAssemblyCacheImpl *cache;
287 TRACE("(%p, %d)\n", ppAsmCache, dwReserved);
294 cache = HeapAlloc(GetProcessHeap(), 0, sizeof(IAssemblyCacheImpl));
296 return E_OUTOFMEMORY;
298 cache->lpIAssemblyCacheVtbl = &AssemblyCacheVtbl;
301 *ppAsmCache = (IAssemblyCache *)cache;
306 /* IAssemblyCacheItem */
309 const IAssemblyCacheItemVtbl *lpIAssemblyCacheItemVtbl;
312 } IAssemblyCacheItemImpl;
314 static HRESULT WINAPI IAssemblyCacheItemImpl_QueryInterface(IAssemblyCacheItem *iface,
315 REFIID riid, LPVOID *ppobj)
317 IAssemblyCacheItemImpl *This = (IAssemblyCacheItemImpl *)iface;
319 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
323 if (IsEqualIID(riid, &IID_IUnknown) ||
324 IsEqualIID(riid, &IID_IAssemblyCacheItem))
326 IUnknown_AddRef(iface);
331 WARN("(%p, %s, %p): not found\n", This, debugstr_guid(riid), ppobj);
332 return E_NOINTERFACE;
335 static ULONG WINAPI IAssemblyCacheItemImpl_AddRef(IAssemblyCacheItem *iface)
337 IAssemblyCacheItemImpl *This = (IAssemblyCacheItemImpl *)iface;
338 ULONG refCount = InterlockedIncrement(&This->ref);
340 TRACE("(%p)->(ref before = %u)\n", This, refCount - 1);
345 static ULONG WINAPI IAssemblyCacheItemImpl_Release(IAssemblyCacheItem *iface)
347 IAssemblyCacheItemImpl *This = (IAssemblyCacheItemImpl *)iface;
348 ULONG refCount = InterlockedDecrement(&This->ref);
350 TRACE("(%p)->(ref before = %u)\n", This, refCount + 1);
353 HeapFree(GetProcessHeap(), 0, This);
358 static HRESULT WINAPI IAssemblyCacheItemImpl_CreateStream(IAssemblyCacheItem *iface,
360 LPCWSTR pszStreamName,
364 ULARGE_INTEGER *puliMaxSize)
366 FIXME("(%p, %d, %s, %d, %d, %p, %p) stub!\n", iface, dwFlags,
367 debugstr_w(pszStreamName), dwFormat, dwFormatFlags, ppIStream, puliMaxSize);
372 static HRESULT WINAPI IAssemblyCacheItemImpl_Commit(IAssemblyCacheItem *iface,
374 ULONG *pulDisposition)
376 FIXME("(%p, %d, %p) stub!\n", iface, dwFlags, pulDisposition);
380 static HRESULT WINAPI IAssemblyCacheItemImpl_AbortItem(IAssemblyCacheItem *iface)
382 FIXME("(%p) stub!\n", iface);
386 static const IAssemblyCacheItemVtbl AssemblyCacheItemVtbl = {
387 IAssemblyCacheItemImpl_QueryInterface,
388 IAssemblyCacheItemImpl_AddRef,
389 IAssemblyCacheItemImpl_Release,
390 IAssemblyCacheItemImpl_CreateStream,
391 IAssemblyCacheItemImpl_Commit,
392 IAssemblyCacheItemImpl_AbortItem
398 const IAssemblyEnumVtbl *lpIAssemblyEnumVtbl;
403 static HRESULT WINAPI IAssemblyEnumImpl_QueryInterface(IAssemblyEnum *iface,
404 REFIID riid, LPVOID *ppobj)
406 IAssemblyEnumImpl *This = (IAssemblyEnumImpl *)iface;
408 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
412 if (IsEqualIID(riid, &IID_IUnknown) ||
413 IsEqualIID(riid, &IID_IAssemblyEnum))
415 IUnknown_AddRef(iface);
420 WARN("(%p, %s, %p): not found\n", This, debugstr_guid(riid), ppobj);
421 return E_NOINTERFACE;
424 static ULONG WINAPI IAssemblyEnumImpl_AddRef(IAssemblyEnum *iface)
426 IAssemblyEnumImpl *This = (IAssemblyEnumImpl *)iface;
427 ULONG refCount = InterlockedIncrement(&This->ref);
429 TRACE("(%p)->(ref before = %u)\n", This, refCount - 1);
434 static ULONG WINAPI IAssemblyEnumImpl_Release(IAssemblyEnum *iface)
436 IAssemblyEnumImpl *This = (IAssemblyEnumImpl *)iface;
437 ULONG refCount = InterlockedDecrement(&This->ref);
439 TRACE("(%p)->(ref before = %u)\n", This, refCount + 1);
442 HeapFree(GetProcessHeap(), 0, This);
447 static HRESULT WINAPI IAssemblyEnumImpl_GetNextAssembly(IAssemblyEnum *iface,
449 IAssemblyName **ppName,
452 FIXME("(%p, %p, %p, %d) stub!\n", iface, pvReserved, ppName, dwFlags);
456 static HRESULT WINAPI IAssemblyEnumImpl_Reset(IAssemblyEnum *iface)
458 FIXME("(%p) stub!\n", iface);
462 static HRESULT WINAPI IAssemblyEnumImpl_Clone(IAssemblyEnum *iface,
463 IAssemblyEnum **ppEnum)
465 FIXME("(%p, %p) stub!\n", iface, ppEnum);
469 static const IAssemblyEnumVtbl AssemblyEnumVtbl = {
470 IAssemblyEnumImpl_QueryInterface,
471 IAssemblyEnumImpl_AddRef,
472 IAssemblyEnumImpl_Release,
473 IAssemblyEnumImpl_GetNextAssembly,
474 IAssemblyEnumImpl_Reset,
475 IAssemblyEnumImpl_Clone