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