Allow storing private pointer in FilenameDB.

Add GetFile.
This commit is contained in:
Glenn Maynard
2003-12-10 04:58:47 +00:00
parent 8d6b19ad7a
commit 990dfb570a
2 changed files with 27 additions and 6 deletions
+21 -3
View File
@@ -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<CString> 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<File>::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 )
+6 -3
View File
@@ -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. */