1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Define bridge interface to minizip IOAPI

This commit is contained in:
AlexVinS 2015-08-11 14:44:47 +03:00 committed by AlexVinS
parent 8f209b17b6
commit b3ac146ba9
8 changed files with 159 additions and 6 deletions

View File

@ -19,6 +19,7 @@ set(lib_SRCS
filesystem/CZipLoader.cpp
filesystem/Filesystem.cpp
filesystem/ResourceID.cpp
filesystem/MinizipExtensions.cpp
mapObjects/CArmedInstance.cpp
mapObjects/CBank.cpp

View File

@ -222,6 +222,7 @@
<Unit filename="filesystem/CFileInputStream.h" />
<Unit filename="filesystem/CFilesystemLoader.cpp" />
<Unit filename="filesystem/CFilesystemLoader.h" />
<Unit filename="filesystem/CInputOutputStream.h" />
<Unit filename="filesystem/CInputStream.h" />
<Unit filename="filesystem/CMemoryBuffer.cpp" />
<Unit filename="filesystem/CMemoryBuffer.h" />
@ -234,6 +235,8 @@
<Unit filename="filesystem/Filesystem.cpp" />
<Unit filename="filesystem/Filesystem.h" />
<Unit filename="filesystem/ISimpleResourceLoader.h" />
<Unit filename="filesystem/MinizipExtensions.cpp" />
<Unit filename="filesystem/MinizipExtensions.h" />
<Unit filename="filesystem/ResourceID.cpp" />
<Unit filename="filesystem/ResourceID.h" />
<Unit filename="int3.h" />

View File

@ -0,0 +1,9 @@
#pragma once
#include "CInputStream.h"
#include "COutputStream.h"
class CInputOutputStream: public CInputStream, public COutputStream
{
};

View File

@ -18,7 +18,7 @@ CMemoryBuffer::CMemoryBuffer():
}
si64 CMemoryBuffer::write(ui8 * data, si64 size)
si64 CMemoryBuffer::write(const ui8 * data, si64 size)
{
buffer.reserve(tell()+size);

View File

@ -11,14 +11,14 @@
*/
#include "CInputStream.h"
#include "COutputStream.h"
#include "CInputOutputStream.h"
/**
* A class which provides IO memory buffer.
*/
class DLL_LINKAGE CMemoryBuffer : public CInputStream, public COutputStream
class DLL_LINKAGE CMemoryBuffer : public CInputOutputStream
{
public:
typedef std::vector<ui8> TBuffer;
@ -36,7 +36,7 @@ public:
* @param size The number of bytes to write.
* @return the number of bytes written actually.
*/
si64 write(ui8 * data, si64 size) override;
si64 write(const ui8 * data, si64 size) override;
/**
* Reads n bytes from the stream into the data buffer.

View File

@ -30,5 +30,5 @@ public:
* @param size The number of bytes to write.
* @return the number of bytes written actually.
*/
virtual si64 write(ui8 * data, si64 size) = 0;
virtual si64 write(const ui8 * data, si64 size) = 0;
};

View File

@ -0,0 +1,106 @@
/*
* 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"
static voidpf ZCALLBACK openFileProxy(voidpf opaque, const void * filename, int mode)
{
assert(opaque != nullptr);
std::string filename_s;
if(filename != nullptr)
filename_s = (const char *)filename;
return ((CIOApi *)opaque)->openFile(filename_s, mode);
}
static uLong ZCALLBACK readFileProxy(voidpf opaque, voidpf stream, void * buf, uLong size)
{
assert(opaque != nullptr);
assert(stream != nullptr);
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
return actualStream->read((ui8 *)buf, size);
}
static uLong ZCALLBACK writeFileProxy(voidpf opaque, voidpf stream, const void * buf, uLong size)
{
assert(opaque != nullptr);
assert(stream != nullptr);
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
return (uLong)actualStream->write((const ui8 *)buf, size);
}
static ZPOS64_T ZCALLBACK tellFileProxy(voidpf opaque, voidpf stream)
{
assert(opaque != nullptr);
assert(stream != nullptr);
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
return actualStream->tell();
}
static long ZCALLBACK seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
{
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;
}
static int ZCALLBACK closeFileProxy(voidpf opaque, voidpf stream)
{
assert(opaque != nullptr);
assert(stream != nullptr);
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
delete actualStream;
return 0;
}
static int ZCALLBACK errorFileProxy(voidpf opaque, voidpf stream)
{
return 0;
}
void CIOApi::fillApiStructure(zlib_filefunc64_def & api)
{
api.opaque = this;
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;
}

View File

@ -0,0 +1,34 @@
#pragma once
/*
* 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
*
*/
#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
#include "CInputOutputStream.h"
class CIOApi
{
public:
virtual ~CIOApi(){};
void fillApiStructure(zlib_filefunc64_def & api);
virtual CInputOutputStream * openFile(const std::string & filename, int mode) = 0;
};