Changeset 10818

Show
Ignore:
Timestamp:
11/23/09 11:19:37 (5 years ago)
Author:
robert
Message:

From Chris Hanson, " Add support for requesting and setting the current directory (a la getcwd/chdir) via a
C++-friendly string-class API.

Prevent osgDB::concatPaths from faulting if the supplied "left" path string is empty."

Location:
OpenSceneGraph/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgDB/FileUtils

    r10171 r10818  
    4141extern OSGDB_EXPORT bool makeDirectoryForFile( const std::string &filePath ); 
    4242     
     43// Get current working directory. 
     44extern OSGDB_EXPORT std::string getCurrentWorkingDirectory( void ); 
     45 
     46// Set current working directory. 
     47extern OSGDB_EXPORT bool setCurrentWorkingDirectory( const std::string &newCurrentWorkingDirectory ); 
     48 
    4349 
    4450/** return true if a file exists. */ 
     
    9197extern OSGDB_EXPORT std::string findLibraryFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE); 
    9298 
    93 /** convert a string containing a list of paths  delimited either with ';' (Windows) or ':' (All other platforms) into FilePath representation.*/ 
     99/** convert a string containing a list of paths delimited either with ';' (Windows) or ':' (All other platforms) into FilePath representation.*/ 
    94100extern OSGDB_EXPORT void convertStringPathIntoFilePathList(const std::string& paths,FilePathList& filepath); 
    95101 
  • OpenSceneGraph/trunk/src/osgDB/FileNameUtils.cpp

    r9884 r10818  
    251251#endif 
    252252 
     253    if(left.empty()) 
     254    { 
     255        return(right); 
     256    } 
    253257    char lastChar = left[left.size() - 1]; 
    254258 
  • OpenSceneGraph/trunk/src/osgDB/FileUtils.cpp

    r10171 r10818  
    1111 * OpenSceneGraph Public License for more details. 
    1212*/ 
     13 
     14// handle TCHAR type on various platforms 
     15// #ifndef is inspired by https://svn.apache.org/repos/asf/logging/log4cxx/tags/v0_9_4/include/log4cxx/helpers/tchar.h 
     16// defining type as plain char is from unzip.h, line 64 
     17 
     18#ifndef TCHAR 
     19typedef char TCHAR; 
     20#endif 
     21 
    1322 
    1423// currently this impl is for _all_ platforms, except as defined. 
     
    194203    return makeDirectory( getFilePath( path )); 
    195204} 
     205 
     206 
     207std::string osgDB::getCurrentWorkingDirectory( void ) 
     208{ 
     209    // MAX_PATH/cwd inspired by unzip.cpp 
     210#ifndef MAX_PATH 
     211    #define MAX_PATH 1024 
     212#endif 
     213    TCHAR rootdir[MAX_PATH]; 
     214    if(getcwd(rootdir,MAX_PATH-1)) 
     215    { 
     216        return(rootdir); 
     217    } 
     218    return(""); 
     219}// osgDB::getCurrentWorkingDirectory 
     220 
     221 
     222 
     223bool osgDB::setCurrentWorkingDirectory( const std::string &newCurrentWorkingDirectory ) 
     224{ 
     225    if (newCurrentWorkingDirectory.empty()) 
     226    { 
     227        osg::notify(osg::DEBUG_INFO) << "osgDB::setCurrentWorkingDirectory(): called with empty string." << std::endl; 
     228        return false; 
     229    } 
     230     
     231#ifdef OSG_USE_UTF8_FILENAME 
     232    return _wchdir( OSGDB_STRING_TO_FILENAME(newCurrentWorkingDirectory).c_str()) == 0; 
     233#else 
     234    return chdir( newCurrentWorkingDirectory.c_str()) == 0; 
     235#endif 
     236 
     237    return true; 
     238} // osgDB::setCurrentWorkingDirectory 
     239 
     240 
    196241 
    197242void osgDB::convertStringPathIntoFilePathList(const std::string& paths,FilePathList& filepath)