[LT2013]
[reactos.git] / dll / win32 / fusion / fusion.c
1 /*
2 * Implementation of the Fusion API
3 *
4 * Copyright 2008 James Hawkins
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 #include <stdarg.h>
26
27 #define COBJMACROS
28
29 #include <windef.h>
30 #include <winbase.h>
31 //#include "winuser.h"
32 #include <ole2.h>
33 #include <fusion.h>
34 #include <wine/debug.h>
35 #include <wine/unicode.h>
36
37 WINE_DEFAULT_DEBUG_CHANNEL(fusion);
38
39 /******************************************************************
40 * ClearDownloadCache (FUSION.@)
41 */
42 HRESULT WINAPI ClearDownloadCache(void)
43 {
44 FIXME("stub!\n");
45 return E_NOTIMPL;
46 }
47
48 /******************************************************************
49 * CreateInstallReferenceEnum (FUSION.@)
50 */
51 HRESULT WINAPI CreateInstallReferenceEnum(IInstallReferenceEnum **ppRefEnum,
52 IAssemblyName *pName, DWORD dwFlags,
53 LPVOID pvReserved)
54 {
55 FIXME("(%p, %p, %08x, %p) stub!\n", ppRefEnum, pName, dwFlags, pvReserved);
56 return E_NOTIMPL;
57 }
58
59 /******************************************************************
60 * CreateApplicationContext (FUSION.@)
61 */
62 HRESULT WINAPI CreateApplicationContext(IAssemblyName *name, void *ctx)
63 {
64 FIXME("%p, %p\n", name, ctx);
65 return E_NOTIMPL;
66 }
67
68 static HRESULT (WINAPI *pGetCORVersion)(LPWSTR pbuffer, DWORD cchBuffer,
69 DWORD *dwLength);
70
71 static HRESULT get_corversion(LPWSTR version, DWORD size)
72 {
73 HMODULE hmscoree;
74 HRESULT hr;
75 DWORD len;
76
77 hmscoree = LoadLibraryA("mscoree.dll");
78 if (!hmscoree)
79 return E_FAIL;
80
81 pGetCORVersion = (void *)GetProcAddress(hmscoree, "GetCORVersion");
82 if (!pGetCORVersion)
83 return E_FAIL;
84
85 hr = pGetCORVersion(version, size, &len);
86
87 FreeLibrary(hmscoree);
88 return hr;
89 }
90
91 /******************************************************************
92 * GetCachePath (FUSION.@)
93 */
94 HRESULT WINAPI GetCachePath(ASM_CACHE_FLAGS dwCacheFlags, LPWSTR pwzCachePath,
95 PDWORD pcchPath)
96 {
97 WCHAR path[MAX_PATH];
98 WCHAR windir[MAX_PATH];
99 WCHAR version[MAX_PATH];
100 DWORD len;
101 HRESULT hr = S_OK;
102
103 static const WCHAR backslash[] = {'\\',0};
104 static const WCHAR assembly[] = {'a','s','s','e','m','b','l','y',0};
105 static const WCHAR gac[] = {'G','A','C',0};
106 static const WCHAR nativeimg[] = {
107 'N','a','t','i','v','e','I','m','a','g','e','s','_',0};
108 #ifdef _WIN64
109 static const WCHAR zapfmt[] = {'%','s','\\','%','s','\\','%','s','%','s','_','6','4',0};
110 #else
111 static const WCHAR zapfmt[] = {'%','s','\\','%','s','\\','%','s','%','s','_','3','2',0};
112 #endif
113
114 TRACE("(%08x, %p, %p)\n", dwCacheFlags, pwzCachePath, pcchPath);
115
116 if (!pcchPath)
117 return E_INVALIDARG;
118
119 GetWindowsDirectoryW(windir, MAX_PATH);
120 lstrcpyW(path, windir);
121 lstrcatW(path, backslash);
122 lstrcatW(path, assembly);
123
124 switch (dwCacheFlags)
125 {
126 case ASM_CACHE_ZAP:
127 {
128 hr = get_corversion(version, MAX_PATH);
129 if (FAILED(hr))
130 return hr;
131
132 sprintfW(path, zapfmt, windir, assembly, nativeimg, version);
133 break;
134 }
135
136 case ASM_CACHE_GAC:
137 {
138 lstrcatW(path, backslash);
139 lstrcatW(path, gac);
140 break;
141 }
142
143 case ASM_CACHE_DOWNLOAD:
144 {
145 FIXME("Download cache not implemented\n");
146 return E_FAIL;
147 }
148
149 case ASM_CACHE_ROOT:
150 break; /* already set */
151
152 default:
153 return E_INVALIDARG;
154 }
155
156 len = lstrlenW(path) + 1;
157 if (*pcchPath <= len || !pwzCachePath)
158 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
159 else if (pwzCachePath)
160 lstrcpyW(pwzCachePath, path);
161
162 *pcchPath = len;
163
164 return hr;
165 }