2008-06-12 09:45:51 +03:00
|
|
|
#define VCMI_DLL
|
2008-01-09 19:21:31 +02:00
|
|
|
#include "../stdafx.h"
|
2008-06-12 09:45:51 +03:00
|
|
|
#include "zlib.h"
|
2007-07-01 15:54:59 +03:00
|
|
|
#include "CLodHandler.h"
|
|
|
|
#include <sstream>
|
2007-07-07 14:09:25 +03:00
|
|
|
#include <algorithm>
|
2007-07-17 23:51:49 +03:00
|
|
|
#include <cctype>
|
2007-07-07 14:09:25 +03:00
|
|
|
#include <cstring>
|
2009-10-11 02:25:34 +03:00
|
|
|
#include <iostream>
|
2011-04-23 13:27:44 +03:00
|
|
|
#include "boost/filesystem.hpp"
|
2008-06-14 13:20:18 +03:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
2008-06-16 13:51:14 +03:00
|
|
|
#include <boost/thread.hpp>
|
2010-11-09 13:27:58 +02:00
|
|
|
#include <boost/foreach.hpp>
|
2011-10-08 04:23:46 +03:00
|
|
|
#include "vcmi_endian.h"
|
2008-12-08 00:38:04 +02:00
|
|
|
#ifdef max
|
|
|
|
#undef max
|
|
|
|
#endif
|
2009-04-15 17:03:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CLodHandler.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-02-09 15:48:14 +02:00
|
|
|
std::string readString(const unsigned char * bufor, int &i)
|
|
|
|
{
|
2011-10-08 04:23:46 +03:00
|
|
|
int len = read_le_u32(bufor + i); i+=4;
|
2010-02-28 14:39:38 +02:00
|
|
|
assert(len >= 0 && len <= 500000); //not too long
|
2010-02-09 15:48:14 +02:00
|
|
|
std::string ret; ret.reserve(len);
|
|
|
|
for(int gg=0; gg<len; ++gg)
|
|
|
|
{
|
|
|
|
ret += bufor[i++];
|
2007-07-01 15:54:59 +03:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2009-10-11 02:25:34 +03:00
|
|
|
|
2011-07-18 18:21:16 +03:00
|
|
|
void CLodHandler::convertName(std::string &filename, std::string *extension)
|
2010-11-09 13:27:58 +02:00
|
|
|
{
|
2011-07-18 18:21:16 +03:00
|
|
|
std::transform(filename.begin(), filename.end(), filename.begin(), toupper);
|
2011-01-14 18:52:37 +02:00
|
|
|
|
2011-07-18 18:21:16 +03:00
|
|
|
size_t dotPos = filename.find_last_of("/.");
|
|
|
|
|
|
|
|
if ( dotPos != std::string::npos && filename[dotPos] == '.')
|
|
|
|
{
|
|
|
|
if (extension)
|
|
|
|
*extension = filename.substr(dotPos);
|
|
|
|
filename.erase(dotPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char * CLodHandler::giveFile(std::string fname, LodFileType type, int * length)
|
|
|
|
{
|
|
|
|
convertName(fname);
|
2011-01-14 18:52:37 +02:00
|
|
|
boost::unordered_set<Entry>::const_iterator en_it = entries.find(Entry(fname, type));
|
|
|
|
|
|
|
|
if(en_it == entries.end()) //nothing's been found
|
2008-03-03 21:41:10 +02:00
|
|
|
{
|
2010-11-09 13:27:58 +02:00
|
|
|
tlog1 << "Cannot find file: " << fname << std::endl;
|
2008-06-12 09:45:51 +03:00
|
|
|
return NULL;
|
2008-03-03 21:41:10 +02:00
|
|
|
}
|
2011-01-14 18:52:37 +02:00
|
|
|
Entry ourEntry = *en_it;
|
|
|
|
|
2010-11-09 13:27:58 +02:00
|
|
|
if(length) *length = ourEntry.realSize;
|
2009-05-26 07:52:34 +03:00
|
|
|
mutex->lock();
|
2009-10-11 02:25:34 +03:00
|
|
|
|
2007-07-17 23:51:49 +03:00
|
|
|
unsigned char * outp;
|
2010-11-09 13:27:58 +02:00
|
|
|
if (ourEntry.offset<0) //file is in the sprites/ folder; no compression
|
2008-02-25 01:06:27 +02:00
|
|
|
{
|
2009-10-05 04:47:48 +03:00
|
|
|
int result;
|
2010-11-15 17:15:00 +02:00
|
|
|
outp = new unsigned char[ourEntry.realSize];
|
2010-11-09 13:27:58 +02:00
|
|
|
FILE * f = fopen((myDir + "/" + ourEntry.realName).c_str(), "rb");
|
2010-11-15 17:15:00 +02:00
|
|
|
if (f)
|
|
|
|
{
|
2010-11-09 13:27:58 +02:00
|
|
|
result = fread(outp,1,ourEntry.realSize,f);
|
2009-10-05 04:47:48 +03:00
|
|
|
fclose(f);
|
2010-11-15 17:15:00 +02:00
|
|
|
}
|
|
|
|
else
|
2009-10-05 04:47:48 +03:00
|
|
|
result = -1;
|
2009-05-26 07:52:34 +03:00
|
|
|
mutex->unlock();
|
2010-11-15 17:15:00 +02:00
|
|
|
if(result<0)
|
|
|
|
{
|
2010-11-09 13:27:58 +02:00
|
|
|
tlog1<<"Error in file reading: " << myDir << "/" << ourEntry.name << std::endl;
|
2009-10-05 04:47:48 +03:00
|
|
|
delete[] outp;
|
|
|
|
return NULL;
|
2010-11-15 17:15:00 +02:00
|
|
|
}
|
|
|
|
else
|
2008-06-12 09:45:51 +03:00
|
|
|
return outp;
|
2008-02-25 01:06:27 +02:00
|
|
|
}
|
2010-11-09 13:27:58 +02:00
|
|
|
else if (ourEntry.size==0) //file is not compressed
|
2007-07-17 23:51:49 +03:00
|
|
|
{
|
2010-11-09 13:27:58 +02:00
|
|
|
outp = new unsigned char[ourEntry.realSize];
|
2009-10-11 02:25:34 +03:00
|
|
|
|
2010-11-09 13:27:58 +02:00
|
|
|
LOD.seekg(ourEntry.offset, std::ios::beg);
|
|
|
|
LOD.read((char*)outp, ourEntry.realSize);
|
2009-05-26 07:52:34 +03:00
|
|
|
mutex->unlock();
|
2008-06-12 09:45:51 +03:00
|
|
|
return outp;
|
2007-07-17 23:51:49 +03:00
|
|
|
}
|
2009-05-26 07:52:34 +03:00
|
|
|
else //we will decompress file
|
2007-07-17 23:51:49 +03:00
|
|
|
{
|
2010-11-09 13:27:58 +02:00
|
|
|
outp = new unsigned char[ourEntry.size];
|
2009-10-11 02:25:34 +03:00
|
|
|
|
2010-11-09 13:27:58 +02:00
|
|
|
LOD.seekg(ourEntry.offset, std::ios::beg);
|
|
|
|
LOD.read((char*)outp, ourEntry.size);
|
2007-07-17 23:51:49 +03:00
|
|
|
unsigned char * decomp = NULL;
|
2010-11-09 13:27:58 +02:00
|
|
|
infs2(outp, ourEntry.size, ourEntry.realSize, decomp);
|
2010-11-05 19:29:10 +02:00
|
|
|
mutex->unlock();
|
2009-05-26 07:52:34 +03:00
|
|
|
delete[] outp;
|
2008-06-12 09:45:51 +03:00
|
|
|
return decomp;
|
2007-07-17 23:51:49 +03:00
|
|
|
}
|
2008-06-12 09:45:51 +03:00
|
|
|
return NULL;
|
2007-10-17 01:39:11 +03:00
|
|
|
}
|
2009-10-11 02:25:34 +03:00
|
|
|
|
2011-07-18 18:21:16 +03:00
|
|
|
std::string CLodHandler::getFileName(std::string lodFile, LodFileType type)
|
2010-10-18 18:08:59 +03:00
|
|
|
{
|
2011-07-18 18:21:16 +03:00
|
|
|
convertName(lodFile);
|
|
|
|
boost::unordered_set<Entry>::const_iterator it = entries.find(Entry(lodFile, type));
|
|
|
|
|
|
|
|
if (it != entries.end())
|
|
|
|
return it->realName;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CLodHandler::haveFile(std::string name, LodFileType type)
|
|
|
|
{
|
|
|
|
convertName(name);
|
|
|
|
return vstd::contains(entries, Entry(name, type));
|
2010-10-18 18:08:59 +03:00
|
|
|
}
|
|
|
|
|
2009-05-26 07:52:34 +03:00
|
|
|
DLL_EXPORT int CLodHandler::infs2(unsigned char * in, int size, int realSize, unsigned char *& out, int wBits)
|
2007-07-07 14:09:25 +03:00
|
|
|
{
|
|
|
|
int ret;
|
2009-05-26 07:52:34 +03:00
|
|
|
unsigned have;
|
2007-07-07 14:09:25 +03:00
|
|
|
z_stream strm;
|
2009-05-26 07:52:34 +03:00
|
|
|
out = new unsigned char [realSize];
|
|
|
|
int latPosOut = 0;
|
2007-07-07 14:09:25 +03:00
|
|
|
|
|
|
|
/* allocate inflate state */
|
|
|
|
strm.zalloc = Z_NULL;
|
|
|
|
strm.zfree = Z_NULL;
|
|
|
|
strm.opaque = Z_NULL;
|
|
|
|
strm.avail_in = 0;
|
|
|
|
strm.next_in = Z_NULL;
|
2009-05-26 07:52:34 +03:00
|
|
|
ret = inflateInit2(&strm, wBits);
|
2007-07-07 14:09:25 +03:00
|
|
|
if (ret != Z_OK)
|
|
|
|
return ret;
|
2009-05-26 07:52:34 +03:00
|
|
|
int chunkNumber = 0;
|
|
|
|
do
|
2007-07-07 14:09:25 +03:00
|
|
|
{
|
2009-09-27 14:37:15 +03:00
|
|
|
if(size < chunkNumber * NLoadHandlerHelp::fCHUNK)
|
|
|
|
break;
|
|
|
|
strm.avail_in = std::min(NLoadHandlerHelp::fCHUNK, size - chunkNumber * NLoadHandlerHelp::fCHUNK);
|
2009-05-26 07:52:34 +03:00
|
|
|
if (strm.avail_in == 0)
|
|
|
|
break;
|
2009-09-27 14:37:15 +03:00
|
|
|
strm.next_in = in + chunkNumber * NLoadHandlerHelp::fCHUNK;
|
2007-07-07 14:09:25 +03:00
|
|
|
|
2009-05-26 07:52:34 +03:00
|
|
|
/* run inflate() on input until output buffer not full */
|
|
|
|
do
|
|
|
|
{
|
2009-09-27 14:37:15 +03:00
|
|
|
strm.avail_out = realSize - latPosOut;
|
|
|
|
strm.next_out = out + latPosOut;
|
2009-05-26 07:52:34 +03:00
|
|
|
ret = inflate(&strm, Z_NO_FLUSH);
|
|
|
|
//assert(ret != Z_STREAM_ERROR); /* state not clobbered */
|
2009-09-27 14:37:15 +03:00
|
|
|
bool breakLoop = false;
|
2009-05-26 07:52:34 +03:00
|
|
|
switch (ret)
|
|
|
|
{
|
2009-09-27 14:37:15 +03:00
|
|
|
case Z_STREAM_END:
|
|
|
|
breakLoop = true;
|
|
|
|
break;
|
|
|
|
case Z_NEED_DICT:
|
|
|
|
ret = Z_DATA_ERROR; /* and fall through */
|
|
|
|
case Z_DATA_ERROR:
|
|
|
|
case Z_MEM_ERROR:
|
|
|
|
(void)inflateEnd(&strm);
|
|
|
|
return ret;
|
2009-05-26 07:52:34 +03:00
|
|
|
}
|
2009-09-27 14:37:15 +03:00
|
|
|
|
|
|
|
if(breakLoop)
|
|
|
|
break;
|
|
|
|
|
|
|
|
have = realSize - latPosOut - strm.avail_out;
|
|
|
|
latPosOut += have;
|
2009-05-26 07:52:34 +03:00
|
|
|
} while (strm.avail_out == 0);
|
2007-07-07 14:09:25 +03:00
|
|
|
|
2009-09-27 14:37:15 +03:00
|
|
|
++chunkNumber;
|
2009-05-26 07:52:34 +03:00
|
|
|
/* done when inflate() says it's done */
|
|
|
|
} while (ret != Z_STREAM_END);
|
2007-07-07 14:09:25 +03:00
|
|
|
|
2009-05-26 07:52:34 +03:00
|
|
|
/* clean up and return */
|
|
|
|
(void)inflateEnd(&strm);
|
|
|
|
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
|
2007-07-07 14:09:25 +03:00
|
|
|
}
|
|
|
|
|
2011-11-01 15:58:01 +03:00
|
|
|
void CLodHandler::extractFile(const std::string FName, const std::string name, LodFileType type)
|
2007-07-07 14:09:25 +03:00
|
|
|
{
|
2009-10-25 16:36:11 +02:00
|
|
|
int len; //length of file to write
|
2011-11-01 15:58:01 +03:00
|
|
|
unsigned char * outp = giveFile(name, type, &len);
|
2009-10-25 16:36:11 +02:00
|
|
|
std::ofstream out;
|
|
|
|
out.open(FName.c_str(), std::ios::binary);
|
|
|
|
if(!out.is_open())
|
2007-07-07 14:09:25 +03:00
|
|
|
{
|
2009-10-25 16:36:11 +02:00
|
|
|
tlog1<<"Unable to create "<<FName<<std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out.write(reinterpret_cast<char*>(outp), len);
|
|
|
|
out.close();
|
2007-06-30 19:24:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-18 18:21:16 +03:00
|
|
|
void CLodHandler::initEntry(Entry &e, std::string name)
|
2007-06-30 19:24:05 +03:00
|
|
|
{
|
2010-11-09 13:27:58 +02:00
|
|
|
std::string ext;
|
2011-07-18 18:21:16 +03:00
|
|
|
convertName(name, &ext);
|
|
|
|
e.name = name;
|
|
|
|
|
2010-11-09 13:27:58 +02:00
|
|
|
std::map<std::string, LodFileType>::iterator it = extMap.find(ext);
|
|
|
|
if (it == extMap.end())
|
|
|
|
e.type = FILE_OTHER;
|
|
|
|
else
|
|
|
|
e.type = it->second;
|
|
|
|
}
|
2009-10-11 02:25:34 +03:00
|
|
|
|
2010-11-09 13:27:58 +02:00
|
|
|
void CLodHandler::init(const std::string lodFile, const std::string dirName)
|
|
|
|
{
|
|
|
|
#define EXT(NAME, TYPE) extMap.insert(std::pair<std::string, LodFileType>(NAME, TYPE));
|
|
|
|
EXT(".TXT", FILE_TEXT);
|
2011-07-21 21:29:22 +03:00
|
|
|
EXT(".JSON",FILE_TEXT);
|
2010-11-09 13:27:58 +02:00
|
|
|
EXT(".DEF", FILE_ANIMATION);
|
|
|
|
EXT(".MSK", FILE_MASK);
|
|
|
|
EXT(".MSG", FILE_MASK);
|
|
|
|
EXT(".H3C", FILE_CAMPAIGN);
|
|
|
|
EXT(".H3M", FILE_MAP);
|
|
|
|
EXT(".FNT", FILE_FONT);
|
|
|
|
EXT(".BMP", FILE_GRAPHICS);
|
|
|
|
EXT(".JPG", FILE_GRAPHICS);
|
|
|
|
EXT(".PCX", FILE_GRAPHICS);
|
|
|
|
EXT(".PNG", FILE_GRAPHICS);
|
2011-07-18 18:21:16 +03:00
|
|
|
EXT(".TGA", FILE_GRAPHICS);
|
2010-11-09 13:27:58 +02:00
|
|
|
#undef EXT
|
|
|
|
|
|
|
|
myDir = dirName;
|
|
|
|
|
2009-10-11 02:25:34 +03:00
|
|
|
LOD.open(lodFile.c_str(), std::ios::in | std::ios::binary);
|
|
|
|
|
2009-12-28 06:08:24 +02:00
|
|
|
if (!LOD.is_open())
|
|
|
|
{
|
2009-02-14 17:00:29 +02:00
|
|
|
tlog1 << "Cannot open " << lodFile << std::endl;
|
2011-09-28 01:03:43 +03:00
|
|
|
return;
|
2009-02-14 17:00:29 +02:00
|
|
|
}
|
2009-10-11 02:25:34 +03:00
|
|
|
|
2011-09-28 01:03:43 +03:00
|
|
|
Uint32 temp;
|
|
|
|
LOD.seekg(8);
|
|
|
|
LOD.read((char *)&temp, 4);
|
|
|
|
totalFiles = SDL_SwapLE32(temp);
|
2009-10-11 02:25:34 +03:00
|
|
|
|
2011-09-28 01:03:43 +03:00
|
|
|
LOD.seekg(0x5c, std::ios::beg);
|
|
|
|
if(!LOD)
|
|
|
|
{
|
|
|
|
tlog2 << lodFile << " doesn't store anything!\n";
|
|
|
|
return;
|
|
|
|
}
|
2009-10-11 02:25:34 +03:00
|
|
|
|
2011-09-28 01:03:43 +03:00
|
|
|
struct LodEntry *lodEntries = new struct LodEntry[totalFiles];
|
|
|
|
LOD.read((char *)lodEntries, sizeof(struct LodEntry) * totalFiles);
|
2011-09-28 00:54:40 +03:00
|
|
|
|
2011-09-28 01:03:43 +03:00
|
|
|
for (unsigned int i=0; i<totalFiles; i++)
|
|
|
|
{
|
|
|
|
Entry entry;
|
|
|
|
initEntry(entry, lodEntries[i].filename);
|
|
|
|
|
|
|
|
entry.offset= SDL_SwapLE32(lodEntries[i].offset);
|
|
|
|
entry.realSize = SDL_SwapLE32(lodEntries[i].uncompressedSize);
|
|
|
|
entry.size = SDL_SwapLE32(lodEntries[i].size);
|
|
|
|
|
|
|
|
entries.insert(entry);
|
2011-09-28 00:54:40 +03:00
|
|
|
}
|
2009-10-11 02:25:34 +03:00
|
|
|
|
2011-09-28 01:03:43 +03:00
|
|
|
delete [] lodEntries;
|
|
|
|
|
2011-04-23 13:27:44 +03:00
|
|
|
boost::filesystem::recursive_directory_iterator enddir;
|
2008-06-14 13:20:18 +03:00
|
|
|
if(boost::filesystem::exists(dirName))
|
|
|
|
{
|
2011-04-23 13:27:44 +03:00
|
|
|
std::vector<std::string> path;
|
|
|
|
for (boost::filesystem::recursive_directory_iterator dir(dirName); dir!=enddir; dir++)
|
2008-06-14 13:20:18 +03:00
|
|
|
{
|
2011-04-23 13:27:44 +03:00
|
|
|
//If a directory was found - add name to vector to recreate full path later
|
|
|
|
if (boost::filesystem::is_directory(dir->status()))
|
|
|
|
{
|
|
|
|
path.resize(dir.level()+1);
|
|
|
|
path.back() = dir->path().leaf();
|
|
|
|
}
|
2008-06-14 13:20:18 +03:00
|
|
|
if(boost::filesystem::is_regular(dir->status()))
|
|
|
|
{
|
2010-11-09 13:27:58 +02:00
|
|
|
Entry e;
|
2011-04-23 13:27:44 +03:00
|
|
|
|
|
|
|
//we can't get relative path with boost at the moment - need to create path to file manually
|
|
|
|
for (size_t i=0; i<dir.level() && i<path.size(); i++)
|
|
|
|
e.realName += path[i] + '/';
|
|
|
|
|
|
|
|
e.realName += dir->path().leaf();
|
|
|
|
|
2010-11-09 13:27:58 +02:00
|
|
|
initEntry(e, e.realName);
|
|
|
|
|
|
|
|
if(vstd::contains(entries, e)) //file present in .lod - overwrite its entry
|
|
|
|
entries.erase(e);
|
|
|
|
|
|
|
|
e.offset = -1;
|
|
|
|
e.realSize = e.size = boost::filesystem::file_size(dir->path());
|
|
|
|
entries.insert(e);
|
2008-06-14 13:20:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2009-02-14 17:00:29 +02:00
|
|
|
{
|
2011-11-01 15:58:01 +03:00
|
|
|
if (!dirName.empty())
|
|
|
|
tlog1<<"Warning: No "+dirName+"/ folder!"<<std::endl;
|
2009-02-14 17:00:29 +02:00
|
|
|
}
|
2007-06-30 19:24:05 +03:00
|
|
|
}
|
2011-07-18 18:21:16 +03:00
|
|
|
std::string CLodHandler::getTextFile(std::string name, LodFileType type)
|
2007-07-16 17:42:44 +03:00
|
|
|
{
|
2008-06-12 09:45:51 +03:00
|
|
|
int length=-1;
|
2010-11-09 13:27:58 +02:00
|
|
|
unsigned char* data = giveFile(name, type, &length);
|
2009-10-05 04:47:48 +03:00
|
|
|
|
|
|
|
if (!data) {
|
2010-02-12 17:04:01 +02:00
|
|
|
tlog1<<"Fatal error. Missing game file: " << name << ". Aborting!"<<std::endl;
|
2009-10-05 04:47:48 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2009-10-25 16:36:11 +02:00
|
|
|
std::string ret(data, data+length);
|
2008-06-12 09:45:51 +03:00
|
|
|
delete [] data;
|
|
|
|
return ret;
|
2007-07-16 17:42:44 +03:00
|
|
|
}
|
2009-06-23 11:14:49 +03:00
|
|
|
|
|
|
|
CLodHandler::CLodHandler()
|
|
|
|
{
|
|
|
|
mutex = new boost::mutex;
|
|
|
|
totalFiles = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CLodHandler::~CLodHandler()
|
|
|
|
{
|
|
|
|
delete mutex;
|
2009-08-02 18:18:35 +03:00
|
|
|
}
|
2010-02-09 15:48:14 +02:00
|
|
|
|
|
|
|
unsigned char * CLodHandler::getUnpackedFile( const std::string & path, int * sizeOut )
|
|
|
|
{
|
|
|
|
const int bufsize = 65536;
|
|
|
|
int mapsize = 0;
|
|
|
|
|
|
|
|
gzFile map = gzopen(path.c_str(), "rb");
|
2010-02-18 16:09:16 +02:00
|
|
|
assert(map);
|
2010-02-09 15:48:14 +02:00
|
|
|
std::vector<unsigned char *> mapstr;
|
|
|
|
|
|
|
|
// Read a map by chunks
|
|
|
|
// We could try to read the map size directly (cf RFC 1952) and then read
|
|
|
|
// directly the whole map, but that would create more problems.
|
|
|
|
do {
|
|
|
|
unsigned char *buf = new unsigned char[bufsize];
|
|
|
|
|
|
|
|
int ret = gzread(map, buf, bufsize);
|
|
|
|
if (ret == 0 || ret == -1) {
|
|
|
|
delete [] buf;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mapstr.push_back(buf);
|
|
|
|
mapsize += ret;
|
|
|
|
} while(1);
|
|
|
|
|
|
|
|
gzclose(map);
|
|
|
|
|
|
|
|
// Now that we know the uncompressed size, reassemble the chunks
|
|
|
|
unsigned char *initTable = new unsigned char[mapsize];
|
|
|
|
|
|
|
|
std::vector<unsigned char *>::iterator it;
|
|
|
|
int offset;
|
|
|
|
int tocopy = mapsize;
|
|
|
|
for (it = mapstr.begin(), offset = 0;
|
|
|
|
it != mapstr.end();
|
|
|
|
it++, offset+=bufsize ) {
|
|
|
|
memcpy(&initTable[offset], *it, tocopy > bufsize ? bufsize : tocopy);
|
|
|
|
tocopy -= bufsize;
|
|
|
|
delete [] *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
*sizeOut = mapsize;
|
|
|
|
return initTable;
|
2010-08-21 03:39:37 +03:00
|
|
|
}
|