#include "../stdafx.h" #include #include "CSndHandler.h" #include /* * CSndHandler.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 * */ CSndHandler::~CSndHandler() { entries.clear(); fimap.clear(); mfile->close(); delete mfile; } // Analyze the sound file. Half of this could go away if we were using // a simple structure. However, some post treatment would be necessary: file // size and offsets are little endian, and filename have a NUL in // them. */ CSndHandler::CSndHandler(std::string fname) { mfile = new boost::iostreams::mapped_file_source(fname); if (!mfile->is_open()) { tlog1 << "Cannot open " << fname << std::endl; throw std::string("Cannot open ")+fname; } const unsigned char *data = (const unsigned char *)mfile->data(); unsigned int numFiles = readNormalNr(&data[0]); for (unsigned int i=0; idata(); out.write(&data[entries[index].offset], entries[index].size); out.close(); } void CSndHandler::extract(std::string srcfile, std::string dstfile, bool caseSens) //saves selected file { if (caseSens) { for (size_t i=0;idata(); return &data[entries[index].offset]; } const char * CSndHandler::extract (std::string srcName, int &size) { int index; std::map::iterator fit; if ((fit = fimap.find(srcName)) != fimap.end()) { index = fit->second; return this->extract(index, size); } size = 0; return NULL; } CVidHandler::~CVidHandler() { entries.clear(); file.close(); } CVidHandler::CVidHandler(std::string fname):CHUNK(65535) { file.open(fname.c_str(),std::ios::binary); if (!file.is_open()) #ifndef __GNUC__ throw new std::exception((std::string("Cannot open ")+fname).c_str()); #else throw new std::exception(); #endif int nr = readNormalNr(0,4); char tempc; for (int i=0;i0) entries[i-1].size=entry.offset-entries[i-1].offset; if (i==nr-1) { file.seekg(0,std::ios::end); entry.size = ((int)file.tellg())-entry.offset; file.seekg(0,std::ios::beg); } entries.push_back(entry); } } int CVidHandler::readNormalNr (int pos, int bytCon) { if (pos>=0) file.seekg(pos,std::ios_base::beg); int ret=0; int amp=1; unsigned char zcz=0; for (int i=0; iCHUNK) { file.read(buffer,CHUNK); out.write(buffer,CHUNK); toRead-=CHUNK; } file.read(buffer,toRead); out.write(buffer,toRead); out.close(); } void CVidHandler::extract(std::string srcfile, std::string dstfile, bool caseSens) //saves selected file { if (caseSens) { for (size_t i=0;i