IOBase.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include "IOBase.h"
  2. #include "ZLib/ioapi.h"
  3. voidpf ZCALLBACK iobase_open_file_func OF((voidpf opaque, const char* filename, int mode));
  4. uLong ZCALLBACK iobase_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
  5. uLong ZCALLBACK iobase_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
  6. long ZCALLBACK iobase_tell_file_func OF((voidpf opaque, voidpf stream));
  7. long ZCALLBACK iobase_seek_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
  8. int ZCALLBACK iobase_close_file_func OF((voidpf opaque, voidpf stream));
  9. int ZCALLBACK iobase_error_file_func OF((voidpf opaque, voidpf stream));
  10. voidpf ZCALLBACK iobase_open_file_func (voidpf opaque,const char* filename,int mode)
  11. {
  12. CIOBase* _stream=NULL;
  13. if(opaque){
  14. _stream = (CIOBase*)opaque;
  15. _stream->OpenFile();
  16. }
  17. return _stream;
  18. }
  19. uLong ZCALLBACK iobase_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
  20. {
  21. uLong ret=0;
  22. CIOBase* _stream=NULL;
  23. if(stream!=NULL)
  24. _stream=( CIOBase* )stream;
  25. if(_stream!=NULL){
  26. if(ret =_stream->ReadFile(buf,size)){
  27. }
  28. }
  29. return ret;
  30. }
  31. uLong ZCALLBACK iobase_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
  32. {
  33. uLong ret=0;
  34. CIOBase* _stream=NULL;
  35. if(stream!=NULL)
  36. _stream=( CIOBase* )stream;
  37. if(_stream!=NULL){
  38. _stream->WriteFile(buf,size);
  39. ret = size;
  40. }
  41. return ret;
  42. }
  43. long ZCALLBACK iobase_tell_file_func (voidpf opaque,voidpf stream)
  44. {
  45. long ret=-1;
  46. CIOBase* _stream=NULL;
  47. if(stream!=NULL)
  48. _stream=( CIOBase* )stream;
  49. if(_stream!=NULL){
  50. ret=_stream->TellFile();
  51. }
  52. return ret;
  53. }
  54. long ZCALLBACK iobase_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
  55. {
  56. long dwMoveMethod=0xFFFFFFFF;
  57. long ret=-1;
  58. CIOBase* _stream=NULL;
  59. if(stream!=NULL)
  60. _stream=( CIOBase* )stream;
  61. switch (origin)
  62. {
  63. case ZLIB_FILEFUNC_SEEK_CUR :
  64. dwMoveMethod = CIOBase::CURRENT;
  65. break;
  66. case ZLIB_FILEFUNC_SEEK_END :
  67. dwMoveMethod = CIOBase::END;
  68. break;
  69. case ZLIB_FILEFUNC_SEEK_SET :
  70. dwMoveMethod = CIOBase::BEGIN;
  71. break;
  72. default: return -1;
  73. }
  74. if(_stream!=NULL){
  75. _stream->SeekFile(offset,dwMoveMethod);
  76. ret =0;
  77. }
  78. return ret;
  79. }
  80. int ZCALLBACK iobase_close_file_func (voidpf opaque, voidpf stream)
  81. {
  82. int ret=-1;
  83. CIOBase* _stream=NULL;
  84. if(stream!=NULL)
  85. _stream=( CIOBase* )stream;
  86. if(_stream!=NULL){
  87. _stream->CloseFile();
  88. ret=0;
  89. }
  90. return ret;
  91. }
  92. int ZCALLBACK iobase_error_file_func (voidpf opaque,voidpf stream)
  93. {
  94. int ret=-1;
  95. CIOBase* _stream=NULL;
  96. if(stream!=NULL){
  97. _stream=( CIOBase* )stream;
  98. ret =0;
  99. }
  100. return ret;
  101. }
  102. void fill_mfc_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
  103. {
  104. pzlib_filefunc_def->zopen_file = iobase_open_file_func;
  105. pzlib_filefunc_def->zread_file = iobase_read_file_func;
  106. pzlib_filefunc_def->zwrite_file = iobase_write_file_func;
  107. pzlib_filefunc_def->ztell_file = iobase_tell_file_func;
  108. pzlib_filefunc_def->zseek_file = iobase_seek_file_func;
  109. pzlib_filefunc_def->zclose_file = iobase_close_file_func;
  110. pzlib_filefunc_def->zerror_file = iobase_error_file_func;
  111. pzlib_filefunc_def->opaque = NULL;
  112. }
  113. CIOBase::CIOBase(void):m_pzlib_filefunc_def(NULL)
  114. {
  115. zlib_filefunc_def* pzlib_filefunc_def =new zlib_filefunc_def;
  116. m_pzlib_filefunc_def = pzlib_filefunc_def;
  117. fill_mfc_filefunc(pzlib_filefunc_def);
  118. pzlib_filefunc_def->opaque = this;
  119. }
  120. CIOBase::~CIOBase(void)
  121. {
  122. if(m_pzlib_filefunc_def!=NULL){
  123. delete m_pzlib_filefunc_def;
  124. m_pzlib_filefunc_def = NULL;
  125. }
  126. }