mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
settings: Add update/getPersistent/isIgnored methods
Add interfaces::Node methods to give GUI finer grained control over settings.json file. Update method is used to write settings to the file, getPersistent and isIgnored methods are used to find out about settings file and command line option interactions.
This commit is contained in:
@@ -592,6 +592,13 @@ bool ArgsManager::WriteSettingsFile(std::vector<std::string>* errors) const
|
||||
return true;
|
||||
}
|
||||
|
||||
util::SettingsValue ArgsManager::GetPersistentSetting(const std::string& name) const
|
||||
{
|
||||
LOCK(cs_args);
|
||||
return util::GetSetting(m_settings, m_network, name, !UseDefaultSection("-" + name),
|
||||
/*ignore_nonpersistent=*/true, /*get_chain_name=*/false);
|
||||
}
|
||||
|
||||
bool ArgsManager::IsArgNegated(const std::string& strArg) const
|
||||
{
|
||||
return GetSetting(strArg).isFalse();
|
||||
@@ -600,18 +607,33 @@ bool ArgsManager::IsArgNegated(const std::string& strArg) const
|
||||
std::string ArgsManager::GetArg(const std::string& strArg, const std::string& strDefault) const
|
||||
{
|
||||
const util::SettingsValue value = GetSetting(strArg);
|
||||
return SettingToString(value, strDefault);
|
||||
}
|
||||
|
||||
std::string SettingToString(const util::SettingsValue& value, const std::string& strDefault)
|
||||
{
|
||||
return value.isNull() ? strDefault : value.isFalse() ? "0" : value.isTrue() ? "1" : value.isNum() ? value.getValStr() : value.get_str();
|
||||
}
|
||||
|
||||
int64_t ArgsManager::GetIntArg(const std::string& strArg, int64_t nDefault) const
|
||||
{
|
||||
const util::SettingsValue value = GetSetting(strArg);
|
||||
return SettingToInt(value, nDefault);
|
||||
}
|
||||
|
||||
int64_t SettingToInt(const util::SettingsValue& value, int64_t nDefault)
|
||||
{
|
||||
return value.isNull() ? nDefault : value.isFalse() ? 0 : value.isTrue() ? 1 : value.isNum() ? value.getInt<int64_t>() : LocaleIndependentAtoi<int64_t>(value.get_str());
|
||||
}
|
||||
|
||||
bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const
|
||||
{
|
||||
const util::SettingsValue value = GetSetting(strArg);
|
||||
return SettingToBool(value, fDefault);
|
||||
}
|
||||
|
||||
bool SettingToBool(const util::SettingsValue& value, bool fDefault)
|
||||
{
|
||||
return value.isNull() ? fDefault : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
|
||||
}
|
||||
|
||||
@@ -1002,6 +1024,7 @@ std::string ArgsManager::GetChainName() const
|
||||
LOCK(cs_args);
|
||||
util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg),
|
||||
/* ignore_default_section_config= */ false,
|
||||
/*ignore_nonpersistent=*/false,
|
||||
/* get_chain_name= */ true);
|
||||
return value.isNull() ? false : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
|
||||
};
|
||||
@@ -1034,7 +1057,8 @@ util::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
|
||||
{
|
||||
LOCK(cs_args);
|
||||
return util::GetSetting(
|
||||
m_settings, m_network, SettingName(arg), !UseDefaultSection(arg), /* get_chain_name= */ false);
|
||||
m_settings, m_network, SettingName(arg), !UseDefaultSection(arg),
|
||||
/*ignore_nonpersistent=*/false, /*get_chain_name=*/false);
|
||||
}
|
||||
|
||||
std::vector<util::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const
|
||||
|
||||
Reference in New Issue
Block a user