示例#1
0
EXTERN_C
BOOL
PALAPI
PAL_FetchConfigurationStringW(
                    IN BOOL bPerMachine,
                    IN LPCWSTR lpParameterName,
                    OUT LPWSTR lpParameterValue,
                    IN UINT cbParameterValueLength)
{
    BOOL b;
    HINI hIni = NULL;
    WCHAR ConfigFileName[_MAX_PATH];
    DWORD cch = sizeof(ConfigFileName)/sizeof(ConfigFileName[0]);

    if (bPerMachine) {
        b = PAL_GetMachineConfigurationDirectoryW(ConfigFileName, cch);
    } else {
        b = PAL_GetUserConfigurationDirectoryW(ConfigFileName, cch);
    }

    if (!b) {
        goto LExit;
    }

    if (wcslen(ConfigFileName)+sizeof(CONFIG_FILE_NAME)/sizeof(WCHAR) >=
        _MAX_PATH) {
        // buffer would overflow
        b = FALSE;
        goto LExit;
    }
    wcscat(ConfigFileName, CONFIG_FILE_NAME);

    hIni = PAL_IniCreate();
    if (!hIni) {
        b = FALSE;
        goto LExit;
    }

    b = PAL_IniLoad(hIni, ConfigFileName);
    if (b == FALSE) {
        goto LExit;
    }

    b = PAL_IniGetString(hIni,
                         L"Rotor",
                         lpParameterName,
                         lpParameterValue,
                         cbParameterValueLength);

LExit:
    if (hIni) {
        PAL_IniClose(hIni);
    }
    return b;
}
示例#2
0
HRESULT StoreFusionInfo(IAssemblyName *pName, LPWSTR pszDir, DWORD *pdwFileSizeLow)
{
    HRESULT hr = S_OK;
    WCHAR  pszFilePath[MAX_PATH+1];
    PBYTE  pMVID=NULL;
    PBYTE  pCustom=NULL;
    LPWSTR pszCustomString=NULL;
    LPWSTR pszURL=NULL;
    LPWSTR pszDisplayName=NULL;
    DWORD  cbSize=0;
    BOOL fRet = FALSE;
    DWORD  dwSize;
    LPWSTR pszBuf=NULL;
    HINI hIni=NULL;

    if(( lstrlenW(pszDir) + lstrlenW(g_FusionInfoFile) + 1) >= MAX_PATH)
    {
        hr = HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME);
        goto exit;
    }

    StrCpy(pszFilePath, pszDir);
    PathAddBackslash(pszFilePath);
    StrCat(pszFilePath, g_FusionInfoFile);

    if ((hIni = PAL_IniCreate()) == NULL)
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }

#define _WriteString(section, key, value) PAL_IniWriteString(hIni, section, key, value)

    pszBuf = NEW(WCHAR[MAX_URL_LENGTH+1]);
    if (!pszBuf)
    {
        hr = E_OUTOFMEMORY;
        goto exit;
    }

    cbSize = 0;
    if(FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_MVID, 
            &pMVID, &cbSize)))
        goto exit;

    if(cbSize && (cbSize == MVID_LENGTH))
    {
        CParseUtils::BinToUnicodeHex(pMVID, cbSize, pszBuf);

        pszBuf[MVID_LENGTH*2] = L'\0';

        fRet = _WriteString(ASSEMBLY_INFO_STRING, MVID_KEY_STRING, pszBuf);
        if (!fRet)
        {
            hr = FusionpHresultFromLastError();
            goto exit;
        }
    }

    cbSize = 0;
    if(FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CUSTOM, 
            &pCustom, &cbSize)))
        goto exit;

    if(cbSize)
    {
        pszCustomString = (LPWSTR) pCustom;
        fRet = _WriteString(ASSEMBLY_INFO_STRING, CUSTOM_BLOB_STRING, pszCustomString);
        if (!fRet)
        {
            hr = FusionpHresultFromLastError();
            goto exit;
        }
    }
    else
    {
        // if there is no Custom Blob try storing URL.
        cbSize = 0;
        if(FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CODEBASE_URL, (LPBYTE*) &pszURL, &cbSize)))
            goto exit;

        if(cbSize)
        {
            fRet = _WriteString(ASSEMBLY_INFO_STRING, URL_STRING, pszURL);
            if (!fRet)
            {
                hr = FusionpHresultFromLastError();
                goto exit;
            }
        }

        dwSize = 0;
        hr = pName->GetDisplayName(NULL, &dwSize, 0);
        if (hr != HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) {
            ASSERT(0);
            hr = E_UNEXPECTED;
            goto exit;
        }

        pszDisplayName = NEW(WCHAR[dwSize]);
        if (!pszDisplayName) {
            hr = E_OUTOFMEMORY;
            goto exit;
        }

        hr = pName->GetDisplayName(pszDisplayName, &dwSize, 0);
        if (FAILED(hr)) {
            goto exit;
        }

        cbSize = dwSize * sizeof(WCHAR);
        if(cbSize)
        {
            fRet = _WriteString(ASSEMBLY_INFO_STRING, DISPLAY_NAME_STRING, pszDisplayName);
            if (!fRet)
            {
                hr = FusionpHresultFromLastError();
                goto exit;
            }
        }
    }

    if (!PAL_IniSave(hIni, pszFilePath, TRUE))
    {
        hr = FusionpHresultFromLastError();
        goto exit;        
    }

    {
        DWORD dwSizeHigh=0;
        *pdwFileSizeLow = 512; // hard-code info file size.

        hr = GetFileSizeRoundedToCluster(INVALID_HANDLE_VALUE, pdwFileSizeLow, &dwSizeHigh);
    }

exit:

    if (hIni != NULL)
        PAL_IniClose(hIni);

    SAFEDELETEARRAY(pszBuf);
    SAFEDELETEARRAY(pszDisplayName);
    SAFEDELETEARRAY(pMVID);
    SAFEDELETEARRAY(pCustom);
    SAFEDELETEARRAY(pszURL);

    return hr;
}