diff --git a/include/osgDB/FileUtils b/include/osgDB/FileUtils index df90edbbd8d..0276cb2f0a6 100644 --- a/include/osgDB/FileUtils +++ b/include/osgDB/FileUtils @@ -129,6 +129,9 @@ extern OSGDB_EXPORT std::string findLibraryFile(const std::string& filename,Case /** convert a string containing a list of paths delimited either with ';' (Windows) or ':' (All other platforms) into FilePath representation.*/ extern OSGDB_EXPORT void convertStringPathIntoFilePathList(const std::string& paths,FilePathList& filepath); +/** Return true if FilePathList contains a filepath that is significies checking of the current working directory.*/ +extern OSGDB_EXPORT bool containsCurrentWorkingDirectoryReference(const FilePathList& paths); + extern OSGDB_EXPORT void appendPlatformSpecificLibraryFilePaths(FilePathList& filepath); extern OSGDB_EXPORT void appendPlatformSpecificResourceFilePaths(FilePathList& filepath); diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index f5693e67300..3f119a3f541 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -652,6 +652,19 @@ osgDB::FileOpResult::Value osgDB::copyFile(const std::string & source, const std } +bool osgDB::containsCurrentWorkingDirectoryReference(const FilePathList& paths) +{ + const std::string cwd("."); + for(FilePathList::const_iterator itr = paths.begin(); + itr != paths.end(); + ++itr) + { + if (itr->empty()) return true; + if (*itr==cwd) return true; + } + return false; +} + ///////////////////////////////////////////////////////////////////////////////////////////////// // // Implementation of appendPlatformSpecificLibraryFilePaths(..) @@ -1226,7 +1239,3 @@ osgDB::FileOpResult::Value osgDB::copyFile(const std::string & source, const std #endif - - - - diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 66eb1903273..ee169215224 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -985,27 +985,50 @@ std::string Registry::findDataFileImplementation(const std::string& filename, co // if data file contains a server address then we can't find it in local directories so return empty string. if (containsServerAddress(filename)) return std::string(); - if (osgDB::isAbsolutePath(filename) && fileExists(filename)) + bool absolutePath = osgDB::isAbsolutePath(filename); + + if (absolutePath && fileExists(filename)) { OSG_DEBUG << "FindFileInPath(" << filename << "): returning " << filename << std::endl; return filename; } std::string fileFound; + bool pathsContainsCurrentWorkingDirectory = false; if (options && !options->getDatabasePathList().empty()) { fileFound = findFileInPath(filename, options->getDatabasePathList(), caseSensitivity); if (!fileFound.empty()) return fileFound; + + if (osgDB::containsCurrentWorkingDirectoryReference(options->getDatabasePathList())) + { + pathsContainsCurrentWorkingDirectory = true; + } + } - const FilePathList& filepath = Registry::instance()->getDataFilePathList(); - if (!filepath.empty()) + const FilePathList& filepaths = Registry::instance()->getDataFilePathList(); + if (!filepaths.empty()) { - fileFound = findFileInPath(filename, filepath,caseSensitivity); + fileFound = findFileInPath(filename, filepaths, caseSensitivity); if (!fileFound.empty()) return fileFound; + + if (!pathsContainsCurrentWorkingDirectory && osgDB::containsCurrentWorkingDirectoryReference(filepaths)) + { + pathsContainsCurrentWorkingDirectory = true; + } } + if (!absolutePath && !pathsContainsCurrentWorkingDirectory) + { + // check current working directory + if (fileExists(filename)) + { + return filename; + } + } + // if a directory is included in the filename, get just the (simple) filename itself and try that std::string simpleFileName = getSimpleFileName(filename); @@ -1024,9 +1047,9 @@ std::string Registry::findDataFileImplementation(const std::string& filename, co if (!fileFound.empty()) return fileFound; } - if (!filepath.empty()) + if (!filepaths.empty()) { - fileFound = findFileInPath(simpleFileName, filepath,caseSensitivity); + fileFound = findFileInPath(simpleFileName, filepaths,caseSensitivity); if (!fileFound.empty()) return fileFound; }