1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-25 21:38:59 +02:00

Wip on zip serialize fixes

This commit is contained in:
AlexVinS 2015-08-13 03:29:13 +03:00 committed by AlexVinS
parent 27a29bd035
commit f2164abf1b
6 changed files with 32 additions and 9 deletions

View File

@ -75,6 +75,8 @@ public:
* @return the length in bytes of the stream.
*/
si64 getSize() override;
const TBuffer & getBuffer(){return buffer;}
private:
/** Actual data. */

View File

@ -66,6 +66,9 @@ std::unordered_map<ResourceID, unz_file_pos> CZipLoader::listFiles(const std::st
std::unordered_map<ResourceID, unz_file_pos> ret;
unzFile file = unzOpen2_64(archive.c_str(), &zlibApi);
if(file == nullptr)
logGlobal->errorStream() << archive << " failed to open";
if (unzGoToFirstFile(file) == UNZ_OK)
{

View File

@ -18,7 +18,7 @@ CZipOutputStream::CZipOutputStream(CZipSaver * owner_, zipFile archive, const st
{
//zip_fileinfo fileInfo;
zipOpenNewFileInZip(handle,
int status = zipOpenNewFileInZip(handle,
archiveFilename.c_str(),
nullptr,//todo: use fileInfo,
nullptr,
@ -28,6 +28,10 @@ CZipOutputStream::CZipOutputStream(CZipSaver * owner_, zipFile archive, const st
"",
Z_DEFLATED,
Z_DEFAULT_COMPRESSION);
if(status != ZIP_OK)
throw new std::runtime_error("CZipOutputStream: zipOpenNewFileInZip failed");
owner->activeStream = this;
}
@ -57,7 +61,7 @@ CZipSaver::CZipSaver(std::shared_ptr<CIOApi> api, const std::string & path):
handle = zipOpen2_64(path.c_str(), APPEND_STATUS_CREATE, nullptr, &zipApi);
if (handle == nullptr)
throw new std::runtime_error("Failed to create archive");
throw new std::runtime_error("CZipSaver: Failed to create archive");
}
CZipSaver::~CZipSaver()

View File

@ -68,10 +68,10 @@ long ZCALLBACK CIOApi::seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T off
actualStream->skip(offset);//TODO: should we check actual skipped?
break;
case ZLIB_FILEFUNC_SEEK_END :
ret = -1;
actualStream->seek(actualStream->getSize() - offset);
break;
case ZLIB_FILEFUNC_SEEK_SET :
ret = actualStream->seek(offset);
actualStream->seek(offset);
break;
default: ret = -1;
}

View File

@ -306,6 +306,7 @@ void CMapSaverJson::saveHeader()
auto s = out.str();
std::unique_ptr<COutputStream> stream = saver.addFile(HEADER_FILE_NAME);
stream->write((const ui8*)s.c_str(), s.size());
if (stream->write((const ui8*)s.c_str(), s.size()) != s.size())
throw new std::runtime_error("CMapSaverJson::saveHeader() zip compression failed.");
}
}

View File

@ -19,8 +19,11 @@
#include "../lib/rmg/CMapGenerator.h"
#include "../lib/mapping/MapFormatJson.h"
#include "../lib/VCMIDirs.h"
#include "MapComparer.h"
static const int TEST_RANDOM_SEED = 1337;
static std::unique_ptr<CMap> initialMap;
@ -60,6 +63,17 @@ BOOST_AUTO_TEST_CASE(CMapFormatVCMI_Simple)
CMapSaverJson saver(&serializeBuffer);
saver.saveMap(initialMap);
}
#if 1
{
std::ofstream tmp((VCMIDirs::get().userDataPath()/"temp.zip").string());
tmp.write((const char *)&serializeBuffer.getBuffer()[0],serializeBuffer.getSize());
tmp.flush();
}
#endif // 1
serializeBuffer.seek(0);
{
CMapLoaderJson loader(&serializeBuffer);
@ -71,10 +85,9 @@ BOOST_AUTO_TEST_CASE(CMapFormatVCMI_Simple)
logGlobal->info("CMapFormatVCMI_Simple finish");
}
catch(const std::exception & e)
catch(...)
{
logGlobal->info("CMapFormatVCMI_Simple crash");
logGlobal-> errorStream() << e.what();
throw;
handleException();
BOOST_FAIL("Test case crashed");
}
}