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.
5 // --------------------------------------------------------------------------------------------------
9 // Access and update configuration values, falling back on legacy CLRConfig methods where necessary.
11 // --------------------------------------------------------------------------------------------------
15 #include "clrconfig.h"
16 #include "configuration.h"
18 LPCWSTR *knobNames = nullptr;
19 LPCWSTR *knobValues = nullptr;
20 int numberOfKnobs = 0;
22 void Configuration::InitializeConfigurationKnobs(int numberOfConfigs, LPCWSTR *names, LPCWSTR *values)
24 numberOfKnobs = numberOfConfigs;
26 // Neither should be null, or both should be null
27 _ASSERT(!((names == nullptr) ^ (values == nullptr)));
33 static LPCWSTR GetConfigurationValue(LPCWSTR name)
35 _ASSERT(name != nullptr);
36 if (name == nullptr || knobNames == nullptr || knobValues == nullptr)
41 for (int i = 0; i < numberOfKnobs; ++i)
43 _ASSERT(knobNames[i] != nullptr);
44 if (wcscmp(name, knobNames[i]) == 0)
53 DWORD Configuration::GetKnobDWORDValue(LPCWSTR name, const CLRConfig::ConfigDWORDInfo& dwordInfo)
55 bool returnedDefaultValue;
56 DWORD legacyValue = CLRConfig::GetConfigValue(dwordInfo, true /* acceptExplicitDefaultFromRegutil */, &returnedDefaultValue);
57 if (!returnedDefaultValue)
62 LPCWSTR knobValue = GetConfigurationValue(name);
63 if (knobValue != nullptr)
65 return wcstoul(knobValue, nullptr, 0);
71 DWORD Configuration::GetKnobDWORDValue(LPCWSTR name, DWORD defaultValue)
73 LPCWSTR knobValue = GetConfigurationValue(name);
74 if (knobValue != nullptr)
76 return wcstoul(knobValue, nullptr, 0);
82 ULONGLONG Configuration::GetKnobULONGLONGValue(LPCWSTR name)
84 LPCWSTR knobValue = GetConfigurationValue(name);
85 if (knobValue != nullptr)
87 return _wcstoui64(knobValue, nullptr, 0);
93 LPCWSTR Configuration::GetKnobStringValue(LPCWSTR name, const CLRConfig::ConfigStringInfo& stringInfo)
95 LPCWSTR value = CLRConfig::GetConfigValue(stringInfo);
98 value = GetConfigurationValue(name);
104 LPCWSTR Configuration::GetKnobStringValue(LPCWSTR name)
106 return GetConfigurationValue(name);
109 bool Configuration::GetKnobBooleanValue(LPCWSTR name, const CLRConfig::ConfigDWORDInfo& dwordInfo)
111 bool returnedDefaultValue;
112 DWORD legacyValue = CLRConfig::GetConfigValue(dwordInfo, true /* acceptExplicitDefaultFromRegutil */, &returnedDefaultValue);
113 if (!returnedDefaultValue)
115 return (legacyValue != 0);
118 LPCWSTR knobValue = GetConfigurationValue(name);
119 if (knobValue != nullptr)
121 return (wcscmp(knobValue, W("true")) == 0);
124 return (legacyValue != 0);
127 bool Configuration::GetKnobBooleanValue(LPCWSTR name, bool defaultValue)
129 LPCWSTR knobValue = GetConfigurationValue(name);
130 if (knobValue != nullptr)
132 return (wcscmp(knobValue, W("true")) == 0);