From 3ebc5efe05f3e8c8baa1b16d10ac666447bc9f6d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 17 Jan 2007 15:59:29 +0000 Subject: [PATCH] From Joakim Simonsson, added osgDB::concateFile and osgDB::getRealPath. Tweaks by Robert Osfield - Moved methods to FileNameUtils, added unix implementation of getRealPath add extern and OSGDB_EXPORT to function declarations. --- include/osgDB/FileNameUtils | 7 +++++ src/osgDB/FileNameUtils.cpp | 52 +++++++++++++++++++++++++++---------- src/osgDB/FileUtils.cpp | 5 +++- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/include/osgDB/FileNameUtils b/include/osgDB/FileNameUtils index c842d0066..c963ad799 100644 --- a/include/osgDB/FileNameUtils +++ b/include/osgDB/FileNameUtils @@ -41,6 +41,13 @@ extern OSGDB_EXPORT bool containsServerAddress(const std::string& filename); extern OSGDB_EXPORT std::string getServerAddress(const std::string& filename); extern OSGDB_EXPORT std::string getServerFileName(const std::string& filename); +/** Concatenates two paths */ +extern OSGDB_EXPORT std::string concatPaths(const std::string& left, const std::string& right); + +/** Removes .. and . dirs in a path */ +extern OSGDB_EXPORT std::string getRealPath(const std::string& path); + + } #endif diff --git a/src/osgDB/FileNameUtils.cpp b/src/osgDB/FileNameUtils.cpp index 581f1c033..00dfec5ca 100644 --- a/src/osgDB/FileNameUtils.cpp +++ b/src/osgDB/FileNameUtils.cpp @@ -202,17 +202,43 @@ std::string osgDB::getServerFileName(const std::string& filename) return filename; } +std::string osgDB::concatPaths(const std::string& left, const std::string& right) +{ +#ifdef WIN32 + const char delimiterNative = '\\'; + const char delimiterForeign = '/'; +#else + const char delimiterNative = '/'; + const char delimiterForeign = '\\'; +#endif -// // here a little test I wrote to make sure a couple of the above methods are -// // working fine. -// void test() -// { -// std::string test("/here/we/are.exe"); -// std::string test2("\\there\\you\\go.dll"); -// std::cout << "getFilePath("<empty() ? filename : *itr + '/'+ filename; + std::string path = itr->empty() ? filename : concatPaths(*itr, filename); + + path = getRealPath(path); + osg::notify(osg::DEBUG_INFO) << "FindFileInPath() : trying " << path << " ...\n"; if(fileExists(path)) {