From d62570c1fc41024acda20b7d2df78ba4af572a46 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 8 Dec 2003 00:04:47 +0000 Subject: [PATCH] add FilenameDB::AddFile --- stepmania/src/RageUtil_FileDB.cpp | 38 +++++++++++++++++++++++++++++++ stepmania/src/RageUtil_FileDB.h | 9 ++++---- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/stepmania/src/RageUtil_FileDB.cpp b/stepmania/src/RageUtil_FileDB.cpp index 147b3e0468..10f461cd84 100644 --- a/stepmania/src/RageUtil_FileDB.cpp +++ b/stepmania/src/RageUtil_FileDB.cpp @@ -241,6 +241,44 @@ void FilenameDB::AddFileSet( CString sPath, FileSet *fs ) dirs[sPath] = fs; } +/* Add the file or directory "sPath". sPath is a directory if it ends with + * a slash. */ +void FilenameDB::AddFile( const CString &sPath, int size, int mtime ) +{ + vector parts; + split( sPath, "/", parts, false ); + + CStringArray::const_iterator begin = parts.begin(); + CStringArray::const_iterator end = parts.end(); + + bool IsDir = true; + if( sPath[sPath.size()-1] != '/' ) + IsDir = false; + else + --end; + + do + { + /* Combine all but the last part. */ + CString dir = join( "/", begin, end-1 ) + "/"; + const CString &fn = *(end-1); + FileSet &fs = GetFileSet( dir ); + + File f; + f.SetName( fn ); + if( fs.files.find( f ) == fs.files.end() ) + { + f.dir = IsDir; + f.size = size; + f.mtime = mtime; + fs.files.insert( f ); + } + IsDir = true; + + --end; + } while( begin != end ); +} + void FilenameDB::FlushDirCache() { for( map::iterator i = dirs.begin(); i != dirs.end(); ++i ) diff --git a/stepmania/src/RageUtil_FileDB.h b/stepmania/src/RageUtil_FileDB.h index 11ad8bffd9..92adbc1b3d 100644 --- a/stepmania/src/RageUtil_FileDB.h +++ b/stepmania/src/RageUtil_FileDB.h @@ -73,18 +73,17 @@ protected: void GetFilesMatching(const CString &dir, const CString &beginning, const CString &containing, const CString &ending, vector &out, bool bOnlyDirs); + void AddFileSet( CString sPath, FileSet *fs ); - /* The given path wasn't cached. Cache it, and return the cached FileSet or - * NULL on failure. */ - virtual void PopulateFileSet( FileSet &fs, const CString &sPath ) = 0; - + /* The given path wasn't cached. Cache it. */ + virtual void PopulateFileSet( FileSet &fs, const CString &sPath ) { } public: FilenameDB::FilenameDB(): ExpireSeconds( -1 ) { } virtual FilenameDB::~FilenameDB() { FlushDirCache(); } - void AddFileSet( CString sPath, FileSet *fs ); + void AddFile( const CString &sPath, int size, int mtime ); /* This handles at most two * wildcards. If we need anything more complicated, * we'll need to use fnmatch or regex. */