diff --git a/stepmania/src/RageFileDriver.cpp b/stepmania/src/RageFileDriver.cpp index ae19108095..165523f076 100644 --- a/stepmania/src/RageFileDriver.cpp +++ b/stepmania/src/RageFileDriver.cpp @@ -1,6 +1,12 @@ #include "global.h" #include "RageFileDriver.h" #include "RageUtil.h" +#include "RageUtil_FileDB.h" + +RageFileDriver::~RageFileDriver() +{ + delete FDB; +} void RageFileObj::SetError( const CString &err ) { @@ -93,6 +99,32 @@ int RageFileDriver::GetPathValue( CString path ) return 0; } +void RageFileDriver::GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ) +{ + FDB->GetDirListing( sPath, AddTo, bOnlyDirs, bReturnPathToo ); +} + +RageFileManager::FileType RageFileDriver::GetFileType( CString sPath ) +{ + /* XXX */ + return (RageFileManager::FileType) FDB->GetFileType( sPath ); +} + +int RageFileDriver::GetFileSizeInBytes( CString sPath ) +{ + return FDB->GetFileSize( sPath ); +} + +int RageFileDriver::GetFileModTime( CString sPath ) +{ + return FDB->GetFileModTime( sPath ); +} + +void RageFileDriver::FlushDirCache( const CString &sPath ) +{ + FDB->FlushDirCache(); +} + /* * Copyright (c) 2003 by the person(s) listed below. All rights reserved. * Glenn Maynard diff --git a/stepmania/src/RageFileDriver.h b/stepmania/src/RageFileDriver.h index 379cd6c9f2..b28acf79ac 100644 --- a/stepmania/src/RageFileDriver.h +++ b/stepmania/src/RageFileDriver.h @@ -5,17 +5,23 @@ #include "RageFileManager.h" class RageFileObj; +class FilenameDB; class RageFileDriver { public: + RageFileDriver( FilenameDB *db ) { FDB = db; } + virtual ~RageFileDriver(); virtual RageFileObj *Open( CString path, RageFile::OpenMode mode, RageFile &p, int &err ) = 0; - virtual void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ) = 0; - virtual RageFileManager::FileType GetFileType( CString sPath ) = 0; - virtual int GetFileSizeInBytes( CString sFilePath ) = 0; - virtual int GetFileModTime( CString sPath ) = 0; + virtual void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ); + virtual RageFileManager::FileType GetFileType( CString sPath ); + virtual int GetFileSizeInBytes( CString sFilePath ); + virtual int GetFileModTime( CString sPath ); virtual int GetPathValue( CString path ); virtual bool Ready() { return true; } /* see RageFileManager::MountpointIsReady */ - virtual void FlushDirCache( const CString &sPath ) { } + virtual void FlushDirCache( const CString &sPath ); + +protected: + FilenameDB *FDB; }; class RageFileObj diff --git a/stepmania/src/RageFileDriverDirect.cpp b/stepmania/src/RageFileDriverDirect.cpp index 3ec3566c1f..52d81c9b89 100644 --- a/stepmania/src/RageFileDriverDirect.cpp +++ b/stepmania/src/RageFileDriverDirect.cpp @@ -26,8 +26,18 @@ class DirectFilenameDB: public FilenameDB { protected: virtual void PopulateFileSet( FileSet &fs, const CString &sPath ); + CString root; + public: - DirectFilenameDB() { ExpireSeconds = 30; } + DirectFilenameDB( CString root_ ) + { + ExpireSeconds = 30; + root = root_; + if( root.Right(1) != "/" ) + root += '/'; + if( root == "./" ) + root = ""; + } }; void DirectFilenameDB::PopulateFileSet( FileSet &fs, const CString &path ) @@ -46,7 +56,7 @@ void DirectFilenameDB::PopulateFileSet( FileSet &fs, const CString &path ) if ( sPath.size() > 0 && sPath.Right(1) == SLASH ) sPath.erase( sPath.size() - 1 ); - HANDLE hFind = FindFirstFile( sPath+SLASH "*", &fd ); + HANDLE hFind = FindFirstFile( root+sPath+SLASH "*", &fd ); if( hFind == INVALID_HANDLE_VALUE ) return; @@ -69,7 +79,7 @@ void DirectFilenameDB::PopulateFileSet( FileSet &fs, const CString &path ) if( OldDir == -1 ) RageException::Throw( "Couldn't open(.): %s", strerror(errno) ); - if( chdir(sPath) == -1 ) + if( chdir(root+sPath) == -1 ) { /* Only log once per dir. */ if( LOG ) @@ -133,32 +143,13 @@ public: RageFileDriverDirect::RageFileDriverDirect( CString root_ ): + RageFileDriver( new DirectFilenameDB(root_) ), root(root_) { - FDB = new DirectFilenameDB; - if( root.Right(1) != "/" ) root += '/'; } -RageFileDriverDirect::~RageFileDriverDirect() -{ - delete FDB; -} - -void RageFileDriverDirect::GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ) -{ - const unsigned OldStart = AddTo.size(); - FDB->GetDirListing( root+sPath, AddTo, bOnlyDirs, bReturnPathToo ); - - if( bReturnPathToo ) - { - /* Remove the root path. */ - for( unsigned j = OldStart; j < AddTo.size(); ++j ) - AddTo[j].erase( 0, root.size() ); - } -} - /* mkdir -p. Doesn't fail if Path already exists and is a directory. */ static bool CreateDirectories( CString Path ) { @@ -234,22 +225,6 @@ RageFileObj *RageFileDriverDirect::Open( CString sPath, RageFile::OpenMode mode, return new RageFileObjDirect( fd, p ); } -RageFileManager::FileType RageFileDriverDirect::GetFileType( CString sPath ) -{ - /* XXX */ - return (RageFileManager::FileType) FDB->GetFileType( root + sPath ); -} - -int RageFileDriverDirect::GetFileSizeInBytes( CString sPath ) -{ - return FDB->GetFileSize( root + sPath ); -} - -int RageFileDriverDirect::GetFileModTime( CString sPath ) -{ - return FDB->GetFileModTime( root + sPath ); -} - #ifdef _WINDOWS #include "windows.h" #endif @@ -289,7 +264,7 @@ bool RageFileDriverDirect::Ready() CreateDirectories( root ); // XXX // Try to write a file. - CString sFile = root + "temp"; + CString sFile = root + "temp"; /* XXX no */ RageFile f; if( !f.Open( sFile, RageFile::WRITE ) ) return false; @@ -300,11 +275,6 @@ bool RageFileDriverDirect::Ready() #endif } -void RageFileDriverDirect::FlushDirCache( const CString &sPath ) -{ - FDB->FlushDirCache(); -} - RageFileObjDirect::RageFileObjDirect( int fd_, RageFile &p ): RageFileObj( p ) diff --git a/stepmania/src/RageFileDriverDirect.h b/stepmania/src/RageFileDriverDirect.h index eb8d5a5631..e51e5c48b3 100644 --- a/stepmania/src/RageFileDriverDirect.h +++ b/stepmania/src/RageFileDriverDirect.h @@ -3,24 +3,16 @@ #include "RageFileDriver.h" -class FilenameDB; class RageFileDriverDirect: public RageFileDriver { public: RageFileDriverDirect( CString root ); - virtual ~RageFileDriverDirect(); RageFileObj *Open( CString path, RageFile::OpenMode mode, RageFile &p, int &err ); - void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ); - RageFileManager::FileType GetFileType( CString sPath ); - int GetFileSizeInBytes( CString sFilePath ); - int GetFileModTime( CString sPath ); bool Ready(); - void FlushDirCache( const CString &sPath ); private: CString root; - FilenameDB *FDB; }; #endif