2015-08-11 13:44:47 +02:00
|
|
|
/*
|
|
|
|
* MinizipExtensions.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 13:44:47 +02:00
|
|
|
|
|
|
|
#ifdef USE_SYSTEM_MINIZIP
|
|
|
|
#include <minizip/unzip.h>
|
|
|
|
#include <minizip/zip.h>
|
|
|
|
#include <minizip/ioapi.h>
|
|
|
|
#else
|
|
|
|
#include "../minizip/unzip.h"
|
|
|
|
#include "../minizip/zip.h"
|
|
|
|
#include "../minizip/ioapi.h"
|
|
|
|
#endif
|
2022-07-26 15:07:42 +02:00
|
|
|
|
2024-02-06 00:29:13 +02:00
|
|
|
// system zlib on old Androids isn't capable of using _64 functions: https://github.com/madler/zlib/pull/436
|
|
|
|
#if defined(__ANDROID_API__) && (__ANDROID_API__ < 24)
|
|
|
|
#define MINIZIP_NEEDS_32BIT_FUNCS 1
|
|
|
|
#endif
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2016-02-10 06:28:00 +02:00
|
|
|
class CInputStream;
|
2015-08-11 20:20:13 +02:00
|
|
|
class CInputOutputStream;
|
|
|
|
class CMemoryBuffer;
|
2015-08-11 13:44:47 +02:00
|
|
|
|
2015-08-11 15:56:07 +02:00
|
|
|
class DLL_LINKAGE CIOApi
|
2015-08-11 13:44:47 +02:00
|
|
|
{
|
|
|
|
public:
|
2023-02-15 00:09:07 +02:00
|
|
|
virtual ~CIOApi() = default;
|
2016-02-05 08:28:36 +02:00
|
|
|
|
2016-02-10 06:28:00 +02:00
|
|
|
virtual zlib_filefunc64_def getApiStructure() = 0;
|
2015-08-11 15:56:07 +02:00
|
|
|
};
|
2015-08-11 13:44:47 +02:00
|
|
|
|
2015-08-11 20:20:13 +02:00
|
|
|
///redirects back to minizip ioapi
|
|
|
|
//todo: replace with Virtual FileSystem interface
|
2015-08-11 15:56:07 +02:00
|
|
|
class DLL_LINKAGE CDefaultIOApi: public CIOApi
|
|
|
|
{
|
|
|
|
public:
|
2016-02-10 06:28:00 +02:00
|
|
|
zlib_filefunc64_def getApiStructure() override;
|
2024-02-06 00:29:13 +02:00
|
|
|
#if MINIZIP_NEEDS_32BIT_FUNCS
|
|
|
|
zlib_filefunc_def getApiStructure32();
|
|
|
|
#endif
|
2015-08-11 15:56:07 +02:00
|
|
|
};
|
|
|
|
|
2015-08-11 20:20:13 +02:00
|
|
|
///redirects all file IO to single stream
|
|
|
|
class DLL_LINKAGE CProxyIOApi: public CIOApi
|
2015-08-11 15:56:07 +02:00
|
|
|
{
|
|
|
|
public:
|
2015-08-11 20:20:13 +02:00
|
|
|
CProxyIOApi(CInputOutputStream * buffer);
|
2023-02-15 00:09:07 +02:00
|
|
|
~CProxyIOApi() override;
|
2016-02-10 06:28:00 +02:00
|
|
|
|
|
|
|
zlib_filefunc64_def getApiStructure() override;
|
2015-08-11 15:56:07 +02:00
|
|
|
private:
|
2016-02-10 06:28:00 +02:00
|
|
|
CInputOutputStream * openFile(const boost::filesystem::path & filename, int mode);
|
|
|
|
|
2015-08-11 20:20:13 +02:00
|
|
|
CInputOutputStream * data;
|
2016-02-10 06:28:00 +02:00
|
|
|
|
|
|
|
static voidpf ZCALLBACK openFileProxy(voidpf opaque, const void * filename, int mode);
|
|
|
|
static uLong ZCALLBACK readFileProxy(voidpf opaque, voidpf stream, void * buf, uLong size);
|
|
|
|
static uLong ZCALLBACK writeFileProxy(voidpf opaque, voidpf stream, const void * buf, uLong size);
|
|
|
|
static ZPOS64_T ZCALLBACK tellFileProxy(voidpf opaque, voidpf stream);
|
|
|
|
static long ZCALLBACK seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin);
|
|
|
|
static int ZCALLBACK closeFileProxy(voidpf opaque, voidpf stream);
|
|
|
|
static int ZCALLBACK errorFileProxy(voidpf opaque, voidpf stream);
|
2015-08-11 13:44:47 +02:00
|
|
|
};
|
2016-02-10 06:28:00 +02:00
|
|
|
|
|
|
|
///redirects all file IO to single stream read-only
|
|
|
|
class DLL_LINKAGE CProxyROIOApi: public CIOApi
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CProxyROIOApi(CInputStream * buffer);
|
2023-02-15 00:09:07 +02:00
|
|
|
~CProxyROIOApi() override;
|
2016-02-10 06:28:00 +02:00
|
|
|
|
|
|
|
zlib_filefunc64_def getApiStructure() override;
|
|
|
|
private:
|
|
|
|
CInputStream * openFile(const boost::filesystem::path & filename, int mode);
|
|
|
|
|
|
|
|
CInputStream * data;
|
|
|
|
|
|
|
|
static voidpf ZCALLBACK openFileProxy(voidpf opaque, const void * filename, int mode);
|
|
|
|
static uLong ZCALLBACK readFileProxy(voidpf opaque, voidpf stream, void * buf, uLong size);
|
|
|
|
static uLong ZCALLBACK writeFileProxy(voidpf opaque, voidpf stream, const void * buf, uLong size);
|
|
|
|
static ZPOS64_T ZCALLBACK tellFileProxy(voidpf opaque, voidpf stream);
|
|
|
|
static long ZCALLBACK seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin);
|
|
|
|
static int ZCALLBACK closeFileProxy(voidpf opaque, voidpf stream);
|
|
|
|
static int ZCALLBACK errorFileProxy(voidpf opaque, voidpf stream);
|
|
|
|
};
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|