CZipSaver.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * CZipSaver.h, 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. #pragma once
  11. #include "COutputStream.h"
  12. #include "MinizipExtensions.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CZipSaver;
  15. class DLL_LINKAGE CZipOutputStream: public COutputStream
  16. {
  17. public:
  18. /**
  19. * @brief constructs zip stream from already opened file
  20. * @param archive archive handle, must be opened
  21. * @param archiveFilename name of file to write
  22. */
  23. explicit CZipOutputStream(CZipSaver * owner_, zipFile archive, const std::string & archiveFilename);
  24. ~CZipOutputStream();
  25. si64 write(const ui8 * data, si64 size) override;
  26. si64 seek(si64 position) override {return -1;};
  27. si64 tell() override {return 0;};
  28. si64 skip(si64 delta) override {return 0;};
  29. si64 getSize() override {return 0;};
  30. private:
  31. zipFile handle;
  32. CZipSaver * owner;
  33. };
  34. class DLL_LINKAGE CZipSaver
  35. {
  36. public:
  37. explicit CZipSaver(std::shared_ptr<CIOApi> api, const boost::filesystem::path & path);
  38. virtual ~CZipSaver();
  39. std::unique_ptr<COutputStream> addFile(const std::string & archiveFilename);
  40. private:
  41. std::shared_ptr<CIOApi> ioApi;
  42. zlib_filefunc64_def zipApi;
  43. zipFile handle;
  44. ///due to minizip design only one file stream may opened at a time
  45. COutputStream * activeStream;
  46. friend class CZipOutputStream;
  47. };
  48. VCMI_LIB_NAMESPACE_END