add RageFileManager::Remove

This commit is contained in:
Glenn Maynard
2003-12-16 07:23:54 +00:00
parent b2f375f4ec
commit d5abb2b0c8
5 changed files with 79 additions and 2 deletions
+1
View File
@@ -19,6 +19,7 @@ public:
virtual int GetPathValue( const CString &path ); virtual int GetPathValue( const CString &path );
virtual bool Ready() { return true; } /* see RageFileManager::MountpointIsReady */ virtual bool Ready() { return true; } /* see RageFileManager::MountpointIsReady */
virtual void FlushDirCache( const CString &sPath ); virtual void FlushDirCache( const CString &sPath );
virtual bool Remove( const CString &sPath ) { return false; }
protected: protected:
FilenameDB *FDB; FilenameDB *FDB;
+56
View File
@@ -68,6 +68,28 @@ static HANDLE DoFindFirstFile( const CString &sPath, WIN32_FIND_DATA *fd )
} }
#endif #endif
static int DoRemove( const CString &sPath )
{
#if defined(XBOX)
CString TempPath = sPath;
TempPath.Replace( "/", "\\" );
return remove( sPath );
#else
return remove( sPath );
#endif
}
static int DoRmdir( const CString &sPath )
{
#if defined(XBOX)
CString TempPath = sPath;
TempPath.Replace( "/", "\\" );
return rmdir( sPath );
#else
return rmdir( sPath );
#endif
}
/* This driver handles direct file access. */ /* This driver handles direct file access. */
class DirectFilenameDB: public FilenameDB class DirectFilenameDB: public FilenameDB
@@ -279,6 +301,7 @@ RageFileObj *RageFileDriverDirect::Open( const CString &path, RageFile::OpenMode
/* This partially resolves. For example, if "abc/def" exists, and we're opening /* This partially resolves. For example, if "abc/def" exists, and we're opening
* "ABC/DEF/GHI/jkl/mno", this will resolve it to "abc/def/GHI/jkl/mno"; we'll * "ABC/DEF/GHI/jkl/mno", this will resolve it to "abc/def/GHI/jkl/mno"; we'll
* create the missing parts below. */ * create the missing parts below. */
/* XXX: does it? */
FDB->ResolvePath( sPath ); FDB->ResolvePath( sPath );
if( mode == RageFile::WRITE ) if( mode == RageFile::WRITE )
@@ -291,6 +314,39 @@ RageFileObj *RageFileDriverDirect::Open( const CString &path, RageFile::OpenMode
return MakeFileObjDirect( root + sPath, mode, p, err ); return MakeFileObjDirect( root + sPath, mode, p, err );
} }
bool RageFileDriverDirect::Remove( const CString &path )
{
CString sPath = path;
FDB->ResolvePath( sPath );
switch( this->GetFileType(sPath) )
{
case TTYPE_FILE:
LOG->Trace("remove '%s'", (root + sPath).c_str());
if( DoRemove( root + sPath ) == -1 )
{
LOG->Warn("remove(%s) failed: %s",
(root + sPath).c_str(), strerror(errno) );
return false;
}
FDB->DelFile( sPath );
return true;
case TTYPE_DIR:
LOG->Trace("rmdir '%s'", (root + sPath).c_str());
if( DoRmdir( root + sPath ) == -1 )
{
LOG->Warn("rmdir(%s) failed: %s",
(root + sPath).c_str(), strerror(errno) );
return false;
}
FDB->DelFile( sPath );
return true;
case TTYPE_NONE: return false;
default: ASSERT(0); return false;
}
}
RageFileObj *RageFileObjDirect::Copy( RageFile &p ) const RageFileObj *RageFileObjDirect::Copy( RageFile &p ) const
{ {
int err; int err;
+1
View File
@@ -9,6 +9,7 @@ public:
RageFileDriverDirect( CString root ); RageFileDriverDirect( CString root );
RageFileObj *Open( const CString &path, RageFile::OpenMode mode, RageFile &p, int &err ); RageFileObj *Open( const CString &path, RageFile::OpenMode mode, RageFile &p, int &err );
bool Remove( const CString &sPath );
bool Ready(); bool Ready();
private: private:
+19 -1
View File
@@ -153,7 +153,7 @@ CString LoadedDriver::GetPath( CString path )
bool ilt( const CString &a, const CString &b ) { return a.CompareNoCase(b) < 0; } bool ilt( const CString &a, const CString &b ) { return a.CompareNoCase(b) < 0; }
bool ieq( const CString &a, const CString &b ) { return a.CompareNoCase(b) == 0; } bool ieq( const CString &a, const CString &b ) { return a.CompareNoCase(b) == 0; }
void RageFileManager::GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ) void RageFileManager::GetDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo )
{ {
for( unsigned i = 0; i < g_Drivers.size(); ++i ) for( unsigned i = 0; i < g_Drivers.size(); ++i )
{ {
@@ -179,6 +179,24 @@ void RageFileManager::GetDirListing( CString sPath, CStringArray &AddTo, bool bO
AddTo.erase(it, AddTo.end()); AddTo.erase(it, AddTo.end());
} }
bool RageFileManager::Remove( const CString &sPath )
{
/* Multiple drivers may have the same file. */
bool Deleted = false;
for( unsigned i = 0; i < g_Drivers.size(); ++i )
{
const CString p = g_Drivers[i].GetPath( sPath );
if( p.size() == 0 )
continue;
bool ret = g_Drivers[i].driver->Remove( p );
if( !ret )
Deleted = true;
}
return Deleted;
}
#include "RageFileDriverDirect.h" #include "RageFileDriverDirect.h"
#include "RageFileDriverZip.h" #include "RageFileDriverZip.h"
void RageFileManager::Mount( CString Type, CString Root, CString MountPoint ) void RageFileManager::Mount( CString Type, CString Root, CString MountPoint )
+2 -1
View File
@@ -10,7 +10,8 @@ public:
RageFileManager(); RageFileManager();
~RageFileManager(); ~RageFileManager();
void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ); void GetDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo );
bool Remove( const CString &sPath );
enum FileType { TYPE_FILE, TYPE_DIR, TYPE_NONE }; enum FileType { TYPE_FILE, TYPE_DIR, TYPE_NONE };
FileType GetFileType( const CString &sPath ); FileType GetFileType( const CString &sPath );