2013-07-30 18:02:55 +03:00
|
|
|
/*
|
|
|
|
* CZipLoader.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
2013-07-30 18:02:55 +03:00
|
|
|
|
|
|
|
#include "ISimpleResourceLoader.h"
|
|
|
|
#include "CInputStream.h"
|
2013-11-08 23:36:26 +03:00
|
|
|
#include "ResourceID.h"
|
2013-07-30 18:02:55 +03:00
|
|
|
#include "CCompressedStream.h"
|
|
|
|
|
2015-08-11 15:56:07 +02:00
|
|
|
#include "MinizipExtensions.h"
|
2013-07-30 18:02:55 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2013-07-30 18:02:55 +03:00
|
|
|
class DLL_LINKAGE CZipStream : public CBufferedStream
|
|
|
|
{
|
|
|
|
unzFile file;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief constructs zip stream from already opened file
|
2015-08-11 15:56:07 +02:00
|
|
|
* @param api virtual filesystem interface
|
2013-07-30 18:02:55 +03:00
|
|
|
* @param archive path to archive to open
|
|
|
|
* @param filepos position of file to open
|
|
|
|
*/
|
2023-02-15 00:09:07 +02:00
|
|
|
CZipStream(const std::shared_ptr<CIOApi> & api, const boost::filesystem::path & archive, unz64_file_pos filepos);
|
2013-07-30 18:02:55 +03:00
|
|
|
~CZipStream();
|
|
|
|
|
2013-11-09 16:49:36 +03:00
|
|
|
si64 getSize() override;
|
|
|
|
ui32 calculateCRC32() override;
|
2013-07-30 18:02:55 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
si64 readMore(ui8 * data, si64 size) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CZipLoader : public ISimpleResourceLoader
|
|
|
|
{
|
2015-08-11 15:56:07 +02:00
|
|
|
std::shared_ptr<CIOApi> ioApi;
|
|
|
|
zlib_filefunc64_def zlibApi;
|
2016-01-16 17:36:16 +02:00
|
|
|
boost::filesystem::path archiveName;
|
2013-07-30 18:02:55 +03:00
|
|
|
std::string mountPoint;
|
|
|
|
|
2016-01-16 17:36:16 +02:00
|
|
|
std::unordered_map<ResourceID, unz64_file_pos> files;
|
2013-07-30 18:02:55 +03:00
|
|
|
|
2016-01-16 17:36:16 +02:00
|
|
|
std::unordered_map<ResourceID, unz64_file_pos> listFiles(const std::string & mountPoint, const boost::filesystem::path &archive);
|
2013-07-30 18:02:55 +03:00
|
|
|
public:
|
2016-02-04 09:27:51 +02:00
|
|
|
CZipLoader(const std::string & mountPoint, const boost::filesystem::path & archive, std::shared_ptr<CIOApi> api = std::shared_ptr<CIOApi>(new CDefaultIOApi()));
|
2013-07-30 18:02:55 +03:00
|
|
|
|
|
|
|
/// Interface implementation
|
|
|
|
/// @see ISimpleResourceLoader
|
|
|
|
std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
|
|
|
|
bool existsResource(const ResourceID & resourceName) const override;
|
|
|
|
std::string getMountPoint() const override;
|
2016-10-16 22:09:57 +02:00
|
|
|
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override {}
|
2013-07-30 18:02:55 +03:00
|
|
|
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
|
2013-08-19 14:50:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace ZipArchive
|
|
|
|
{
|
|
|
|
/// List all files present in archive
|
2023-02-15 00:09:07 +02:00
|
|
|
std::vector<std::string> DLL_LINKAGE listFiles(const boost::filesystem::path & filename);
|
2013-08-19 14:50:53 +03:00
|
|
|
|
|
|
|
/// extracts all files from archive "from" into destination directory "where". Directory must exist
|
2023-02-15 00:09:07 +02:00
|
|
|
bool DLL_LINKAGE extract(const boost::filesystem::path & from, const boost::filesystem::path & where);
|
2013-08-19 14:50:53 +03:00
|
|
|
|
|
|
|
///same as above, but extracts only files mentioned in "what" list
|
2023-02-15 00:09:07 +02:00
|
|
|
bool DLL_LINKAGE extract(const boost::filesystem::path & from, const boost::filesystem::path & where, const std::vector<std::string> & what);
|
2013-11-08 23:36:26 +03:00
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|