Visual C++ backend for rbuild (for now just a hacked mingw backend) and related compi...
[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 <stdarg.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
29 #include "fusion.h"
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(fusion);
34
35 /******************************************************************
36 * ClearDownloadCache (FUSION.@)
37 */
38 HRESULT WINAPI ClearDownloadCache(void)
39 {
40 FIXME("stub!\n");
41 return E_NOTIMPL;
42 }
43
44 /******************************************************************
45 * CompareAssemblyIdentity (FUSION.@)
46 */
47 HRESULT WINAPI CompareAssemblyIdentity(LPCWSTR pwzAssemblyIdentity1, BOOL fUnified1,
48 LPCWSTR pwzAssemblyIdentity2, BOOL fUnified2,
49 BOOL *pfEquivalent, AssemblyComparisonResult *pResult)
50 {
51 FIXME("(%s, %d, %s, %d, %p, %p) stub!\n", debugstr_w(pwzAssemblyIdentity1),
52 fUnified1, debugstr_w(pwzAssemblyIdentity2), fUnified2, pfEquivalent, pResult);
53
54 return E_NOTIMPL;
55 }
56
57 /******************************************************************
58 * CreateAssemblyEnum (FUSION.@)
59 */
60 HRESULT WINAPI CreateAssemblyEnum(IAssemblyEnum **pEnum, IUnknown *pUnkReserved,
61 IAssemblyName *pName, DWORD dwFlags, LPVOID pvReserved)
62 {
63 FIXME("(%p, %p, %p, %08x, %p) stub!\n", pEnum, pUnkReserved,
64 pName, dwFlags, pvReserved);
65
66 return E_NOTIMPL;
67 }
68
69 /******************************************************************
70 * CreateInstallReferenceEnum (FUSION.@)
71 */
72 HRESULT WINAPI CreateInstallReferenceEnum(IInstallReferenceEnum **ppRefEnum,
73 IAssemblyName *pName, DWORD dwFlags,
74 LPVOID pvReserved)
75 {
76 FIXME("(%p, %p, %08x, %p) stub!\n", ppRefEnum, pName, dwFlags, pvReserved);
77 return E_NOTIMPL;
78 }
79
80 /******************************************************************
81 * GetAssemblyIdentityFromFile (FUSION.@)
82 */
83 HRESULT WINAPI GetAssemblyIdentityFromFile(LPCWSTR pwzFilePath, REFIID riid,
84 IUnknown **ppIdentity)
85 {
86 FIXME("(%s, %s, %p) stub!\n", debugstr_w(pwzFilePath), debugstr_guid(riid),
87 ppIdentity);
88
89 return E_NOTIMPL;
90 }
91
92 static HRESULT (WINAPI *pGetCORVersion)(LPWSTR pbuffer, DWORD cchBuffer,
93 DWORD *dwLength);
94
95 static HRESULT get_corversion(LPWSTR version, DWORD size)
96 {
97 HMODULE hmscoree;
98 HRESULT hr;
99 DWORD len;
100
101 hmscoree = LoadLibraryA("mscoree.dll");
102 if (!hmscoree)
103 return E_FAIL;
104
105 pGetCORVersion = (void *)GetProcAddress(hmscoree, "GetCORVersion");
106 if (!pGetCORVersion)
107 return E_FAIL;
108
109 hr = pGetCORVersion(version, size, &len);
110
111 FreeLibrary(hmscoree);
112 return hr;
113 }
114
115 /******************************************************************
116 * GetCachePath (FUSION.@)
117 */
118 HRESULT WINAPI GetCachePath(ASM_CACHE_FLAGS dwCacheFlags, LPWSTR pwzCachePath,
119 PDWORD pcchPath)
120 {
121 WCHAR path[MAX_PATH];
122 WCHAR windir[MAX_PATH];
123 WCHAR version[MAX_PATH];
124 DWORD len;
125 HRESULT hr = S_OK;
126
127 static const WCHAR backslash[] = {'\\',0};
128 static const WCHAR assembly[] = {'a','s','s','e','m','b','l','y',0};
129 static const WCHAR gac[] = {'G','A','C',0};
130 static const WCHAR nativeimg[] = {
131 'N','a','t','i','v','e','I','m','a','g','e','s','_',0};
132 static const WCHAR zapfmt[] = {
133 '%','s','\\','%','s','\\','%','s','%','s','_','3','2',0};
134
135 TRACE("(%08x, %p, %p)\n", dwCacheFlags, pwzCachePath, pcchPath);
136
137 if (!pcchPath)
138 return E_INVALIDARG;
139
140 GetWindowsDirectoryW(windir, MAX_PATH);
141 lstrcpyW(path, windir);
142 lstrcatW(path, backslash);
143 lstrcatW(path, assembly);
144
145 switch (dwCacheFlags)
146 {
147 case ASM_CACHE_ZAP:
148 {
149 hr = get_corversion(version, MAX_PATH);
150 if (FAILED(hr))
151 return hr;
152
153 sprintfW(path, zapfmt, windir, assembly, nativeimg, version);
154 break;
155 }
156
157 case ASM_CACHE_GAC:
158 {
159 lstrcatW(path, backslash);
160 lstrcatW(path, gac);
161 break;
162 }
163
164 case ASM_CACHE_DOWNLOAD:
165 {
166 FIXME("Download cache not implemented\n");
167 return E_FAIL;
168 }
169
170 case ASM_CACHE_ROOT:
171 break; /* already set */
172
173 default:
174 return E_INVALIDARG;
175 }
176
177 len = lstrlenW(path) + 1;
178 if (*pcchPath <= len || !pwzCachePath)
179 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
180 else if (pwzCachePath)
181 lstrcpyW(pwzCachePath, path);
182
183 *pcchPath = len;
184
185 return hr;
186 }