From 201e73c3c12340605abf33ce5f6466ecbfdc149e Mon Sep 17 00:00:00 2001 From: Paul MARTZ Date: Tue, 16 Mar 2010 21:07:33 +0000 Subject: [PATCH] 2.8 branch: Fix issue with osgDB::concatPaths. This commit merges svn trunk revision 10818 to the 2.8 branch. --- include/osgDB/FileUtils | 8 ++++++- src/osgDB/FileNameUtils.cpp | 4 ++++ src/osgDB/FileUtils.cpp | 45 +++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/include/osgDB/FileUtils b/include/osgDB/FileUtils index 2150cf492..fcbd003bc 100644 --- a/include/osgDB/FileUtils +++ b/include/osgDB/FileUtils @@ -46,6 +46,12 @@ extern OSGDB_EXPORT bool makeDirectory( const std::string &directoryPath ); // Make a new directory for a given file. extern OSGDB_EXPORT bool makeDirectoryForFile( const std::string &filePath ); +// Get current working directory. +extern OSGDB_EXPORT std::string getCurrentWorkingDirectory( void ); + +// Set current working directory. +extern OSGDB_EXPORT bool setCurrentWorkingDirectory( const std::string &newCurrentWorkingDirectory ); + /** return true if a file exists. */ extern OSGDB_EXPORT bool fileExists(const std::string& filename); @@ -96,7 +102,7 @@ inline FilePathList& getLibraryFilePathList() { return osgDB::Registry::instance extern OSGDB_EXPORT std::string findLibraryFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE); -/** convert a string containing a list of paths delimited either with ';' (Windows) or ':' (All other platforms) into FilePath representation.*/ +/** 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); extern OSGDB_EXPORT void appendPlatformSpecificLibraryFilePaths(FilePathList& filepath); diff --git a/src/osgDB/FileNameUtils.cpp b/src/osgDB/FileNameUtils.cpp index 605fc94dc..dedb512b9 100644 --- a/src/osgDB/FileNameUtils.cpp +++ b/src/osgDB/FileNameUtils.cpp @@ -232,6 +232,10 @@ std::string osgDB::concatPaths(const std::string& left, const std::string& right const char delimiterForeign = '\\'; #endif + if(left.empty()) + { + return(right); + } char lastChar = left[left.size() - 1]; if(lastChar == delimiterNative) diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index a0c031565..3954da838 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -11,6 +11,15 @@ * OpenSceneGraph Public License for more details. */ +// handle TCHAR type on various platforms +// #ifndef is inspired by https://svn.apache.org/repos/asf/logging/log4cxx/tags/v0_9_4/include/log4cxx/helpers/tchar.h +// defining type as plain char is from unzip.h, line 64 + +#ifndef TCHAR +typedef char TCHAR; +#endif + + // currently this impl is for _all_ platforms, except as defined. // the mac version will change soon to reflect the path scheme under osx, but // for now, the above include is commented out, and the below code takes precedence. @@ -191,6 +200,42 @@ bool osgDB::makeDirectoryForFile( const std::string &path ) return makeDirectory( getFilePath( path )); } + +std::string osgDB::getCurrentWorkingDirectory( void ) +{ + // MAX_PATH/cwd inspired by unzip.cpp +#ifndef MAX_PATH + #define MAX_PATH 1024 +#endif + TCHAR rootdir[MAX_PATH]; + if(getcwd(rootdir,MAX_PATH-1)) + { + return(rootdir); + } + return(""); +}// osgDB::getCurrentWorkingDirectory + + + +bool osgDB::setCurrentWorkingDirectory( const std::string &newCurrentWorkingDirectory ) +{ + if (newCurrentWorkingDirectory.empty()) + { + osg::notify(osg::DEBUG_INFO) << "osgDB::setCurrentWorkingDirectory(): called with empty string." << std::endl; + return false; + } + +#ifdef OSG_USE_UTF8_FILENAME + return _wchdir( OSGDB_STRING_TO_FILENAME(newCurrentWorkingDirectory).c_str()) == 0; +#else + return chdir( newCurrentWorkingDirectory.c_str()) == 0; +#endif + + return true; +} // osgDB::setCurrentWorkingDirectory + + + void osgDB::convertStringPathIntoFilePathList(const std::string& paths,FilePathList& filepath) { #if defined(WIN32) && !defined(__CYGWIN__)