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.
This commit is contained in:
parent
89cf88f2a9
commit
5f4c155d6b
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user