wined3d: Pack hardcoded local constants in ARB.
[wine] / dlls / 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  *  CreateInstallReferenceEnum   (FUSION.@)
59  */
60 HRESULT WINAPI CreateInstallReferenceEnum(IInstallReferenceEnum **ppRefEnum,
61                                           IAssemblyName *pName, DWORD dwFlags,
62                                           LPVOID pvReserved)
63 {
64     FIXME("(%p, %p, %08x, %p) stub!\n", ppRefEnum, pName, dwFlags, pvReserved);
65     return E_NOTIMPL;
66 }
67
68 /******************************************************************
69  *  GetAssemblyIdentityFromFile   (FUSION.@)
70  */
71 HRESULT WINAPI GetAssemblyIdentityFromFile(LPCWSTR pwzFilePath, REFIID riid,
72                                            IUnknown **ppIdentity)
73 {
74     FIXME("(%s, %s, %p) stub!\n", debugstr_w(pwzFilePath), debugstr_guid(riid),
75           ppIdentity);
76
77     return E_NOTIMPL;
78 }
79
80 static HRESULT (WINAPI *pGetCORVersion)(LPWSTR pbuffer, DWORD cchBuffer,
81                                         DWORD *dwLength);
82
83 static HRESULT get_corversion(LPWSTR version, DWORD size)
84 {
85     HMODULE hmscoree;
86     HRESULT hr;
87     DWORD len;
88
89     hmscoree = LoadLibraryA("mscoree.dll");
90     if (!hmscoree)
91         return E_FAIL;
92
93     pGetCORVersion = (void *)GetProcAddress(hmscoree, "GetCORVersion");
94     if (!pGetCORVersion)
95         return E_FAIL;
96
97     hr = pGetCORVersion(version, size, &len);
98
99     FreeLibrary(hmscoree);
100     return hr;
101 }
102
103 /******************************************************************
104  *  GetCachePath   (FUSION.@)
105  */
106 HRESULT WINAPI GetCachePath(ASM_CACHE_FLAGS dwCacheFlags, LPWSTR pwzCachePath,
107                             PDWORD pcchPath)
108 {
109     WCHAR path[MAX_PATH];
110     WCHAR windir[MAX_PATH];
111     WCHAR version[MAX_PATH];
112     DWORD len;
113     HRESULT hr = S_OK;
114
115     static const WCHAR backslash[] = {'\\',0};
116     static const WCHAR assembly[] = {'a','s','s','e','m','b','l','y',0};
117     static const WCHAR gac[] = {'G','A','C',0};
118     static const WCHAR nativeimg[] = {
119         'N','a','t','i','v','e','I','m','a','g','e','s','_',0};
120 #ifdef _WIN64
121     static const WCHAR zapfmt[] = {'%','s','\\','%','s','\\','%','s','%','s','_','6','4',0};
122 #else
123     static const WCHAR zapfmt[] = {'%','s','\\','%','s','\\','%','s','%','s','_','3','2',0};
124 #endif
125
126     TRACE("(%08x, %p, %p)\n", dwCacheFlags, pwzCachePath, pcchPath);
127
128     if (!pcchPath)
129         return E_INVALIDARG;
130
131     GetWindowsDirectoryW(windir, MAX_PATH);
132     lstrcpyW(path, windir);
133     lstrcatW(path, backslash);
134     lstrcatW(path, assembly);
135
136     switch (dwCacheFlags)
137     {
138         case ASM_CACHE_ZAP:
139         {
140             hr = get_corversion(version, MAX_PATH);
141             if (FAILED(hr))
142                 return hr;
143
144             sprintfW(path, zapfmt, windir, assembly, nativeimg, version);
145             break;
146         }
147
148         case ASM_CACHE_GAC:
149         {
150             lstrcatW(path, backslash);
151             lstrcatW(path, gac);
152             break;
153         }
154
155         case ASM_CACHE_DOWNLOAD:
156         {
157             FIXME("Download cache not implemented\n");
158             return E_FAIL;
159         }
160
161         case ASM_CACHE_ROOT:
162             break; /* already set */
163
164         default:
165             return E_INVALIDARG;
166     }
167
168     len = lstrlenW(path) + 1;
169     if (*pcchPath <= len || !pwzCachePath)
170         hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
171     else if (pwzCachePath)
172         lstrcpyW(pwzCachePath, path);
173
174     *pcchPath = len;
175
176     return hr;
177 }