stop passing ugly back-references to the RageFile to RageFileObj
This commit is contained in:
@@ -41,13 +41,13 @@ private:
|
||||
int m_iMode;
|
||||
|
||||
public:
|
||||
RageFileObjDirect( const CString &path, int fd_, int mode_, RageFile &p );
|
||||
RageFileObjDirect( const CString &path, int fd_, int mode_ );
|
||||
virtual ~RageFileObjDirect();
|
||||
virtual int Read(void *buffer, size_t bytes);
|
||||
virtual int Write(const void *buffer, size_t bytes);
|
||||
virtual int Flush();
|
||||
virtual int Seek( int offset );
|
||||
virtual RageFileObj *Copy( RageFile &p ) const;
|
||||
virtual RageFileObj *Copy() const;
|
||||
virtual CString GetDisplayPath() const { return path; }
|
||||
virtual int GetFileSize();
|
||||
};
|
||||
@@ -74,7 +74,7 @@ static CString MakeTempFilename( const CString &sPath )
|
||||
return Dirname(sPath) + "new." + Basename(sPath) + ".new";
|
||||
}
|
||||
|
||||
RageFileObj *MakeFileObjDirect( CString sPath, int mode, RageFile &p, int &err )
|
||||
RageFileObj *MakeFileObjDirect( CString sPath, int mode, int &err )
|
||||
{
|
||||
int fd;
|
||||
if( mode & RageFile::READ )
|
||||
@@ -103,10 +103,10 @@ RageFileObj *MakeFileObjDirect( CString sPath, int mode, RageFile &p, int &err )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new RageFileObjDirect( sPath, fd, mode, p );
|
||||
return new RageFileObjDirect( sPath, fd, mode );
|
||||
}
|
||||
|
||||
RageFileObj *RageFileDriverDirect::Open( const CString &path, int mode, RageFile &p, int &err )
|
||||
RageFileObj *RageFileDriverDirect::Open( const CString &path, int mode, int &err )
|
||||
{
|
||||
CString sPath = path;
|
||||
|
||||
@@ -122,7 +122,7 @@ RageFileObj *RageFileDriverDirect::Open( const CString &path, int mode, RageFile
|
||||
CreateDirectories( root + dir );
|
||||
}
|
||||
|
||||
return MakeFileObjDirect( root + sPath, mode, p, err );
|
||||
return MakeFileObjDirect( root + sPath, mode, err );
|
||||
}
|
||||
|
||||
bool RageFileDriverDirect::Remove( const CString &path )
|
||||
@@ -158,10 +158,10 @@ bool RageFileDriverDirect::Remove( const CString &path )
|
||||
}
|
||||
}
|
||||
|
||||
RageFileObj *RageFileObjDirect::Copy( RageFile &p ) const
|
||||
RageFileObj *RageFileObjDirect::Copy() const
|
||||
{
|
||||
int err;
|
||||
RageFileObj *ret = MakeFileObjDirect( path, m_iMode, p, err );
|
||||
RageFileObj *ret = MakeFileObjDirect( path, m_iMode, err );
|
||||
|
||||
if( ret == NULL )
|
||||
RageException::Throw("Couldn't reopen \"%s\": %s", path.c_str(), strerror(err) );
|
||||
@@ -177,8 +177,7 @@ bool RageFileDriverDirect::Ready()
|
||||
}
|
||||
|
||||
static const unsigned int BUFSIZE = 1024*64;
|
||||
RageFileObjDirect::RageFileObjDirect( const CString &path_, int fd_, int mode_, RageFile &p ):
|
||||
RageFileObj( p )
|
||||
RageFileObjDirect::RageFileObjDirect( const CString &path_, int fd_, int mode_ )
|
||||
{
|
||||
path = path_;
|
||||
fd = fd_;
|
||||
|
||||
@@ -8,7 +8,7 @@ class RageFileDriverDirect: public RageFileDriver
|
||||
public:
|
||||
RageFileDriverDirect( CString root );
|
||||
|
||||
RageFileObj *Open( const CString &path, int mode, RageFile &p, int &err );
|
||||
RageFileObj *Open( const CString &path, int mode, int &err );
|
||||
bool Remove( const CString &sPath );
|
||||
bool Ready();
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ private:
|
||||
int m_iFilePos;
|
||||
|
||||
public:
|
||||
RageFileObjMem( RageFileObjMemFile *pFile, RageFile &p ):
|
||||
RageFileObj(p)
|
||||
RageFileObjMem( RageFileObjMemFile *pFile )
|
||||
{
|
||||
m_pFile = pFile;
|
||||
m_iFilePos = 0;
|
||||
@@ -80,13 +79,13 @@ public:
|
||||
return m_pFile->m_sBuf.size();
|
||||
}
|
||||
|
||||
RageFileObj *Copy( RageFile &p ) const
|
||||
RageFileObj *Copy() const
|
||||
{
|
||||
m_pFile->m_Mutex.Unlock();
|
||||
++m_pFile->m_iRefs;
|
||||
m_pFile->m_Mutex.Lock();
|
||||
|
||||
RageFileObjMem *pRet = new RageFileObjMem( m_pFile, p );
|
||||
RageFileObjMem *pRet = new RageFileObjMem( m_pFile );
|
||||
pRet->m_iFilePos = m_iFilePos;
|
||||
|
||||
return pRet;
|
||||
@@ -111,7 +110,7 @@ RageFileDriverMem::~RageFileDriverMem()
|
||||
}
|
||||
}
|
||||
|
||||
RageFileObj *RageFileDriverMem::Open( const CString &sPath, int mode, RageFile &p, int &err )
|
||||
RageFileObj *RageFileDriverMem::Open( const CString &sPath, int mode, int &err )
|
||||
{
|
||||
LockMut(m_Mutex);
|
||||
|
||||
@@ -125,7 +124,7 @@ RageFileObj *RageFileDriverMem::Open( const CString &sPath, int mode, RageFile &
|
||||
m_Files.push_back( pFile );
|
||||
FDB->AddFile( sPath, 0, 0, pFile );
|
||||
|
||||
return new RageFileObjMem( pFile, p );
|
||||
return new RageFileObjMem( pFile );
|
||||
}
|
||||
|
||||
RageFileObjMemFile *pFile = (RageFileObjMemFile *) FDB->GetFilePriv( sPath );
|
||||
@@ -135,7 +134,7 @@ RageFileObj *RageFileDriverMem::Open( const CString &sPath, int mode, RageFile &
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new RageFileObjMem( pFile, p );
|
||||
return new RageFileObjMem( pFile );
|
||||
}
|
||||
|
||||
bool RageFileDriverMem::Remove( const CString &sPath )
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
RageFileDriverMem();
|
||||
~RageFileDriverMem();
|
||||
|
||||
RageFileObj *Open( const CString &sPath, int mode, RageFile &p, int &err );
|
||||
RageFileObj *Open( const CString &sPath, int mode, int &err );
|
||||
void FlushDirCache( const CString &sPath ) { }
|
||||
|
||||
bool Remove( const CString &sPath );
|
||||
|
||||
@@ -78,14 +78,14 @@ private:
|
||||
int decomp_buf_avail;
|
||||
|
||||
public:
|
||||
RageFileObjZipDeflated( const RageFile &f, const FileInfo &info, RageFile &p );
|
||||
RageFileObjZipDeflated( const RageFileObjZipDeflated &cpy, RageFile &p );
|
||||
RageFileObjZipDeflated( const RageFile &f, const FileInfo &info );
|
||||
RageFileObjZipDeflated( const RageFileObjZipDeflated &cpy );
|
||||
~RageFileObjZipDeflated();
|
||||
int Read(void *buffer, size_t bytes);
|
||||
int Write(const void *buffer, size_t bytes) { SetError( "Not implemented" ); return -1; }
|
||||
int Seek( int offset );
|
||||
int GetFileSize() { return info.uncompr_size; }
|
||||
RageFileObj *Copy( RageFile &p ) const
|
||||
RageFileObj *Copy() const
|
||||
{
|
||||
RageException::Throw( "Loading ZIPs from deflated ZIPs is currently disabled; see RageFileObjZipDeflated" );
|
||||
|
||||
@@ -101,16 +101,16 @@ private:
|
||||
int FilePos;
|
||||
|
||||
public:
|
||||
RageFileObjZipStored( const RageFile &f, const FileInfo &info, RageFile &p );
|
||||
RageFileObjZipStored( const RageFile &f, const FileInfo &info );
|
||||
int Read(void *buffer, size_t bytes);
|
||||
int Write(const void *buffer, size_t bytes) { SetError( "Not implemented" ); return -1; }
|
||||
|
||||
int Seek( int offset );
|
||||
int GetFileSize() { return info.uncompr_size; }
|
||||
|
||||
RageFileObj *Copy( RageFile &p ) const
|
||||
RageFileObj *Copy() const
|
||||
{
|
||||
RageFileObjZipStored *pRet = new RageFileObjZipStored( zip, info, p );
|
||||
RageFileObjZipStored *pRet = new RageFileObjZipStored( zip, info );
|
||||
pRet->FilePos = FilePos;
|
||||
return pRet;
|
||||
}
|
||||
@@ -383,7 +383,7 @@ RageFileDriverZip::~RageFileDriverZip()
|
||||
delete Files[i];
|
||||
}
|
||||
|
||||
RageFileObj *RageFileDriverZip::Open( const CString &path, int mode, RageFile &p, int &err )
|
||||
RageFileObj *RageFileDriverZip::Open( const CString &path, int mode, int &err )
|
||||
{
|
||||
if( mode == RageFile::WRITE )
|
||||
{
|
||||
@@ -434,9 +434,9 @@ RageFileObj *RageFileDriverZip::Open( const CString &path, int mode, RageFile &p
|
||||
switch( info->compression_method )
|
||||
{
|
||||
case STORED:
|
||||
return new RageFileObjZipStored( zip, *info, p );
|
||||
return new RageFileObjZipStored( zip, *info );
|
||||
case DEFLATED:
|
||||
return new RageFileObjZipDeflated( zip, *info, p );
|
||||
return new RageFileObjZipDeflated( zip, *info );
|
||||
default:
|
||||
/* unknown compression method */
|
||||
ASSERT( 0 );
|
||||
@@ -453,8 +453,7 @@ void RageFileDriverZip::FlushDirCache( const CString &sPath )
|
||||
|
||||
/* We make a copy of the RageFile: multiple files may read from the same ZIP at once;
|
||||
* this way, we don't have to keep seeking around. */
|
||||
RageFileObjZipDeflated::RageFileObjZipDeflated( const RageFile &f, const FileInfo &info_, RageFile &p ):
|
||||
RageFileObj( p ),
|
||||
RageFileObjZipDeflated::RageFileObjZipDeflated( const RageFile &f, const FileInfo &info_ ):
|
||||
info(info_),
|
||||
zip( f )
|
||||
{
|
||||
@@ -473,8 +472,8 @@ RageFileObjZipDeflated::RageFileObjZipDeflated( const RageFile &f, const FileInf
|
||||
CFilePos = UFilePos = 0;
|
||||
}
|
||||
|
||||
RageFileObjZipDeflated::RageFileObjZipDeflated( const RageFileObjZipDeflated &cpy, RageFile &p ):
|
||||
RageFileObj( p ),
|
||||
RageFileObjZipDeflated::RageFileObjZipDeflated( const RageFileObjZipDeflated &cpy ):
|
||||
RageFileObj( cpy ),
|
||||
info( cpy.info ),
|
||||
zip( cpy.zip )
|
||||
{
|
||||
@@ -606,8 +605,7 @@ int RageFileObjZipDeflated::Seek( int iPos )
|
||||
return UFilePos;
|
||||
}
|
||||
|
||||
RageFileObjZipStored::RageFileObjZipStored( const RageFile &f, const FileInfo &info_, RageFile &p ):
|
||||
RageFileObj( p ),
|
||||
RageFileObjZipStored::RageFileObjZipStored( const RageFile &f, const FileInfo &info_ ):
|
||||
info(info_),
|
||||
zip( f )
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
RageFileDriverZip( CString path );
|
||||
virtual ~RageFileDriverZip();
|
||||
|
||||
RageFileObj *Open( const CString &path, int mode, RageFile &p, int &err );
|
||||
RageFileObj *Open( const CString &path, int mode, int &err );
|
||||
void FlushDirCache( const CString &sPath );
|
||||
|
||||
private:
|
||||
|
||||
@@ -102,7 +102,7 @@ class RageFileDriverMountpoints: public RageFileDriver
|
||||
{
|
||||
public:
|
||||
RageFileDriverMountpoints(): RageFileDriver( new FilenameDB ) { }
|
||||
RageFileObj *Open( const CString &path, int mode, RageFile &p, int &err )
|
||||
RageFileObj *Open( const CString &path, int mode, int &err )
|
||||
{
|
||||
err = (mode == RageFile::WRITE)? ERROR_WRITING_NOT_SUPPORTED:ENOENT;
|
||||
return NULL;
|
||||
@@ -648,7 +648,7 @@ RageFileObj *RageFileManager::Open( CString sPath, int mode, RageFile &p, int &e
|
||||
/* If writing, we need to do a heuristic to figure out which driver to write with--there
|
||||
* may be several that will work. */
|
||||
if( mode & RageFile::WRITE )
|
||||
return OpenForWriting( sPath, mode, p, err );
|
||||
return OpenForWriting( sPath, mode, err );
|
||||
|
||||
NormalizePath( sPath );
|
||||
|
||||
@@ -662,7 +662,7 @@ RageFileObj *RageFileManager::Open( CString sPath, int mode, RageFile &p, int &e
|
||||
if( path.size() == 0 )
|
||||
continue;
|
||||
int error;
|
||||
RageFileObj *ret = ld.driver->Open( path, mode, p, error );
|
||||
RageFileObj *ret = ld.driver->Open( path, mode, error );
|
||||
if( ret )
|
||||
{
|
||||
AddReference( ret, ld.driver );
|
||||
@@ -688,7 +688,7 @@ RageFileObj *RageFileManager::CopyFileObj( const RageFileObj *cpy, RageFile &p )
|
||||
FileReferences::const_iterator it = g_Refs.find( cpy );
|
||||
ASSERT_M( it != g_Refs.end(), ssprintf( "CopyFileObj: Missing reference (%s)", cpy->GetDisplayPath().c_str() ) );
|
||||
|
||||
RageFileObj *ret = cpy->Copy( p );
|
||||
RageFileObj *ret = cpy->Copy();
|
||||
|
||||
/* It's from the same driver as the original. */
|
||||
AddReference( ret, it->second );
|
||||
@@ -696,7 +696,7 @@ RageFileObj *RageFileManager::CopyFileObj( const RageFileObj *cpy, RageFile &p )
|
||||
return ret;
|
||||
}
|
||||
|
||||
RageFileObj *RageFileManager::OpenForWriting( CString sPath, int mode, RageFile &p, int &err )
|
||||
RageFileObj *RageFileManager::OpenForWriting( CString sPath, int mode, int &err )
|
||||
{
|
||||
/*
|
||||
* The value for a driver to open a file is the number of directories and/or files
|
||||
@@ -748,7 +748,7 @@ RageFileObj *RageFileManager::OpenForWriting( CString sPath, int mode, RageFile
|
||||
ASSERT( path.size() );
|
||||
|
||||
int error;
|
||||
RageFileObj *ret = ld.driver->Open( path, mode, p, error );
|
||||
RageFileObj *ret = ld.driver->Open( path, mode, error );
|
||||
if( ret )
|
||||
{
|
||||
AddReference( ret, ld.driver );
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
RageFileObj *CopyFileObj( const RageFileObj *cpy, RageFile &p );
|
||||
|
||||
private:
|
||||
RageFileObj *OpenForWriting( CString sPath, int mode, RageFile &p, int &err );
|
||||
RageFileObj *OpenForWriting( CString sPath, int mode, int &err );
|
||||
};
|
||||
|
||||
extern RageFileManager *FILEMAN;
|
||||
|
||||
Reference in New Issue
Block a user