From 78a0fd5a16917787ac3fe29585772d1c3dc774c4 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 25 Nov 2003 09:04:41 +0000 Subject: [PATCH] Added support for case insenstive searches of the filepaths. --- include/osgDB/FileUtils | 22 ++++++++++++++++++---- src/osgDB/FileUtils.cpp | 29 +++++++++++++++++++---------- src/osgDB/ReadFile.cpp | 21 ++++++++++++++++++++- 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/include/osgDB/FileUtils b/include/osgDB/FileUtils index c48486136..76ffa38ce 100644 --- a/include/osgDB/FileUtils +++ b/include/osgDB/FileUtils @@ -23,20 +23,26 @@ namespace osgDB { +enum CaseSensitivity +{ + CASE_SENSITIVE, + CASE_INSENSITIVE, +}; + /** return true if a file exisits. */ extern OSGDB_EXPORT bool fileExists(const std::string& filename); /** find specified file in specified file path.*/ -extern OSGDB_EXPORT std::string findFileInPath(const std::string& filename, const FilePathList& filePath); +extern OSGDB_EXPORT std::string findFileInPath(const std::string& filename, const FilePathList& filePath,CaseSensitivity caseSensitivity=CASE_SENSITIVE); /** return the directory/filename of a file if its is contained within specified directory. * return "" if directory does not contain file. If caseInsensitive is set to true then * a case insensitive comparison is used to compare fileName to directory contents. * This is useful when unix programs attempt read case insentive windows filenames. */ -extern OSGDB_EXPORT std::string findFileInDirectory(const std::string& fileName,const std::string& dirName,bool caseInsensitive=false); +extern OSGDB_EXPORT std::string findFileInDirectory(const std::string& fileName,const std::string& dirName,CaseSensitivity caseSensitivity=CASE_SENSITIVE); /** simple list of names to represent a directory's contents. */ typedef std::vector DirectoryContents; @@ -53,7 +59,7 @@ inline void setDataFilePathList(const std::string& paths) { osgDB::Registry::ins inline FilePathList& getDataFilePathList() { return osgDB::Registry::instance()->getDataFilePathList(); } -extern OSGDB_EXPORT std::string findDataFile(const std::string& filename); +extern OSGDB_EXPORT std::string findDataFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE); /** Convinience class for pushing a path on construction, and popping the path * and destruction. This helps keep the addition of a path local to a block @@ -79,8 +85,16 @@ inline void setLibraryFilePathList(const std::string& paths) { osgDB::Registry:: inline FilePathList& getLibraryFilePathList() { return osgDB::Registry::instance()->getLibraryFilePathList(); } -extern OSGDB_EXPORT std::string findLibraryFile(const std::string& filename); +extern OSGDB_EXPORT std::string findLibraryFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE); +// +// +// /** Deprecated. */ +// inline std::string findFileInDirectory(const std::string& fileName,const std::string& dirName,bool caseInsensitive) +// { +// return findFileInDirectory(fileName,dirName,caseInsensitive?CASE_SENSITIVE:CASE_INSENSITIVE); +// } +// } diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index 3a80bfc9f..27a25b99a 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -43,7 +43,7 @@ bool osgDB::fileExists(const std::string& filename) return access( filename.c_str(), F_OK ) == 0; } -std::string osgDB::findFileInPath(const std::string& filename, const FilePathList& filepath) +std::string osgDB::findFileInPath(const std::string& filename, const FilePathList& filepath,CaseSensitivity caseSensitivity) { if (filename.empty()) return filename; @@ -65,25 +65,34 @@ std::string osgDB::findFileInPath(const std::string& filename, const FilePathLis osg::notify(osg::DEBUG_INFO) << "FindFileInPath() : USING " << path << "\n"; return path; } +#ifndef WIN32 +// windows already case insensitive so no need to retry.. + else if (caseSensitivity==CASE_INSENSITIVE) + { + std::string foundfile = findFileInDirectory(filename,*itr,CASE_INSENSITIVE); + if (!foundfile.empty()) return foundfile; + } +#endif + } return std::string(); } -std::string osgDB::findDataFile(const std::string& filename) +std::string osgDB::findDataFile(const std::string& filename,CaseSensitivity caseSensitivity) { if (filename.empty()) return filename; const FilePathList& filepath = Registry::instance()->getDataFilePathList(); - std::string fileFound = findFileInPath(filename, filepath); + std::string fileFound = findFileInPath(filename, filepath,caseSensitivity); if (!fileFound.empty()) return fileFound; // if a directory is included in the filename, get just the (simple) filename itself and try that std::string simpleFileName = getSimpleFileName(filename); if (simpleFileName!=filename) { - std::string fileFound = findFileInPath(simpleFileName, filepath); + std::string fileFound = findFileInPath(simpleFileName, filepath,caseSensitivity); if (!fileFound.empty()) return fileFound; } @@ -91,14 +100,14 @@ std::string osgDB::findDataFile(const std::string& filename) return std::string(); } -std::string osgDB::findLibraryFile(const std::string& filename) +std::string osgDB::findLibraryFile(const std::string& filename,CaseSensitivity caseSensitivity) { if (filename.empty()) return filename; const FilePathList& filepath = Registry::instance()->getLibraryFilePathList(); - std::string fileFound = findFileInPath(filename, filepath); + std::string fileFound = findFileInPath(filename, filepath,caseSensitivity); if (!fileFound.empty()) return fileFound; @@ -106,16 +115,16 @@ std::string osgDB::findLibraryFile(const std::string& filename) std::string simpleFileName = getSimpleFileName(filename); if (simpleFileName!=filename) { - std::string fileFound = findFileInPath(simpleFileName, filepath); + std::string fileFound = findFileInPath(simpleFileName, filepath,caseSensitivity); if (!fileFound.empty()) return fileFound; } // failed with direct paths, // now try prepending the filename with "osgPlugins/" - return findFileInPath("osgPlugins/"+simpleFileName,filepath); + return findFileInPath("osgPlugins/"+simpleFileName,filepath,caseSensitivity); } -std::string osgDB::findFileInDirectory(const std::string& fileName,const std::string& dirName,bool caseInsensitive) +std::string osgDB::findFileInDirectory(const std::string& fileName,const std::string& dirName,CaseSensitivity caseSensitivity) { bool needFollowingBackslash = false; bool needDirectoryName = true; @@ -147,7 +156,7 @@ std::string osgDB::findFileInDirectory(const std::string& fileName,const std::st itr!=dc.end(); ++itr) { - if ((caseInsensitive && osgDB::equalCaseInsensitive(fileName,*itr)) || + if ((caseSensitivity==CASE_INSENSITIVE && osgDB::equalCaseInsensitive(fileName,*itr)) || (fileName==*itr)) { if (!needDirectoryName) return *itr; diff --git a/src/osgDB/ReadFile.cpp b/src/osgDB/ReadFile.cpp index 3c01e3fe4..4c2d9a5c9 100644 --- a/src/osgDB/ReadFile.cpp +++ b/src/osgDB/ReadFile.cpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include @@ -112,8 +114,25 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,bool useObjectCache) typedef std::vector NodeList; NodeList nodeList; - // note currently doesn't delete the loaded file entries from the command line yet... + std::string filename; + while (arguments.read("--image",filename)) + { + osg::Image* image = readImageFile(filename.c_str(), useObjectCache); + if (image) nodeList.push_back(osg::createGeodeForImage(image)); + } + while (arguments.read("--dem",filename)) + { + osg::HeightField* hf = readHeightFieldFile(filename.c_str(), useObjectCache); + if (hf) + { + osg::Geode* geode = new osg::Geode; + geode->addDrawable(new osg::ShapeDrawable(hf)); + nodeList.push_back(geode); + } + } + + // note currently doesn't delete the loaded file entries from the command line yet... for(int pos=1;pos