fusion.c 5.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * Implementation of the Fusion API
 *
 * Copyright 2008 James Hawkins
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdarg.h>

#define COBJMACROS

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "ole2.h"
#include "fusion.h"
#include "wine/debug.h"
31
#include "wine/unicode.h"
32 33 34

WINE_DEFAULT_DEBUG_CHANNEL(fusion);

35 36 37 38 39 40 41 42 43 44

/******************************************************************
 *  InitializeFusion   (FUSION.@)
 */
HRESULT WINAPI InitializeFusion(void)
{
    FIXME("\n");
    return E_NOTIMPL;
}

45 46 47 48 49 50 51 52 53
/******************************************************************
 *  ClearDownloadCache   (FUSION.@)
 */
HRESULT WINAPI ClearDownloadCache(void)
{
    FIXME("stub!\n");
    return E_NOTIMPL;
}

54 55 56 57 58 59 60 61 62
/******************************************************************
 *  CopyPDBs   (FUSION.@)
 */
HRESULT WINAPI CopyPDBs(void *unknown)
{
    FIXME("(%p) stub!\n", unknown);
    return E_NOTIMPL;
}

63 64 65 66 67 68 69 70 71 72 73
/******************************************************************
 *  CreateInstallReferenceEnum   (FUSION.@)
 */
HRESULT WINAPI CreateInstallReferenceEnum(IInstallReferenceEnum **ppRefEnum,
                                          IAssemblyName *pName, DWORD dwFlags,
                                          LPVOID pvReserved)
{
    FIXME("(%p, %p, %08x, %p) stub!\n", ppRefEnum, pName, dwFlags, pvReserved);
    return E_NOTIMPL;
}

74 75 76 77 78 79 80 81 82
/******************************************************************
 *  CreateApplicationContext   (FUSION.@)
 */
HRESULT WINAPI CreateApplicationContext(IAssemblyName *name, void *ctx)
{
    FIXME("%p, %p\n", name, ctx);
    return E_NOTIMPL;
}

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
static HRESULT (WINAPI *pGetCORVersion)(LPWSTR pbuffer, DWORD cchBuffer,
                                        DWORD *dwLength);

static HRESULT get_corversion(LPWSTR version, DWORD size)
{
    HMODULE hmscoree;
    HRESULT hr;
    DWORD len;

    hmscoree = LoadLibraryA("mscoree.dll");
    if (!hmscoree)
        return E_FAIL;

    pGetCORVersion = (void *)GetProcAddress(hmscoree, "GetCORVersion");
    if (!pGetCORVersion)
98 99 100
        hr = E_FAIL;
    else
        hr = pGetCORVersion(version, size, &len);
101 102 103 104 105

    FreeLibrary(hmscoree);
    return hr;
}

106 107 108 109 110 111
/******************************************************************
 *  GetCachePath   (FUSION.@)
 */
HRESULT WINAPI GetCachePath(ASM_CACHE_FLAGS dwCacheFlags, LPWSTR pwzCachePath,
                            PDWORD pcchPath)
{
112 113 114 115
    static const WCHAR assembly[] = {'\\','a','s','s','e','m','b','l','y',0};
    static const WCHAR gac[] = {'\\','G','A','C',0};
    static const WCHAR nativeimg[] = {'N','a','t','i','v','e','I','m','a','g','e','s','_',0};
    static const WCHAR dotnet[] = {'\\','M','i','c','r','o','s','o','f','t','.','N','E','T',0};
116 117 118 119 120
#ifdef _WIN64
    static const WCHAR zapfmt[] = {'%','s','\\','%','s','\\','%','s','%','s','_','6','4',0};
#else
    static const WCHAR zapfmt[] = {'%','s','\\','%','s','\\','%','s','%','s','_','3','2',0};
#endif
121 122 123
    WCHAR path[MAX_PATH], windir[MAX_PATH], version[MAX_PATH];
    DWORD len;
    HRESULT hr = S_OK;
124 125 126 127 128 129

    TRACE("(%08x, %p, %p)\n", dwCacheFlags, pwzCachePath, pcchPath);

    if (!pcchPath)
        return E_INVALIDARG;

130 131
    len = GetWindowsDirectoryW(windir, MAX_PATH);
    strcpyW(path, windir);
132 133 134 135 136 137 138 139 140

    switch (dwCacheFlags)
    {
        case ASM_CACHE_ZAP:
        {
            hr = get_corversion(version, MAX_PATH);
            if (FAILED(hr))
                return hr;

141
            len = sprintfW(path, zapfmt, windir, assembly + 1, nativeimg, version);
142 143 144 145
            break;
        }
        case ASM_CACHE_GAC:
        {
146 147 148 149
            strcpyW(path + len, assembly);
            len += sizeof(assembly)/sizeof(WCHAR) - 1;
            strcpyW(path + len, gac);
            len += sizeof(gac)/sizeof(WCHAR) - 1;
150 151 152 153 154 155 156 157
            break;
        }
        case ASM_CACHE_DOWNLOAD:
        {
            FIXME("Download cache not implemented\n");
            return E_FAIL;
        }
        case ASM_CACHE_ROOT:
158 159 160 161 162 163 164 165 166
            strcpyW(path + len, assembly);
            len += sizeof(assembly)/sizeof(WCHAR) - 1;
            break;
        case ASM_CACHE_ROOT_EX:
            strcpyW(path + len, dotnet);
            len += sizeof(dotnet)/sizeof(WCHAR) - 1;
            strcpyW(path + len, assembly);
            len += sizeof(assembly)/sizeof(WCHAR) - 1;
            break;
167 168 169 170
        default:
            return E_INVALIDARG;
    }

171
    len++;
172
    if (*pcchPath <= len || !pwzCachePath)
173
        hr = E_NOT_SUFFICIENT_BUFFER;
174
    else if (pwzCachePath)
175
        strcpyW(pwzCachePath, path);
176 177 178

    *pcchPath = len;
    return hr;
179
}