* move ReadConfigFile() : i2p::filesystem -> i2p::config * don't export i2p::config::mapArgs outside namespace

This commit is contained in:
hagen 2016-01-18 00:00:00 +00:00
parent 6740ec464c
commit 7565843fbe
3 changed files with 22 additions and 23 deletions

View file

@ -65,7 +65,7 @@ namespace i2p
LogPrint(eLogInfo, "i2pd v", VERSION, " starting");
LogPrint(eLogDebug, "FS: data directory: ", i2p::util::filesystem::GetDataDir().string());
i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs);
i2p::util::config::ReadConfigFile(i2p::util::filesystem::GetConfigFile());
isDaemon = i2p::util::config::GetArg("-daemon", 0);
isLogging = i2p::util::config::GetArg("-log", 1);

View file

@ -124,6 +124,26 @@ namespace config
return atoi(mapArgs[strArg].c_str());
return nDefault;
}
void ReadConfigFile(boost::filesystem::path path)
{
boost::filesystem::ifstream streamConfig(path);
if (!streamConfig.good())
return; // No i2pd.conf file is OK
std::set<std::string> setOptions;
setOptions.insert("*");
for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
{
// Don't overwrite existing settings so command line settings override i2pd.conf
std::string strKey = std::string("-") + it->string_key;
if (mapArgs.count(strKey) == 0)
{
mapArgs[strKey] = it->value[0];
}
}
}
}
namespace filesystem
@ -193,26 +213,6 @@ namespace filesystem
return pathTunnelsConfigFile;
}
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet)
{
boost::filesystem::ifstream streamConfig(GetConfigFile());
if (!streamConfig.good())
return; // No i2pd.conf file is OK
std::set<std::string> setOptions;
setOptions.insert("*");
for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
{
// Don't overwrite existing settings so command line settings override i2pd.conf
std::string strKey = std::string("-") + it->string_key;
if (mapSettingsRet.count(strKey) == 0)
{
mapSettingsRet[strKey] = it->value[0];
}
}
}
boost::filesystem::path GetDefaultDataDir()
{
// Windows < Vista: C:\Documents and Settings\Username\.i2pd

3
util.h
View file

@ -16,10 +16,10 @@ namespace util
{
namespace config
{
extern std::map<std::string, std::string> mapArgs;
void OptionParser(int argc, const char* const argv[]);
int GetArg(const std::string& strArg, int nDefault);
std::string GetArg(const std::string& strArg, const std::string& strDefault);
void ReadConfigFile(boost::filesystem::path path);
}
namespace filesystem
@ -32,7 +32,6 @@ namespace util
boost::filesystem::path GetDefaultDataDir();
boost::filesystem::path GetConfigFile();
boost::filesystem::path GetTunnelsConfigFile();
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet);
boost::filesystem::path GetCertificatesDir();
}