Skip to content

Commit

Permalink
Added back in support for checking the current working directory by d…
Browse files Browse the repository at this point in the history
…efault, 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.
  • Loading branch information
robertosfield committed Feb 9, 2012
1 parent 61afab4 commit 049e1ca
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
3 changes: 3 additions & 0 deletions include/osgDB/FileUtils
Expand Up @@ -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);

Expand Down
17 changes: 13 additions & 4 deletions src/osgDB/FileUtils.cpp
Expand Up @@ -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(..)
Expand Down Expand Up @@ -1226,7 +1239,3 @@ osgDB::FileOpResult::Value osgDB::copyFile(const std::string & source, const std
#endif






35 changes: 29 additions & 6 deletions src/osgDB/Registry.cpp
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 049e1ca

Please sign in to comment.