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
)
96 static const WCHAR gac
[] =
97 {'\\','a','s','s','e','m','b','l','y','\\','G','A','C','_','M','S','I','L',0};
99 FIXME("Ignoring assembly architecture\n");
101 GetWindowsDirectoryW(dir
, size
);
109 const IAssemblyCacheVtbl
*lpIAssemblyCacheVtbl
;
112 } IAssemblyCacheImpl
;
114 static HRESULT WINAPI
IAssemblyCacheImpl_QueryInterface(IAssemblyCache
*iface
,
115 REFIID riid
, LPVOID
*ppobj
)
117 IAssemblyCacheImpl
*This
= (IAssemblyCacheImpl
*)iface
;
119 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
123 if (IsEqualIID(riid
, &IID_IUnknown
) ||
124 IsEqualIID(riid
, &IID_IAssemblyCache
))
126 IUnknown_AddRef(iface
);
131 WARN("(%p, %s, %p): not found\n", This
, debugstr_guid(riid
), ppobj
);
132 return E_NOINTERFACE
;
135 static ULONG WINAPI
IAssemblyCacheImpl_AddRef(IAssemblyCache
*iface
)
137 IAssemblyCacheImpl
*This
= (IAssemblyCacheImpl
*)iface
;
138 ULONG refCount
= InterlockedIncrement(&This
->ref
);
140 TRACE("(%p)->(ref before = %u)\n", This
, refCount
- 1);
145 static ULONG WINAPI
IAssemblyCacheImpl_Release(IAssemblyCache
*iface
)
147 IAssemblyCacheImpl
*This
= (IAssemblyCacheImpl
*)iface
;
148 ULONG refCount
= InterlockedDecrement(&This
->ref
);
150 TRACE("(%p)->(ref before = %u)\n", This
, refCount
+ 1);
153 HeapFree(GetProcessHeap(), 0, This
);
158 static HRESULT WINAPI
IAssemblyCacheImpl_UninstallAssembly(IAssemblyCache
*iface
,
160 LPCWSTR pszAssemblyName
,
161 LPCFUSION_INSTALL_REFERENCE pRefData
,
162 ULONG
*pulDisposition
)
164 FIXME("(%p, %d, %s, %p, %p) stub!\n", iface
, dwFlags
,
165 debugstr_w(pszAssemblyName
), pRefData
, pulDisposition
);
170 static HRESULT WINAPI
IAssemblyCacheImpl_QueryAssemblyInfo(IAssemblyCache
*iface
,
172 LPCWSTR pszAssemblyName
,
173 ASSEMBLY_INFO
*pAsmInfo
)
175 IAssemblyName
*asmname
, *next
= NULL
;
176 IAssemblyEnum
*asmenum
= NULL
;
179 TRACE("(%p, %d, %s, %p)\n", iface
, dwFlags
,
180 debugstr_w(pszAssemblyName
), pAsmInfo
);
184 if (pAsmInfo
->cbAssemblyInfo
== 0)
185 pAsmInfo
->cbAssemblyInfo
= sizeof(ASSEMBLY_INFO
);
186 else if (pAsmInfo
->cbAssemblyInfo
!= sizeof(ASSEMBLY_INFO
))
190 hr
= CreateAssemblyNameObject(&asmname
, pszAssemblyName
,
191 CANOF_PARSE_DISPLAY_NAME
, NULL
);
195 hr
= CreateAssemblyEnum(&asmenum
, NULL
, asmname
, ASM_CACHE_GAC
, NULL
);
199 hr
= IAssemblyEnum_GetNextAssembly(asmenum
, NULL
, &next
, 0);
202 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
209 pAsmInfo
->dwAssemblyFlags
= ASSEMBLYINFO_FLAG_INSTALLED
;
212 IAssemblyName_Release(asmname
);
213 if (next
) IAssemblyName_Release(next
);
214 if (asmenum
) IAssemblyEnum_Release(asmenum
);
219 static HRESULT WINAPI
IAssemblyCacheImpl_CreateAssemblyCacheItem(IAssemblyCache
*iface
,
222 IAssemblyCacheItem
**ppAsmItem
,
223 LPCWSTR pszAssemblyName
)
225 FIXME("(%p, %d, %p, %p, %s) stub!\n", iface
, dwFlags
, pvReserved
,
226 ppAsmItem
, debugstr_w(pszAssemblyName
));
231 static HRESULT WINAPI
IAssemblyCacheImpl_CreateAssemblyScavenger(IAssemblyCache
*iface
,
232 IUnknown
**ppUnkReserved
)
234 FIXME("(%p, %p) stub!\n", iface
, ppUnkReserved
);
238 static HRESULT WINAPI
IAssemblyCacheImpl_InstallAssembly(IAssemblyCache
*iface
,
240 LPCWSTR pszManifestFilePath
,
241 LPCFUSION_INSTALL_REFERENCE pRefData
)
243 static const WCHAR format
[] =
244 {'%','s','\\','%','s','\\','%','s','_','_','%','s','\\',0};
250 LPWSTR version
= NULL
;
251 LPWSTR asmpath
= NULL
;
252 WCHAR path
[MAX_PATH
];
253 WCHAR asmdir
[MAX_PATH
];
257 static const WCHAR ext_exe
[] = {'.','e','x','e',0};
258 static const WCHAR ext_dll
[] = {'.','d','l','l',0};
260 TRACE("(%p, %d, %s, %p)\n", iface
, dwFlags
,
261 debugstr_w(pszManifestFilePath
), pRefData
);
263 if (!pszManifestFilePath
|| !*pszManifestFilePath
)
266 if (!(ext
= strrchrW(pszManifestFilePath
, '.')))
267 return HRESULT_FROM_WIN32(ERROR_INVALID_NAME
);
269 if (lstrcmpiW(ext
, ext_exe
) && lstrcmpiW(ext
, ext_dll
))
270 return HRESULT_FROM_WIN32(ERROR_INVALID_NAME
);
272 if (GetFileAttributesW(pszManifestFilePath
) == INVALID_FILE_ATTRIBUTES
)
273 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
275 hr
= assembly_create(&assembly
, pszManifestFilePath
);
278 hr
= COR_E_ASSEMBLYEXPECTED
;
282 hr
= assembly_get_name(assembly
, &name
);
286 hr
= assembly_get_pubkey_token(assembly
, &token
);
290 hr
= assembly_get_version(assembly
, &version
);
294 get_assembly_directory(asmdir
, MAX_PATH
);
296 sprintfW(path
, format
, asmdir
, name
, version
, token
);
298 create_full_path(path
);
300 hr
= assembly_get_path(assembly
, &asmpath
);
304 filename
= PathFindFileNameW(asmpath
);
306 strcatW(path
, filename
);
307 if (!CopyFileW(asmpath
, path
, FALSE
))
308 hr
= HRESULT_FROM_WIN32(GetLastError());
311 HeapFree(GetProcessHeap(), 0, name
);
312 HeapFree(GetProcessHeap(), 0, token
);
313 HeapFree(GetProcessHeap(), 0, version
);
314 HeapFree(GetProcessHeap(), 0, asmpath
);
315 assembly_release(assembly
);
319 static const IAssemblyCacheVtbl AssemblyCacheVtbl
= {
320 IAssemblyCacheImpl_QueryInterface
,
321 IAssemblyCacheImpl_AddRef
,
322 IAssemblyCacheImpl_Release
,
323 IAssemblyCacheImpl_UninstallAssembly
,
324 IAssemblyCacheImpl_QueryAssemblyInfo
,
325 IAssemblyCacheImpl_CreateAssemblyCacheItem
,
326 IAssemblyCacheImpl_CreateAssemblyScavenger
,
327 IAssemblyCacheImpl_InstallAssembly
330 /******************************************************************
331 * CreateAssemblyCache (FUSION.@)
333 HRESULT WINAPI
CreateAssemblyCache(IAssemblyCache
**ppAsmCache
, DWORD dwReserved
)
335 IAssemblyCacheImpl
*cache
;
337 TRACE("(%p, %d)\n", ppAsmCache
, dwReserved
);
344 cache
= HeapAlloc(GetProcessHeap(), 0, sizeof(IAssemblyCacheImpl
));
346 return E_OUTOFMEMORY
;
348 cache
->lpIAssemblyCacheVtbl
= &AssemblyCacheVtbl
;
351 *ppAsmCache
= (IAssemblyCache
*)cache
;
356 /* IAssemblyCacheItem */
359 const IAssemblyCacheItemVtbl
*lpIAssemblyCacheItemVtbl
;
362 } IAssemblyCacheItemImpl
;
364 static HRESULT WINAPI
IAssemblyCacheItemImpl_QueryInterface(IAssemblyCacheItem
*iface
,
365 REFIID riid
, LPVOID
*ppobj
)
367 IAssemblyCacheItemImpl
*This
= (IAssemblyCacheItemImpl
*)iface
;
369 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppobj
);
373 if (IsEqualIID(riid
, &IID_IUnknown
) ||
374 IsEqualIID(riid
, &IID_IAssemblyCacheItem
))
376 IUnknown_AddRef(iface
);
381 WARN("(%p, %s, %p): not found\n", This
, debugstr_guid(riid
), ppobj
);
382 return E_NOINTERFACE
;
385 static ULONG WINAPI
IAssemblyCacheItemImpl_AddRef(IAssemblyCacheItem
*iface
)
387 IAssemblyCacheItemImpl
*This
= (IAssemblyCacheItemImpl
*)iface
;
388 ULONG refCount
= InterlockedIncrement(&This
->ref
);
390 TRACE("(%p)->(ref before = %u)\n", This
, refCount
- 1);
395 static ULONG WINAPI
IAssemblyCacheItemImpl_Release(IAssemblyCacheItem
*iface
)
397 IAssemblyCacheItemImpl
*This
= (IAssemblyCacheItemImpl
*)iface
;
398 ULONG refCount
= InterlockedDecrement(&This
->ref
);
400 TRACE("(%p)->(ref before = %u)\n", This
, refCount
+ 1);
403 HeapFree(GetProcessHeap(), 0, This
);
408 static HRESULT WINAPI
IAssemblyCacheItemImpl_CreateStream(IAssemblyCacheItem
*iface
,
410 LPCWSTR pszStreamName
,
414 ULARGE_INTEGER
*puliMaxSize
)
416 FIXME("(%p, %d, %s, %d, %d, %p, %p) stub!\n", iface
, dwFlags
,
417 debugstr_w(pszStreamName
), dwFormat
, dwFormatFlags
, ppIStream
, puliMaxSize
);
422 static HRESULT WINAPI
IAssemblyCacheItemImpl_Commit(IAssemblyCacheItem
*iface
,
424 ULONG
*pulDisposition
)
426 FIXME("(%p, %d, %p) stub!\n", iface
, dwFlags
, pulDisposition
);
430 static HRESULT WINAPI
IAssemblyCacheItemImpl_AbortItem(IAssemblyCacheItem
*iface
)
432 FIXME("(%p) stub!\n", iface
);
436 static const IAssemblyCacheItemVtbl AssemblyCacheItemVtbl
= {
437 IAssemblyCacheItemImpl_QueryInterface
,
438 IAssemblyCacheItemImpl_AddRef
,
439 IAssemblyCacheItemImpl_Release
,
440 IAssemblyCacheItemImpl_CreateStream
,
441 IAssemblyCacheItemImpl_Commit
,
442 IAssemblyCacheItemImpl_AbortItem