simplify; use RageBasicFile instead of RageFileObj
This commit is contained in:
@@ -24,6 +24,11 @@ RageFile::RageFile( const RageFile &cpy ):
|
|||||||
m_Mode = cpy.m_Mode;
|
m_Mode = cpy.m_Mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RageBasicFile *RageFile::Copy() const
|
||||||
|
{
|
||||||
|
return new RageFile( *this );
|
||||||
|
}
|
||||||
|
|
||||||
CString RageFile::GetPath() const
|
CString RageFile::GetPath() const
|
||||||
{
|
{
|
||||||
if ( !IsOpen() )
|
if ( !IsOpen() )
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ public:
|
|||||||
* Flush() to flush pending data, in order to check for errors. */
|
* Flush() to flush pending data, in order to check for errors. */
|
||||||
virtual int Flush() = 0;
|
virtual int Flush() = 0;
|
||||||
|
|
||||||
|
/* This returns a descriptive path for the file, or "". */
|
||||||
|
virtual CString GetDisplayPath() const { return ""; }
|
||||||
|
|
||||||
|
virtual RageBasicFile *Copy() const = 0;
|
||||||
|
|
||||||
virtual int GetLine( CString &out ) = 0;
|
virtual int GetLine( CString &out ) = 0;
|
||||||
virtual int PutLine( const CString &str ) = 0;
|
virtual int PutLine( const CString &str ) = 0;
|
||||||
|
|
||||||
@@ -73,6 +78,7 @@ public:
|
|||||||
RageFile();
|
RageFile();
|
||||||
~RageFile() { Close(); }
|
~RageFile() { Close(); }
|
||||||
RageFile( const RageFile &cpy );
|
RageFile( const RageFile &cpy );
|
||||||
|
RageBasicFile *Copy() const;
|
||||||
|
|
||||||
/* Use GetRealPath to get the path this file was opened with; use that if you
|
/* Use GetRealPath to get the path this file was opened with; use that if you
|
||||||
* want a path that will probably get you the same file again.
|
* want a path that will probably get you the same file again.
|
||||||
@@ -116,7 +122,7 @@ protected:
|
|||||||
void SetError( const CString &err );
|
void SetError( const CString &err );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RageFileObj *m_File;
|
RageBasicFile *m_File;
|
||||||
CString m_Path;
|
CString m_Path;
|
||||||
CString m_sError;
|
CString m_sError;
|
||||||
int m_Mode;
|
int m_Mode;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class RageFileDriver
|
|||||||
public:
|
public:
|
||||||
RageFileDriver( FilenameDB *db ) { FDB = db; }
|
RageFileDriver( FilenameDB *db ) { FDB = db; }
|
||||||
virtual ~RageFileDriver();
|
virtual ~RageFileDriver();
|
||||||
virtual RageFileObj *Open( const CString &path, int mode, int &err ) = 0;
|
virtual RageBasicFile *Open( const CString &path, int mode, int &err ) = 0;
|
||||||
virtual void GetDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo );
|
virtual void GetDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo );
|
||||||
virtual RageFileManager::FileType GetFileType( const CString &sPath );
|
virtual RageFileManager::FileType GetFileType( const CString &sPath );
|
||||||
virtual int GetFileSizeInBytes( const CString &sFilePath );
|
virtual int GetFileSizeInBytes( const CString &sFilePath );
|
||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
|
|
||||||
virtual int GetFileSize() const = 0;
|
virtual int GetFileSize() const = 0;
|
||||||
virtual CString GetDisplayPath() const { return ""; }
|
virtual CString GetDisplayPath() const { return ""; }
|
||||||
virtual RageFileObj *Copy() const { FAIL_M( "Copying unimplemented" ); }
|
virtual RageBasicFile *Copy() const { FAIL_M( "Copying unimplemented" ); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int SeekInternal( int iOffset ) { FAIL_M( "Seeking unimplemented" ); }
|
virtual int SeekInternal( int iOffset ) { FAIL_M( "Seeking unimplemented" ); }
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
virtual int WriteInternal( const void *pBuffer, size_t iBytes );
|
virtual int WriteInternal( const void *pBuffer, size_t iBytes );
|
||||||
virtual int FlushInternal();
|
virtual int FlushInternal();
|
||||||
virtual int SeekInternal( int offset );
|
virtual int SeekInternal( int offset );
|
||||||
virtual RageFileObj *Copy() const;
|
virtual RageBasicFile *Copy() const;
|
||||||
virtual CString GetDisplayPath() const { return path; }
|
virtual CString GetDisplayPath() const { return path; }
|
||||||
virtual int GetFileSize() const;
|
virtual int GetFileSize() const;
|
||||||
};
|
};
|
||||||
@@ -158,7 +158,7 @@ bool RageFileDriverDirect::Remove( const CString &path )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RageFileObj *RageFileObjDirect::Copy() const
|
RageBasicFile *RageFileObjDirect::Copy() const
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
RageFileObj *ret = MakeFileObjDirect( path, m_iMode, err );
|
RageFileObj *ret = MakeFileObjDirect( path, m_iMode, err );
|
||||||
|
|||||||
@@ -83,14 +83,15 @@ int RageFileObjMem::GetFileSize() const
|
|||||||
return m_pFile->m_sBuf.size();
|
return m_pFile->m_sBuf.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
RageFileObjMem::RageFileObjMem( const RageFileObjMem &cpy )
|
RageFileObjMem::RageFileObjMem( const RageFileObjMem &cpy ):
|
||||||
|
RageFileObj( cpy )
|
||||||
{
|
{
|
||||||
m_pFile = cpy.m_pFile;
|
m_pFile = cpy.m_pFile;
|
||||||
m_iFilePos = cpy.m_iFilePos;
|
m_iFilePos = cpy.m_iFilePos;
|
||||||
RageFileObjMemFile::AddReference( m_pFile );
|
RageFileObjMemFile::AddReference( m_pFile );
|
||||||
}
|
}
|
||||||
|
|
||||||
RageFileObj *RageFileObjMem::Copy() const
|
RageBasicFile *RageFileObjMem::Copy() const
|
||||||
{
|
{
|
||||||
RageFileObjMem *pRet = new RageFileObjMem( *this );
|
RageFileObjMem *pRet = new RageFileObjMem( *this );
|
||||||
return pRet;
|
return pRet;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public:
|
|||||||
int WriteInternal( const void *buffer, size_t bytes );
|
int WriteInternal( const void *buffer, size_t bytes );
|
||||||
int SeekInternal( int offset );
|
int SeekInternal( int offset );
|
||||||
int GetFileSize() const;
|
int GetFileSize() const;
|
||||||
RageFileObj *Copy() const;
|
RageBasicFile *Copy() const;
|
||||||
|
|
||||||
/* Retrieve the contents of this file. */
|
/* Retrieve the contents of this file. */
|
||||||
const CString &GetString() const;
|
const CString &GetString() const;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public:
|
|||||||
int WriteInternal( const void *pBuffer, size_t iBytes ) { SetError( "Not implemented" ); return -1; }
|
int WriteInternal( const void *pBuffer, size_t iBytes ) { SetError( "Not implemented" ); return -1; }
|
||||||
int SeekInternal( int iOffset );
|
int SeekInternal( int iOffset );
|
||||||
int GetFileSize() const { return info.uncompr_size; }
|
int GetFileSize() const { return info.uncompr_size; }
|
||||||
RageFileObj *Copy() const
|
RageBasicFile *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" );
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ public:
|
|||||||
int SeekInternal( int iOffset );
|
int SeekInternal( int iOffset );
|
||||||
int GetFileSize() const { return info.uncompr_size; }
|
int GetFileSize() const { return info.uncompr_size; }
|
||||||
|
|
||||||
RageFileObj *Copy() const
|
RageBasicFile *Copy() const
|
||||||
{
|
{
|
||||||
RageFileObjZipStored *pRet = new RageFileObjZipStored( zip, info );
|
RageFileObjZipStored *pRet = new RageFileObjZipStored( zip, info );
|
||||||
pRet->FilePos = FilePos;
|
pRet->FilePos = FilePos;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ static RageEvent *g_Mutex;
|
|||||||
CString InitialWorkingDirectory;
|
CString InitialWorkingDirectory;
|
||||||
CString DirOfExecutable;
|
CString DirOfExecutable;
|
||||||
|
|
||||||
typedef map< const RageFileObj *, RageFileDriver * > FileReferences;
|
typedef map< const RageBasicFile *, RageFileDriver * > FileReferences;
|
||||||
static FileReferences g_Refs;
|
static FileReferences g_Refs;
|
||||||
|
|
||||||
struct LoadedDriver
|
struct LoadedDriver
|
||||||
@@ -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, int &err )
|
RageBasicFile *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;
|
||||||
@@ -593,11 +593,11 @@ static bool SortBySecond( const pair<int,int> &a, const pair<int,int> &b )
|
|||||||
return a.second < b.second;
|
return a.second < b.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddReference( const RageFileObj *obj, RageFileDriver *driver )
|
void AddReference( const RageBasicFile *obj, RageFileDriver *driver )
|
||||||
{
|
{
|
||||||
LockMut( *g_Mutex );
|
LockMut( *g_Mutex );
|
||||||
|
|
||||||
pair< const RageFileObj *, RageFileDriver * > ref;
|
pair< const RageBasicFile *, RageFileDriver * > ref;
|
||||||
ref.first = obj;
|
ref.first = obj;
|
||||||
ref.second = driver;
|
ref.second = driver;
|
||||||
|
|
||||||
@@ -607,7 +607,7 @@ void AddReference( const RageFileObj *obj, RageFileDriver *driver )
|
|||||||
ASSERT_M( ret.second, ssprintf( "RemoveReference: Duplicate reference (%s)", obj->GetDisplayPath().c_str() ) );
|
ASSERT_M( ret.second, ssprintf( "RemoveReference: Duplicate reference (%s)", obj->GetDisplayPath().c_str() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveReference( const RageFileObj *obj )
|
void RemoveReference( const RageBasicFile *obj )
|
||||||
{
|
{
|
||||||
LockMut( *g_Mutex );
|
LockMut( *g_Mutex );
|
||||||
|
|
||||||
@@ -638,7 +638,7 @@ static bool PathUsesSlowFlush( const CString &sPath )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Used only by RageFile: */
|
/* Used only by RageFile: */
|
||||||
RageFileObj *RageFileManager::Open( CString sPath, int mode, int &err )
|
RageBasicFile *RageFileManager::Open( CString sPath, int mode, int &err )
|
||||||
{
|
{
|
||||||
err = ENOENT;
|
err = ENOENT;
|
||||||
|
|
||||||
@@ -662,7 +662,7 @@ RageFileObj *RageFileManager::Open( CString sPath, int mode, int &err )
|
|||||||
if( path.size() == 0 )
|
if( path.size() == 0 )
|
||||||
continue;
|
continue;
|
||||||
int error;
|
int error;
|
||||||
RageFileObj *ret = ld.driver->Open( path, mode, error );
|
RageBasicFile *ret = ld.driver->Open( path, mode, error );
|
||||||
if( ret )
|
if( ret )
|
||||||
{
|
{
|
||||||
AddReference( ret, ld.driver );
|
AddReference( ret, ld.driver );
|
||||||
@@ -680,15 +680,15 @@ RageFileObj *RageFileManager::Open( CString sPath, int mode, int &err )
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy a RageFileObj for a new RageFile. */
|
/* Copy a RageBasicFile for a new RageFile. */
|
||||||
RageFileObj *RageFileManager::CopyFileObj( const RageFileObj *cpy )
|
RageBasicFile *RageFileManager::CopyFileObj( const RageBasicFile *cpy )
|
||||||
{
|
{
|
||||||
LockMut( *g_Mutex );
|
LockMut( *g_Mutex );
|
||||||
|
|
||||||
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();
|
RageBasicFile *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 )
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
RageFileObj *RageFileManager::OpenForWriting( CString sPath, int mode, int &err )
|
RageBasicFile *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, int &err
|
|||||||
ASSERT( path.size() );
|
ASSERT( path.size() );
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
RageFileObj *ret = ld.driver->Open( path, mode, error );
|
RageBasicFile *ret = ld.driver->Open( path, mode, error );
|
||||||
if( ret )
|
if( ret )
|
||||||
{
|
{
|
||||||
AddReference( ret, ld.driver );
|
AddReference( ret, ld.driver );
|
||||||
@@ -769,7 +769,7 @@ RageFileObj *RageFileManager::OpenForWriting( CString sPath, int mode, int &err
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageFileManager::Close( RageFileObj *obj )
|
void RageFileManager::Close( RageBasicFile *obj )
|
||||||
{
|
{
|
||||||
if( obj == NULL )
|
if( obj == NULL )
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
extern CString InitialWorkingDirectory;
|
extern CString InitialWorkingDirectory;
|
||||||
extern CString DirOfExecutable;
|
extern CString DirOfExecutable;
|
||||||
|
|
||||||
class RageFileObj;
|
|
||||||
class RageFileManager
|
class RageFileManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -45,12 +44,12 @@ public:
|
|||||||
void FlushDirCache( CString sPath );
|
void FlushDirCache( CString sPath );
|
||||||
|
|
||||||
/* Used only by RageFile: */
|
/* Used only by RageFile: */
|
||||||
RageFileObj *Open( CString sPath, int mode, int &err );
|
RageBasicFile *Open( CString sPath, int mode, int &err );
|
||||||
void Close( RageFileObj *obj );
|
void Close( RageBasicFile *obj );
|
||||||
RageFileObj *CopyFileObj( const RageFileObj *cpy );
|
RageBasicFile *CopyFileObj( const RageBasicFile *cpy );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RageFileObj *OpenForWriting( CString sPath, int mode, int &err );
|
RageBasicFile *OpenForWriting( CString sPath, int mode, int &err );
|
||||||
};
|
};
|
||||||
|
|
||||||
extern RageFileManager *FILEMAN;
|
extern RageFileManager *FILEMAN;
|
||||||
|
|||||||
Reference in New Issue
Block a user