8 #include <boost/filesystem.hpp> 10 #include "fwCore/base.hpp" 11 #include "fwTools/Os.hpp" 20 std::string
getEnv(
const std::string &name,
bool *ok)
22 char *value = std::getenv(name.c_str());
23 bool exists = (value != NULL);
28 return std::string(exists ? value :
"");
33 std::string
getEnv(
const std::string &name,
const std::string &defaultValue)
36 std::string value =
getEnv(name, &ok);
37 return ok ? value : defaultValue;
42 std::string
getUserDataDir( std::string company, std::string appName,
bool createDirectory )
46 char *appData = std::getenv(
"APPDATA");
47 dataDir = ::fwTools::os::getEnv(
"APPDATA");
49 bool hasXdgConfigHome =
false;
51 std::string xdgConfigHome = ::fwTools::os::getEnv(
"XDG_CONFIG_HOME", &hasXdgConfigHome);
52 std::string home = ::fwTools::os::getEnv(
"HOME", &hasHome);
53 dataDir = hasXdgConfigHome ? xdgConfigHome : (hasHome ? std::string(home) +
"/.config" :
"");
56 if ( !company.empty() )
58 dataDir +=
"/" + company;
62 if ( !appName.empty() )
64 dataDir +=
"/" + appName;
67 if ( !dataDir.empty() )
69 if (boost::filesystem::exists(dataDir))
71 if ( !boost::filesystem::is_directory(dataDir) )
73 OSLM_ERROR( dataDir <<
" already exists and is not a directory." );
77 else if (createDirectory)
79 OSLM_INFO(
"Creating application data directory: "<< dataDir);
80 boost::filesystem::create_directories(dataDir);
#define OSLM_INFO(message)
#define OSLM_ERROR(message)