This commit is contained in:
Glenn Maynard
2003-12-06 06:17:21 +00:00
parent 6ea32749b7
commit 80f1d11633
+13 -47
View File
@@ -19,6 +19,7 @@
#include "windows.h" #include "windows.h"
#endif #endif
enum FileType { TTYPE_FILE, TTYPE_DIR, TTYPE_NONE };
struct File struct File
{ {
@@ -67,9 +68,8 @@ struct FileSet
const CString &beginning, const CString &containing, const CString &ending, const CString &beginning, const CString &containing, const CString &ending,
vector<CString> &out, bool bOnlyDirs) const; vector<CString> &out, bool bOnlyDirs) const;
void GetFilesEqualTo(const CString &pat, vector<CString> &out, bool bOnlyDirs) const; void GetFilesEqualTo(const CString &pat, vector<CString> &out, bool bOnlyDirs) const;
bool DoesFileExist(const CString &path) const;
bool IsADirectory(const CString &path) const; FileType GetFileType( const CString &path ) const;
bool IsAFile(const CString &path) const;
int GetFileSize(const CString &path) const; int GetFileSize(const CString &path) const;
int GetFileModTime(const CString &path) const; int GetFileModTime(const CString &path) const;
}; };
@@ -204,25 +204,13 @@ void FileSet::GetFilesEqualTo(const CString &str, vector<CString> &out, bool bOn
out.push_back( i->name ); out.push_back( i->name );
} }
bool FileSet::DoesFileExist(const CString &path) const FileType FileSet::GetFileType(const CString &path ) const
{
return files.find( File(path) ) != files.end();
}
bool FileSet::IsADirectory(const CString &path) const
{ {
set<File>::const_iterator i = files.find( File(path) ); set<File>::const_iterator i = files.find( File(path) );
if(i == files.end()) if(i == files.end())
return false; return TTYPE_NONE;
return i->dir;
}
bool FileSet::IsAFile(const CString &path) const return i->dir? TTYPE_DIR:TTYPE_FILE;
{
set<File>::const_iterator i = files.find( File(path) );
if(i == files.end())
return false;
return !i->dir;
} }
int FileSet::GetFileSize(const CString &path) const int FileSet::GetFileSize(const CString &path) const
@@ -294,44 +282,22 @@ public:
* case. If "path" doesn't exist at all, return false and don't change it. */ * case. If "path" doesn't exist at all, return false and don't change it. */
bool ResolvePath(CString &path); bool ResolvePath(CString &path);
bool DoesFileExist(const CString &path); FileType GetFileType( const CString &path );
bool IsAFile(const CString &path);
bool IsADirectory(const CString &path);
int GetFileSize(const CString &path); int GetFileSize(const CString &path);
int GetFileModTime( const CString &sFilePath ); int GetFileModTime( const CString &sFilePath );
void FlushDirCache(); void FlushDirCache();
}; };
bool FilenameDB::DoesFileExist( const CString &sPath )
FileType FilenameDB::GetFileType( const CString &sPath )
{ {
CString Dir, Name; CString Dir, Name;
SplitPath( sPath, Dir, Name ); SplitPath( sPath, Dir, Name );
FileSet &fs = GetFileSet( Dir ); FileSet &fs = GetFileSet( Dir );
return fs.DoesFileExist(Name); return fs.GetFileType( Name );
} }
bool FilenameDB::IsAFile( const CString &sPath )
{
CString Dir, Name;
SplitPath(sPath, Dir, Name);
FileSet &fs = GetFileSet( Dir );
return fs.IsAFile(Name);
}
bool FilenameDB::IsADirectory( const CString &sPath )
{
CString Dir, Name;
SplitPath(sPath, Dir, Name);
FileSet &fs = GetFileSet( Dir );
#ifdef _XBOX
if ( ( Dir == "D:\\" ) && ( Name == "" ) )
return true ;
#endif
return fs.IsADirectory(Name);
}
int FilenameDB::GetFileSize( const CString &sPath ) int FilenameDB::GetFileSize( const CString &sPath )
{ {
@@ -531,9 +497,9 @@ void FlushDirCache()
#if 0 #if 0
bool DoesFileExist( const CString &sPath ) { return FDB.DoesFileExist(sPath); } bool DoesFileExist( const CString &sPath ) { return FDB.GetFileType( sPath ) != TTYPE_NONE; }
bool IsAFile( const CString &sPath ) { return FDB.IsAFile(sPath); } bool IsAFile( const CString &sPath ) { return FDB.GetFileType( sPath ) == TTYPE_FILE; }
bool IsADirectory( const CString &sPath ) { return FDB.IsADirectory(sPath); } bool IsADirectory( const CString &sPath ) { return FDB.GetFileType( sPath ) == TTYPE_DIR; }
int GetFileModTime( const CString &sPath ) { return FDB.GetFileModTime(sPath); } int GetFileModTime( const CString &sPath ) { return FDB.GetFileModTime(sPath); }
unsigned GetFileSizeInBytes( const CString &sPath ) unsigned GetFileSizeInBytes( const CString &sPath )
{ {