CZipLoader.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. /*
  3. * CZipLoader.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 "ISimpleResourceLoader.h"
  12. #include "CInputStream.h"
  13. #include "Filesystem.h"
  14. #include "CCompressedStream.h"
  15. // Necessary here in order to get all types
  16. #include "../minizip/unzip.h"
  17. class DLL_LINKAGE CZipStream : public CBufferedStream
  18. {
  19. unzFile file;
  20. public:
  21. /**
  22. * @brief constructs zip stream from already opened file
  23. * @param archive path to archive to open
  24. * @param filepos position of file to open
  25. */
  26. CZipStream(const std::string & archive, unz_file_pos filepos);
  27. ~CZipStream();
  28. si64 getSize();
  29. protected:
  30. si64 readMore(ui8 * data, si64 size) override;
  31. };
  32. class DLL_LINKAGE CZipLoader : public ISimpleResourceLoader
  33. {
  34. std::string archiveName;
  35. std::string mountPoint;
  36. std::unordered_map<ResourceID, unz_file_pos> files;
  37. std::unordered_map<ResourceID, unz_file_pos> listFiles(const std::string & mountPoint, const std::string &archive);
  38. public:
  39. CZipLoader(const std::string & mountPoint, const std::string & archive);
  40. /// Interface implementation
  41. /// @see ISimpleResourceLoader
  42. std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
  43. bool existsResource(const ResourceID & resourceName) const override;
  44. std::string getMountPoint() const override;
  45. std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
  46. };
  47. namespace ZipArchive
  48. {
  49. /// List all files present in archive
  50. std::vector<std::string> DLL_LINKAGE listFiles(std::string filename);
  51. /// extracts all files from archive "from" into destination directory "where". Directory must exist
  52. bool DLL_LINKAGE extract(std::string from, std::string where);
  53. ///same as above, but extracts only files mentioned in "what" list
  54. bool DLL_LINKAGE extract(std::string from, std::string where, std::vector<std::string> what);
  55. }