- Timestamp:
- May 30, 2015, 12:22:27 PM (9 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/ApplicationPaths.cc
r10457 r10509 27 27 */ 28 28 29 #include " PathConfig.h"29 #include "ApplicationPaths.h" 30 30 31 31 #include <cassert> … … 53 53 #include "util/Output.h" 54 54 #include "util/Exception.h" 55 #include "commandline/CommandLineIncludes.h"56 55 57 56 // Differentiate Boost Filesystem v2 and v3 … … 59 58 # define BF_LEAF leaf 60 59 # define BF_GENERIC_STRING string 61 # define BF_NATIVE_STRING file_string62 60 #else 63 61 # define BF_LEAF path().filename().string 64 62 # define BF_GENERIC_STRING generic_string 65 # define BF_NATIVE_STRING string66 63 #endif 67 64 … … 71 68 72 69 //! Static pointer to the singleton 73 PathConfig* PathConfig::singletonPtr_s = 0; 74 75 SetCommandLineArgument(externalDataPath, "").information("Path to the external data files"); 76 SetCommandLineArgument(writingPathSuffix, "").information("Additional subfolder for config and log files"); 77 78 PathConfig::PathConfig() 70 ApplicationPaths* ApplicationPaths::singletonPtr_s = 0; 71 72 ApplicationPaths::ApplicationPaths() 79 73 : rootPath_(*(new bf::path())) 80 74 , executablePath_(*(new bf::path())) 81 75 , modulePath_(*(new bf::path())) 82 , dataPath_(*(new bf::path()))83 , externalDataPath_(*(new bf::path()))84 , configPath_(*(new bf::path()))85 , logPath_(*(new bf::path()))86 76 , bBuildDirectoryRun_(false) 87 77 { … … 138 128 { 139 129 orxout(internal_info) << "Running from the build tree." << endl; 140 PathConfig::bBuildDirectoryRun_ = true;130 ApplicationPaths::bBuildDirectoryRun_ = true; 141 131 modulePath_ = specialConfig::moduleDevDirectory; 142 132 } … … 167 157 } 168 158 169 PathConfig::~PathConfig()159 ApplicationPaths::~ApplicationPaths() 170 160 { 171 161 delete &rootPath_; 172 162 delete &executablePath_; 173 163 delete &modulePath_; 174 delete &dataPath_; 175 delete &externalDataPath_; 176 delete &configPath_; 177 delete &logPath_; 178 } 179 180 void PathConfig::setConfigurablePaths() 181 { 182 if (bBuildDirectoryRun_) 183 { 184 dataPath_ = specialConfig::dataDevDirectory; 185 configPath_ = specialConfig::configDevDirectory; 186 logPath_ = specialConfig::logDevDirectory; 187 188 // Check for data path override by the command line 189 if (!CommandLineParser::getArgument("externalDataPath")->hasDefaultValue()) 190 externalDataPath_ = CommandLineParser::getValue("externalDataPath").get<std::string>(); 191 else 192 externalDataPath_ = specialConfig::externalDataDevDirectory; 193 } 194 else 195 { 196 197 #ifdef INSTALL_COPYABLE // --> relative paths 198 199 // Using paths relative to the install prefix, complete them 200 dataPath_ = rootPath_ / specialConfig::defaultDataPath; 201 configPath_ = rootPath_ / specialConfig::defaultConfigPath; 202 logPath_ = rootPath_ / specialConfig::defaultLogPath; 203 204 #else 205 206 dataPath_ = specialConfig::dataInstallDirectory; 207 208 // Get user directory 209 #ifdef ORXONOX_PLATFORM_UNIX 210 char* userDataPathPtr(getenv("HOME")); 211 #else 212 char* userDataPathPtr(getenv("APPDATA")); 213 #endif 214 if (userDataPathPtr == NULL) 215 ThrowException(General, "Could not retrieve user data path."); 216 bf::path userDataPath(userDataPathPtr); 217 userDataPath /= ".orxonox"; 218 219 configPath_ = userDataPath / specialConfig::defaultConfigPath; 220 logPath_ = userDataPath / specialConfig::defaultLogPath; 221 222 #endif 223 224 } 225 226 // Option to put all the config and log files in a separate folder 227 if (!CommandLineParser::getArgument("writingPathSuffix")->hasDefaultValue()) 228 { 229 const std::string& directory(CommandLineParser::getValue("writingPathSuffix").get<std::string>()); 230 configPath_ = configPath_ / directory; 231 logPath_ = logPath_ / directory; 232 } 233 234 // Create directories to avoid problems when opening files in non existent folders. 235 std::vector<std::pair<bf::path, std::string> > directories; 236 directories.push_back(std::make_pair(bf::path(configPath_), std::string("config"))); 237 directories.push_back(std::make_pair(bf::path(logPath_), std::string("log"))); 238 239 for (std::vector<std::pair<bf::path, std::string> >::iterator it = directories.begin(); 240 it != directories.end(); ++it) 241 { 242 if (bf::exists(it->first) && !bf::is_directory(it->first)) 243 { 244 ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \ 245 Please remove " + it->first.BF_GENERIC_STRING()); 246 } 247 if (bf::create_directories(it->first)) // function may not return true at all (bug?) 248 { 249 orxout(internal_info) << "Created " << it->second << " directory" << endl; 250 } 251 } 252 } 253 254 std::vector<std::string> PathConfig::getModulePaths() 164 } 165 166 std::vector<std::string> ApplicationPaths::getModulePaths() 255 167 { 256 168 std::vector<std::string> modulePaths; … … 288 200 } 289 201 290 /*static*/ std::string PathConfig::getRootPathString()202 /*static*/ std::string ApplicationPaths::getRootPathString() 291 203 { 292 204 return getInstance().rootPath_.BF_GENERIC_STRING() + '/'; 293 205 } 294 206 295 /*static*/ std::string PathConfig::getExecutablePathString()207 /*static*/ std::string ApplicationPaths::getExecutablePathString() 296 208 { 297 209 return getInstance().executablePath_.BF_GENERIC_STRING() + '/'; 298 210 } 299 211 300 /*static*/ std::string PathConfig::getDataPathString() 301 { 302 return getInstance().dataPath_.BF_GENERIC_STRING() + '/'; 303 } 304 305 /*static*/ std::string PathConfig::getExternalDataPathString() 306 { 307 return getInstance().externalDataPath_.BF_GENERIC_STRING() + '/'; 308 } 309 310 /*static*/ std::string PathConfig::getConfigPathString() 311 { 312 return getInstance().configPath_.BF_GENERIC_STRING() + '/'; 313 } 314 315 /*static*/ std::string PathConfig::getLogPathString() 316 { 317 return getInstance().logPath_.BF_GENERIC_STRING() + '/'; 318 } 319 320 /*static*/ std::string PathConfig::getModulePathString() 212 /*static*/ std::string ApplicationPaths::getModulePathString() 321 213 { 322 214 return getInstance().modulePath_.BF_GENERIC_STRING() + '/';
Note: See TracChangeset
for help on using the changeset viewer.