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