- Timestamp:
- May 30, 2015, 12:22:27 PM (9 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/ConfigurablePaths.cc
r10457 r10509 27 27 */ 28 28 29 #include " PathConfig.h"29 #include "ConfigurablePaths.h" 30 30 31 31 #include <cassert> … … 57 57 // Differentiate Boost Filesystem v2 and v3 58 58 #if (BOOST_FILESYSTEM_VERSION < 3) 59 # define BF_LEAF leaf60 59 # define BF_GENERIC_STRING string 61 # define BF_NATIVE_STRING file_string62 60 #else 63 # define BF_LEAF path().filename().string64 61 # define BF_GENERIC_STRING generic_string 65 # define BF_NATIVE_STRING string66 62 #endif 67 63 … … 71 67 72 68 //! Static pointer to the singleton 73 PathConfig* PathConfig::singletonPtr_s = 0;69 ConfigurablePaths* ConfigurablePaths::singletonPtr_s = 0; 74 70 75 71 SetCommandLineArgument(externalDataPath, "").information("Path to the external data files"); 76 72 SetCommandLineArgument(writingPathSuffix, "").information("Additional subfolder for config and log files"); 77 73 78 PathConfig::PathConfig() 79 : rootPath_(*(new bf::path())) 80 , executablePath_(*(new bf::path())) 81 , modulePath_(*(new bf::path())) 82 , dataPath_(*(new bf::path())) 74 ConfigurablePaths::ConfigurablePaths() 75 : dataPath_(*(new bf::path())) 83 76 , externalDataPath_(*(new bf::path())) 84 77 , configPath_(*(new bf::path())) 85 78 , logPath_(*(new bf::path())) 86 , bBuildDirectoryRun_(false)87 79 { 88 //////////////////////////89 // FIND EXECUTABLE PATH //90 //////////////////////////91 92 #ifdef ORXONOX_PLATFORM_WINDOWS93 // get executable module94 TCHAR buffer[1024];95 if (GetModuleFileName(NULL, buffer, 1024) == 0)96 ThrowException(General, "Could not retrieve executable path.");97 98 #elif defined(ORXONOX_PLATFORM_APPLE)99 char buffer[1024];100 uint32_t path_len = 1023;101 if (_NSGetExecutablePath(buffer, &path_len))102 ThrowException(General, "Could not retrieve executable path.");103 104 #else /* Linux */105 /* written by Nicolai Haehnle <prefect_@gmx.net> */106 107 /* Get our PID and build the name of the link in /proc */108 char linkname[64]; /* /proc/<pid>/exe */109 if (snprintf(linkname, sizeof(linkname), "/proc/%i/exe", getpid()) < 0)110 {111 /* This should only happen on large word systems. I'm not sure112 what the proper response is here.113 Since it really is an assert-like condition, aborting the114 program seems to be in order. */115 assert(false);116 }117 118 /* Now read the symbolic link */119 char buffer[1024];120 int ret;121 ret = readlink(linkname, buffer, 1024);122 /* In case of an error, leave the handling up to the caller */123 if (ret == -1)124 ThrowException(General, "Could not retrieve executable path.");125 126 /* Ensure proper NUL termination */127 buffer[ret] = 0;128 #endif129 130 // Remove executable filename131 executablePath_ = bf::path(buffer).branch_path();132 133 /////////////////////134 // SET MODULE PATH //135 /////////////////////136 137 if (bf::exists(executablePath_ / "orxonox_dev_build.keep_me"))138 {139 orxout(internal_info) << "Running from the build tree." << endl;140 PathConfig::bBuildDirectoryRun_ = true;141 modulePath_ = specialConfig::moduleDevDirectory;142 }143 else144 {145 146 #ifdef INSTALL_COPYABLE // --> relative paths147 148 // Also set the root path149 bf::path relativeExecutablePath(specialConfig::defaultRuntimePath);150 rootPath_ = executablePath_;151 while (!bf::equivalent(rootPath_ / relativeExecutablePath, executablePath_) && !rootPath_.empty())152 rootPath_ = rootPath_.branch_path();153 if (rootPath_.empty())154 ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");155 156 // Module path is fixed as well157 modulePath_ = rootPath_ / specialConfig::defaultModulePath;158 159 #else160 161 // There is no root path, so don't set it at all162 // Module path is fixed as well163 modulePath_ = specialConfig::moduleInstallDirectory;164 165 #endif166 }167 80 } 168 81 169 PathConfig::~PathConfig()82 ConfigurablePaths::~ConfigurablePaths() 170 83 { 171 delete &rootPath_;172 delete &executablePath_;173 delete &modulePath_;174 84 delete &dataPath_; 175 85 delete &externalDataPath_; … … 178 88 } 179 89 180 void PathConfig::setConfigurablePaths()90 void ConfigurablePaths::setConfigurablePaths(const ApplicationPaths& applicationPaths) 181 91 { 182 if ( bBuildDirectoryRun_)92 if (applicationPaths.buildDirectoryRun()) 183 93 { 184 94 dataPath_ = specialConfig::dataDevDirectory; … … 198 108 199 109 // Using paths relative to the install prefix, complete them 200 dataPath_ = rootPath_/ specialConfig::defaultDataPath;201 configPath_ = rootPath_/ specialConfig::defaultConfigPath;202 logPath_ = rootPath_/ specialConfig::defaultLogPath;110 dataPath_ = applicationPaths.getRootPath() / specialConfig::defaultDataPath; 111 configPath_ = applicationPaths.getRootPath() / specialConfig::defaultConfigPath; 112 logPath_ = applicationPaths.getRootPath() / specialConfig::defaultLogPath; 203 113 204 114 #else … … 252 162 } 253 163 254 std::vector<std::string> PathConfig::getModulePaths() 255 { 256 std::vector<std::string> modulePaths; 257 258 // We search for helper files with the following extension 259 const std::string& moduleextension = specialConfig::moduleExtension; 260 size_t moduleextensionlength = moduleextension.size(); 261 262 // Make sure the path exists, otherwise don't load modules 263 if (!boost::filesystem::exists(modulePath_)) 264 return modulePaths; 265 266 boost::filesystem::directory_iterator file(modulePath_); 267 boost::filesystem::directory_iterator end; 268 269 // Iterate through all files 270 while (file != end) 271 { 272 std::string filename = file->BF_LEAF(); 273 274 // Check if the file ends with the extension in question 275 if (filename.size() > moduleextensionlength) 276 { 277 if (filename.substr(filename.size() - moduleextensionlength) == moduleextension) 278 { 279 // We've found a helper file 280 const std::string& library = filename.substr(0, filename.size() - moduleextensionlength); 281 modulePaths.push_back(getModulePathString() + library); 282 } 283 } 284 ++file; 285 } 286 287 return modulePaths; 288 } 289 290 /*static*/ std::string PathConfig::getRootPathString() 291 { 292 return getInstance().rootPath_.BF_GENERIC_STRING() + '/'; 293 } 294 295 /*static*/ std::string PathConfig::getExecutablePathString() 296 { 297 return getInstance().executablePath_.BF_GENERIC_STRING() + '/'; 298 } 299 300 /*static*/ std::string PathConfig::getDataPathString() 164 /*static*/ std::string ConfigurablePaths::getDataPathString() 301 165 { 302 166 return getInstance().dataPath_.BF_GENERIC_STRING() + '/'; 303 167 } 304 168 305 /*static*/ std::string PathConfig::getExternalDataPathString()169 /*static*/ std::string ConfigurablePaths::getExternalDataPathString() 306 170 { 307 171 return getInstance().externalDataPath_.BF_GENERIC_STRING() + '/'; 308 172 } 309 173 310 /*static*/ std::string PathConfig::getConfigPathString()174 /*static*/ std::string ConfigurablePaths::getConfigPathString() 311 175 { 312 176 return getInstance().configPath_.BF_GENERIC_STRING() + '/'; 313 177 } 314 178 315 /*static*/ std::string PathConfig::getLogPathString()179 /*static*/ std::string ConfigurablePaths::getLogPathString() 316 180 { 317 181 return getInstance().logPath_.BF_GENERIC_STRING() + '/'; 318 182 } 319 320 /*static*/ std::string PathConfig::getModulePathString()321 {322 return getInstance().modulePath_.BF_GENERIC_STRING() + '/';323 }324 183 }
Note: See TracChangeset
for help on using the changeset viewer.