Load() methods, to allow error checking
This commit is contained in:
@@ -30,35 +30,64 @@ struct FileInfo
|
|||||||
int m_iCompressedSize, m_iUncompressedSize;
|
int m_iCompressedSize, m_iUncompressedSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
RageFileDriverZip::RageFileDriverZip():
|
||||||
|
RageFileDriver( new NullFilenameDB ),
|
||||||
|
m_Mutex( "RageFileDriverZip" )
|
||||||
|
{
|
||||||
|
m_bFileOwned = false;
|
||||||
|
m_pZip = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
RageFileDriverZip::RageFileDriverZip( CString sPath ):
|
RageFileDriverZip::RageFileDriverZip( CString sPath ):
|
||||||
RageFileDriver( new NullFilenameDB ),
|
RageFileDriver( new NullFilenameDB ),
|
||||||
m_Mutex( ssprintf("RageFileDriverZip(%s)", sPath.c_str()) )
|
m_Mutex( "RageFileDriverZip" )
|
||||||
{
|
{
|
||||||
|
m_bFileOwned = false;
|
||||||
|
m_pZip = NULL;
|
||||||
|
Load( sPath );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* deprecated */
|
||||||
|
RageFileDriverZip::RageFileDriverZip( RageFileBasic *pFile ):
|
||||||
|
RageFileDriver( new NullFilenameDB ),
|
||||||
|
m_Mutex( "RageFileDriverZip" )
|
||||||
|
{
|
||||||
|
m_bFileOwned = false;
|
||||||
|
m_pZip = NULL;
|
||||||
|
Load( pFile );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RageFileDriverZip::Load( const CString &sPath )
|
||||||
|
{
|
||||||
|
ASSERT( m_pZip == NULL ); /* don't load twice */
|
||||||
|
|
||||||
m_bFileOwned = true;
|
m_bFileOwned = true;
|
||||||
m_sPath = sPath;
|
m_sPath = sPath;
|
||||||
|
m_Mutex.SetName( ssprintf("RageFileDriverZip(%s)", sPath.c_str()) );
|
||||||
|
|
||||||
RageFile *pFile = new RageFile;
|
RageFile *pFile = new RageFile;
|
||||||
m_pZip = pFile;
|
|
||||||
|
|
||||||
if( !pFile->Open(sPath) )
|
if( !pFile->Open(sPath) )
|
||||||
{
|
{
|
||||||
LOG->Warn( "Couldn't open %s: %s", sPath.c_str(), pFile->GetError().c_str() );
|
LOG->Warn( "Couldn't open %s: %s", sPath.c_str(), pFile->GetError().c_str() );
|
||||||
return;
|
delete pFile;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseZipfile();
|
|
||||||
}
|
|
||||||
|
|
||||||
RageFileDriverZip::RageFileDriverZip( RageFileBasic *pFile ):
|
|
||||||
RageFileDriver( new NullFilenameDB ),
|
|
||||||
m_Mutex( ssprintf("RageFileDriverZip(%p)", pFile) )
|
|
||||||
{
|
|
||||||
m_sPath = ssprintf("%p", pFile);
|
|
||||||
|
|
||||||
m_bFileOwned = false;
|
|
||||||
m_pZip = pFile;
|
m_pZip = pFile;
|
||||||
|
|
||||||
ParseZipfile();
|
return ParseZipfile();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RageFileDriverZip::Load( RageFileBasic *pFile )
|
||||||
|
{
|
||||||
|
ASSERT( m_pZip == NULL ); /* don't load twice */
|
||||||
|
m_sPath = ssprintf("%p", pFile);
|
||||||
|
m_Mutex.SetName( ssprintf("RageFileDriverZip(%p)", pFile) );
|
||||||
|
|
||||||
|
m_pZip = pFile;
|
||||||
|
|
||||||
|
return ParseZipfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -118,18 +147,18 @@ bool RageFileDriverZip::SeekToEndCentralRecord()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageFileDriverZip::ParseZipfile()
|
bool RageFileDriverZip::ParseZipfile()
|
||||||
{
|
{
|
||||||
if( !SeekToEndCentralRecord() )
|
if( !SeekToEndCentralRecord() )
|
||||||
{
|
{
|
||||||
LOG->Warn( "Couldn't open %s: couldn't find end of central directory record", m_sPath.c_str() );
|
LOG->Warn( "Couldn't open %s: couldn't find end of central directory record", m_sPath.c_str() );
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the end of central directory record. */
|
/* Read the end of central directory record. */
|
||||||
int iTotalEntries, iCentralDirectoryOffset;
|
int iTotalEntries, iCentralDirectoryOffset;
|
||||||
if( !ReadEndCentralRecord(iTotalEntries, iCentralDirectoryOffset) )
|
if( !ReadEndCentralRecord(iTotalEntries, iCentralDirectoryOffset) )
|
||||||
return; /* warned already */
|
return false; /* warned already */
|
||||||
|
|
||||||
/* Seek to the start of the central file directory. */
|
/* Seek to the start of the central file directory. */
|
||||||
m_pZip->Seek( iCentralDirectoryOffset );
|
m_pZip->Seek( iCentralDirectoryOffset );
|
||||||
@@ -152,6 +181,8 @@ void RageFileDriverZip::ParseZipfile()
|
|||||||
|
|
||||||
if( m_pFiles.size() == 0 )
|
if( m_pFiles.size() == 0 )
|
||||||
LOG->Warn( "%s: no files found in central file header", m_sPath.c_str() );
|
LOG->Warn( "%s: no files found in central file header", m_sPath.c_str() );
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RageFileDriverZip::ProcessCdirFileHdr( FileInfo &info )
|
int RageFileDriverZip::ProcessCdirFileHdr( FileInfo &info )
|
||||||
@@ -311,8 +342,7 @@ RageFileBasic *RageFileDriverZip::Open( const CString &sPath, int iMode, int &iE
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
/* unknown compression method */
|
/* unknown compression method */
|
||||||
ASSERT( 0 );
|
iErr = ENOSYS;
|
||||||
iErr = EINVAL;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,12 @@ struct end_central_dir_record;
|
|||||||
class RageFileDriverZip: public RageFileDriver
|
class RageFileDriverZip: public RageFileDriver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
RageFileDriverZip();
|
||||||
RageFileDriverZip( CString sPath );
|
RageFileDriverZip( CString sPath );
|
||||||
RageFileDriverZip( RageFileBasic *pFile );
|
RageFileDriverZip( RageFileBasic *pFile );
|
||||||
|
bool Load( const CString &sPath );
|
||||||
|
bool Load( RageFileBasic *pFile );
|
||||||
|
|
||||||
virtual ~RageFileDriverZip();
|
virtual ~RageFileDriverZip();
|
||||||
|
|
||||||
RageFileBasic *Open( const CString &sPath, int iMode, int &iErr );
|
RageFileBasic *Open( const CString &sPath, int iMode, int &iErr );
|
||||||
@@ -32,7 +36,7 @@ private:
|
|||||||
* around in it when reading files. */
|
* around in it when reading files. */
|
||||||
RageMutex m_Mutex;
|
RageMutex m_Mutex;
|
||||||
|
|
||||||
void ParseZipfile();
|
bool ParseZipfile();
|
||||||
bool ReadEndCentralRecord( int &total_entries_central_dir, int &offset_start_central_directory );
|
bool ReadEndCentralRecord( int &total_entries_central_dir, int &offset_start_central_directory );
|
||||||
int ProcessCdirFileHdr( FileInfo &info );
|
int ProcessCdirFileHdr( FileInfo &info );
|
||||||
bool SeekToEndCentralRecord();
|
bool SeekToEndCentralRecord();
|
||||||
|
|||||||
Reference in New Issue
Block a user