| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | #ifndef TCHAR |
|---|
| 19 | typedef char TCHAR; |
|---|
| 20 | #endif |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | #if defined(WIN32) && !defined(__CYGWIN__) |
|---|
| 28 | #include <io.h> |
|---|
| 29 | #define WINBASE_DECLARE_GET_MODULE_HANDLE_EX |
|---|
| 30 | #include <windows.h> |
|---|
| 31 | #include <winbase.h> |
|---|
| 32 | #include <sys/types.h> |
|---|
| 33 | #include <sys/stat.h> |
|---|
| 34 | #include <direct.h> |
|---|
| 35 | |
|---|
| 36 | #define mkdir(x,y) _mkdir((x)) |
|---|
| 37 | #define stat64 _stati64 |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | #ifndef F_OK |
|---|
| 41 | #define F_OK 4 |
|---|
| 42 | #endif |
|---|
| 43 | |
|---|
| 44 | #else // unix |
|---|
| 45 | |
|---|
| 46 | #if defined( __APPLE__ ) |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | #include <AvailabilityMacros.h> |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | #if (MAC_OS_X_VERSION_MAX_ALLOWED <= 1040) |
|---|
| 59 | #define stat64 stat |
|---|
| 60 | #endif |
|---|
| 61 | #elif defined(__CYGWIN__) || defined(__FreeBSD__) || (defined(__hpux) && !defined(_LARGEFILE64_SOURCE)) |
|---|
| 62 | #define stat64 stat |
|---|
| 63 | #endif |
|---|
| 64 | |
|---|
| 65 | #include <stdlib.h> |
|---|
| 66 | #include <unistd.h> |
|---|
| 67 | #include <sys/types.h> |
|---|
| 68 | #include <sys/stat.h> |
|---|
| 69 | #endif |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | #if !defined(S_ISDIR) |
|---|
| 73 | # if defined( _S_IFDIR) && !defined( __S_IFDIR) |
|---|
| 74 | # define __S_IFDIR _S_IFDIR |
|---|
| 75 | # endif |
|---|
| 76 | # define S_ISDIR(mode) (mode&__S_IFDIR) |
|---|
| 77 | #endif |
|---|
| 78 | |
|---|
| 79 | #include <osg/Config> |
|---|
| 80 | #include <osgDB/ConvertUTF> |
|---|
| 81 | #include <osg/Notify> |
|---|
| 82 | |
|---|
| 83 | #include <osgDB/FileUtils> |
|---|
| 84 | #include <osgDB/FileNameUtils> |
|---|
| 85 | #include <osgDB/Registry> |
|---|
| 86 | |
|---|
| 87 | #include <errno.h> |
|---|
| 88 | #include <string.h> |
|---|
| 89 | |
|---|
| 90 | #include <stack> |
|---|
| 91 | |
|---|
| 92 | namespace osgDB |
|---|
| 93 | { |
|---|
| 94 | #ifdef OSG_USE_UTF8_FILENAME |
|---|
| 95 | #define OSGDB_STRING_TO_FILENAME(s) osgDB::convertUTF8toUTF16(s) |
|---|
| 96 | #define OSGDB_FILENAME_TO_STRING(s) osgDB::convertUTF16toUTF8(s) |
|---|
| 97 | #define OSGDB_FILENAME_TEXT(x) L ## x |
|---|
| 98 | #define OSGDB_WINDOWS_FUNCT(x) x ## W |
|---|
| 99 | #define OSGDB_WINDOWS_FUNCT_STRING(x) #x "W" |
|---|
| 100 | typedef wchar_t filenamechar; |
|---|
| 101 | typedef std::wstring filenamestring; |
|---|
| 102 | #else |
|---|
| 103 | #define OSGDB_STRING_TO_FILENAME(s) s |
|---|
| 104 | #define OSGDB_FILENAME_TO_STRING(s) s |
|---|
| 105 | #define OSGDB_FILENAME_TEXT(x) x |
|---|
| 106 | #define OSGDB_WINDOWS_FUNCT(x) x ## A |
|---|
| 107 | #define OSGDB_WINDOWS_FUNCT_STRING(x) #x "A" |
|---|
| 108 | typedef char filenamechar; |
|---|
| 109 | typedef std::string filenamestring; |
|---|
| 110 | #endif |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | FILE* osgDB::fopen(const char* filename, const char* mode) |
|---|
| 114 | { |
|---|
| 115 | #ifdef OSG_USE_UTF8_FILENAME |
|---|
| 116 | return ::_wfopen(convertUTF8toUTF16(filename).c_str(), convertUTF8toUTF16(mode).c_str()); |
|---|
| 117 | #else |
|---|
| 118 | return ::fopen(filename, mode); |
|---|
| 119 | #endif |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | bool osgDB::makeDirectory( const std::string &path ) |
|---|
| 123 | { |
|---|
| 124 | if (path.empty()) |
|---|
| 125 | { |
|---|
| 126 | osg::notify(osg::DEBUG_INFO) << "osgDB::makeDirectory(): cannot create an empty directory" << std::endl; |
|---|
| 127 | return false; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | struct stat64 stbuf; |
|---|
| 131 | #ifdef OSG_USE_UTF8_FILENAME |
|---|
| 132 | if( _wstat64( OSGDB_STRING_TO_FILENAME(path).c_str(), &stbuf ) == 0 ) |
|---|
| 133 | #else |
|---|
| 134 | if( stat64( path.c_str(), &stbuf ) == 0 ) |
|---|
| 135 | #endif |
|---|
| 136 | { |
|---|
| 137 | if( S_ISDIR(stbuf.st_mode)) |
|---|
| 138 | return true; |
|---|
| 139 | else |
|---|
| 140 | { |
|---|
| 141 | osg::notify(osg::DEBUG_INFO) << "osgDB::makeDirectory(): " << |
|---|
| 142 | path << " already exists and is not a directory!" << std::endl; |
|---|
| 143 | return false; |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | std::string dir = path; |
|---|
| 148 | std::stack<std::string> paths; |
|---|
| 149 | while( true ) |
|---|
| 150 | { |
|---|
| 151 | if( dir.empty() ) |
|---|
| 152 | break; |
|---|
| 153 | |
|---|
| 154 | #ifdef OSG_USE_UTF8_FILENAME |
|---|
| 155 | if( _wstat64( OSGDB_STRING_TO_FILENAME(dir).c_str(), &stbuf ) < 0 ) |
|---|
| 156 | #else |
|---|
| 157 | if( stat64( dir.c_str(), &stbuf ) < 0 ) |
|---|
| 158 | #endif |
|---|
| 159 | { |
|---|
| 160 | switch( errno ) |
|---|
| 161 | { |
|---|
| 162 | case ENOENT: |
|---|
| 163 | case ENOTDIR: |
|---|
| 164 | paths.push( dir ); |
|---|
| 165 | break; |
|---|
| 166 | |
|---|
| 167 | default: |
|---|
| 168 | osg::notify(osg::DEBUG_INFO) << "osgDB::makeDirectory(): " << strerror(errno) << std::endl; |
|---|
| 169 | return false; |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | dir = getFilePath(std::string(dir)); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | while( !paths.empty() ) |
|---|
| 176 | { |
|---|
| 177 | std::string dir = paths.top(); |
|---|
| 178 | |
|---|
| 179 | #if defined(WIN32) |
|---|
| 180 | |
|---|
| 181 | if (dir.size() == 2 && dir.c_str()[1] == ':') { |
|---|
| 182 | paths.pop(); |
|---|
| 183 | continue; |
|---|
| 184 | } |
|---|
| 185 | #endif |
|---|
| 186 | |
|---|
| 187 | #ifdef OSG_USE_UTF8_FILENAME |
|---|
| 188 | if ( _wmkdir(OSGDB_STRING_TO_FILENAME(dir).c_str())< 0 ) |
|---|
| 189 | #else |
|---|
| 190 | if( mkdir( dir.c_str(), 0755 )< 0 ) |
|---|
| 191 | #endif |
|---|
| 192 | { |
|---|
| 193 | osg::notify(osg::DEBUG_INFO) << "osgDB::makeDirectory(): " << strerror(errno) << std::endl; |
|---|
| 194 | return false; |
|---|
| 195 | } |
|---|
| 196 | paths.pop(); |
|---|
| 197 | } |
|---|
| 198 | return true; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | bool osgDB::makeDirectoryForFile( const std::string &path ) |
|---|
| 202 | { |
|---|
| 203 | return makeDirectory( getFilePath( path )); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | std::string osgDB::getCurrentWorkingDirectory( void ) |
|---|
| 208 | { |
|---|
| 209 | |
|---|
| 210 | #ifndef MAX_PATH |
|---|
| 211 | #define MAX_PATH 1024 |
|---|
| 212 | #endif |
|---|
| 213 | TCHAR rootdir[MAX_PATH]; |
|---|
| 214 | if(getcwd(rootdir,MAX_PATH-1)) |
|---|
| 215 | { |
|---|
| 216 | return(rootdir); |
|---|
| 217 | } |
|---|
| 218 | return(""); |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | bool osgDB::setCurrentWorkingDirectory( const std::string &newCurrentWorkingDirectory ) |
|---|
| 224 | { |
|---|
| 225 | if (newCurrentWorkingDirectory.empty()) |
|---|
| 226 | { |
|---|
| 227 | osg::notify(osg::DEBUG_INFO) << "osgDB::setCurrentWorkingDirectory(): called with empty string." << std::endl; |
|---|
| 228 | return false; |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | #ifdef OSG_USE_UTF8_FILENAME |
|---|
| 232 | return _wchdir( OSGDB_STRING_TO_FILENAME(newCurrentWorkingDirectory).c_str()) == 0; |
|---|
| 233 | #else |
|---|
| 234 | return chdir( newCurrentWorkingDirectory.c_str()) == 0; |
|---|
| 235 | #endif |
|---|
| 236 | |
|---|
| 237 | return true; |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | void osgDB::convertStringPathIntoFilePathList(const std::string& paths,FilePathList& filepath) |
|---|
| 243 | { |
|---|
| 244 | #if defined(WIN32) && !defined(__CYGWIN__) |
|---|
| 245 | char delimitor = ';'; |
|---|
| 246 | #else |
|---|
| 247 | char delimitor = ':'; |
|---|
| 248 | #endif |
|---|
| 249 | |
|---|
| 250 | if (!paths.empty()) |
|---|
| 251 | { |
|---|
| 252 | std::string::size_type start = 0; |
|---|
| 253 | std::string::size_type end; |
|---|
| 254 | while ((end = paths.find_first_of(delimitor,start))!=std::string::npos) |
|---|
| 255 | { |
|---|
| 256 | filepath.push_back(std::string(paths,start,end-start)); |
|---|
| 257 | start = end+1; |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | std::string lastPath(paths,start,std::string::npos); |
|---|
| 261 | if (!lastPath.empty()) |
|---|
| 262 | filepath.push_back(lastPath); |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | bool osgDB::fileExists(const std::string& filename) |
|---|
| 268 | { |
|---|
| 269 | #ifdef OSG_USE_UTF8_FILENAME |
|---|
| 270 | return _waccess( OSGDB_STRING_TO_FILENAME(filename).c_str(), F_OK ) == 0; |
|---|
| 271 | #else |
|---|
| 272 | return access( filename.c_str(), F_OK ) == 0; |
|---|
| 273 | #endif |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | osgDB::FileType osgDB::fileType(const std::string& filename) |
|---|
| 277 | { |
|---|
| 278 | struct stat64 fileStat; |
|---|
| 279 | #ifdef OSG_USE_UTF8_FILENAME |
|---|
| 280 | if ( _wstat64(OSGDB_STRING_TO_FILENAME(filename).c_str(), &fileStat) != 0 ) |
|---|
| 281 | #else |
|---|
| 282 | if ( stat64(filename.c_str(), &fileStat) != 0 ) |
|---|
| 283 | #endif |
|---|
| 284 | { |
|---|
| 285 | return FILE_NOT_FOUND; |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | if ( fileStat.st_mode & S_IFDIR ) |
|---|
| 289 | return DIRECTORY; |
|---|
| 290 | else if ( fileStat.st_mode & S_IFREG ) |
|---|
| 291 | return REGULAR_FILE; |
|---|
| 292 | |
|---|
| 293 | return FILE_NOT_FOUND; |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | std::string osgDB::findFileInPath(const std::string& filename, const FilePathList& filepath,CaseSensitivity caseSensitivity) |
|---|
| 297 | { |
|---|
| 298 | if (filename.empty()) |
|---|
| 299 | return filename; |
|---|
| 300 | |
|---|
| 301 | if (!isFileNameNativeStyle(filename)) |
|---|
| 302 | return findFileInPath(convertFileNameToNativeStyle(filename), filepath, caseSensitivity); |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | for(FilePathList::const_iterator itr=filepath.begin(); |
|---|
| 306 | itr!=filepath.end(); |
|---|
| 307 | ++itr) |
|---|
| 308 | { |
|---|
| 309 | osg::notify(osg::DEBUG_INFO) << "itr='" <<*itr<< "'\n"; |
|---|
| 310 | std::string path = itr->empty() ? filename : concatPaths(*itr, filename); |
|---|
| 311 | |
|---|
| 312 | path = getRealPath(path); |
|---|
| 313 | |
|---|
| 314 | osg::notify(osg::DEBUG_INFO) << "FindFileInPath() : trying " << path << " ...\n"; |
|---|
| 315 | if(fileExists(path)) |
|---|
| 316 | { |
|---|
| 317 | osg::notify(osg::DEBUG_INFO) << "FindFileInPath() : USING " << path << "\n"; |
|---|
| 318 | return path; |
|---|
| 319 | } |
|---|
| 320 | #ifndef WIN32 |
|---|
| 321 | |
|---|
| 322 | else if (caseSensitivity==CASE_INSENSITIVE) |
|---|
| 323 | { |
|---|
| 324 | std::string foundfile = findFileInDirectory(filename,*itr,CASE_INSENSITIVE); |
|---|
| 325 | if (!foundfile.empty()) return foundfile; |
|---|
| 326 | } |
|---|
| 327 | #endif |
|---|
| 328 | |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | return std::string(); |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | std::string osgDB::findDataFile(const std::string& filename,CaseSensitivity caseSensitivity) |
|---|
| 336 | { |
|---|
| 337 | return findDataFile(filename,static_cast<Options*>(0),caseSensitivity); |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | OSGDB_EXPORT std::string osgDB::findDataFile(const std::string& filename,const Options* options, CaseSensitivity caseSensitivity) |
|---|
| 341 | { |
|---|
| 342 | return Registry::instance()->findDataFile(filename, options, caseSensitivity); |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | std::string osgDB::findLibraryFile(const std::string& filename,CaseSensitivity caseSensitivity) |
|---|
| 346 | { |
|---|
| 347 | return Registry::instance()->findLibraryFile(filename, osgDB::Registry::instance()->getOptions(), caseSensitivity); |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | std::string osgDB::findFileInDirectory(const std::string& fileName,const std::string& dirName,CaseSensitivity caseSensitivity) |
|---|
| 351 | { |
|---|
| 352 | bool needFollowingBackslash = false; |
|---|
| 353 | bool needDirectoryName = true; |
|---|
| 354 | osgDB::DirectoryContents dc; |
|---|
| 355 | |
|---|
| 356 | std::string realDirName = dirName; |
|---|
| 357 | std::string realFileName = fileName; |
|---|
| 358 | |
|---|
| 359 | |
|---|
| 360 | #ifdef WIN32 |
|---|
| 361 | bool win32 = true; |
|---|
| 362 | #else |
|---|
| 363 | bool win32 = false; |
|---|
| 364 | #endif |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | |
|---|
| 368 | if (fileName != getSimpleFileName(fileName)) |
|---|
| 369 | { |
|---|
| 370 | |
|---|
| 371 | if (realDirName.empty()) |
|---|
| 372 | { |
|---|
| 373 | realDirName = getFilePath(fileName); |
|---|
| 374 | } |
|---|
| 375 | else if (realDirName=="." || realDirName=="./" || realDirName==".\\") |
|---|
| 376 | { |
|---|
| 377 | realDirName = "./" + getFilePath(fileName); |
|---|
| 378 | } |
|---|
| 379 | else |
|---|
| 380 | { |
|---|
| 381 | char lastChar = dirName[dirName.size()-1]; |
|---|
| 382 | if ((lastChar == '/') || (lastChar == '\\')) |
|---|
| 383 | realDirName = dirName + getFilePath(fileName); |
|---|
| 384 | else |
|---|
| 385 | realDirName = dirName + "/" + getFilePath(fileName); |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | |
|---|
| 389 | realFileName = getSimpleFileName(fileName); |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | osg::notify(osg::DEBUG_INFO) << "findFileInDirectory() : looking for " << realFileName << " in " << realDirName << "...\n"; |
|---|
| 393 | |
|---|
| 394 | if (realDirName.empty()) |
|---|
| 395 | { |
|---|
| 396 | dc = osgDB::getDirectoryContents("."); |
|---|
| 397 | needFollowingBackslash = false; |
|---|
| 398 | needDirectoryName = false; |
|---|
| 399 | } |
|---|
| 400 | else if (realDirName=="." || realDirName=="./" || realDirName==".\\") |
|---|
| 401 | { |
|---|
| 402 | dc = osgDB::getDirectoryContents("."); |
|---|
| 403 | needFollowingBackslash = false; |
|---|
| 404 | needDirectoryName = false; |
|---|
| 405 | } |
|---|
| 406 | else if (realDirName=="/") |
|---|
| 407 | { |
|---|
| 408 | dc = osgDB::getDirectoryContents("/"); |
|---|
| 409 | needFollowingBackslash = false; |
|---|
| 410 | needDirectoryName = true; |
|---|
| 411 | } |
|---|
| 412 | else |
|---|
| 413 | { |
|---|
| 414 | |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | if ((caseSensitivity == CASE_INSENSITIVE) && (!win32)) |
|---|
| 418 | { |
|---|
| 419 | |
|---|
| 420 | std::string parentPath = getFilePath(realDirName); |
|---|
| 421 | std::string lastElement = getSimpleFileName(realDirName); |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | if ((parentPath.empty()) && (!lastElement.empty())) |
|---|
| 425 | { |
|---|
| 426 | |
|---|
| 427 | |
|---|
| 428 | realDirName = findFileInDirectory(lastElement, "/", |
|---|
| 429 | CASE_INSENSITIVE); |
|---|
| 430 | |
|---|
| 431 | dc = osgDB::getDirectoryContents(realDirName); |
|---|
| 432 | needFollowingBackslash = true; |
|---|
| 433 | needDirectoryName = true; |
|---|
| 434 | } |
|---|
| 435 | else |
|---|
| 436 | { |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | realDirName = findFileInDirectory(lastElement, parentPath, |
|---|
| 440 | CASE_INSENSITIVE); |
|---|
| 441 | |
|---|
| 442 | dc = osgDB::getDirectoryContents(realDirName); |
|---|
| 443 | char lastChar = realDirName[realDirName.size()-1]; |
|---|
| 444 | if (lastChar=='/') needFollowingBackslash = false; |
|---|
| 445 | else if (lastChar=='\\') needFollowingBackslash = false; |
|---|
| 446 | else needFollowingBackslash = true; |
|---|
| 447 | needDirectoryName = true; |
|---|
| 448 | } |
|---|
| 449 | } |
|---|
| 450 | else |
|---|
| 451 | { |
|---|
| 452 | |
|---|
| 453 | dc = osgDB::getDirectoryContents(realDirName); |
|---|
| 454 | char lastChar = realDirName[realDirName.size()-1]; |
|---|
| 455 | if (lastChar=='/') needFollowingBackslash = false; |
|---|
| 456 | else if (lastChar=='\\') needFollowingBackslash = false; |
|---|
| 457 | else needFollowingBackslash = true; |
|---|
| 458 | needDirectoryName = true; |
|---|
| 459 | } |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | for(osgDB::DirectoryContents::iterator itr=dc.begin(); |
|---|
| 463 | itr!=dc.end(); |
|---|
| 464 | ++itr) |
|---|
| 465 | { |
|---|
| 466 | if ((caseSensitivity==CASE_INSENSITIVE && osgDB::equalCaseInsensitive(realFileName,*itr)) || |
|---|
| 467 | (realFileName==*itr)) |
|---|
| 468 | { |
|---|
| 469 | if (!needDirectoryName) return *itr; |
|---|
| 470 | else if (needFollowingBackslash) return realDirName+'/'+*itr; |
|---|
| 471 | else return realDirName+*itr; |
|---|
| 472 | } |
|---|
| 473 | } |
|---|
| 474 | return ""; |
|---|
| 475 | } |
|---|
| 476 | |
|---|
| 477 | static void appendInstallationLibraryFilePaths(osgDB::FilePathList& filepath) |
|---|
| 478 | { |
|---|
| 479 | #ifdef OSG_DEFAULT_LIBRARY_PATH |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | filepath.push_back(ADDQUOTES(OSG_DEFAULT_LIBRARY_PATH)); |
|---|
| 483 | #endif |
|---|
| 484 | } |
|---|
| 485 | |
|---|
| 486 | #if defined(WIN32) && !defined(__CYGWIN__) |
|---|
| 487 | #include <io.h> |
|---|
| 488 | #include <direct.h> |
|---|
| 489 | |
|---|
| 490 | osgDB::DirectoryContents osgDB::getDirectoryContents(const std::string& dirName) |
|---|
| 491 | { |
|---|
| 492 | osgDB::DirectoryContents contents; |
|---|
| 493 | |
|---|
| 494 | OSGDB_WINDOWS_FUNCT(WIN32_FIND_DATA) data; |
|---|
| 495 | HANDLE handle = OSGDB_WINDOWS_FUNCT(FindFirstFile)((OSGDB_STRING_TO_FILENAME(dirName) + OSGDB_FILENAME_TEXT("\\*")).c_str(), &data); |
|---|
| 496 | if (handle != INVALID_HANDLE_VALUE) |
|---|
| 497 | { |
|---|
| 498 | do |
|---|
| 499 | { |
|---|
| 500 | contents.push_back(OSGDB_FILENAME_TO_STRING(data.cFileName)); |
|---|
| 501 | } |
|---|
| 502 | while (OSGDB_WINDOWS_FUNCT(FindNextFile)(handle, &data) != 0); |
|---|
| 503 | |
|---|
| 504 | FindClose(handle); |
|---|
| 505 | } |
|---|
| 506 | return contents; |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | #else |
|---|
| 510 | |
|---|
| 511 | #include <dirent.h> |
|---|
| 512 | osgDB::DirectoryContents osgDB::getDirectoryContents(const std::string& dirName) |
|---|
| 513 | { |
|---|
| 514 | osgDB::DirectoryContents contents; |
|---|
| 515 | |
|---|
| 516 | DIR *handle = opendir(dirName.c_str()); |
|---|
| 517 | if (handle) |
|---|
| 518 | { |
|---|
| 519 | dirent *rc; |
|---|
| 520 | while((rc = readdir(handle))!=NULL) |
|---|
| 521 | { |
|---|
| 522 | contents.push_back(rc->d_name); |
|---|
| 523 | } |
|---|
| 524 | closedir(handle); |
|---|
| 525 | } |
|---|
| 526 | |
|---|
| 527 | return contents; |
|---|
| 528 | } |
|---|
| 529 | |
|---|
| 530 | #endif // unix getDirectoryContexts |
|---|
| 531 | |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | |
|---|
| 535 | |
|---|
| 536 | |
|---|
| 537 | #ifdef __sgi |
|---|
| 538 | |
|---|
| 539 | void osgDB::appendPlatformSpecificLibraryFilePaths(FilePathList& filepath) |
|---|
| 540 | { |
|---|
| 541 | convertStringPathIntoFilePathList("/usr/lib32/:/usr/local/lib32/",filepath); |
|---|
| 542 | |
|---|
| 543 | |
|---|
| 544 | char* ptr; |
|---|
| 545 | |
|---|
| 546 | #if (_MIPS_SIM == _MIPS_SIM_ABI32) |
|---|
| 547 | if( (ptr = getenv( "LD_LIBRARY_PATH" ))) |
|---|
| 548 | { |
|---|
| 549 | convertStringPathIntoFilePathList(ptr,filepath); |
|---|
| 550 | } |
|---|
| 551 | |
|---|
| 552 | #elif (_MIPS_SIM == _MIPS_SIM_NABI32) |
|---|
| 553 | |
|---|
| 554 | if( !(ptr = getenv( "LD_LIBRARYN32_PATH" ))) |
|---|
| 555 | ptr = getenv( "LD_LIBRARY_PATH" ); |
|---|
| 556 | |
|---|
| 557 | if( ptr ) |
|---|
| 558 | { |
|---|
| 559 | convertStringPathIntoFilePathList(ptr,filepath); |
|---|
| 560 | } |
|---|
| 561 | |
|---|
| 562 | #elif (_MIPS_SIM == _MIPS_SIM_ABI64) |
|---|
| 563 | |
|---|
| 564 | if( !(ptr = getenv( "LD_LIBRARY64_PATH" ))) |
|---|
| 565 | ptr = getenv( "LD_LIBRARY_PATH" ); |
|---|
| 566 | |
|---|
| 567 | if( ptr ) |
|---|
| 568 | { |
|---|
| 569 | convertStringPathIntoFilePathList(ptr,filepath); |
|---|
| 570 | } |
|---|
| 571 | #endif |
|---|
| 572 | |
|---|
| 573 | appendInstallationLibraryFilePaths(filepath); |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | |
|---|
| 577 | #elif defined(__CYGWIN__) |
|---|
| 578 | |
|---|
| 579 | void osgDB::appendPlatformSpecificLibraryFilePaths(FilePathList& filepath) |
|---|
| 580 | { |
|---|
| 581 | char* ptr; |
|---|
| 582 | if ((ptr = getenv( "PATH" ))) |
|---|
| 583 | { |
|---|
| 584 | convertStringPathIntoFilePathList(ptr,filepath); |
|---|
| 585 | } |
|---|
| 586 | |
|---|
| 587 | appendInstallationLibraryFilePaths(filepath); |
|---|
| 588 | |
|---|
| 589 | convertStringPathIntoFilePathList("/usr/bin/:/usr/local/bin/",filepath); |
|---|
| 590 | } |
|---|
| 591 | |
|---|
| 592 | #elif defined(WIN32) |
|---|
| 593 | |
|---|
| 594 | void osgDB::appendPlatformSpecificLibraryFilePaths(FilePathList& filepath) |
|---|
| 595 | { |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 | |
|---|
| 599 | |
|---|
| 600 | |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | |
|---|
| 608 | DWORD retval = 0; |
|---|
| 609 | const DWORD size = MAX_PATH; |
|---|
| 610 | filenamechar path[size]; |
|---|
| 611 | retval = OSGDB_WINDOWS_FUNCT(GetModuleFileName)(NULL, path, size); |
|---|
| 612 | if (retval != 0 && retval < size) |
|---|
| 613 | { |
|---|
| 614 | filenamestring pathstr(path); |
|---|
| 615 | filenamestring executableDir(pathstr, 0, |
|---|
| 616 | pathstr.find_last_of(OSGDB_FILENAME_TEXT("\\/"))); |
|---|
| 617 | convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(executableDir), filepath); |
|---|
| 618 | } |
|---|
| 619 | else |
|---|
| 620 | { |
|---|
| 621 | osg::notify(osg::WARN) << "Could not get application directory " |
|---|
| 622 | "using Win32 API. It will not be searched." << std::endl; |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | #if defined(_MSC_VER) |
|---|
| 629 | |
|---|
| 630 | |
|---|
| 631 | |
|---|
| 632 | OSGDB_WINDOWS_FUNCT(PGET_MODULE_HANDLE_EX) pGetModuleHandleEx = reinterpret_cast<OSGDB_WINDOWS_FUNCT(PGET_MODULE_HANDLE_EX)> |
|---|
| 633 | (GetProcAddress( GetModuleHandleA("kernel32.dll"), OSGDB_WINDOWS_FUNCT_STRING(GetModuleHandleEx))); |
|---|
| 634 | if( pGetModuleHandleEx ) |
|---|
| 635 | { |
|---|
| 636 | HMODULE thisModule = 0; |
|---|
| 637 | static filenamechar static_variable = 0; |
|---|
| 638 | |
|---|
| 639 | if( pGetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, &static_variable, &thisModule) ) |
|---|
| 640 | { |
|---|
| 641 | retval = OSGDB_WINDOWS_FUNCT(GetModuleFileName)(thisModule, path, size); |
|---|
| 642 | if (retval != 0 && retval < size) |
|---|
| 643 | { |
|---|
| 644 | filenamestring pathstr(path); |
|---|
| 645 | filenamestring dllDir(pathstr, 0, |
|---|
| 646 | pathstr.find_last_of(OSGDB_FILENAME_TEXT("\\/"))); |
|---|
| 647 | convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(dllDir), filepath); |
|---|
| 648 | } |
|---|
| 649 | else |
|---|
| 650 | { |
|---|
| 651 | osg::notify(osg::WARN) << "Could not get dll directory " |
|---|
| 652 | "using Win32 API. It will not be searched." << std::endl; |
|---|
| 653 | } |
|---|
| 654 | } |
|---|
| 655 | else |
|---|
| 656 | { |
|---|
| 657 | osg::notify(osg::WARN) << "Could not get dll module handle " |
|---|
| 658 | "using Win32 API. Dll directory will not be searched." << std::endl; |
|---|
| 659 | } |
|---|
| 660 | } |
|---|
| 661 | #endif |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | |
|---|
| 665 | filenamechar systemDir[(UINT)size]; |
|---|
| 666 | retval = OSGDB_WINDOWS_FUNCT(GetSystemDirectory)(systemDir, (UINT)size); |
|---|
| 667 | |
|---|
| 668 | if (retval != 0 && retval < size) |
|---|
| 669 | { |
|---|
| 670 | convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(systemDir), |
|---|
| 671 | filepath); |
|---|
| 672 | } |
|---|
| 673 | else |
|---|
| 674 | { |
|---|
| 675 | osg::notify(osg::WARN) << "Could not get system directory using " |
|---|
| 676 | "Win32 API, using default directory." << std::endl; |
|---|
| 677 | convertStringPathIntoFilePathList("C:\\Windows\\System32", |
|---|
| 678 | filepath); |
|---|
| 679 | } |
|---|
| 680 | |
|---|
| 681 | |
|---|
| 682 | |
|---|
| 683 | |
|---|
| 684 | |
|---|
| 685 | filenamechar windowsDir[(UINT)size]; |
|---|
| 686 | retval = OSGDB_WINDOWS_FUNCT(GetWindowsDirectory)(windowsDir, (UINT)size); |
|---|
| 687 | if (retval != 0 && retval < size) |
|---|
| 688 | { |
|---|
| 689 | convertStringPathIntoFilePathList(std::string(OSGDB_FILENAME_TO_STRING(windowsDir)) + |
|---|
| 690 | "\\System", filepath); |
|---|
| 691 | convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(windowsDir), |
|---|
| 692 | filepath); |
|---|
| 693 | } |
|---|
| 694 | else |
|---|
| 695 | { |
|---|
| 696 | osg::notify(osg::WARN) << "Could not get Windows directory using " |
|---|
| 697 | "Win32 API, using default directory." << std::endl; |
|---|
| 698 | convertStringPathIntoFilePathList("C:\\Windows", filepath); |
|---|
| 699 | convertStringPathIntoFilePathList("C:\\Windows\\System", filepath); |
|---|
| 700 | } |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | |
|---|
| 704 | convertStringPathIntoFilePathList(".", filepath); |
|---|
| 705 | |
|---|
| 706 | |
|---|
| 707 | |
|---|
| 708 | |
|---|
| 709 | filenamechar* ptr; |
|---|
| 710 | #ifdef OSG_USE_UTF8_FILENAME |
|---|
| 711 | if ((ptr = _wgetenv(OSGDB_FILENAME_TEXT("PATH")))) |
|---|
| 712 | #else |
|---|
| 713 | if ((ptr = getenv("PATH"))) |
|---|
| 714 | #endif |
|---|
| 715 | { |
|---|
| 716 | |
|---|
| 717 | |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(ptr), filepath); |
|---|
| 721 | } |
|---|
| 722 | |
|---|
| 723 | appendInstallationLibraryFilePaths(filepath); |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | #elif defined(__APPLE__) |
|---|
| 727 | |
|---|
| 728 | |
|---|
| 729 | #define COMPILE_CARBON_VERSION |
|---|
| 730 | |
|---|
| 731 | #ifdef COMPILE_COCOA_VERSION |
|---|
| 732 | #include <Foundation/Foundation.h> |
|---|
| 733 | #endif |
|---|
| 734 | #ifdef COMPILE_CARBON_VERSION |
|---|
| 735 | #include <CoreServices/CoreServices.h> |
|---|
| 736 | #include <CoreFoundation/CoreFoundation.h> |
|---|
| 737 | #include <Carbon/Carbon.h> |
|---|
| 738 | #endif |
|---|
| 739 | #include <iostream> |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | |
|---|
| 743 | std::string GetShortenedPath(std::string path, int numToShorten) |
|---|
| 744 | { |
|---|
| 745 | unsigned int i = path.length() - 1; |
|---|
| 746 | if(path[i] == '/') i--; |
|---|
| 747 | while(i > 1 && numToShorten) |
|---|
| 748 | { |
|---|
| 749 | if(path[i] == '/') |
|---|
| 750 | numToShorten--; |
|---|
| 751 | i--; |
|---|
| 752 | } |
|---|
| 753 | return path.substr(0,i + 1); |
|---|
| 754 | } |
|---|
| 755 | |
|---|
| 756 | |
|---|
| 757 | std::string GetPathFromCFURLRef(CFURLRef urlRef) |
|---|
| 758 | { |
|---|
| 759 | char buffer[1024]; |
|---|
| 760 | std::string path; |
|---|
| 761 | if(CFURLGetFileSystemRepresentation(urlRef, true, (UInt8*)buffer, 1024)) |
|---|
| 762 | path = std::string(buffer); |
|---|
| 763 | return path; |
|---|
| 764 | } |
|---|
| 765 | |
|---|
| 766 | |
|---|
| 767 | std::string GetApplicationBundlePath(CFBundleRef mainBundle) |
|---|
| 768 | { |
|---|
| 769 | std::string path; |
|---|
| 770 | CFURLRef urlRef = CFBundleCopyBundleURL(mainBundle); |
|---|
| 771 | if(urlRef) |
|---|
| 772 | { |
|---|
| 773 | path = GetPathFromCFURLRef(urlRef); |
|---|
| 774 | CFRelease(urlRef); |
|---|
| 775 | } |
|---|
| 776 | return path; |
|---|
| 777 | |
|---|
| 778 | } |
|---|
| 779 | |
|---|
| 780 | std::string GetApplicationParentPath(CFBundleRef mainBundle) |
|---|
| 781 | { |
|---|
| 782 | return GetShortenedPath(GetApplicationBundlePath(mainBundle), 1); |
|---|
| 783 | } |
|---|
| 784 | |
|---|
| 785 | std::string GetApplicationPluginsPath(CFBundleRef mainBundle) |
|---|
| 786 | { |
|---|
| 787 | std::string path; |
|---|
| 788 | CFURLRef urlRef = CFBundleCopyBuiltInPlugInsURL(mainBundle); |
|---|
| 789 | if(urlRef) |
|---|
| 790 | { |
|---|
| 791 | path = GetPathFromCFURLRef(urlRef); |
|---|
| 792 | CFRelease(urlRef); |
|---|
| 793 | } |
|---|
| 794 | return path; |
|---|
| 795 | |
|---|
| 796 | } |
|---|
| 797 | |
|---|
| 798 | std::string GetApplicationResourcesPath(CFBundleRef mainBundle) |
|---|
| 799 | { |
|---|
| 800 | std::string path; |
|---|
| 801 | CFURLRef urlRef = CFBundleCopyResourcesDirectoryURL(mainBundle); |
|---|
| 802 | if(urlRef) |
|---|
| 803 | { |
|---|
| 804 | path = GetPathFromCFURLRef(urlRef); |
|---|
| 805 | CFRelease(urlRef); |
|---|
| 806 | } |
|---|
| 807 | return path; |
|---|
| 808 | } |
|---|
| 809 | |
|---|
| 810 | |
|---|
| 811 | |
|---|
| 812 | |
|---|
| 813 | |
|---|
| 814 | |
|---|
| 815 | |
|---|
| 816 | |
|---|
| 817 | |
|---|
| 818 | |
|---|
| 819 | |
|---|
| 820 | |
|---|
| 821 | |
|---|
| 822 | |
|---|
| 823 | |
|---|
| 824 | |
|---|
| 825 | |
|---|
| 826 | #ifdef COMPILE_COCOA_VERSION |
|---|
| 827 | |
|---|
| 828 | |
|---|
| 829 | |
|---|
| 830 | |
|---|
| 831 | |
|---|
| 832 | |
|---|
| 833 | |
|---|
| 834 | |
|---|
| 835 | |
|---|
| 836 | |
|---|
| 837 | |
|---|
| 838 | |
|---|
| 839 | |
|---|
| 840 | |
|---|
| 841 | |
|---|
| 842 | |
|---|
| 843 | |
|---|
| 844 | |
|---|
| 845 | |
|---|
| 846 | |
|---|
| 847 | |
|---|
| 848 | |
|---|
| 849 | |
|---|
| 850 | |
|---|
| 851 | |
|---|
| 852 | |
|---|
| 853 | |
|---|
| 854 | void osgDB::appendPlatformSpecificLibraryFilePaths(FilePathList& filepath) |
|---|
| 855 | { |
|---|
| 856 | char* ptr; |
|---|
| 857 | if ((ptr = getenv( "DYLD_LIBRARY_PATH" )) ) |
|---|
| 858 | { |
|---|
| 859 | convertStringPathIntoFilePathList(ptr, filepath); |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | appendInstallationLibraryFilePaths(filepath); |
|---|
| 863 | |
|---|
| 864 | |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | |
|---|
| 868 | |
|---|
| 869 | |
|---|
| 870 | NSAutoreleasePool* mypool = [[NSAutoreleasePool alloc] init]; |
|---|
| 871 | |
|---|
| 872 | NSString* myBundlePlugInPath; |
|---|
| 873 | NSString* userSupportDir; |
|---|
| 874 | |
|---|
| 875 | |
|---|
| 876 | |
|---|
| 877 | |
|---|
| 878 | myBundlePlugInPath = [[NSBundle mainBundle] builtInPlugInsPath]; |
|---|
| 879 | |
|---|
| 880 | |
|---|
| 881 | |
|---|
| 882 | |
|---|
| 883 | |
|---|
| 884 | userSupportDir = [@"~/Library/Application Support/OpenSceneGraph/PlugIns" stringByExpandingTildeInPath]; |
|---|
| 885 | |
|---|
| 886 | |
|---|
| 887 | |
|---|
| 888 | |
|---|
| 889 | |
|---|
| 890 | |
|---|
| 891 | filepath.push_back( [myBundlePlugInPath UTF8String] ); |
|---|
| 892 | filepath.push_back( [userSupportDir UTF8String] ); |
|---|
| 893 | |
|---|
| 894 | filepath.push_back( "/Library/Application Support/OpenSceneGraph/PlugIns" ); |
|---|
| 895 | filepath.push_back( "/Network/Library/Application Support/OpenSceneGraph/PlugIns" ); |
|---|
| 896 | |
|---|
| 897 | |
|---|
| 898 | [mypool release]; |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | #elif defined(COMPILE_CARBON_VERSION) |
|---|
| 902 | |
|---|
| 903 | |
|---|
| 904 | |
|---|
| 905 | |
|---|
| 906 | |
|---|
| 907 | |
|---|
| 908 | |
|---|
| 909 | |
|---|
| 910 | |
|---|
| 911 | |
|---|
| 912 | |
|---|
| 913 | |
|---|
| 914 | |
|---|
| 915 | |
|---|
| 916 | |
|---|
| 917 | |
|---|
| 918 | |
|---|
| 919 | |
|---|
| 920 | |
|---|
| 921 | |
|---|
| 922 | |
|---|
| 923 | |
|---|
| 924 | |
|---|
| 925 | |
|---|
| 926 | void osgDB::appendPlatformSpecificLibraryFilePaths(FilePathList& filepath) |
|---|
| 927 | { |
|---|
| 928 | char* ptr; |
|---|
| 929 | if ((ptr = getenv( "DYLD_LIBRARY_PATH" )) ) |
|---|
| 930 | { |
|---|
| 931 | convertStringPathIntoFilePathList(ptr, filepath); |
|---|
| 932 | } |
|---|
| 933 | |
|---|
| 934 | appendInstallationLibraryFilePaths(filepath); |
|---|
| 935 | |
|---|
| 936 | const std::string OSG_PLUGIN_PATH("/OpenSceneGraph/PlugIns"); |
|---|
| 937 | CFURLRef url; |
|---|
| 938 | CFBundleRef myBundle; |
|---|
| 939 | FSRef f; |
|---|
| 940 | OSErr errCode; |
|---|
| 941 | |
|---|
| 942 | |
|---|
| 943 | |
|---|
| 944 | |
|---|
| 945 | |
|---|
| 946 | myBundle = CFBundleGetMainBundle(); |
|---|
| 947 | |
|---|
| 948 | if(myBundle != NULL) |
|---|
| 949 | { |
|---|
| 950 | |
|---|
| 951 | |
|---|
| 952 | |
|---|
| 953 | |
|---|
| 954 | std::string bundlePath = GetApplicationBundlePath(myBundle); |
|---|
| 955 | if( bundlePath.substr(bundlePath.length() - 4, 4) == std::string(".app") ) |
|---|
| 956 | filepath.push_back(GetApplicationPluginsPath(myBundle)); |
|---|
| 957 | } |
|---|
| 958 | else |
|---|
| 959 | { |
|---|
| 960 | osg::notify( osg::DEBUG_INFO ) << "Couldn't find the Application Bundle" << std::endl; |
|---|
| 961 | } |
|---|
| 962 | |
|---|
| 963 | |
|---|
| 964 | errCode = FSFindFolder( kUserDomain, kApplicationSupportFolderType, kDontCreateFolder, &f ); |
|---|
| 965 | if(noErr == errCode) |
|---|
| 966 | { |
|---|
| 967 | |
|---|
| 968 | url = CFURLCreateFromFSRef( 0, &f ); |
|---|
| 969 | if(url) |
|---|
| 970 | { |
|---|
| 971 | filepath.push_back(GetPathFromCFURLRef(url) + OSG_PLUGIN_PATH); |
|---|
| 972 | CFRelease( url ); |
|---|
| 973 | } |
|---|
| 974 | else |
|---|
| 975 | osg::notify( osg::DEBUG_INFO ) << "Couldn't create CFURLRef for User's application support Path" << std::endl; |
|---|
| 976 | |
|---|
| 977 | url = NULL; |
|---|
| 978 | } |
|---|
| 979 | else |
|---|
| 980 | { |
|---|
| 981 | osg::notify( osg::DEBUG_INFO ) << "Couldn't find the User's Application Support Path" << std::endl; |
|---|
| 982 | } |
|---|
| 983 | |
|---|
| 984 | |
|---|
| 985 | errCode = FSFindFolder( kLocalDomain, kApplicationSupportFolderType, kDontCreateFolder, &f ); |
|---|
| 986 | if(noErr == errCode) |
|---|
| 987 | { |
|---|
| 988 | |
|---|
| 989 | url = CFURLCreateFromFSRef( 0, &f ); |
|---|
| 990 | |
|---|
| 991 | if(url) |
|---|
| 992 | { |
|---|
| 993 | filepath.push_back(GetPathFromCFURLRef(url) + OSG_PLUGIN_PATH); |
|---|
| 994 | CFRelease( url ); |
|---|
| 995 | } |
|---|
| 996 | else |
|---|
| 997 | osg::notify( osg::DEBUG_INFO ) << "Couldn't create CFURLRef for local System's ApplicationSupport Path" << std::endl; |
|---|
| 998 | |
|---|
| 999 | url = NULL; |
|---|
| 1000 | } |
|---|
| 1001 | else |
|---|
| 1002 | { |
|---|
| 1003 | osg::notify( osg::DEBUG_INFO ) << "Couldn't find the Local System's Application Support Path" << std::endl; |
|---|
| 1004 | } |
|---|
| 1005 | |
|---|
| 1006 | |
|---|
| 1007 | |
|---|
| 1008 | |
|---|
| 1009 | errCode = FSFindFolder( kNetworkDomain, kApplicationSupportFolderType, kDontCreateFolder, &f ); |
|---|
| 1010 | if(noErr == errCode) |
|---|
| 1011 | { |
|---|
| 1012 | |
|---|
| 1013 | url = CFURLCreateFromFSRef( 0, &f ); |
|---|
| 1014 | |
|---|
| 1015 | if(url) |
|---|
| 1016 | { |
|---|
| 1017 | filepath.push_back(GetPathFromCFURLRef(url) + OSG_PLUGIN_PATH); |
|---|
| 1018 | CFRelease( url ); |
|---|
| 1019 | } |
|---|
| 1020 | else |
|---|
| 1021 | osg::notify( osg::DEBUG_INFO ) << "Couldn't create CFURLRef for network Application Support Path" << std::endl; |
|---|
| 1022 | |
|---|
| 1023 | url = NULL; |
|---|
| 1024 | } |
|---|
| 1025 | else |
|---|
| 1026 | { |
|---|
| 1027 | |
|---|
| 1028 | |
|---|
| 1029 | } |
|---|
| 1030 | } |
|---|
| 1031 | #else |
|---|
| 1032 | void osgDB::appendPlatformSpecificLibraryFilePaths(FilePathList& filepath) |
|---|
| 1033 | { |
|---|
| 1034 | char* ptr; |
|---|
| 1035 | if ((ptr = getenv( "DYLD_LIBRARY_PATH" )) ) |
|---|
| 1036 | { |
|---|
| 1037 | convertStringPathIntoFilePathList(ptr, filepath); |
|---|
| 1038 | } |
|---|
| 1039 | |
|---|
| 1040 | appendInstallationLibraryFilePaths(filepath); |
|---|
| 1041 | } |
|---|
| 1042 | #endif |
|---|
| 1043 | |
|---|
| 1044 | #else |
|---|
| 1045 | |
|---|
| 1046 | void osgDB::appendPlatformSpecificLibraryFilePaths(FilePathList& filepath) |
|---|
| 1047 | { |
|---|
| 1048 | |
|---|
| 1049 | char* ptr; |
|---|
| 1050 | if( (ptr = getenv( "LD_LIBRARY_PATH" )) ) |
|---|
| 1051 | { |
|---|
| 1052 | convertStringPathIntoFilePathList(ptr,filepath); |
|---|
| 1053 | } |
|---|
| 1054 | |
|---|
| 1055 | appendInstallationLibraryFilePaths(filepath); |
|---|
| 1056 | |
|---|
| 1057 | #if defined(__ia64__) || defined(__x86_64__) |
|---|
| 1058 | convertStringPathIntoFilePathList("/usr/lib/:/usr/lib64/:/usr/local/lib/:/usr/local/lib64/",filepath); |
|---|
| 1059 | #else |
|---|
| 1060 | convertStringPathIntoFilePathList("/usr/lib/:/usr/local/lib/",filepath); |
|---|
| 1061 | #endif |
|---|
| 1062 | |
|---|
| 1063 | } |
|---|
| 1064 | |
|---|
| 1065 | #endif |
|---|
| 1066 | |
|---|
| 1067 | |
|---|
| 1068 | |
|---|
| 1069 | |
|---|
| 1070 | #ifdef __APPLE__ |
|---|
| 1071 | void osgDB::appendPlatformSpecificResourceFilePaths(FilePathList& filepath) |
|---|
| 1072 | { |
|---|
| 1073 | |
|---|
| 1074 | CFBundleRef mainBundle = CFBundleGetMainBundle(); |
|---|
| 1075 | |
|---|
| 1076 | if (mainBundle != NULL) { |
|---|
| 1077 | |
|---|
| 1078 | std::string bundlePath = GetApplicationBundlePath(mainBundle); |
|---|
| 1079 | std::string resourcesPath = GetApplicationResourcesPath(mainBundle); |
|---|
| 1080 | |
|---|
| 1081 | |
|---|
| 1082 | if(bundlePath.substr(bundlePath.length() - 4, 4) == std::string(".app")) |
|---|
| 1083 | { |
|---|
| 1084 | if(resourcesPath != std::string("")) |
|---|
| 1085 | filepath.push_back( resourcesPath ); |
|---|
| 1086 | |
|---|
| 1087 | std::string parentPath = GetShortenedPath(bundlePath, 1); |
|---|
| 1088 | if(parentPath != std::string("")) |
|---|
| 1089 | filepath.push_back( parentPath ); |
|---|
| 1090 | } |
|---|
| 1091 | } |
|---|
| 1092 | else |
|---|
| 1093 | { |
|---|
| 1094 | osg::notify( osg::DEBUG_INFO ) << "Couldn't find the Application Bundle." << std::endl; |
|---|
| 1095 | } |
|---|
| 1096 | } |
|---|
| 1097 | #else |
|---|
| 1098 | void osgDB::appendPlatformSpecificResourceFilePaths(FilePathList& ) |
|---|
| 1099 | { |
|---|
| 1100 | } |
|---|
| 1101 | #endif |
|---|
| 1102 | |
|---|
| 1103 | |
|---|
| 1104 | |
|---|
| 1105 | |
|---|
| 1106 | |
|---|