Browse Source

Custom datadir + cleanup

pull/21/head
Meeh 11 years ago
parent
commit
2fd31c6c8d
  1. 11
      i2p.cpp
  2. 27
      util.cpp
  3. 1
      util.h

11
i2p.cpp

@ -24,16 +24,7 @@ int main( int argc, char* argv[] ) @@ -24,16 +24,7 @@ int main( int argc, char* argv[] )
#endif
LogPrint("\n\n\n\ni2pd starting\n");
LogPrint("default data directory: ", i2p::util::filesystem::GetDefaultDataDir().string());
if (!boost::filesystem::exists( i2p::util::filesystem::GetDefaultDataDir() ))
{
// Create data directory
if (!boost::filesystem::create_directory( i2p::util::filesystem::GetDefaultDataDir() ))
{
LogPrint("Failed to create data directory, exiting! :(");
return -1;
}
}
LogPrint("data directory: ", i2p::util::filesystem::GetDataDir().string());
i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs);
//TODO: This is an ugly workaround. fix it.

27
util.cpp

@ -89,30 +89,37 @@ namespace config @@ -89,30 +89,37 @@ namespace config
namespace filesystem
{
const boost::filesystem::path &GetDataDir(bool fNetSpecific)
const boost::filesystem::path &GetDataDir()
{
static boost::filesystem::path path;
if (config::mapArgs.count("-datadir")) {
path = boost::filesystem::system_complete(config::mapArgs["-datadir"]);
if (!boost::filesystem::is_directory(path)) {
path = "";
return path;
}
if (i2p::util::config::mapArgs.count("-datadir")) {
path = boost::filesystem::system_complete(i2p::util::config::mapArgs["-datadir"]);
} else {
path = GetDefaultDataDir();
}
boost::filesystem::create_directory(path);
if (!boost::filesystem::exists( path ))
{
// Create data directory
if (!boost::filesystem::create_directory( path ))
{
LogPrint("Failed to create data directory!");
return "";
}
}
if (!boost::filesystem::is_directory(path)) {
path = GetDefaultDataDir();
}
LogPrint("Debug: ",path.string());
return path;
}
boost::filesystem::path GetConfigFile()
{
boost::filesystem::path pathConfigFile(i2p::util::config::GetArg("-conf", "i2p.conf"));
if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir(false) / pathConfigFile;
if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir() / pathConfigFile;
return pathConfigFile;
}

1
util.h

@ -22,6 +22,7 @@ namespace util @@ -22,6 +22,7 @@ namespace util
namespace filesystem
{
const boost::filesystem::path &GetDataDir();
boost::filesystem::path GetDefaultDataDir();
boost::filesystem::path GetConfigFile();
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet,

Loading…
Cancel
Save