2015-08-11 13:44:47 +02:00
|
|
|
/*
|
|
|
|
* MinizipExtensions.cpp, 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
|
|
|
|
#include "MinizipExtensions.h"
|
|
|
|
|
2015-08-11 15:56:07 +02:00
|
|
|
voidpf ZCALLBACK CIOApi::openFileProxy(voidpf opaque, const void * filename, int mode)
|
2015-08-11 13:44:47 +02:00
|
|
|
{
|
|
|
|
assert(opaque != nullptr);
|
|
|
|
|
|
|
|
std::string filename_s;
|
|
|
|
|
|
|
|
if(filename != nullptr)
|
|
|
|
filename_s = (const char *)filename;
|
|
|
|
|
|
|
|
return ((CIOApi *)opaque)->openFile(filename_s, mode);
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:56:07 +02:00
|
|
|
uLong ZCALLBACK CIOApi::readFileProxy(voidpf opaque, voidpf stream, void * buf, uLong size)
|
2015-08-11 13:44:47 +02:00
|
|
|
{
|
|
|
|
assert(opaque != nullptr);
|
|
|
|
assert(stream != nullptr);
|
|
|
|
|
|
|
|
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
|
|
|
|
|
|
|
|
return actualStream->read((ui8 *)buf, size);
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:56:07 +02:00
|
|
|
uLong ZCALLBACK CIOApi::writeFileProxy(voidpf opaque, voidpf stream, const void * buf, uLong size)
|
2015-08-11 13:44:47 +02:00
|
|
|
{
|
|
|
|
assert(opaque != nullptr);
|
|
|
|
assert(stream != nullptr);
|
|
|
|
|
|
|
|
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
|
|
|
|
return (uLong)actualStream->write((const ui8 *)buf, size);
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:56:07 +02:00
|
|
|
ZPOS64_T ZCALLBACK CIOApi::tellFileProxy(voidpf opaque, voidpf stream)
|
2015-08-11 13:44:47 +02:00
|
|
|
{
|
|
|
|
assert(opaque != nullptr);
|
|
|
|
assert(stream != nullptr);
|
|
|
|
|
|
|
|
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
|
|
|
|
return actualStream->tell();
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:56:07 +02:00
|
|
|
long ZCALLBACK CIOApi::seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
|
2015-08-11 13:44:47 +02:00
|
|
|
{
|
|
|
|
assert(opaque != nullptr);
|
|
|
|
assert(stream != nullptr);
|
|
|
|
|
|
|
|
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
|
|
|
|
|
|
|
|
long ret = 0;
|
|
|
|
switch (origin)
|
|
|
|
{
|
|
|
|
case ZLIB_FILEFUNC_SEEK_CUR :
|
|
|
|
actualStream->skip(offset);//TODO: should we check actual skipped?
|
|
|
|
break;
|
|
|
|
case ZLIB_FILEFUNC_SEEK_END :
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
case ZLIB_FILEFUNC_SEEK_SET :
|
|
|
|
ret = actualStream->seek(offset);
|
|
|
|
break;
|
|
|
|
default: ret = -1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:56:07 +02:00
|
|
|
int ZCALLBACK CIOApi::closeFileProxy(voidpf opaque, voidpf stream)
|
2015-08-11 13:44:47 +02:00
|
|
|
{
|
|
|
|
assert(opaque != nullptr);
|
|
|
|
assert(stream != nullptr);
|
|
|
|
|
|
|
|
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
|
|
|
|
|
|
|
|
delete actualStream;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:56:07 +02:00
|
|
|
int ZCALLBACK CIOApi::errorFileProxy(voidpf opaque, voidpf stream)
|
2015-08-11 13:44:47 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:56:07 +02:00
|
|
|
///CIOApi
|
|
|
|
zlib_filefunc64_def CIOApi::getApiStructure() const
|
2015-08-11 13:44:47 +02:00
|
|
|
{
|
2015-08-11 15:56:07 +02:00
|
|
|
zlib_filefunc64_def api;
|
|
|
|
api.opaque = (void *) this;
|
2015-08-11 13:44:47 +02:00
|
|
|
api.zopen64_file = &openFileProxy;
|
|
|
|
api.zread_file = &readFileProxy;
|
|
|
|
api.zwrite_file = &writeFileProxy;
|
|
|
|
api.ztell64_file = &tellFileProxy;
|
|
|
|
api.zseek64_file = &seekFileProxy;
|
|
|
|
api.zclose_file = &closeFileProxy;
|
|
|
|
api.zerror_file = &errorFileProxy;
|
2015-08-11 15:56:07 +02:00
|
|
|
|
|
|
|
return api;
|
|
|
|
}
|
|
|
|
|
|
|
|
CDefaultIOApi::CDefaultIOApi()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CDefaultIOApi::~CDefaultIOApi()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
zlib_filefunc64_def CDefaultIOApi::getApiStructure() const
|
|
|
|
{
|
|
|
|
zlib_filefunc64_def api;
|
|
|
|
|
|
|
|
fill_fopen64_filefunc(&api);
|
|
|
|
|
|
|
|
return api;
|
|
|
|
}
|
|
|
|
|
|
|
|
CInputOutputStream * CDefaultIOApi::openFile(const std::string& filename, int mode) const
|
|
|
|
{
|
|
|
|
throw new std::runtime_error("CDefaultIOApi::openFile call not expected.");
|
|
|
|
}
|
|
|
|
|
|
|
|
CZipArchive::CZipArchive(const CIOApi* api)
|
|
|
|
{
|
|
|
|
|
2015-08-11 13:44:47 +02:00
|
|
|
}
|
|
|
|
|
2015-08-11 15:56:07 +02:00
|
|
|
CZipArchive::~CZipArchive()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|