Changeset 13041 for OpenSceneGraph/trunk/src/osgDB/FileUtils.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgDB/FileUtils.cpp (modified) (42 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgDB/FileUtils.cpp
r12969 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 33 33 #include <sys/stat.h> 34 34 #include <direct.h> // for _mkdir 35 35 36 36 #define mkdir(x,y) _mkdir((x)) 37 37 #define stat64 _stati64 … … 52 52 //IOS includes 53 53 #include "TargetConditionals.h" 54 55 #if (TARGET_OS_IPHONE) 54 55 #if (TARGET_OS_IPHONE) 56 56 #include <Availability.h> 57 57 // workaround a bug which appears when compiling for SDK < 4.0 and for the simulator 58 58 #ifdef __IPHONE_4_0 && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) 59 59 #define stat64 stat 60 #else 60 #else 61 61 #if !TARGET_IPHONE_SIMULATOR 62 62 #define stat64 stat … … 69 69 // By default, MAC_OS_X_VERSION_MAX_ALLOWED is set to the latest 70 70 // system the headers know about. So I will use this as the control 71 // variable. (MIN_ALLOWED is set low by default so it is 72 // unhelpful in this case.) 71 // variable. (MIN_ALLOWED is set low by default so it is 72 // unhelpful in this case.) 73 73 // Unfortunately, we can't use the label MAC_OS_X_VERSION_10_4 74 74 // for older OS's like Jaguar, Panther since they are not defined, … … 145 145 return false; 146 146 } 147 147 148 148 struct stat64 stbuf; 149 149 #ifdef OSG_USE_UTF8_FILENAME … … 169 169 if( dir.empty() ) 170 170 break; 171 171 172 172 #ifdef OSG_USE_UTF8_FILENAME 173 173 if( _wstat64( OSGDB_STRING_TO_FILENAME(dir).c_str(), &stbuf ) < 0 ) … … 182 182 paths.push( dir ); 183 183 break; 184 184 185 185 default: 186 186 OSG_DEBUG << "osgDB::makeDirectory(): " << strerror(errno) << std::endl; … … 194 194 { 195 195 std::string dir = paths.top(); 196 196 197 197 #if defined(WIN32) 198 198 //catch drive name … … 211 211 OSG_DEBUG << "osgDB::makeDirectory(): " << strerror(errno) << std::endl; 212 212 return false; 213 } 213 } 214 214 paths.pop(); 215 215 } … … 246 246 return false; 247 247 } 248 248 249 249 #ifdef OSG_USE_UTF8_FILENAME 250 250 return _wchdir( OSGDB_STRING_TO_FILENAME(newCurrentWorkingDirectory).c_str()) == 0; … … 280 280 filepath.push_back(lastPath); 281 281 } 282 282 283 283 } 284 284 … … 314 314 std::string osgDB::findFileInPath(const std::string& filename, const FilePathList& filepath,CaseSensitivity caseSensitivity) 315 315 { 316 if (filename.empty()) 316 if (filename.empty()) 317 317 return filename; 318 318 319 if (!isFileNameNativeStyle(filename)) 319 if (!isFileNameNativeStyle(filename)) 320 320 return findFileInPath(convertFileNameToNativeStyle(filename), filepath, caseSensitivity); 321 321 … … 327 327 OSG_DEBUG << "itr='" <<*itr<< "'\n"; 328 328 std::string path = itr->empty() ? filename : concatPaths(*itr, filename); 329 329 330 330 path = getRealPath(path); 331 331 332 332 OSG_DEBUG << "FindFileInPath() : trying " << path << " ...\n"; 333 if(fileExists(path)) 333 if(fileExists(path)) 334 334 { 335 335 OSG_DEBUG << "FindFileInPath() : USING " << path << "\n"; 336 336 return path; 337 337 } 338 #ifndef WIN32 338 #ifndef WIN32 339 339 // windows already case insensitive so no need to retry.. 340 else if (caseSensitivity==CASE_INSENSITIVE) 340 else if (caseSensitivity==CASE_INSENSITIVE) 341 341 { 342 342 std::string foundfile = findFileInDirectory(filename,*itr,CASE_INSENSITIVE); … … 344 344 } 345 345 #endif 346 346 347 347 } 348 348 … … 381 381 bool win32 = false; 382 382 #endif 383 383 384 384 // If the fileName contains extra path information, make that part of the 385 385 // directory name instead … … 459 459 realDirName = findFileInDirectory(lastElement, parentPath, 460 460 CASE_INSENSITIVE); 461 461 462 462 dc = osgDB::getDirectoryContents(realDirName); 463 463 char lastChar = realDirName[realDirName.size()-1]; … … 724 724 convertStringPathIntoFilePathList("/usr/bin/:/usr/local/bin/",filepath); 725 725 } 726 726 727 727 #elif defined(WIN32) 728 728 … … 731 731 // See http://msdn2.microsoft.com/en-us/library/ms682586.aspx 732 732 733 // Safe DLL search mode changes the DLL search order to search for 733 // Safe DLL search mode changes the DLL search order to search for 734 734 // DLLs in the current directory after the system directories, instead 735 // of right after the application's directory. According to the article 736 // linked above, on Windows XP and Windows 2000, Safe DLL search mode 737 // is disabled by default. However, it is a good idea to enable it. We 735 // of right after the application's directory. According to the article 736 // linked above, on Windows XP and Windows 2000, Safe DLL search mode 737 // is disabled by default. However, it is a good idea to enable it. We 738 738 // will search as if it was enabled. 739 739 … … 748 748 { 749 749 filenamestring pathstr(path); 750 filenamestring executableDir(pathstr, 0, 750 filenamestring executableDir(pathstr, 0, 751 751 pathstr.find_last_of(OSGDB_FILENAME_TEXT("\\/"))); 752 752 convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(executableDir), filepath); … … 797 797 #endif 798 798 799 // 3. The system directory. Use the GetSystemDirectory function to 799 // 3. The system directory. Use the GetSystemDirectory function to 800 800 // get the path of this directory. 801 801 filenamechar systemDir[(UINT)size]; … … 804 804 if (retval != 0 && retval < size) 805 805 { 806 convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(systemDir), 806 convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(systemDir), 807 807 filepath); 808 808 } … … 811 811 OSG_WARN << "Could not get system directory using " 812 812 "Win32 API, using default directory." << std::endl; 813 convertStringPathIntoFilePathList("C:\\Windows\\System32", 813 convertStringPathIntoFilePathList("C:\\Windows\\System32", 814 814 filepath); 815 815 } 816 816 817 // 4. The 16-bit system directory. There is no function that obtains 817 // 4. The 16-bit system directory. There is no function that obtains 818 818 // the path of this directory, but it is searched. 819 // 5. The Windows directory. Use the GetWindowsDirectory function to 819 // 5. The Windows directory. Use the GetWindowsDirectory function to 820 820 // get the path of this directory. 821 821 filenamechar windowsDir[(UINT)size]; … … 823 823 if (retval != 0 && retval < size) 824 824 { 825 convertStringPathIntoFilePathList(std::string(OSGDB_FILENAME_TO_STRING(windowsDir)) + 825 convertStringPathIntoFilePathList(std::string(OSGDB_FILENAME_TO_STRING(windowsDir)) + 826 826 "\\System", filepath); 827 convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(windowsDir), 827 convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(windowsDir), 828 828 filepath); 829 829 } … … 840 840 convertStringPathIntoFilePathList(".", filepath); 841 841 842 // 7. The directories that are listed in the PATH environment 843 // variable. Note that this does not include the per-application 842 // 7. The directories that are listed in the PATH environment 843 // variable. Note that this does not include the per-application 844 844 // path specified by the App Paths registry key. 845 845 filenamechar* ptr; … … 859 859 appendInstallationLibraryFilePaths(filepath); 860 860 } 861 861 862 862 #elif defined(__APPLE__) 863 863 #if (TARGET_OS_IPHONE) … … 876 876 #endif 877 877 #include <iostream> 878 878 879 879 // These functions are local to FileUtils.cpp and not exposed to the API 880 880 // returns the path string except for numToShorten directories stripped off the end … … 913 913 } 914 914 return path; 915 915 916 916 } 917 917 … … 931 931 } 932 932 return path; 933 933 934 934 } 935 935 … … 948 948 // The Cocoa version is about 10 lines of code. 949 949 // The Carbon version is noticably longer. 950 // Unfortunately, the Cocoa version requires -lobjc to be 951 // linked in when creating an executable. 950 // Unfortunately, the Cocoa version requires -lobjc to be 951 // linked in when creating an executable. 952 952 // Rumor is that this will be done autmatically in gcc 3.5/Tiger, 953 953 // but for now, this will cause a lot of headaches for people 954 // who aren't familiar with this concept, so the Carbon version 954 // who aren't familiar with this concept, so the Carbon version 955 955 // is preferable. 956 956 // But for the curious, both implementations are here. 957 // Note that if the Cocoa version is used, the file should be 957 // Note that if the Cocoa version is used, the file should be 958 958 // renamed to use the .mm extension to denote Objective-C++. 959 959 // And of course, you will need to link against Cocoa 960 // Update: There is a bug in the Cocoa version. Advanced users can remap 960 // Update: There is a bug in the Cocoa version. Advanced users can remap 961 961 // their systems so these paths go somewhere else. The Carbon calls 962 962 // will catch this, but the hardcoded Cocoa code below will not. … … 969 969 // /Library/Application Support/OpenSceneGraph/PlugIns 970 970 // /Network/Library/Application Support/OpenSceneGraph/PlugIns 971 // 972 // As a side effect of this function, if the application is not a 971 // 972 // As a side effect of this function, if the application is not a 973 973 // bundle, the first place searched becomes 974 974 // YourProgram/PlugIns … … 977 977 // ~/Library/Application Support/YourProgram/PlugIns 978 978 // /Library/Application Support/YourProgram/PlugIns 979 // /Network/Library/Application Support/TheProgram/PlugIns 980 // But I'm not going to worry about it for now because the 981 // bundle's PlugIns directory is supposed to be the preferred 979 // /Network/Library/Application Support/TheProgram/PlugIns 980 // But I'm not going to worry about it for now because the 981 // bundle's PlugIns directory is supposed to be the preferred 982 982 // place for this anyway. 983 983 // … … 985 985 // the directory the program resides in, 986 986 // but I'm worried about multiplatform distribution. 987 // Because .so is used by other platforms like Linux, we 987 // Because .so is used by other platforms like Linux, we 988 988 // could end up loading the wrong binary. 989 989 // I'm not sure how robust the current code is for this case. 990 // Assuming the program doesn't crash, will OSG move on to the 990 // Assuming the program doesn't crash, will OSG move on to the 991 991 // next search directory, or just give up? 992 992 void osgDB::appendPlatformSpecificLibraryFilePaths(FilePathList& filepath) … … 1002 1002 // Since this is currently the only Objective-C code in the 1003 1003 // library, we need an autoreleasepool for obj-c memory management. 1004 // If more Obj-C is added, we might move this pool to another 1004 // If more Obj-C is added, we might move this pool to another 1005 1005 // location so it can be shared. Pools seem to be stackable, 1006 1006 // so I don't think there will be a problem if multiple pools … … 1018 1018 // Now setup the other search paths 1019 1019 // Cocoa has a nice method for tilde expansion. 1020 // There's probably a better way of getting this directory, but I 1020 // There's probably a better way of getting this directory, but I 1021 1021 // can't find the call. 1022 1022 userSupportDir = [@"~/Library/Application Support/OpenSceneGraph/PlugIns" stringByExpandingTildeInPath]; … … 1049 1049 // ~/Library/Application Support/YourProgram/PlugIns 1050 1050 // /Library/Application Support/YourProgram/PlugIns 1051 // /Network/Library/Application Support/TheProgram/PlugIns 1052 // But I'm not going to worry about it for now because the 1053 // bundle's PlugIns directory is supposed to be the preferred 1051 // /Network/Library/Application Support/TheProgram/PlugIns 1052 // But I'm not going to worry about it for now because the 1053 // bundle's PlugIns directory is supposed to be the preferred 1054 1054 // place for this anyway. 1055 1055 // … … 1057 1057 // the directory the program resides in, 1058 1058 // but I'm worried about multiplatform distribution. 1059 // Because .so is used by other platforms like Linux, we 1059 // Because .so is used by other platforms like Linux, we 1060 1060 // could end up loading the wrong binary. 1061 1061 // I'm not sure how robust the current code is for this case. 1062 // Assuming the program doesn't crash, will OSG move on to the 1062 // Assuming the program doesn't crash, will OSG move on to the 1063 1063 // next search directory, or just give up? 1064 1064 void osgDB::appendPlatformSpecificLibraryFilePaths(FilePathList& filepath) … … 1083 1083 // we are not keeping a reference 1084 1084 myBundle = CFBundleGetMainBundle(); 1085 1085 1086 1086 if(myBundle != NULL) 1087 1087 { 1088 // CFBundleGetMainBundle will return a bundle ref even if 1088 // CFBundleGetMainBundle will return a bundle ref even if 1089 1089 // the application isn't part of a bundle, so we need to check 1090 1090 // if the path to the bundle ends in ".app" to see if it is a … … 1126 1126 // Get the URL 1127 1127 url = CFURLCreateFromFSRef( 0, &f ); 1128 1128 1129 1129 if(url) 1130 1130 { … … 1150 1150 // Get the URL 1151 1151 url = CFURLCreateFromFSRef( 0, &f ); 1152 1152 1153 1153 if(url) 1154 1154 { … … 1179 1179 } 1180 1180 #endif 1181 1182 #else 1181 1182 #else 1183 1183 1184 1184 void osgDB::appendPlatformSpecificLibraryFilePaths(FilePathList& filepath) … … 1211 1211 // Get the main application bundle 1212 1212 CFBundleRef mainBundle = CFBundleGetMainBundle(); 1213 1213 1214 1214 if (mainBundle != NULL) { 1215 1215 // Get the parent directory and the resources directory 1216 1216 std::string bundlePath = GetApplicationBundlePath(mainBundle); 1217 1217 std::string resourcesPath = GetApplicationResourcesPath(mainBundle); 1218 1218 1219 1219 // check if application is really part of a .app bundle 1220 1220 if(bundlePath.substr(bundlePath.length() - 4, 4) == std::string(".app")) … … 1222 1222 if(resourcesPath != std::string("")) 1223 1223 filepath.push_back( resourcesPath ); 1224 1224 1225 1225 std::string parentPath = GetShortenedPath(bundlePath, 1); 1226 1226 if(parentPath != std::string(""))
