MinizipExtensions.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * MinizipExtensions.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "MinizipExtensions.h"
  12. voidpf ZCALLBACK CIOApi::openFileProxy(voidpf opaque, const void * filename, int mode)
  13. {
  14. assert(opaque != nullptr);
  15. std::string filename_s;
  16. if(filename != nullptr)
  17. filename_s = (const char *)filename;
  18. return ((CIOApi *)opaque)->openFile(filename_s, mode);
  19. }
  20. uLong ZCALLBACK CIOApi::readFileProxy(voidpf opaque, voidpf stream, void * buf, uLong size)
  21. {
  22. assert(opaque != nullptr);
  23. assert(stream != nullptr);
  24. CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
  25. return actualStream->read((ui8 *)buf, size);
  26. }
  27. uLong ZCALLBACK CIOApi::writeFileProxy(voidpf opaque, voidpf stream, const void * buf, uLong size)
  28. {
  29. assert(opaque != nullptr);
  30. assert(stream != nullptr);
  31. CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
  32. return (uLong)actualStream->write((const ui8 *)buf, size);
  33. }
  34. ZPOS64_T ZCALLBACK CIOApi::tellFileProxy(voidpf opaque, voidpf stream)
  35. {
  36. assert(opaque != nullptr);
  37. assert(stream != nullptr);
  38. CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
  39. return actualStream->tell();
  40. }
  41. long ZCALLBACK CIOApi::seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
  42. {
  43. assert(opaque != nullptr);
  44. assert(stream != nullptr);
  45. CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
  46. long ret = 0;
  47. switch (origin)
  48. {
  49. case ZLIB_FILEFUNC_SEEK_CUR :
  50. actualStream->skip(offset);//TODO: should we check actual skipped?
  51. break;
  52. case ZLIB_FILEFUNC_SEEK_END :
  53. ret = -1;
  54. break;
  55. case ZLIB_FILEFUNC_SEEK_SET :
  56. ret = actualStream->seek(offset);
  57. break;
  58. default: ret = -1;
  59. }
  60. return ret;
  61. }
  62. int ZCALLBACK CIOApi::closeFileProxy(voidpf opaque, voidpf stream)
  63. {
  64. assert(opaque != nullptr);
  65. assert(stream != nullptr);
  66. CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
  67. delete actualStream;
  68. return 0;
  69. }
  70. int ZCALLBACK CIOApi::errorFileProxy(voidpf opaque, voidpf stream)
  71. {
  72. return 0;
  73. }
  74. ///CIOApi
  75. zlib_filefunc64_def CIOApi::getApiStructure() const
  76. {
  77. zlib_filefunc64_def api;
  78. api.opaque = (void *) this;
  79. api.zopen64_file = &openFileProxy;
  80. api.zread_file = &readFileProxy;
  81. api.zwrite_file = &writeFileProxy;
  82. api.ztell64_file = &tellFileProxy;
  83. api.zseek64_file = &seekFileProxy;
  84. api.zclose_file = &closeFileProxy;
  85. api.zerror_file = &errorFileProxy;
  86. return api;
  87. }
  88. CDefaultIOApi::CDefaultIOApi()
  89. {
  90. }
  91. CDefaultIOApi::~CDefaultIOApi()
  92. {
  93. }
  94. zlib_filefunc64_def CDefaultIOApi::getApiStructure() const
  95. {
  96. zlib_filefunc64_def api;
  97. fill_fopen64_filefunc(&api);
  98. return api;
  99. }
  100. CInputOutputStream * CDefaultIOApi::openFile(const std::string& filename, int mode) const
  101. {
  102. throw new std::runtime_error("CDefaultIOApi::openFile call not expected.");
  103. }
  104. CZipArchive::CZipArchive(const CIOApi* api)
  105. {
  106. }
  107. CZipArchive::~CZipArchive()
  108. {
  109. }