00001
#ifndef RAGE_UTIL_FILEDB
00002 #define RAGE_UTIL_FILEDB 1
00003
00004
#include <set>
00005
#include <map>
00006
#include "RageTimer.h"
00007
#include "RageThreads.h"
00008
#include "RageFileManager.h"
00009
00010
struct FileSet;
00011 struct File
00012 {
00013 CString name;
00014 CString lname;
00015
00016 void SetName(
const CString &fn )
00017 {
00018
name = fn;
00019
lname =
name;
00020
lname.MakeLower();
00021 }
00022
00023 bool dir;
00024 int size;
00025
00026
00027 int hash;
00028
00029
00030 void *
priv;
00031
00032
00033
00034 const FileSet *
dirp;
00035
00036 File() {
dir=
false;
dirp=NULL;
size=-1;
hash=-1;
priv=NULL;}
00037 File(
const CString &fn )
00038 {
00039 SetName( fn );
00040
dir=
false;
size=-1;
hash=-1;
priv=NULL;
00041 }
00042
00043 bool operator== (
const File &rhs)
const {
return lname==rhs.
lname; }
00044 bool operator< (
const File &rhs)
const {
return lname<rhs.
lname; }
00045
00046 bool equal(
const File &rhs)
const {
return lname == rhs.
lname; }
00047 bool equal(
const CString &rhs)
const
00048
{
00049
CString l = rhs;
00050 l.MakeLower();
00051
return lname == l;
00052 }
00053 };
00054
00055
00056 struct FileSet
00057 {
00058 set<File>
files;
00059 RageTimer age;
00060
00061
00062
00063
00064
00065
00066 bool m_bFilled;
00067
00068 FileSet() {
m_bFilled =
true; }
00069
00070
void GetFilesMatching(
00071
const CString &beginning,
const CString &containing,
const CString &ending,
00072 vector<CString> &out,
bool bOnlyDirs)
const;
00073
void GetFilesEqualTo(
const CString &pat, vector<CString> &out,
bool bOnlyDirs)
const;
00074
00075 RageFileManager::FileType GetFileType(
const CString &path )
const;
00076
int GetFileSize(
const CString &path)
const;
00077
int GetFileHash(
const CString &path)
const;
00078 };
00079
00080 class FilenameDB
00081 {
00082
protected:
00083 RageEvent m_Mutex;
00084
00085
FileSet *
GetFileSet( CString dir,
bool create=
true );
00086
00087
00088 map<CString, FileSet *>
dirs;
00089
00090 int ExpireSeconds;
00091
00092
void GetFilesEqualTo(
const CString &dir,
const CString &fn, vector<CString> &out,
bool bOnlyDirs);
00093
void GetFilesMatching(
const CString &dir,
00094
const CString &beginning,
const CString &containing,
const CString &ending,
00095 vector<CString> &out,
bool bOnlyDirs);
00096
void DelFileSet( map<CString, FileSet *>::iterator dir );
00097
00098
00099 virtual void PopulateFileSet(
FileSet &fs,
const CString &sPath ) { }
00100
00101
public:
00102 FilenameDB::FilenameDB():
00103
m_Mutex("
FilenameDB"),
ExpireSeconds( -1 ) { }
00104 virtual FilenameDB::~FilenameDB() {
FlushDirCache(); }
00105
00106
void AddFile(
const CString &sPath,
int size,
int hash,
void *priv=NULL );
00107
void DelFile(
const CString &sPath );
00108
const File *GetFile(
const CString &path );
00109
const void *GetFilePriv(
const CString &path );
00110
00111
00112
00113
void GetFilesSimpleMatch(
const CString &dir,
const CString &fn, vector<CString> &out,
bool bOnlyDirs);
00114
00115
00116
00117
00118
bool ResolvePath( CString &path );
00119
00120 RageFileManager::FileType GetFileType(
const CString &path );
00121
int GetFileSize(
const CString &path);
00122
int GetFileHash(
const CString &sFilePath );
00123
void GetDirListing( CString sPath, CStringArray &AddTo,
bool bOnlyDirs,
bool bReturnPathToo );
00124
00125
void FlushDirCache();
00126
00127
void GetFileSetCopy( CString dir,
FileSet &out );
00128 };
00129
00130
00131 class NullFilenameDB:
public FilenameDB
00132 {
00133
public:
00134 NullFilenameDB() { ExpireSeconds = -1; }
00135
00136
protected:
00137 void PopulateFileSet(
FileSet &fs,
const CString &sPath ) { }
00138 };
00139
00140
#endif
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165