1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4// ============================================================
5//
6// Variables.cpp
7//
8
9
10//
11// Implements the Variables class
12//
13// ============================================================
14
15#include "variables.hpp"
16
17#include "ex.h"
18
19namespace BINDER_SPACE
20{
21#ifdef FEATURE_VERSIONING_LOG
22 namespace
23 {
24 HRESULT CheckFileExistence(LPCWSTR pwzFile, LPDWORD pdwAttrib)
25 {
26 HRESULT hr = S_FALSE;
27 DWORD dwRet = 0;
28
29 _ASSERTE(pwzFile && pdwAttrib);
30
31 *pdwAttrib = 0;
32
33 dwRet = WszGetFileAttributes(pwzFile);
34 if (dwRet == INVALID_FILE_ATTRIBUTES)
35 {
36 hr = HRESULT_FROM_GetLastError();
37
38 if ((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) ||
39 (hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)))
40 {
41 GO_WITH_HRESULT(S_FALSE);
42 }
43 }
44 else
45 {
46 *pdwAttrib = dwRet;
47 GO_WITH_HRESULT(S_OK);
48 }
49
50 Exit:
51 return hr;
52 }
53 };
54#endif // FEATURE_VERSIONING_LOG
55
56 Variables *g_BinderVariables = NULL;
57
58 Variables::Variables()
59 {
60 // Nothing to do here
61 }
62
63 Variables::~Variables()
64 {
65 // Nothing to do here
66 }
67
68 HRESULT Variables::Init()
69 {
70 HRESULT hr = S_OK;
71
72 EX_TRY
73 {
74 // ApplicationContext string constants
75
76 // AssemblyBinder string constants
77 httpURLPrefix.SetLiteral(W("http://"));
78
79 // AssemblyName string constants
80 architectureMSIL.SetLiteral(W("MSIL"));
81 architectureX86.SetLiteral(W("x86"));
82 architectureAMD64.SetLiteral(W("AMD64"));
83 architectureARM.SetLiteral(W("ARM"));
84 architectureARM64.SetLiteral(W("ARM64"));
85 cultureNeutral.SetLiteral(W("neutral"));
86 mscorlib.SetLiteral(CoreLibName_W);
87
88 emptyString.Clear();
89
90#ifdef FEATURE_VERSIONING_LOG
91 REGUTIL::CORConfigLevel kCorConfigLevel =
92 static_cast<REGUTIL::CORConfigLevel>(REGUTIL::COR_CONFIG_ENV |
93 REGUTIL::COR_CONFIG_FUSION);
94
95 DWORD dwLoggingNeeded = REGUTIL::GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_ForceLog,
96 0,
97 kCorConfigLevel,
98 TRUE);
99 fLoggingNeeded = (dwLoggingNeeded ? TRUE : FALSE);
100
101 NewArrayHolder<WCHAR> pwzLogDirectory = REGUTIL::GetConfigString_DontUse_(CLRConfig::INTERNAL_LogPath,
102 TRUE,
103 kCorConfigLevel,
104 FALSE /* fUsePerfCache */);
105
106 // When no directory is specified, we can't log.
107 if (pwzLogDirectory == NULL)
108 {
109 fLoggingNeeded = FALSE;
110 }
111 else
112 {
113 DWORD dwAttr = 0;
114
115 // If we do not get a regular directory, then we can't log either
116 hr = CheckFileExistence(pwzLogDirectory, &dwAttr);
117 if ((hr == S_OK) && ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) != 0))
118 {
119 logPath.Set(pwzLogDirectory);
120 }
121 else
122 {
123 // Any failure here simply yields no logging.
124 hr = S_OK;
125 fLoggingNeeded = FALSE;
126 }
127 }
128#endif // FEATURE_VERSIONING_LOG
129 }
130 EX_CATCH_HRESULT(hr);
131
132 return hr;
133 }
134};
135