mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Complete json map format integration
This commit is contained in:
@@ -13,53 +13,31 @@
|
||||
#include "CMemoryBuffer.h"
|
||||
#include "FileStream.h"
|
||||
|
||||
///CIOApi
|
||||
voidpf ZCALLBACK CIOApi::openFileProxy(voidpf opaque, const void * filename, int mode)
|
||||
{
|
||||
assert(opaque != nullptr);
|
||||
|
||||
boost::filesystem::path path;
|
||||
|
||||
if(filename != nullptr)
|
||||
path = static_cast<const boost::filesystem::path::value_type *>(filename);
|
||||
|
||||
return ((CIOApi *)opaque)->openFile(path, mode);
|
||||
}
|
||||
|
||||
uLong ZCALLBACK CIOApi::readFileProxy(voidpf opaque, voidpf stream, void * buf, uLong size)
|
||||
template <class _Stream> inline uLong streamRead(voidpf opaque, voidpf stream, void * buf, uLong size)
|
||||
{
|
||||
assert(opaque != nullptr);
|
||||
assert(stream != nullptr);
|
||||
|
||||
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
|
||||
_Stream * actualStream = static_cast<_Stream *>(stream);
|
||||
|
||||
return actualStream->read((ui8 *)buf, size);
|
||||
}
|
||||
|
||||
uLong ZCALLBACK CIOApi::writeFileProxy(voidpf opaque, voidpf stream, const void * buf, uLong size)
|
||||
template <class _Stream> inline ZPOS64_T streamTell(voidpf opaque, voidpf stream)
|
||||
{
|
||||
assert(opaque != nullptr);
|
||||
assert(stream != nullptr);
|
||||
|
||||
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
|
||||
return (uLong)actualStream->write((const ui8 *)buf, size);
|
||||
}
|
||||
|
||||
ZPOS64_T ZCALLBACK CIOApi::tellFileProxy(voidpf opaque, voidpf stream)
|
||||
{
|
||||
assert(opaque != nullptr);
|
||||
assert(stream != nullptr);
|
||||
|
||||
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
|
||||
_Stream * actualStream = static_cast<_Stream *>(stream);
|
||||
return actualStream->tell();
|
||||
}
|
||||
|
||||
long ZCALLBACK CIOApi::seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
|
||||
template <class _Stream> inline long streamSeek(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
|
||||
{
|
||||
assert(opaque != nullptr);
|
||||
assert(stream != nullptr);
|
||||
|
||||
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
|
||||
_Stream * actualStream = static_cast<_Stream *>(stream);
|
||||
|
||||
long ret = 0;
|
||||
switch (origin)
|
||||
@@ -82,47 +60,24 @@ long ZCALLBACK CIOApi::seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T off
|
||||
default: ret = -1;
|
||||
}
|
||||
if(ret == -1)
|
||||
logGlobal->error("CIOApi::seekFileProxy: seek failed");
|
||||
logGlobal->error("Stream seek failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK CIOApi::closeFileProxy(voidpf opaque, voidpf stream)
|
||||
template <class _Stream> inline int streamProxyClose(voidpf opaque, voidpf stream)
|
||||
{
|
||||
assert(opaque != nullptr);
|
||||
assert(stream != nullptr);
|
||||
|
||||
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
|
||||
_Stream * actualStream = static_cast<_Stream *>(stream);
|
||||
|
||||
((CIOApi *)opaque)->closeFile(actualStream);
|
||||
logGlobal->traceStream() << "Proxy stream closed";
|
||||
|
||||
actualStream->seek(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZCALLBACK CIOApi::errorFileProxy(voidpf opaque, voidpf stream)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
zlib_filefunc64_def CIOApi::getApiStructure() const
|
||||
{
|
||||
zlib_filefunc64_def api;
|
||||
api.opaque = (void *) 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;
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
void CIOApi::closeFile(CInputOutputStream * stream) const
|
||||
{
|
||||
delete stream;
|
||||
}
|
||||
|
||||
///CDefaultIOApi
|
||||
CDefaultIOApi::CDefaultIOApi()
|
||||
{
|
||||
@@ -134,16 +89,11 @@ CDefaultIOApi::~CDefaultIOApi()
|
||||
|
||||
}
|
||||
|
||||
zlib_filefunc64_def CDefaultIOApi::getApiStructure() const
|
||||
zlib_filefunc64_def CDefaultIOApi::getApiStructure()
|
||||
{
|
||||
return * FileStream::GetMinizipFilefunc();
|
||||
}
|
||||
|
||||
CInputOutputStream * CDefaultIOApi::openFile(const boost::filesystem::path & filename, int mode) const
|
||||
{
|
||||
throw new std::runtime_error("CDefaultIOApi::openFile call not expected.");
|
||||
}
|
||||
|
||||
///CProxyIOApi
|
||||
CProxyIOApi::CProxyIOApi(CInputOutputStream * buffer):
|
||||
data(buffer)
|
||||
@@ -156,7 +106,68 @@ CProxyIOApi::~CProxyIOApi()
|
||||
|
||||
}
|
||||
|
||||
CInputOutputStream * CProxyIOApi::openFile(const boost::filesystem::path & filename, int mode) const
|
||||
zlib_filefunc64_def CProxyIOApi::getApiStructure()
|
||||
{
|
||||
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;
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
voidpf ZCALLBACK CProxyIOApi::openFileProxy(voidpf opaque, const void * filename, int mode)
|
||||
{
|
||||
assert(opaque != nullptr);
|
||||
|
||||
boost::filesystem::path path;
|
||||
|
||||
if(filename != nullptr)
|
||||
path = static_cast<const boost::filesystem::path::value_type *>(filename);
|
||||
|
||||
return ((CProxyIOApi *)opaque)->openFile(path, mode);
|
||||
}
|
||||
|
||||
uLong ZCALLBACK CProxyIOApi::readFileProxy(voidpf opaque, voidpf stream, void * buf, uLong size)
|
||||
{
|
||||
return streamRead<CInputOutputStream>(opaque, stream, buf, size);
|
||||
}
|
||||
|
||||
uLong ZCALLBACK CProxyIOApi::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);
|
||||
}
|
||||
|
||||
ZPOS64_T ZCALLBACK CProxyIOApi::tellFileProxy(voidpf opaque, voidpf stream)
|
||||
{
|
||||
return streamTell<CInputOutputStream>(opaque, stream);
|
||||
}
|
||||
|
||||
long ZCALLBACK CProxyIOApi::seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
|
||||
{
|
||||
return streamSeek<CInputOutputStream>(opaque, stream, offset, origin);
|
||||
}
|
||||
|
||||
int ZCALLBACK CProxyIOApi::closeFileProxy(voidpf opaque, voidpf stream)
|
||||
{
|
||||
return streamProxyClose<CInputOutputStream>(opaque, stream);
|
||||
}
|
||||
|
||||
int ZCALLBACK CProxyIOApi::errorFileProxy(voidpf opaque, voidpf stream)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CInputOutputStream * CProxyIOApi::openFile(const boost::filesystem::path & filename, int mode)
|
||||
{
|
||||
logGlobal->traceStream() << "CProxyIOApi: stream opened for " <<filename.string() <<" with mode "<<mode;
|
||||
|
||||
@@ -164,8 +175,80 @@ CInputOutputStream * CProxyIOApi::openFile(const boost::filesystem::path & filen
|
||||
return data;
|
||||
}
|
||||
|
||||
void CProxyIOApi::closeFile(CInputOutputStream * stream) const
|
||||
///CProxyROIOApi
|
||||
CProxyROIOApi::CProxyROIOApi(CInputStream * buffer):
|
||||
data(buffer)
|
||||
{
|
||||
logGlobal->traceStream() << "CProxyIOApi: stream closed";
|
||||
stream->seek(0);//stream is local singleton and even not owned, just seek
|
||||
|
||||
}
|
||||
|
||||
CProxyROIOApi::~CProxyROIOApi()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
zlib_filefunc64_def CProxyROIOApi::getApiStructure()
|
||||
{
|
||||
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;
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
CInputStream * CProxyROIOApi::openFile(const boost::filesystem::path& filename, int mode)
|
||||
{
|
||||
logGlobal->traceStream() << "CProxyIOApi: stream opened for " <<filename.string() <<" with mode "<<mode;
|
||||
|
||||
data->seek(0);
|
||||
return data;
|
||||
}
|
||||
|
||||
voidpf ZCALLBACK CProxyROIOApi::openFileProxy(voidpf opaque, const void* filename, int mode)
|
||||
{
|
||||
assert(opaque != nullptr);
|
||||
|
||||
boost::filesystem::path path;
|
||||
|
||||
if(filename != nullptr)
|
||||
path = static_cast<const boost::filesystem::path::value_type *>(filename);
|
||||
|
||||
return ((CProxyROIOApi *)opaque)->openFile(path, mode);
|
||||
}
|
||||
|
||||
uLong ZCALLBACK CProxyROIOApi::readFileProxy(voidpf opaque, voidpf stream, void * buf, uLong size)
|
||||
{
|
||||
return streamRead<CInputStream>(opaque, stream, buf, size);
|
||||
}
|
||||
|
||||
uLong ZCALLBACK CProxyROIOApi::writeFileProxy(voidpf opaque, voidpf stream, const void* buf, uLong size)
|
||||
{
|
||||
logGlobal->errorStream() << "Attempt to write to read-only stream";
|
||||
return 0;
|
||||
}
|
||||
|
||||
ZPOS64_T ZCALLBACK CProxyROIOApi::tellFileProxy(voidpf opaque, voidpf stream)
|
||||
{
|
||||
return streamTell<CInputStream>(opaque, stream);
|
||||
}
|
||||
|
||||
long ZCALLBACK CProxyROIOApi::seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
|
||||
{
|
||||
return streamSeek<CInputStream>(opaque, stream, offset, origin);
|
||||
}
|
||||
|
||||
int ZCALLBACK CProxyROIOApi::closeFileProxy(voidpf opaque, voidpf stream)
|
||||
{
|
||||
return streamProxyClose<CInputStream>(opaque, stream);
|
||||
}
|
||||
|
||||
int ZCALLBACK CProxyROIOApi::errorFileProxy(voidpf opaque, voidpf stream)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user