2015-08-11 20:20:13 +02:00
|
|
|
/*
|
|
|
|
* CZipSaver.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
|
2015-08-11 20:20:13 +02:00
|
|
|
|
|
|
|
#include "COutputStream.h"
|
|
|
|
|
|
|
|
#include "MinizipExtensions.h"
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2015-08-12 02:31:06 +02:00
|
|
|
class CZipSaver;
|
|
|
|
|
2015-08-11 20:20:13 +02:00
|
|
|
class DLL_LINKAGE CZipOutputStream: public COutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief constructs zip stream from already opened file
|
|
|
|
* @param archive archive handle, must be opened
|
|
|
|
* @param archiveFilename name of file to write
|
2017-06-14 10:56:35 +02:00
|
|
|
*/
|
2015-08-12 02:31:06 +02:00
|
|
|
explicit CZipOutputStream(CZipSaver * owner_, zipFile archive, const std::string & archiveFilename);
|
2015-08-11 20:20:13 +02:00
|
|
|
~CZipOutputStream();
|
2017-06-14 10:56:35 +02:00
|
|
|
|
2015-08-11 20:20:13 +02:00
|
|
|
si64 write(const ui8 * data, si64 size) override;
|
|
|
|
|
|
|
|
si64 seek(si64 position) override {return -1;};
|
|
|
|
si64 tell() override {return 0;};
|
|
|
|
si64 skip(si64 delta) override {return 0;};
|
2017-06-14 10:56:35 +02:00
|
|
|
si64 getSize() override {return 0;};
|
2015-08-11 20:20:13 +02:00
|
|
|
private:
|
|
|
|
zipFile handle;
|
2015-08-12 02:31:06 +02:00
|
|
|
CZipSaver * owner;
|
2015-08-11 20:20:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CZipSaver
|
|
|
|
{
|
2017-06-14 10:56:35 +02:00
|
|
|
public:
|
|
|
|
explicit CZipSaver(std::shared_ptr<CIOApi> api, const boost::filesystem::path & path);
|
2015-08-11 20:20:13 +02:00
|
|
|
virtual ~CZipSaver();
|
2017-06-14 10:56:35 +02:00
|
|
|
|
2015-08-11 20:20:13 +02:00
|
|
|
std::unique_ptr<COutputStream> addFile(const std::string & archiveFilename);
|
|
|
|
private:
|
|
|
|
std::shared_ptr<CIOApi> ioApi;
|
2017-06-14 10:56:35 +02:00
|
|
|
zlib_filefunc64_def zipApi;
|
|
|
|
|
2015-08-11 20:20:13 +02:00
|
|
|
zipFile handle;
|
2017-06-14 10:56:35 +02:00
|
|
|
|
2015-08-11 20:20:13 +02:00
|
|
|
///due to minizip design only one file stream may opened at a time
|
|
|
|
COutputStream * activeStream;
|
2015-08-12 02:31:06 +02:00
|
|
|
friend class CZipOutputStream;
|
2015-08-11 20:20:13 +02:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|