mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
zip format VCMP
This commit is contained in:
@ -16,6 +16,7 @@
|
|||||||
#include "../filesystem/CCompressedStream.h"
|
#include "../filesystem/CCompressedStream.h"
|
||||||
#include "../filesystem/CMemoryStream.h"
|
#include "../filesystem/CMemoryStream.h"
|
||||||
#include "../filesystem/CBinaryReader.h"
|
#include "../filesystem/CBinaryReader.h"
|
||||||
|
#include "../filesystem/CZipLoader.h"
|
||||||
#include "../VCMI_Lib.h"
|
#include "../VCMI_Lib.h"
|
||||||
#include "../constants/StringConstants.h"
|
#include "../constants/StringConstants.h"
|
||||||
#include "../mapping/CMapHeader.h"
|
#include "../mapping/CMapHeader.h"
|
||||||
@ -588,10 +589,42 @@ CampaignTravel CampaignHandler::readScenarioTravelFromMemory(CBinaryReader & rea
|
|||||||
|
|
||||||
std::vector< std::vector<ui8> > CampaignHandler::getFile(std::unique_ptr<CInputStream> file, const std::string & filename, bool headerOnly)
|
std::vector< std::vector<ui8> > CampaignHandler::getFile(std::unique_ptr<CInputStream> file, const std::string & filename, bool headerOnly)
|
||||||
{
|
{
|
||||||
CCompressedStream stream(std::move(file), true);
|
std::vector<ui8> magic(2);
|
||||||
|
file->read(magic.data(), magic.size());
|
||||||
|
file->seek(0);
|
||||||
|
|
||||||
std::vector< std::vector<ui8> > ret;
|
std::vector< std::vector<ui8> > ret;
|
||||||
|
|
||||||
|
if (magic == std::vector<ui8>{0x50, 0x4B}) // VCMP (ZIP)
|
||||||
|
{
|
||||||
|
CInputStream * buffer(file.get());
|
||||||
|
std::shared_ptr<CIOApi> ioApi(new CProxyROIOApi(buffer));
|
||||||
|
CZipLoader loader("", "_", ioApi);
|
||||||
|
|
||||||
|
// load header
|
||||||
|
JsonPath resource = JsonPath::builtin(VCMP_HEADER_FILE_NAME);
|
||||||
|
if(!loader.existsResource(resource))
|
||||||
|
throw std::runtime_error(resource.getName() + " not found in " + filename);
|
||||||
|
auto data = loader.load(resource)->readAll();
|
||||||
|
ret.push_back(std::vector<ui8>(data.first.get(), data.first.get() + data.second));
|
||||||
|
|
||||||
|
// load scenarios
|
||||||
|
JsonNode header(reinterpret_cast<const std::byte*>(data.first.get()), data.second, VCMP_HEADER_FILE_NAME);
|
||||||
|
for(auto scenario : header["scenarios"].Vector())
|
||||||
|
{
|
||||||
|
ResourcePath resource = ResourcePath(scenario["map"].String(), EResType::MAP);
|
||||||
|
if(!loader.existsResource(resource))
|
||||||
|
throw std::runtime_error(resource.getName() + " not found in " + filename);
|
||||||
|
auto data = loader.load(resource)->readAll();
|
||||||
|
ret.push_back(std::vector<ui8>(data.first.get(), data.first.get() + data.second));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
else // H3M
|
||||||
|
{
|
||||||
|
CCompressedStream stream(std::move(file), true);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
@ -615,6 +648,7 @@ std::vector< std::vector<ui8> > CampaignHandler::getFile(std::unique_ptr<CInputS
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
VideoPath CampaignHandler::prologVideoName(ui8 index)
|
VideoPath CampaignHandler::prologVideoName(ui8 index)
|
||||||
{
|
{
|
||||||
|
@ -37,6 +37,7 @@ class DLL_LINKAGE CampaignHandler
|
|||||||
static AudioPath prologMusicName(ui8 index);
|
static AudioPath prologMusicName(ui8 index);
|
||||||
static AudioPath prologVoiceName(ui8 index);
|
static AudioPath prologVoiceName(ui8 index);
|
||||||
|
|
||||||
|
static constexpr auto VCMP_HEADER_FILE_NAME = "header.json";
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<Campaign> getHeader( const std::string & name); //name - name of appropriate file
|
static std::unique_ptr<Campaign> getHeader( const std::string & name); //name - name of appropriate file
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user