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