Changeset View
Changeset View
Standalone View
Standalone View
src/util.cpp
Show First 20 Lines • Show All 435 Lines • ▼ Show 20 Lines | fs::path GetConfigFile(const std::string &confPath) { | ||||
fs::path pathConfigFile(confPath); | fs::path pathConfigFile(confPath); | ||||
if (!pathConfigFile.is_complete()) { | if (!pathConfigFile.is_complete()) { | ||||
pathConfigFile = GetDataDir(false) / pathConfigFile; | pathConfigFile = GetDataDir(false) / pathConfigFile; | ||||
} | } | ||||
return pathConfigFile; | return pathConfigFile; | ||||
} | } | ||||
void ArgsManager::ReadConfigFile(const std::string &confPath) { | void ArgsManager::ReadConfigStream(std::istream &stream) { | ||||
fs::ifstream streamConfig(GetConfigFile(confPath)); | |||||
// No bitcoin.conf file is OK | |||||
if (!streamConfig.good()) { | |||||
return; | |||||
} | |||||
{ | |||||
LOCK(cs_args); | LOCK(cs_args); | ||||
std::set<std::string> setOptions; | std::set<std::string> setOptions; | ||||
setOptions.insert("*"); | setOptions.insert("*"); | ||||
for (boost::program_options::detail::config_file_iterator | for (boost::program_options::detail::config_file_iterator | ||||
it(streamConfig, setOptions), | it(stream, setOptions), | ||||
end; | end; | ||||
it != end; ++it) { | it != end; ++it) { | ||||
// Don't overwrite existing settings so command line settings | // Don't overwrite existing settings so command line settings override | ||||
// override bitcoin.conf | // bitcoin.conf | ||||
std::string strKey = std::string("-") + it->string_key; | std::string strKey = std::string("-") + it->string_key; | ||||
std::string strValue = it->value[0]; | std::string strValue = it->value[0]; | ||||
InterpretNegatedOption(strKey, strValue); | InterpretNegatedOption(strKey, strValue); | ||||
if (mapArgs.count(strKey) == 0) { | if (mapArgs.count(strKey) == 0) { | ||||
mapArgs[strKey] = strValue; | mapArgs[strKey] = strValue; | ||||
} | } | ||||
mapMultiArgs[strKey].push_back(strValue); | mapMultiArgs[strKey].push_back(strValue); | ||||
} | } | ||||
} | } | ||||
void ArgsManager::ReadConfigFile(const std::string &confPath) { | |||||
fs::ifstream stream(GetConfigFile(confPath)); | |||||
// ok to not have a config file | |||||
if (stream.good()) { | |||||
ReadConfigStream(stream); | |||||
} | |||||
// If datadir is changed in .conf file: | // If datadir is changed in .conf file: | ||||
ClearDatadirCache(); | ClearDatadirCache(); | ||||
} | } | ||||
std::string ArgsManager::GetChainName() const { | |||||
bool fRegTest = GetBoolArg("-regtest", false); | |||||
bool fTestNet = GetBoolArg("-testnet", false); | |||||
if (fTestNet && fRegTest) { | |||||
throw std::runtime_error( | |||||
"Invalid combination of -regtest and -testnet."); | |||||
} | |||||
if (fRegTest) { | |||||
return CBaseChainParams::REGTEST; | |||||
} | |||||
if (fTestNet) { | |||||
return CBaseChainParams::TESTNET; | |||||
} | |||||
return CBaseChainParams::MAIN; | |||||
} | |||||
#ifndef WIN32 | #ifndef WIN32 | ||||
fs::path GetPidFile() { | fs::path GetPidFile() { | ||||
fs::path pathPidFile(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME)); | fs::path pathPidFile(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME)); | ||||
if (!pathPidFile.is_complete()) { | if (!pathPidFile.is_complete()) { | ||||
pathPidFile = GetDataDir() / pathPidFile; | pathPidFile = GetDataDir() / pathPidFile; | ||||
} | } | ||||
return pathPidFile; | return pathPidFile; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 241 Lines • Show Last 20 Lines |