Changeset 8351 for code/trunk/src/libraries/core/PathConfig.cc
- Timestamp:
- Apr 28, 2011, 7:15:14 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/core/PathConfig.cc
r6417 r8351 33 33 #include <cstdio> 34 34 #include <vector> 35 #include <boost/version.hpp>36 35 #include <boost/filesystem.hpp> 37 36 … … 56 55 #include "CommandLineParser.h" 57 56 58 // Boost 1.36 has some issues with deprecated functions that have been omitted 59 #if (BOOST_VERSION == 103600) 60 # define BOOST_LEAF_FUNCTION filename 57 // Differentiate Boost Filesystem v2 and v3 58 #if (BOOST_FILESYSTEM_VERSION < 3) 59 # define BF_LEAF leaf 60 # define BF_GENERIC_STRING string 61 # define BF_NATIVE_STRING file_string 61 62 #else 62 # define BOOST_LEAF_FUNCTION leaf 63 # define BF_LEAF path().filename().string 64 # define BF_GENERIC_STRING generic_string 65 # define BF_NATIVE_STRING string 63 66 #endif 64 67 … … 95 98 #elif defined(ORXONOX_PLATFORM_APPLE) 96 99 char buffer[1024]; 97 u nsigned longpath_len = 1023;100 uint32_t path_len = 1023; 98 101 if (_NSGetExecutablePath(buffer, &path_len)) 99 102 ThrowException(General, "Could not retrieve executable path."); … … 125 128 #endif 126 129 127 executablePath_ = bf::path(buffer); 128 #ifndef ORXONOX_PLATFORM_APPLE 129 executablePath_ = executablePath_.branch_path(); // remove executable name 130 #endif 130 // Remove executable filename 131 executablePath_ = bf::path(buffer).branch_path(); 131 132 132 133 ///////////////////// … … 206 207 207 208 // Get user directory 208 # ifdef ORXONOX_PLATFORM_UNIX /* Apple? */209 #ifdef ORXONOX_PLATFORM_UNIX 209 210 char* userDataPathPtr(getenv("HOME")); 210 # 211 #else 211 212 char* userDataPathPtr(getenv("APPDATA")); 212 # 213 #endif 213 214 if (userDataPathPtr == NULL) 214 215 ThrowException(General, "Could not retrieve user data path."); … … 233 234 // Create directories to avoid problems when opening files in non existent folders. 234 235 std::vector<std::pair<bf::path, std::string> > directories; 235 directories.push_back(std::make_pair(bf::path(configPath_), "config"));236 directories.push_back(std::make_pair(bf::path(logPath_), "log"));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"))); 237 238 238 239 for (std::vector<std::pair<bf::path, std::string> >::iterator it = directories.begin(); … … 242 243 { 243 244 ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \ 244 Please remove " + it->first. string());245 Please remove " + it->first.BF_GENERIC_STRING()); 245 246 } 246 247 if (bf::create_directories(it->first)) // function may not return true at all (bug?) … … 259 260 size_t moduleextensionlength = moduleextension.size(); 260 261 262 #ifdef ORXONOX_PLATFORM_WINDOWS 261 263 // Add that path to the PATH variable in case a module depends on another one 262 std::string pathVariable(getenv("PATH")); 263 putenv(const_cast<char*>(("PATH=" + pathVariable + ';' + modulePath_.string()).c_str())); 264 const char* currentPATH = getenv("PATH"); 265 std::string newPATH = modulePath_.BF_NATIVE_STRING(); 266 if (currentPATH != NULL) 267 newPATH = std::string(currentPATH) + ';' + newPATH; 268 putenv(const_cast<char*>(("PATH=" + newPATH).c_str())); 269 #endif 264 270 265 271 // Make sure the path exists, otherwise don't load modules … … 273 279 while (file != end) 274 280 { 275 const std::string& filename = file->BOOST_LEAF_FUNCTION();276 277 // Check if the file ends with the ex ension in question281 std::string filename = file->BF_LEAF(); 282 283 // Check if the file ends with the extension in question 278 284 if (filename.size() > moduleextensionlength) 279 285 { … … 282 288 // We've found a helper file 283 289 const std::string& library = filename.substr(0, filename.size() - moduleextensionlength); 284 modulePaths.push_back( (modulePath_ / library).file_string());290 modulePaths.push_back(getModulePathString() + library); 285 291 } 286 292 } … … 293 299 /*static*/ std::string PathConfig::getRootPathString() 294 300 { 295 return getInstance().rootPath_. string() + '/';301 return getInstance().rootPath_.BF_GENERIC_STRING() + '/'; 296 302 } 297 303 298 304 /*static*/ std::string PathConfig::getExecutablePathString() 299 305 { 300 return getInstance().executablePath_. string() + '/';306 return getInstance().executablePath_.BF_GENERIC_STRING() + '/'; 301 307 } 302 308 303 309 /*static*/ std::string PathConfig::getDataPathString() 304 310 { 305 return getInstance().dataPath_. string() + '/';311 return getInstance().dataPath_.BF_GENERIC_STRING() + '/'; 306 312 } 307 313 308 314 /*static*/ std::string PathConfig::getExternalDataPathString() 309 315 { 310 return getInstance().externalDataPath_. string() + '/';316 return getInstance().externalDataPath_.BF_GENERIC_STRING() + '/'; 311 317 } 312 318 313 319 /*static*/ std::string PathConfig::getConfigPathString() 314 320 { 315 return getInstance().configPath_. string() + '/';321 return getInstance().configPath_.BF_GENERIC_STRING() + '/'; 316 322 } 317 323 318 324 /*static*/ std::string PathConfig::getLogPathString() 319 325 { 320 return getInstance().logPath_. string() + '/';326 return getInstance().logPath_.BF_GENERIC_STRING() + '/'; 321 327 } 322 328 323 329 /*static*/ std::string PathConfig::getModulePathString() 324 330 { 325 return getInstance().modulePath_. string() + '/';331 return getInstance().modulePath_.BF_GENERIC_STRING() + '/'; 326 332 } 327 333 }
Note: See TracChangeset
for help on using the changeset viewer.