From a7190307f3edd1ff1333a0c547ff2a387ba85f70 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 11 Dec 2003 07:24:32 +0000 Subject: [PATCH] fix up path handling --- stepmania/src/RageFile.cpp | 9 ++++++++- stepmania/src/RageUtil_FileDB.cpp | 32 +++++++++++++++++-------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/stepmania/src/RageFile.cpp b/stepmania/src/RageFile.cpp index 9748356917..49fac52dbd 100644 --- a/stepmania/src/RageFile.cpp +++ b/stepmania/src/RageFile.cpp @@ -32,8 +32,9 @@ CString FixSlashes( CString sPath ) void CollapsePath( CString &sPath ) { + /* Don't ignore empty: we do want to keep trailing slashes. */ CStringArray as; - split( sPath, "/", as, true ); + split( sPath, "/", as, false ); for( unsigned i=0; i "foo/bar/". */ + as.erase( as.begin()+i ); + i -= 1; + } else if( as[i] == "." ) { as.erase( as.begin()+i ); diff --git a/stepmania/src/RageUtil_FileDB.cpp b/stepmania/src/RageUtil_FileDB.cpp index 3895eb82a1..570036707b 100644 --- a/stepmania/src/RageUtil_FileDB.cpp +++ b/stepmania/src/RageUtil_FileDB.cpp @@ -77,29 +77,30 @@ int FileSet::GetFileHash(const CString &path) const return i->hash + i->size; } -/* Given "foo/bar/baz/" or "foo/bar/baz", return "foo/bar/" and "baz". */ +/* + * Given "foo/bar/baz/" or "foo/bar/baz", return "foo/bar/" and "baz". + * "foo" -> "", "foo" + */ static void SplitPath( CString Path, CString &Dir, CString &Name ) { - /* Strip off any trailing slashes. */ - if( Path.size() > 0 && Path.Right(1) == "/" ) + CollapsePath( Path ); + if( Path.Right(1) == "/" ) Path.erase( Path.size()-1 ); - static Regex split("(.*/)([^/]+)"); - - CStringArray match; - if(split.Compare(Path, match)) { - /* At least one slash. */ - Dir = match[0]; - Name = match[1]; - } else { - /* No slash. */ - Dir = "./"; + unsigned sep = Path.find_last_of( '/' ); + if( sep == CString::npos ) + { + Dir = ""; Name = Path; } + else + { + Dir = Path.substr( 0, sep+1 ); + Name = Path.substr( sep+1 ); + } } - FileType FilenameDB::GetFileType( const CString &sPath ) { CString Dir, Name; @@ -211,6 +212,9 @@ FileSet &FilenameDB::GetFileSet( CString dir ) dir.Replace("\\", "/"); /* foo\bar -> foo/bar */ dir.Replace("//", "/"); /* foo//bar -> foo/bar */ + if( dir == "" ) + dir = "."; + CString lower = dir; lower.MakeLower();