1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

More post-merge fixes

This commit is contained in:
AlexVinS 2016-02-05 09:28:36 +03:00
parent 483276b128
commit a3f0d1a94e
2 changed files with 40 additions and 44 deletions

View File

@ -11,28 +11,28 @@
#include "MinizipExtensions.h"
#include "CMemoryBuffer.h"
#include "FileStream.h"
///CIOApi
voidpf ZCALLBACK CIOApi::openFileProxy(voidpf opaque, const void * filename, int mode)
{
assert(opaque != nullptr);
std::string filename_s;
boost::filesystem::path path;
if(filename != nullptr)
filename_s = (const char *)filename;
return ((CIOApi *)opaque)->openFile(filename_s, mode);
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)
{
assert(opaque != nullptr);
assert(stream != nullptr);
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
return actualStream->read((ui8 *)buf, size);
}
@ -49,8 +49,8 @@ ZPOS64_T ZCALLBACK CIOApi::tellFileProxy(voidpf opaque, voidpf stream)
{
assert(opaque != nullptr);
assert(stream != nullptr);
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
return actualStream->tell();
}
@ -58,8 +58,8 @@ long ZCALLBACK CIOApi::seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T off
{
assert(opaque != nullptr);
assert(stream != nullptr);
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
long ret = 0;
switch (origin)
@ -73,7 +73,7 @@ long ZCALLBACK CIOApi::seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T off
const si64 pos = actualStream->getSize() - offset;
if(actualStream->seek(pos) != pos)
ret = -1;
}
}
break;
case ZLIB_FILEFUNC_SEEK_SET :
if(actualStream->seek(offset) != offset)
@ -82,7 +82,7 @@ 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("CIOApi::seekFileProxy: seek failed");
return ret;
}
@ -90,11 +90,11 @@ int ZCALLBACK CIOApi::closeFileProxy(voidpf opaque, voidpf stream)
{
assert(opaque != nullptr);
assert(stream != nullptr);
CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
((CIOApi *)opaque)->closeFile(actualStream);
return 0;
}
@ -113,8 +113,8 @@ zlib_filefunc64_def CIOApi::getApiStructure() const
api.ztell64_file = &tellFileProxy;
api.zseek64_file = &seekFileProxy;
api.zclose_file = &closeFileProxy;
api.zerror_file = &errorFileProxy;
api.zerror_file = &errorFileProxy;
return api;
}
@ -126,44 +126,40 @@ void CIOApi::closeFile(CInputOutputStream * stream) const
///CDefaultIOApi
CDefaultIOApi::CDefaultIOApi()
{
}
CDefaultIOApi::~CDefaultIOApi()
{
}
zlib_filefunc64_def CDefaultIOApi::getApiStructure() const
{
zlib_filefunc64_def api;
fill_fopen64_filefunc(&api);
return api;
return * FileStream::GetMinizipFilefunc();
}
CInputOutputStream * CDefaultIOApi::openFile(const std::string& filename, int mode) const
CInputOutputStream * CDefaultIOApi::openFile(const boost::filesystem::path & filename, int mode) const
{
throw new std::runtime_error("CDefaultIOApi::openFile call not expected.");
throw new std::runtime_error("CDefaultIOApi::openFile call not expected.");
}
///CProxyIOApi
CProxyIOApi::CProxyIOApi(CInputOutputStream * buffer):
data(buffer)
{
}
CProxyIOApi::~CProxyIOApi()
{
}
CInputOutputStream * CProxyIOApi::openFile(const std::string& filename, int mode) const
CInputOutputStream * CProxyIOApi::openFile(const boost::filesystem::path & filename, int mode) const
{
logGlobal->traceStream() << "CProxyIOApi: stream opened for " <<filename<<" with mode "<<mode;
logGlobal->traceStream() << "CProxyIOApi: stream opened for " <<filename.string() <<" with mode "<<mode;
data->seek(0);
return data;
}

View File

@ -27,20 +27,20 @@ class DLL_LINKAGE CIOApi
{
public:
virtual ~CIOApi(){};
virtual zlib_filefunc64_def getApiStructure() const;
protected:
virtual CInputOutputStream * openFile(const std::string & filename, int mode) const = 0;
protected:
virtual CInputOutputStream * openFile(const boost::filesystem::path & filename, int mode) const = 0;
///default implementation deletes stream object
virtual void closeFile(CInputOutputStream * stream) const;
private:
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 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);
@ -53,11 +53,11 @@ class DLL_LINKAGE CDefaultIOApi: public CIOApi
public:
CDefaultIOApi();
~CDefaultIOApi();
zlib_filefunc64_def getApiStructure() const override;
protected:
CInputOutputStream * openFile(const std::string & filename, int mode) const override;
CInputOutputStream * openFile(const boost::filesystem::path & filename, int mode) const override;
};
///redirects all file IO to single stream
@ -67,7 +67,7 @@ public:
CProxyIOApi(CInputOutputStream * buffer);
~CProxyIOApi();
protected:
CInputOutputStream * openFile(const std::string & filename, int mode) const override;
CInputOutputStream * openFile(const boost::filesystem::path & filename, int mode) const override;
void closeFile(CInputOutputStream * stream) const override;
private:
CInputOutputStream * data;