add RageFileManager::Remove
This commit is contained in:
@@ -19,6 +19,7 @@ public:
|
||||
virtual int GetPathValue( const CString &path );
|
||||
virtual bool Ready() { return true; } /* see RageFileManager::MountpointIsReady */
|
||||
virtual void FlushDirCache( const CString &sPath );
|
||||
virtual bool Remove( const CString &sPath ) { return false; }
|
||||
|
||||
protected:
|
||||
FilenameDB *FDB;
|
||||
|
||||
@@ -68,6 +68,28 @@ static HANDLE DoFindFirstFile( const CString &sPath, WIN32_FIND_DATA *fd )
|
||||
}
|
||||
#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. */
|
||||
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
|
||||
* "ABC/DEF/GHI/jkl/mno", this will resolve it to "abc/def/GHI/jkl/mno"; we'll
|
||||
* create the missing parts below. */
|
||||
/* XXX: does it? */
|
||||
FDB->ResolvePath( sPath );
|
||||
|
||||
if( mode == RageFile::WRITE )
|
||||
@@ -291,6 +314,39 @@ RageFileObj *RageFileDriverDirect::Open( const CString &path, RageFile::OpenMode
|
||||
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
|
||||
{
|
||||
int err;
|
||||
|
||||
@@ -9,6 +9,7 @@ public:
|
||||
RageFileDriverDirect( CString root );
|
||||
|
||||
RageFileObj *Open( const CString &path, RageFile::OpenMode mode, RageFile &p, int &err );
|
||||
bool Remove( const CString &sPath );
|
||||
bool Ready();
|
||||
|
||||
private:
|
||||
|
||||
@@ -153,7 +153,7 @@ CString LoadedDriver::GetPath( CString path )
|
||||
|
||||
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; }
|
||||
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 )
|
||||
{
|
||||
@@ -179,6 +179,24 @@ void RageFileManager::GetDirListing( CString sPath, CStringArray &AddTo, bool bO
|
||||
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 "RageFileDriverZip.h"
|
||||
void RageFileManager::Mount( CString Type, CString Root, CString MountPoint )
|
||||
|
||||
@@ -10,7 +10,8 @@ public:
|
||||
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 };
|
||||
FileType GetFileType( const CString &sPath );
|
||||
|
||||
Reference in New Issue
Block a user