io_mfc_file.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* iowin32.c -- IO base function header for compress/uncompress .zip
  2. Version 1.1, February 14h, 2010
  3. part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
  4. Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
  5. Modifications for Zip64 support
  6. Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
  7. For more info read MiniZip_info.txt
  8. */
  9. #include "stdafx.h"
  10. #include "io_mfc_file.h"
  11. #include <afx.h>
  12. #ifndef INVALID_HANDLE_VALUE
  13. #define INVALID_HANDLE_VALUE (0xFFFFFFFF)
  14. #endif
  15. #ifndef INVALID_SET_FILE_POINTER
  16. #define INVALID_SET_FILE_POINTER ((DWORD)-1)
  17. #endif
  18. voidpf ZCALLBACK mfc_open_file_func OF((voidpf opaque, const char* filename, int mode));
  19. uLong ZCALLBACK mfc_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
  20. uLong ZCALLBACK mfc_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
  21. long ZCALLBACK mfc_tell_file_func OF((voidpf opaque, voidpf stream));
  22. long ZCALLBACK mfc_seek_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
  23. int ZCALLBACK mfc_close_file_func OF((voidpf opaque, voidpf stream));
  24. int ZCALLBACK mfc_error_file_func OF((voidpf opaque, voidpf stream));
  25. voidpf ZCALLBACK mfc_open_file_func (voidpf opaque,const char* filename,int mode)
  26. {
  27. CFile* file=NULL;
  28. if(opaque){
  29. file = (CFile*)opaque;
  30. }
  31. return file;
  32. }
  33. uLong ZCALLBACK mfc_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
  34. {
  35. uLong ret=0;
  36. CFile* mem_file=NULL;
  37. if(stream!=NULL)
  38. mem_file=( CFile* )stream;
  39. if(mem_file!=NULL){
  40. if(ret =mem_file->Read(buf,size)){
  41. }
  42. }
  43. return ret;
  44. }
  45. uLong ZCALLBACK mfc_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
  46. {
  47. uLong ret=0;
  48. CFile* mem_file=NULL;
  49. if(stream!=NULL)
  50. mem_file=( CFile* )stream;
  51. if(mem_file!=NULL){
  52. mem_file->Write(buf,size);
  53. ret = size;
  54. }
  55. return ret;
  56. }
  57. long ZCALLBACK mfc_tell_file_func (voidpf opaque,voidpf stream)
  58. {
  59. long ret=-1;
  60. HANDLE hFile = NULL;
  61. CFile* mem_file=NULL;
  62. if(stream!=NULL)
  63. mem_file=( CFile* )stream;
  64. if(mem_file!=NULL){
  65. ret=mem_file->GetPosition();
  66. }
  67. return ret;
  68. }
  69. long ZCALLBACK mfc_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
  70. {
  71. DWORD dwMoveMethod=0xFFFFFFFF;
  72. long ret=-1;
  73. CFile* mem_file=NULL;
  74. if(stream!=NULL)
  75. mem_file=( CFile* )stream;
  76. switch (origin)
  77. {
  78. case ZLIB_FILEFUNC_SEEK_CUR :
  79. dwMoveMethod = FILE_CURRENT;
  80. break;
  81. case ZLIB_FILEFUNC_SEEK_END :
  82. dwMoveMethod = FILE_END;
  83. break;
  84. case ZLIB_FILEFUNC_SEEK_SET :
  85. dwMoveMethod = FILE_BEGIN;
  86. break;
  87. default: return -1;
  88. }
  89. if(mem_file!=NULL){
  90. mem_file->Seek(offset,origin);
  91. ret =0;
  92. }
  93. return ret;
  94. }
  95. int ZCALLBACK mfc_close_file_func (voidpf opaque, voidpf stream)
  96. {
  97. int ret=-1;
  98. CFile* mem_file=NULL;
  99. if(stream!=NULL)
  100. mem_file=( CFile* )stream;
  101. if(mem_file!=NULL){
  102. //mem_file->Close();
  103. ret=0;
  104. }
  105. return ret;
  106. }
  107. int ZCALLBACK mfc_error_file_func (voidpf opaque,voidpf stream)
  108. {
  109. int ret=-1;
  110. CFile* mem_file=NULL;
  111. if(stream!=NULL){
  112. mem_file=( CFile* )stream;
  113. ret =0;
  114. }
  115. return ret;
  116. }
  117. void fill_mfc_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
  118. {
  119. pzlib_filefunc_def->zopen_file = mfc_open_file_func;
  120. pzlib_filefunc_def->zread_file = mfc_read_file_func;
  121. pzlib_filefunc_def->zwrite_file = mfc_write_file_func;
  122. pzlib_filefunc_def->ztell_file = mfc_tell_file_func;
  123. pzlib_filefunc_def->zseek_file = mfc_seek_file_func;
  124. pzlib_filefunc_def->zclose_file = mfc_close_file_func;
  125. pzlib_filefunc_def->zerror_file = mfc_error_file_func;
  126. pzlib_filefunc_def->opaque = NULL;
  127. }