Added support for case insenstive searches of the filepaths.
This commit is contained in:
parent
8fd4bbe510
commit
78a0fd5a16
@ -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<std::string> 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);
|
||||
// }
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include <osg/Image>
|
||||
#include <osg/Node>
|
||||
#include <osg/Group>
|
||||
#include <osg/Geode>
|
||||
#include <osg/ShapeDrawable>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
@ -112,8 +114,25 @@ Node* osgDB::readNodeFiles(osg::ArgumentParser& arguments,bool useObjectCache)
|
||||
typedef std::vector<osg::Node*> 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<arguments.argc();++pos)
|
||||
{
|
||||
if (!arguments.isOption(pos))
|
||||
|
Loading…
Reference in New Issue
Block a user