123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #include "IOBase.h"
- #include "ZLib/ioapi.h"
- voidpf ZCALLBACK iobase_open_file_func OF((voidpf opaque, const char* filename, int mode));
- uLong ZCALLBACK iobase_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
- uLong ZCALLBACK iobase_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
- long ZCALLBACK iobase_tell_file_func OF((voidpf opaque, voidpf stream));
- long ZCALLBACK iobase_seek_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
- int ZCALLBACK iobase_close_file_func OF((voidpf opaque, voidpf stream));
- int ZCALLBACK iobase_error_file_func OF((voidpf opaque, voidpf stream));
- voidpf ZCALLBACK iobase_open_file_func (voidpf opaque,const char* filename,int mode)
- {
- CIOBase* _stream=NULL;
- if(opaque){
- _stream = (CIOBase*)opaque;
- _stream->OpenFile();
- }
- return _stream;
- }
- uLong ZCALLBACK iobase_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
- {
- uLong ret=0;
- CIOBase* _stream=NULL;
- if(stream!=NULL)
- _stream=( CIOBase* )stream;
- if(_stream!=NULL){
- if(ret =_stream->ReadFile(buf,size)){
- }
- }
- return ret;
- }
- uLong ZCALLBACK iobase_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
- {
- uLong ret=0;
- CIOBase* _stream=NULL;
- if(stream!=NULL)
- _stream=( CIOBase* )stream;
- if(_stream!=NULL){
- _stream->WriteFile(buf,size);
- ret = size;
- }
- return ret;
- }
- long ZCALLBACK iobase_tell_file_func (voidpf opaque,voidpf stream)
- {
- long ret=-1;
- CIOBase* _stream=NULL;
- if(stream!=NULL)
- _stream=( CIOBase* )stream;
- if(_stream!=NULL){
- ret=_stream->TellFile();
- }
- return ret;
- }
- long ZCALLBACK iobase_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
- {
- long dwMoveMethod=0xFFFFFFFF;
- long ret=-1;
- CIOBase* _stream=NULL;
- if(stream!=NULL)
- _stream=( CIOBase* )stream;
- switch (origin)
- {
- case ZLIB_FILEFUNC_SEEK_CUR :
- dwMoveMethod = CIOBase::CURRENT;
- break;
- case ZLIB_FILEFUNC_SEEK_END :
- dwMoveMethod = CIOBase::END;
- break;
- case ZLIB_FILEFUNC_SEEK_SET :
- dwMoveMethod = CIOBase::BEGIN;
- break;
- default: return -1;
- }
- if(_stream!=NULL){
- _stream->SeekFile(offset,dwMoveMethod);
- ret =0;
- }
- return ret;
- }
- int ZCALLBACK iobase_close_file_func (voidpf opaque, voidpf stream)
- {
- int ret=-1;
- CIOBase* _stream=NULL;
- if(stream!=NULL)
- _stream=( CIOBase* )stream;
- if(_stream!=NULL){
- _stream->CloseFile();
- ret=0;
- }
- return ret;
- }
- int ZCALLBACK iobase_error_file_func (voidpf opaque,voidpf stream)
- {
- int ret=-1;
- CIOBase* _stream=NULL;
- if(stream!=NULL){
- _stream=( CIOBase* )stream;
- ret =0;
- }
- return ret;
- }
- void fill_mfc_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
- {
- pzlib_filefunc_def->zopen_file = iobase_open_file_func;
- pzlib_filefunc_def->zread_file = iobase_read_file_func;
- pzlib_filefunc_def->zwrite_file = iobase_write_file_func;
- pzlib_filefunc_def->ztell_file = iobase_tell_file_func;
- pzlib_filefunc_def->zseek_file = iobase_seek_file_func;
- pzlib_filefunc_def->zclose_file = iobase_close_file_func;
- pzlib_filefunc_def->zerror_file = iobase_error_file_func;
- pzlib_filefunc_def->opaque = NULL;
- }
- CIOBase::CIOBase(void):m_pzlib_filefunc_def(NULL)
- {
- zlib_filefunc_def* pzlib_filefunc_def =new zlib_filefunc_def;
- m_pzlib_filefunc_def = pzlib_filefunc_def;
- fill_mfc_filefunc(pzlib_filefunc_def);
- pzlib_filefunc_def->opaque = this;
- }
- CIOBase::~CIOBase(void)
- {
- if(m_pzlib_filefunc_def!=NULL){
- delete m_pzlib_filefunc_def;
- m_pzlib_filefunc_def = NULL;
- }
- }
|