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