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