From 5f4c155d6b8e95617a91ed7a20dc6329054a228c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 9 Feb 2012 14:28:39 +0000 Subject: [PATCH] Added back in support for checking the current working directory by default, but now do the check after the Options and Registry DataFilePathLists have been checked, which will allow users to better control over where files are searched for. --- include/osgDB/FileUtils | 3 +++ src/osgDB/FileUtils.cpp | 17 +++++++++++++---- src/osgDB/Registry.cpp | 35 +++++++++++++++++++++++++++++------ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/include/osgDB/FileUtils b/include/osgDB/FileUtils index df90edbbd..0276cb2f0 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 f5693e673..3f119a3f5 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 66eb19032..ee1692152 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; }