|
|
|
@ -67,86 +67,6 @@ namespace i2p
@@ -67,86 +67,6 @@ namespace i2p
|
|
|
|
|
{ |
|
|
|
|
namespace util |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
namespace config |
|
|
|
|
{ |
|
|
|
|
std::map<std::string, std::string> mapArgs; |
|
|
|
|
|
|
|
|
|
void OptionParser(int argc, const char* const argv[]) |
|
|
|
|
{ |
|
|
|
|
mapArgs.clear(); |
|
|
|
|
for (int i = 1; i < argc; i++) |
|
|
|
|
{ |
|
|
|
|
std::string strKey (argv[i]); |
|
|
|
|
std::string strValue; |
|
|
|
|
size_t has_data = strKey.find('='); |
|
|
|
|
if (has_data != std::string::npos) |
|
|
|
|
{ |
|
|
|
|
strValue = strKey.substr(has_data+1); |
|
|
|
|
strKey = strKey.substr(0, has_data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef WIN32 |
|
|
|
|
boost::to_lower(strKey); |
|
|
|
|
if (boost::algorithm::starts_with(strKey, "/")) |
|
|
|
|
strKey = "-" + strKey.substr(1); |
|
|
|
|
#endif |
|
|
|
|
if (strKey[0] != '-') |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
mapArgs[strKey] = strValue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BOOST_FOREACH(PAIRTYPE(const std::string,std::string)& entry, mapArgs) |
|
|
|
|
{ |
|
|
|
|
std::string name = entry.first; |
|
|
|
|
|
|
|
|
|
// interpret --foo as -foo (as long as both are not set)
|
|
|
|
|
if (name.find("--") == 0) |
|
|
|
|
{ |
|
|
|
|
std::string singleDash(name.begin()+1, name.end()); |
|
|
|
|
if (mapArgs.count(singleDash) == 0) |
|
|
|
|
mapArgs[singleDash] = entry.second; |
|
|
|
|
name = singleDash; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::string GetArg(const std::string& strArg, const std::string& strDefault) |
|
|
|
|
{ |
|
|
|
|
if (mapArgs.count(strArg)) |
|
|
|
|
return mapArgs[strArg]; |
|
|
|
|
return strDefault; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int GetArg(const std::string& strArg, int nDefault) |
|
|
|
|
{ |
|
|
|
|
if (mapArgs.count(strArg)) |
|
|
|
|
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 |
|
|
|
|
{ |
|
|
|
|
std::string appName ("i2pd"); |
|
|
|
|