move some ZIP handling code into RageFileDriverSlice
This commit is contained in:
@@ -227,7 +227,8 @@ RageFile = \
|
||||
RageFileBasic.cpp RageFileBasic.h \
|
||||
RageFile.cpp RageFile.h RageFileDriver.cpp RageFileDriver.h RageFileManager.cpp RageFileManager.h \
|
||||
RageFileDriverDirect.cpp RageFileDriverDirect.h RageFileDriverDirectHelpers.cpp RageFileDriverDirectHelpers.h \
|
||||
RageFileDriverMemory.cpp RageFileDriverMemory.h RageFileDriverZip.cpp RageFileDriverZip.h
|
||||
RageFileDriverMemory.cpp RageFileDriverMemory.h RageFileDriverZip.cpp RageFileDriverZip.h \
|
||||
RageFileDriverSlice.cpp RageFileDriverSlice.h
|
||||
|
||||
Rage = $(Helpers) $(PCRE) $(RageFile) $(RageSoundFileReaders) \
|
||||
RageBitmapTexture.cpp RageBitmapTexture.h RageDisplay.cpp RageDisplay.h RageDisplay_OGL.cpp RageDisplay_OGL.h \
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
#include "global.h"
|
||||
#include "RageFileDriverSlice.h"
|
||||
|
||||
RageFileDriverSlice::RageFileDriverSlice( RageFileBasic *pFile, int iOffset, int iFileSize )
|
||||
{
|
||||
m_pFile = pFile;
|
||||
m_iOffset = iOffset;
|
||||
m_iFileSize = iFileSize;
|
||||
m_iFilePos = 0;
|
||||
}
|
||||
|
||||
RageFileDriverSlice::~RageFileDriverSlice()
|
||||
{
|
||||
delete m_pFile;
|
||||
}
|
||||
|
||||
RageFileBasic *RageFileDriverSlice::Copy() const
|
||||
{
|
||||
RageFileDriverSlice *pRet = new RageFileDriverSlice( m_pFile->Copy(), m_iOffset, m_iFileSize );
|
||||
pRet->m_iFilePos = m_iFilePos;
|
||||
return pRet;
|
||||
}
|
||||
|
||||
int RageFileDriverSlice::ReadInternal( void *buf, size_t bytes )
|
||||
{
|
||||
/* Make sure we're reading from the right place. We might have been constructed
|
||||
* with a file not pointing to iOffset. */
|
||||
m_pFile->Seek( m_iFilePos+m_iOffset );
|
||||
|
||||
const int bytes_left = m_iFileSize-this->m_iFilePos;
|
||||
const int got = m_pFile->Read( buf, min( (int) bytes, bytes_left ) );
|
||||
if( got == -1 )
|
||||
{
|
||||
SetError( m_pFile->GetError() );
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_iFilePos += got;
|
||||
|
||||
return got;
|
||||
}
|
||||
|
||||
|
||||
int RageFileDriverSlice::SeekInternal( int offset )
|
||||
{
|
||||
ASSERT( offset >= 0 );
|
||||
offset = min( offset, m_iFileSize );
|
||||
|
||||
int ret = m_pFile->Seek( m_iOffset + offset );
|
||||
if( ret == -1 )
|
||||
{
|
||||
SetError( m_pFile->GetError() );
|
||||
return -1;
|
||||
}
|
||||
ret -= m_iOffset;
|
||||
ASSERT( ret >= 0 );
|
||||
m_iFilePos = ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003-2004 Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/* RageFileDriverSlice - Treat a portion of a file as a file. */
|
||||
|
||||
#ifndef RAGE_FILE_DRIVER_SLICE_H
|
||||
#define RAGE_FILE_DRIVER_SLICE_H
|
||||
|
||||
#include "RageFileBasic.h"
|
||||
|
||||
class RageFileDriverSlice: public RageFileObj
|
||||
{
|
||||
public:
|
||||
/* pFile will be freed. */
|
||||
RageFileDriverSlice( RageFileBasic *pFile, int iOffset, int iFileSize );
|
||||
~RageFileDriverSlice();
|
||||
RageFileBasic *Copy() const;
|
||||
|
||||
int ReadInternal( void *pBuffer, size_t iBytes );
|
||||
int WriteInternal( const void *pBuffer, size_t iBytes ) { SetError( "Not implemented" ); return -1; }
|
||||
int SeekInternal( int iOffset );
|
||||
int GetFileSize() const { return m_iFileSize; }
|
||||
|
||||
private:
|
||||
RageFileBasic *m_pFile;
|
||||
int m_iFilePos;
|
||||
int m_iOffset, m_iFileSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003-2004 Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "global.h"
|
||||
#include "RageFileDriverZip.h"
|
||||
#include "RageFileDriverSlice.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageUtil.h"
|
||||
#include "RageUtil_FileDB.h"
|
||||
@@ -94,31 +95,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class RageFileObjZipStored: public RageFileObj
|
||||
{
|
||||
private:
|
||||
RageFileBasic *m_pFile;
|
||||
int m_iFilePos;
|
||||
int m_iOffset, m_iFileSize;
|
||||
|
||||
public:
|
||||
/* pFile will be freed. */
|
||||
RageFileObjZipStored( RageFileBasic *pFile, int iOffset, int iFileSize );
|
||||
~RageFileObjZipStored();
|
||||
|
||||
int ReadInternal( void *pBuffer, size_t iBytes );
|
||||
int WriteInternal( const void *pBuffer, size_t iBytes ) { SetError( "Not implemented" ); return -1; }
|
||||
int SeekInternal( int iOffset );
|
||||
int GetFileSize() const { return m_iFileSize; }
|
||||
|
||||
RageFileBasic *Copy() const
|
||||
{
|
||||
RageFileObjZipStored *pRet = new RageFileObjZipStored( m_pFile->Copy(), m_iOffset, m_iFileSize );
|
||||
pRet->m_iFilePos = m_iFilePos;
|
||||
return pRet;
|
||||
}
|
||||
};
|
||||
|
||||
RageFileDriverZip::RageFileDriverZip( CString path ):
|
||||
RageFileDriver( new NullFilenameDB )
|
||||
{
|
||||
@@ -434,7 +410,7 @@ RageFileBasic *RageFileDriverZip::Open( const CString &path, int mode, int &err
|
||||
|
||||
zip.Seek( info->data_offset );
|
||||
|
||||
RageFileBasic *pFile = new RageFileObjZipStored( zip.Copy(), info->data_offset, info->compr_size );
|
||||
RageFileBasic *pFile = new RageFileDriverSlice( zip.Copy(), info->data_offset, info->compr_size );
|
||||
switch( info->compression_method )
|
||||
{
|
||||
case STORED:
|
||||
@@ -485,6 +461,7 @@ RageFileObjZipDeflated::RageFileObjZipDeflated( const RageFileObjZipDeflated &cp
|
||||
m_pFile = cpy.m_pFile->Copy();
|
||||
inflateCopy( &dstrm, const_cast<z_streamp>(&cpy.dstrm) );
|
||||
|
||||
// memcpy decomp_buf?
|
||||
decomp_buf_ptr = decomp_buf + (cpy.decomp_buf_ptr - cpy.decomp_buf);
|
||||
decomp_buf_avail = cpy.decomp_buf_avail;
|
||||
m_iFilePos = cpy.m_iFilePos;
|
||||
@@ -603,57 +580,6 @@ int RageFileObjZipDeflated::SeekInternal( int iPos )
|
||||
return m_iFilePos;
|
||||
}
|
||||
|
||||
RageFileObjZipStored::RageFileObjZipStored( RageFileBasic *pFile, int iOffset, int iFileSize )
|
||||
{
|
||||
m_pFile = pFile;
|
||||
m_iOffset = iOffset;
|
||||
m_iFileSize = iFileSize;
|
||||
m_iFilePos = 0;
|
||||
}
|
||||
|
||||
RageFileObjZipStored::~RageFileObjZipStored()
|
||||
{
|
||||
delete m_pFile;
|
||||
}
|
||||
|
||||
int RageFileObjZipStored::ReadInternal( void *buf, size_t bytes )
|
||||
{
|
||||
/* Make sure we're reading from the right place. We might have been constructed
|
||||
* with a file not pointing to iOffset. */
|
||||
m_pFile->Seek( m_iFilePos+m_iOffset );
|
||||
|
||||
const int bytes_left = m_iFileSize-this->m_iFilePos;
|
||||
const int got = m_pFile->Read( buf, min( (int) bytes, bytes_left ) );
|
||||
if( got == -1 )
|
||||
{
|
||||
SetError( m_pFile->GetError() );
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_iFilePos += got;
|
||||
|
||||
return got;
|
||||
}
|
||||
|
||||
|
||||
int RageFileObjZipStored::SeekInternal( int offset )
|
||||
{
|
||||
ASSERT( offset >= 0 );
|
||||
offset = min( offset, m_iFileSize );
|
||||
|
||||
int ret = m_pFile->Seek( m_iOffset + offset );
|
||||
if( ret == -1 )
|
||||
{
|
||||
SetError( m_pFile->GetError() );
|
||||
return -1;
|
||||
}
|
||||
ret -= m_iOffset;
|
||||
ASSERT( ret >= 0 );
|
||||
m_iFilePos = ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990-2002 Info-ZIP. All rights reserved.
|
||||
* Copyright (c) 2003-2004 Glenn Maynard. All rights reserved.
|
||||
|
||||
Reference in New Issue
Block a user