Changeset View
Changeset View
Standalone View
Standalone View
src/util/system.cpp
Show First 20 Lines • Show All 571 Lines • ▼ Show 20 Lines | if (!RenameOver(path_tmp, path)) { | ||||
{strprintf("Failed renaming settings file %s to %s\n", | {strprintf("Failed renaming settings file %s to %s\n", | ||||
fs::PathToString(path_tmp), fs::PathToString(path))}, | fs::PathToString(path_tmp), fs::PathToString(path))}, | ||||
errors); | errors); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | 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 { | bool ArgsManager::IsArgNegated(const std::string &strArg) const { | ||||
return GetSetting(strArg).isFalse(); | return GetSetting(strArg).isFalse(); | ||||
} | } | ||||
std::string ArgsManager::GetArg(const std::string &strArg, | std::string ArgsManager::GetArg(const std::string &strArg, | ||||
const std::string &strDefault) const { | const std::string &strDefault) const { | ||||
const util::SettingsValue value = GetSetting(strArg); | 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 | return value.isNull() ? strDefault | ||||
: value.isFalse() ? "0" | : value.isFalse() ? "0" | ||||
: value.isTrue() ? "1" | : value.isTrue() ? "1" | ||||
: value.get_str(); | : value.get_str(); | ||||
} | } | ||||
int64_t ArgsManager::GetIntArg(const std::string &strArg, | int64_t ArgsManager::GetIntArg(const std::string &strArg, | ||||
int64_t nDefault) const { | int64_t nDefault) const { | ||||
const util::SettingsValue value = GetSetting(strArg); | const util::SettingsValue value = GetSetting(strArg); | ||||
return SettingToInt(value, nDefault); | |||||
} | |||||
int64_t SettingToInt(const util::SettingsValue &value, int64_t nDefault) { | |||||
return value.isNull() ? nDefault | return value.isNull() ? nDefault | ||||
: value.isFalse() ? 0 | : value.isFalse() ? 0 | ||||
: value.isTrue() ? 1 | : value.isTrue() ? 1 | ||||
: value.isNum() ? value.get_int64() | : value.isNum() ? value.get_int64() | ||||
: atoi64(value.get_str()); | : atoi64(value.get_str()); | ||||
} | } | ||||
bool ArgsManager::GetBoolArg(const std::string &strArg, bool fDefault) const { | bool ArgsManager::GetBoolArg(const std::string &strArg, bool fDefault) const { | ||||
const util::SettingsValue value = GetSetting(strArg); | const util::SettingsValue value = GetSetting(strArg); | ||||
return SettingToBool(value, fDefault); | |||||
} | |||||
bool SettingToBool(const util::SettingsValue &value, bool fDefault) { | |||||
return value.isNull() ? fDefault | return value.isNull() ? fDefault | ||||
: value.isBool() ? value.get_bool() | : value.isBool() ? value.get_bool() | ||||
: InterpretBool(value.get_str()); | : InterpretBool(value.get_str()); | ||||
} | } | ||||
bool ArgsManager::SoftSetArg(const std::string &strArg, | bool ArgsManager::SoftSetArg(const std::string &strArg, | ||||
const std::string &strValue) { | const std::string &strValue) { | ||||
LOCK(cs_args); | LOCK(cs_args); | ||||
▲ Show 20 Lines • Show All 429 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
std::string ArgsManager::GetChainName() const { | std::string ArgsManager::GetChainName() const { | ||||
auto get_net = [&](const std::string &arg) { | auto get_net = [&](const std::string &arg) { | ||||
LOCK(cs_args); | LOCK(cs_args); | ||||
util::SettingsValue value = | util::SettingsValue value = | ||||
util::GetSetting(m_settings, /* section= */ "", SettingName(arg), | util::GetSetting(m_settings, /* section= */ "", SettingName(arg), | ||||
/* ignore_default_section_config= */ false, | /* ignore_default_section_config= */ false, | ||||
/*ignore_nonpersistent=*/false, | |||||
/* get_chain_name= */ true); | /* get_chain_name= */ true); | ||||
return value.isNull() ? false | return value.isNull() ? false | ||||
: value.isBool() ? value.get_bool() | : value.isBool() ? value.get_bool() | ||||
: InterpretBool(value.get_str()); | : InterpretBool(value.get_str()); | ||||
}; | }; | ||||
const bool fRegTest = get_net("-regtest"); | const bool fRegTest = get_net("-regtest"); | ||||
const bool fTestNet = get_net("-testnet"); | const bool fTestNet = get_net("-testnet"); | ||||
Show All 16 Lines | bool ArgsManager::UseDefaultSection(const std::string &arg) const { | ||||
return m_network == CBaseChainParams::MAIN || | return m_network == CBaseChainParams::MAIN || | ||||
m_network_only_args.count(arg) == 0; | m_network_only_args.count(arg) == 0; | ||||
} | } | ||||
util::SettingsValue ArgsManager::GetSetting(const std::string &arg) const { | util::SettingsValue ArgsManager::GetSetting(const std::string &arg) const { | ||||
LOCK(cs_args); | LOCK(cs_args); | ||||
return util::GetSetting(m_settings, m_network, SettingName(arg), | return util::GetSetting(m_settings, m_network, SettingName(arg), | ||||
!UseDefaultSection(arg), | !UseDefaultSection(arg), | ||||
/*ignore_nonpersistent=*/false, | |||||
/* get_chain_name= */ false); | /* get_chain_name= */ false); | ||||
} | } | ||||
std::vector<util::SettingsValue> | std::vector<util::SettingsValue> | ||||
ArgsManager::GetSettingsList(const std::string &arg) const { | ArgsManager::GetSettingsList(const std::string &arg) const { | ||||
LOCK(cs_args); | LOCK(cs_args); | ||||
return util::GetSettingsList(m_settings, m_network, SettingName(arg), | return util::GetSettingsList(m_settings, m_network, SettingName(arg), | ||||
!UseDefaultSection(arg)); | !UseDefaultSection(arg)); | ||||
▲ Show 20 Lines • Show All 333 Lines • Show Last 20 Lines |