rawdatadat2.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <algorithm>
00024
00025
00026 #include <boost/scoped_array.hpp>
00027 #include <boost/scoped_ptr.hpp>
00028 #include <zlib.h>
00029
00030
00031
00032
00033
00034 #include "vfs/raw/rawdata.h"
00035 #include "vfs/vfs.h"
00036 #include "util/base/exception.h"
00037
00038 #include "rawdatadat2.h"
00039
00040 namespace FIFE {
00041
00042 RawDataDAT2::RawDataDAT2(VFS* vfs, const std::string& datfile, const s_info& info) :
00043 RawDataMemSource(info.unpackedLength) {
00044
00045 boost::scoped_ptr<RawData> input (vfs->open(datfile));
00046 input->setIndex(info.offset);
00047
00048 if (info.type == 1) {
00049 boost::scoped_array<uint8_t> compressed(new uint8_t[info.packedLength]);
00050 input->readInto(compressed.get(), info.packedLength);
00051
00052 uLongf dstlen = info.unpackedLength;
00053 if (uncompress(getRawData(), &dstlen, compressed.get(), info.packedLength) != Z_OK || dstlen != info.unpackedLength) {
00054 throw InvalidFormat("failed to decompress " + info.name + " (inside: " + datfile + ")");
00055 }
00056 } else {
00057 input->readInto(getRawData(), info.unpackedLength);
00058 }
00059 }
00060
00061 }