diff --git a/pcsx2/PathUtils.cpp b/pcsx2/PathUtils.cpp index 83b95f0d93..3cca885154 100644 --- a/pcsx2/PathUtils.cpp +++ b/pcsx2/PathUtils.cpp @@ -191,27 +191,40 @@ string ReplaceFilename( const string& src, const string& newfilename ) if( !newfilename.empty() ) { - dest += '.'; + dest += Separator; dest += newfilename; } return dest; } -void GetFilename( const string& src, string& dest ) +string GetFilename( const string& src ) { int pos = _findFilenamePosition( src ); - dest.assign( src.begin()+pos, src.end() ); + return string( src.begin()+pos, src.end() ); } -void GetDirectory( const string& src, string& dest ) +string GetFilenameWithoutExt( const string& src ) +{ + string fname( GetFilename( src ) ); + + int pos = fname.find_last_of( '.' ); + if( pos == string::npos || pos == 0 ) + return fname; + else + return string( fname.begin(), fname.begin()+pos ); +} + +string GetDirectory( const string& src ) { int pos = _findFilenamePosition( src ); if( pos == 0 ) - dest.clear(); + return string(); else - dest.assign( src.begin(), src.begin()+pos ); + return string( src.begin(), src.begin()+pos ); } +// This function mimics the old ANSI C splitpath function. It's more or less superceeded +// by one of the many other Path utility functions, but someone might find it useful. void Split( const string& src, string& destpath, string& destfile ) { int pos = _findFilenamePosition( src ); @@ -230,13 +243,13 @@ void Split( const string& src, string& destpath, string& destfile ) // Assigns the base/root directory of the given path into dest. // Example /this/that/something.txt -> dest == "/" -void GetRootDirectory( const string& src, string& dest ) +string GetRootDirectory( const string& src ) { int pos = src.find_first_of( Delimiters ); if( pos == string::npos ) - dest.clear(); + return string(); else - dest.assign( src.begin(), src.begin()+pos ); + return string( src.begin(), src.begin()+pos ); } void CreateDirectory( const string& src ) diff --git a/pcsx2/Paths.h b/pcsx2/Paths.h index b92881fae8..225efde585 100644 --- a/pcsx2/Paths.h +++ b/pcsx2/Paths.h @@ -34,9 +34,10 @@ namespace Path extern std::string Combine( const std::string& srcPath, const std::string& srcFile ); extern std::string ReplaceExtension( const std::string& src, const std::string& ext ); extern std::string ReplaceFilename( const std::string& src, const std::string& newfilename ); - extern void GetFilename( const std::string& src, std::string& dest ); - extern void GetDirectory( const std::string& src, std::string& dest ); - extern void GetRootDirectory( const std::string& src, std::string& dest ); + extern std::string GetFilename( const std::string& src ); + extern std::string GetDirectory( const std::string& src ); + extern std::string GetFilenameWithoutExt( const string& src ); + extern std::string GetRootDirectory( const std::string& src ); extern void Split( const std::string& src, std::string& destpath, std::string& destfile ); extern void CreateDirectory( const std::string& src );