CZipSaver.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. /*
  3. * CZipSaver.h, part of VCMI engine
  4. *
  5. * Authors: listed in file AUTHORS in main folder
  6. *
  7. * License: GNU General Public License v2.0 or later
  8. * Full text of license available in license.txt file, in main folder
  9. *
  10. */
  11. #include "COutputStream.h"
  12. #include "MinizipExtensions.h"
  13. class CZipSaver;
  14. class DLL_LINKAGE CZipOutputStream: public COutputStream
  15. {
  16. public:
  17. /**
  18. * @brief constructs zip stream from already opened file
  19. * @param archive archive handle, must be opened
  20. * @param archiveFilename name of file to write
  21. */
  22. explicit CZipOutputStream(CZipSaver * owner_, zipFile archive, const std::string & archiveFilename);
  23. ~CZipOutputStream();
  24. si64 write(const ui8 * data, si64 size) override;
  25. si64 seek(si64 position) override {return -1;};
  26. si64 tell() override {return 0;};
  27. si64 skip(si64 delta) override {return 0;};
  28. si64 getSize() override {return 0;};
  29. private:
  30. zipFile handle;
  31. CZipSaver * owner;
  32. };
  33. class DLL_LINKAGE CZipSaver
  34. {
  35. public:
  36. explicit CZipSaver(std::shared_ptr<CIOApi> api, const boost::filesystem::path & path);
  37. virtual ~CZipSaver();
  38. std::unique_ptr<COutputStream> addFile(const std::string & archiveFilename);
  39. private:
  40. std::shared_ptr<CIOApi> ioApi;
  41. zlib_filefunc64_def zipApi;
  42. zipFile handle;
  43. ///due to minizip design only one file stream may opened at a time
  44. COutputStream * activeStream;
  45. friend class CZipOutputStream;
  46. };