From 990dfb570af841cf73f705483061658ccc0459a4 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 10 Dec 2003 04:58:47 +0000 Subject: [PATCH] Allow storing private pointer in FilenameDB. Add GetFile. --- stepmania/src/RageUtil_FileDB.cpp | 24 +++++++++++++++++++++--- stepmania/src/RageUtil_FileDB.h | 9 ++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/stepmania/src/RageUtil_FileDB.cpp b/stepmania/src/RageUtil_FileDB.cpp index 10f461cd84..25ede452c9 100644 --- a/stepmania/src/RageUtil_FileDB.cpp +++ b/stepmania/src/RageUtil_FileDB.cpp @@ -243,7 +243,7 @@ void FilenameDB::AddFileSet( CString sPath, FileSet *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 ) +void FilenameDB::AddFile( const CString &sPath, int size, int mtime, void *priv ) { vector parts; split( sPath, "/", parts, false ); @@ -269,8 +269,12 @@ void FilenameDB::AddFile( const CString &sPath, int size, int mtime ) if( fs.files.find( f ) == fs.files.end() ) { f.dir = IsDir; - f.size = size; - f.mtime = mtime; + if( !IsDir ) + { + f.size = size; + f.mtime = mtime; + f.priv = priv; + } fs.files.insert( f ); } IsDir = true; @@ -286,6 +290,20 @@ void FilenameDB::FlushDirCache() dirs.clear(); } +File *FilenameDB::GetFile( const CString &sPath ) +{ + CString Dir, Name; + SplitPath(sPath, Dir, Name); + FileSet &fs = GetFileSet( Dir ); + + set::iterator i = fs.files.find( File(Name) ); + if(i == fs.files.end()) + return NULL; + + return &*i; +} + + void FilenameDB::GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ) diff --git a/stepmania/src/RageUtil_FileDB.h b/stepmania/src/RageUtil_FileDB.h index 92adbc1b3d..84d2134604 100644 --- a/stepmania/src/RageUtil_FileDB.h +++ b/stepmania/src/RageUtil_FileDB.h @@ -25,11 +25,13 @@ struct File * when the file has been modified, this value will change. */ int mtime; - File() { dir=false; size=-1; mtime=-1; } + /* Private data, for RageFileDrivers. */ + void *priv; + File() { dir=false; size=-1; mtime=-1; priv=NULL;} File( const CString &fn ) { SetName( fn ); - dir=false; size=-1; mtime=-1; + dir=false; size=-1; mtime=-1; priv=NULL; } bool operator== (const File &rhs) const { return lname==rhs.lname; } @@ -83,7 +85,8 @@ public: ExpireSeconds( -1 ) { } virtual FilenameDB::~FilenameDB() { FlushDirCache(); } - void AddFile( const CString &sPath, int size, int mtime ); + void AddFile( const CString &sPath, int size, int mtime, void *priv=NULL ); + File *GetFile( const CString &path ); /* This handles at most two * wildcards. If we need anything more complicated, * we'll need to use fnmatch or regex. */