示例#1
0
HRESULT OpenLogFile()
{
#define REG_VAL_FUSION_LOG_FILE    TEXT("FusionLogFile")

    HRESULT hr=E_FAIL;
    HANDLE  hFile = NULL;
    WCHAR       szBuf[MAX_PATH+1];
    if (PAL_FetchConfigurationString(TRUE, REG_VAL_FUSION_LOG_FILE, szBuf, MAX_PATH - 50))
        hr = S_OK;

    if(hr == S_OK)
    {
        wnsprintf(szBuf, MAX_PATH, L"%s_%d.txt", szBuf, GetCurrentProcessId());
        hFile = CreateFile(szBuf, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL,
                             CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
        if (hFile == INVALID_HANDLE_VALUE) 
        {
            hr = HRESULT_FROM_WIN32(GetLastError());
            goto exit;
        }

        g_hLogFile = hFile;
    }

exit:

    return hr;
}
示例#2
0
HRESULT GetDownloadUsage(DWORD *pdwDownloadUsageInKB)
{
    HRESULT                         hr=S_OK;
    DWORD                           dwDownloadUsage=0;
    WCHAR szBuf[20];
    LPWSTR endPtr;

    if (!PAL_FetchConfigurationString(FALSE, REG_VAL_FUSION_DOWNLOAD_CACHE_USAGE, szBuf, ARRAYSIZE(szBuf)))
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }    

    dwDownloadUsage = wcstol(szBuf, &endPtr, 10);

    if (endPtr == szBuf)
    {
        hr = E_FAIL;
        goto exit;
    }

    if(pdwDownloadUsageInKB)
        *pdwDownloadUsageInKB = dwDownloadUsage;

exit:
    return hr;
}
示例#3
0
HRESULT GetScavengerQuotasFromReg(DWORD *pdwZapQuotaInGAC,
                                  DWORD *pdwDownloadQuotaAdmin,
                                  DWORD *pdwDownloadQuotaUser)
{
    HRESULT                         hr=S_OK;
    DWORD                           dwDownloadLMQuota=0;
    DWORD                           dwDownloadCUQuota=0;
    WCHAR szBuf[20];
    LPWSTR endPtr;

    if (PAL_FetchConfigurationString(TRUE, REG_VAL_FUSION_DOWNLOAD_CACHE_QUOTA_IN_KB, szBuf, ARRAYSIZE(szBuf)))
    {
        dwDownloadLMQuota = wcstol(szBuf, &endPtr, 10);
    }    
    
    if (PAL_FetchConfigurationString(FALSE, REG_VAL_FUSION_DOWNLOAD_CACHE_QUOTA_IN_KB, szBuf, ARRAYSIZE(szBuf)))
    {
        dwDownloadCUQuota = wcstol(szBuf, &endPtr, 10);
    }

    if(!dwDownloadLMQuota)
    {
        g_DownloadCacheQuotaInKB = 50000; // default Download Cache Quota
    }
    else
    {
        g_DownloadCacheQuotaInKB = dwDownloadLMQuota;
    }

    if(dwDownloadCUQuota)
    {
        g_DownloadCacheQuotaInKB = min(dwDownloadCUQuota, g_DownloadCacheQuotaInKB);
    }

    if(pdwZapQuotaInGAC)
         *pdwZapQuotaInGAC = 0;

    if(pdwDownloadQuotaAdmin)
         *pdwDownloadQuotaAdmin = g_DownloadCacheQuotaInKB;

    if(pdwDownloadQuotaUser)
         *pdwDownloadQuotaUser = g_DownloadCacheQuotaInKB;

    return hr;
}
static DWORD GetConfigDWORD(LPCWSTR wzName, DWORD dwDefault)
{
    WRAPPER_CONTRACT;
    WCHAR wzValue[16];
    DWORD dwValue;

    if (PAL_FetchConfigurationString(TRUE, wzName, wzValue, sizeof(wzValue) / sizeof(WCHAR)))
    {
        LPWSTR pEnd;
        dwValue = wcstol(wzValue, &pEnd, 16);   // treat it has hex
        if (pEnd != wzValue)                    // success
            return dwValue;
    }

    return dwDefault;
}
示例#5
0
HRESULT GetCacheLocationFromReg()
{
    HRESULT     hr = S_OK;
    WCHAR       szBuf[MAX_PATH+1];
    if (!PAL_FetchConfigurationString(TRUE, REG_VAL_FUSION_CACHE_LOCATION, szBuf, MAX_PATH))
    {
        hr = E_FAIL;
        goto exit;
    }

    if(!PathCanonicalize(g_szWindowsDir, szBuf))
    {
        hr = E_FAIL;
        goto exit;
    }

    g_cchWindowsDir = lstrlen(g_szWindowsDir);

    if(g_cchWindowsDir && (IsPathSeparator(g_szWindowsDir[g_cchWindowsDir - 1])))
        g_szWindowsDir[g_cchWindowsDir - 1] = L'\0'; // remove trailing "\"

    // cache location cannot be = MAX_PATH; that won't leave any space for fusion dirs.
    if ((g_cchWindowsDir + TEMP_RANDOM_DIR_LENGTH)>= (MAX_PATH/2) )
    {
        hr = HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME);
        goto exit;
    }

    g_cchWindowsDir = lstrlen(g_szWindowsDir);

    if(GetFileAttributes(g_szWindowsDir) != (DWORD) -1)
        goto exit;

    if(SUCCEEDED(hr = CreateFilePathHierarchy(g_szWindowsDir)))
    {
        if(!CreateDirectory(g_szWindowsDir, NULL))
            hr = FusionpHresultFromLastError();
    }

exit:


    return hr;
}
示例#6
0
文件: dbglog.cpp 项目: ArildF/masters
HRESULT CDebugLog::Init(IApplicationContext *pAppCtx, LPCWSTR pwzAsmName)
{
    HRESULT                                  hr = S_OK;
    LPWSTR                                   wzAppName = NULL;

    if (!pwzAsmName) {
        hr = E_INVALIDARG;
        goto Exit;
    }

    hr = SetAsmName(pwzAsmName);
    if (FAILED(hr)) {
        goto Exit;
    }
    
    // Get the executable name

    hr = ::AppCtxGetWrapper(pAppCtx, ACTAG_APP_NAME, &wzAppName);
    if (FAILED(hr)) {
        goto Exit;
    }

    if (wzAppName && lstrlenW(wzAppName)) {
        _wzEXEName = WSTRDupDynamic(wzAppName);
        if (!_wzEXEName) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
    }
    else {
        LPWSTR               wzFileName;

        // Didn't find EXE name in appctx. Use the .EXE name.

        wzFileName = PathFindFileName(g_wzEXEPath);
        ASSERT(wzFileName);

        _wzEXEName = WSTRDupDynamic(wzFileName);
        if (!_wzEXEName) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
    }

    // Log path
    
    if (!PAL_FetchConfigurationString(TRUE, REG_VAL_FUSION_LOG_PATH, _szLogPath, MAX_PATH))
    {
        // fallback to default
        if (!PAL_GetUserConfigurationDirectory(_szLogPath, MAX_PATH))
        {
            hr = HRESULT_FROM_WIN32(GetLastError());
            goto Exit;
        }

        StrCatBuff(_szLogPath, L"\\FusionLogs", MAX_PATH);
    }

    PathRemoveBackslashW(_szLogPath);

Exit:
    SAFEDELETEARRAY(wzAppName);

    return hr;
}