comctl32: Simplify DATETIME_Char.
[wine/wine64.git] / dlls / fusion / asmcache.c
blob57c7aeded7d1ebd8ada8a0527207b3c1d1769acd
1 /*
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winver.h"
30 #include "wincrypt.h"
31 #include "winreg.h"
32 #include "shlwapi.h"
33 #include "dbghelp.h"
34 #include "ole2.h"
35 #include "fusion.h"
36 #include "corerror.h"
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)
46 LPSTR new_path;
47 BOOL ret = TRUE;
48 int len;
50 new_path = HeapAlloc(GetProcessHeap(), 0, lstrlenA(path) + 1);
51 if (!new_path)
52 return FALSE;
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))
61 LPSTR slash;
62 DWORD last_error = GetLastError();
64 if(last_error == ERROR_ALREADY_EXISTS)
65 break;
67 if(last_error != ERROR_PATH_NOT_FOUND)
69 ret = FALSE;
70 break;
73 if(!(slash = strrchr(new_path, '\\')))
75 ret = FALSE;
76 break;
79 len = slash - new_path;
80 new_path[len] = 0;
81 if(!create_full_path(new_path))
83 ret = FALSE;
84 break;
87 new_path[len] = '\\';
90 HeapFree(GetProcessHeap(), 0, new_path);
91 return ret;
94 /* IAssemblyCache */
96 typedef struct {
97 const IAssemblyCacheVtbl *lpIAssemblyCacheVtbl;
99 LONG ref;
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);
109 *ppobj = NULL;
111 if (IsEqualIID(riid, &IID_IUnknown) ||
112 IsEqualIID(riid, &IID_IAssemblyCache))
114 IUnknown_AddRef(iface);
115 *ppobj = This;
116 return S_OK;
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);
130 return refCount;
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);
140 if (!refCount)
141 HeapFree(GetProcessHeap(), 0, This);
143 return refCount;
146 static HRESULT WINAPI IAssemblyCacheImpl_UninstallAssembly(IAssemblyCache *iface,
147 DWORD dwFlags,
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);
155 return E_NOTIMPL;
158 static HRESULT WINAPI IAssemblyCacheImpl_QueryAssemblyInfo(IAssemblyCache *iface,
159 DWORD dwFlags,
160 LPCWSTR pszAssemblyName,
161 ASSEMBLY_INFO *pAsmInfo)
163 FIXME("(%p, %d, %s, %p) stub!\n", iface, dwFlags,
164 debugstr_w(pszAssemblyName), pAsmInfo);
166 return E_NOTIMPL;
169 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyCacheItem(IAssemblyCache *iface,
170 DWORD dwFlags,
171 PVOID pvReserved,
172 IAssemblyCacheItem **ppAsmItem,
173 LPCWSTR pszAssemblyName)
175 FIXME("(%p, %d, %p, %p, %s) stub!\n", iface, dwFlags, pvReserved,
176 ppAsmItem, debugstr_w(pszAssemblyName));
178 return E_NOTIMPL;
181 static HRESULT WINAPI IAssemblyCacheImpl_CreateAssemblyScavenger(IAssemblyCache *iface,
182 IUnknown **ppUnkReserved)
184 FIXME("(%p, %p) stub!\n", iface, ppUnkReserved);
185 return E_NOTIMPL;
188 static HRESULT WINAPI IAssemblyCacheImpl_InstallAssembly(IAssemblyCache *iface,
189 DWORD dwFlags,
190 LPCWSTR pszManifestFilePath,
191 LPCFUSION_INSTALL_REFERENCE pRefData)
193 ASSEMBLY *assembly;
194 LPSTR filename;
195 LPSTR name = NULL;
196 LPSTR token = NULL;
197 LPSTR version = NULL;
198 LPSTR asmpath = NULL;
199 CHAR path[MAX_PATH];
200 CHAR windir[MAX_PATH];
201 LPWSTR ext;
202 HRESULT hr;
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)
211 return E_INVALIDARG;
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);
223 if (FAILED(hr))
225 hr = COR_E_ASSEMBLYEXPECTED;
226 goto done;
229 hr = assembly_get_name(assembly, &name);
230 if (FAILED(hr))
231 goto done;
233 hr = assembly_get_pubkey_token(assembly, &token);
234 if (FAILED(hr))
235 goto done;
237 hr = assembly_get_version(assembly, &version);
238 if (FAILED(hr))
239 goto done;
241 GetWindowsDirectoryA(windir, MAX_PATH);
243 FIXME("Ignoring assembly architecture!\n");
245 sprintf(path, "%s\\assembly\\GAC_MSIL\\%s\\%s__%s\\", windir, name,
246 version, token);
248 create_full_path(path);
250 hr = assembly_get_path(assembly, &asmpath);
251 if (FAILED(hr))
252 goto done;
254 filename = PathFindFileNameA(asmpath);
256 lstrcatA(path, filename);
257 if (!CopyFileA(asmpath, path, FALSE))
258 hr = HRESULT_FROM_WIN32(GetLastError());
260 done:
261 HeapFree(GetProcessHeap(), 0, name);
262 HeapFree(GetProcessHeap(), 0, token);
263 HeapFree(GetProcessHeap(), 0, version);
264 HeapFree(GetProcessHeap(), 0, asmpath);
265 assembly_release(assembly);
266 return hr;
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);
289 if (!ppAsmCache)
290 return E_INVALIDARG;
292 *ppAsmCache = NULL;
294 cache = HeapAlloc(GetProcessHeap(), 0, sizeof(IAssemblyCacheImpl));
295 if (!cache)
296 return E_OUTOFMEMORY;
298 cache->lpIAssemblyCacheVtbl = &AssemblyCacheVtbl;
299 cache->ref = 1;
301 *ppAsmCache = (IAssemblyCache *)cache;
303 return S_OK;
306 /* IAssemblyCacheItem */
308 typedef struct {
309 const IAssemblyCacheItemVtbl *lpIAssemblyCacheItemVtbl;
311 LONG ref;
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);
321 *ppobj = NULL;
323 if (IsEqualIID(riid, &IID_IUnknown) ||
324 IsEqualIID(riid, &IID_IAssemblyCacheItem))
326 IUnknown_AddRef(iface);
327 *ppobj = This;
328 return S_OK;
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);
342 return refCount;
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);
352 if (!refCount)
353 HeapFree(GetProcessHeap(), 0, This);
355 return refCount;
358 static HRESULT WINAPI IAssemblyCacheItemImpl_CreateStream(IAssemblyCacheItem *iface,
359 DWORD dwFlags,
360 LPCWSTR pszStreamName,
361 DWORD dwFormat,
362 DWORD dwFormatFlags,
363 IStream **ppIStream,
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);
369 return E_NOTIMPL;
372 static HRESULT WINAPI IAssemblyCacheItemImpl_Commit(IAssemblyCacheItem *iface,
373 DWORD dwFlags,
374 ULONG *pulDisposition)
376 FIXME("(%p, %d, %p) stub!\n", iface, dwFlags, pulDisposition);
377 return E_NOTIMPL;
380 static HRESULT WINAPI IAssemblyCacheItemImpl_AbortItem(IAssemblyCacheItem *iface)
382 FIXME("(%p) stub!\n", iface);
383 return E_NOTIMPL;
386 static const IAssemblyCacheItemVtbl AssemblyCacheItemVtbl = {
387 IAssemblyCacheItemImpl_QueryInterface,
388 IAssemblyCacheItemImpl_AddRef,
389 IAssemblyCacheItemImpl_Release,
390 IAssemblyCacheItemImpl_CreateStream,
391 IAssemblyCacheItemImpl_Commit,
392 IAssemblyCacheItemImpl_AbortItem
395 /* IAssemblyEnum */
397 typedef struct {
398 const IAssemblyEnumVtbl *lpIAssemblyEnumVtbl;
400 LONG ref;
401 } IAssemblyEnumImpl;
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);
410 *ppobj = NULL;
412 if (IsEqualIID(riid, &IID_IUnknown) ||
413 IsEqualIID(riid, &IID_IAssemblyEnum))
415 IUnknown_AddRef(iface);
416 *ppobj = This;
417 return S_OK;
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);
431 return refCount;
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);
441 if (!refCount)
442 HeapFree(GetProcessHeap(), 0, This);
444 return refCount;
447 static HRESULT WINAPI IAssemblyEnumImpl_GetNextAssembly(IAssemblyEnum *iface,
448 LPVOID pvReserved,
449 IAssemblyName **ppName,
450 DWORD dwFlags)
452 FIXME("(%p, %p, %p, %d) stub!\n", iface, pvReserved, ppName, dwFlags);
453 return E_NOTIMPL;
456 static HRESULT WINAPI IAssemblyEnumImpl_Reset(IAssemblyEnum *iface)
458 FIXME("(%p) stub!\n", iface);
459 return E_NOTIMPL;
462 static HRESULT WINAPI IAssemblyEnumImpl_Clone(IAssemblyEnum *iface,
463 IAssemblyEnum **ppEnum)
465 FIXME("(%p, %p) stub!\n", iface, ppEnum);
466 return E_NOTIMPL;
469 static const IAssemblyEnumVtbl AssemblyEnumVtbl = {
470 IAssemblyEnumImpl_QueryInterface,
471 IAssemblyEnumImpl_AddRef,
472 IAssemblyEnumImpl_Release,
473 IAssemblyEnumImpl_GetNextAssembly,
474 IAssemblyEnumImpl_Reset,
475 IAssemblyEnumImpl_Clone