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>
|
2008-06-14 13:20:18 +03:00
|
|
|
#include "boost/filesystem/operations.hpp"
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
2008-06-16 13:51:14 +03:00
|
|
|
#include <boost/thread.hpp>
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-06-12 09:45:51 +03:00
|
|
|
DLL_EXPORT int readNormalNr (int pos, int bytCon, unsigned char * str)
|
2007-07-01 15:54:59 +03:00
|
|
|
{
|
|
|
|
int ret=0;
|
|
|
|
int amp=1;
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
for (int i=0; i<bytCon; i++)
|
|
|
|
{
|
|
|
|
ret+=str[pos+i]*amp;
|
2008-01-30 16:19:35 +02:00
|
|
|
amp<<=8;
|
2007-07-01 15:54:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else return -1;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-06-13 00:08:04 +03:00
|
|
|
unsigned char * CLodHandler::giveFile(std::string defName, int * length)
|
2007-07-09 08:57:30 +03:00
|
|
|
{
|
2007-07-31 16:09:34 +03:00
|
|
|
std::transform(defName.begin(), defName.end(), defName.begin(), (int(*)(int))toupper);
|
2007-07-17 23:51:49 +03:00
|
|
|
Entry * ourEntry = entries.znajdz(Entry(defName));
|
2008-03-03 21:41:10 +02:00
|
|
|
if(!ourEntry) //nothing's been found
|
|
|
|
{
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog1<<"Cannot find file: "<<defName;
|
2008-06-12 09:45:51 +03:00
|
|
|
return NULL;
|
2008-03-03 21:41:10 +02:00
|
|
|
}
|
2008-06-12 09:45:51 +03:00
|
|
|
if(length) *length = ourEntry->realSize;
|
2009-05-26 07:52:34 +03:00
|
|
|
mutex->lock();
|
|
|
|
fseek(FLOD, ourEntry->offset, 0);
|
2007-07-17 23:51:49 +03:00
|
|
|
unsigned char * outp;
|
2008-06-12 09:45:51 +03:00
|
|
|
if (ourEntry->offset<0) //file is in the sprites/ folder; no compression
|
2008-02-25 01:06:27 +02:00
|
|
|
{
|
2008-06-12 09:45:51 +03:00
|
|
|
unsigned char * outp = new unsigned char[ourEntry->realSize];
|
2009-05-26 07:52:34 +03:00
|
|
|
char name[30];memset(name,0,30);
|
2008-10-03 18:15:23 +03:00
|
|
|
strcat(name, myDir.c_str());
|
|
|
|
strcat(name, PATHSEPARATOR);
|
2008-12-08 00:38:04 +02:00
|
|
|
strcat(name,ourEntry->nameStr.c_str());
|
2008-02-25 01:06:27 +02:00
|
|
|
FILE * f = fopen(name,"rb");
|
|
|
|
int result = fread(outp,1,ourEntry->realSize,f);
|
2009-05-26 07:52:34 +03:00
|
|
|
mutex->unlock();
|
|
|
|
if(result<0) {tlog1<<"Error in file reading: "<<name<<std::endl;delete[] outp; return NULL;}
|
2008-06-12 09:45:51 +03:00
|
|
|
else
|
|
|
|
return outp;
|
2008-02-25 01:06:27 +02:00
|
|
|
}
|
2009-05-26 07:52:34 +03:00
|
|
|
else if (ourEntry->size==0) //file is not compressed
|
2007-07-17 23:51:49 +03:00
|
|
|
{
|
|
|
|
outp = new unsigned char[ourEntry->realSize];
|
2009-05-26 07:52:34 +03:00
|
|
|
fread((char*)outp, 1, ourEntry->realSize, FLOD);
|
|
|
|
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
|
|
|
{
|
2009-05-26 07:52:34 +03:00
|
|
|
outp = new unsigned char[ourEntry->size];
|
|
|
|
fread((char*)outp, 1, ourEntry->size, FLOD);
|
|
|
|
mutex->unlock();
|
2007-07-17 23:51:49 +03:00
|
|
|
unsigned char * decomp = NULL;
|
2009-05-26 07:52:34 +03:00
|
|
|
int decRes = infs2(outp, ourEntry->size, ourEntry->realSize, decomp);
|
|
|
|
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-05-26 07:52:34 +03:00
|
|
|
int CLodHandler::infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits)
|
2007-07-07 14:09:25 +03:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned have;
|
|
|
|
z_stream strm;
|
|
|
|
unsigned char inx[NLoadHandlerHelp::fCHUNK];
|
|
|
|
unsigned char outx[NLoadHandlerHelp::fCHUNK];
|
|
|
|
|
|
|
|
/* allocate inflate state */
|
|
|
|
strm.zalloc = Z_NULL;
|
|
|
|
strm.zfree = Z_NULL;
|
|
|
|
strm.opaque = Z_NULL;
|
|
|
|
strm.avail_in = 0;
|
|
|
|
strm.next_in = Z_NULL;
|
|
|
|
ret = inflateInit2(&strm, wBits);
|
|
|
|
if (ret != Z_OK)
|
|
|
|
return ret;
|
|
|
|
int chunkNumber = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
int readBytes = 0;
|
|
|
|
for(int i=0; i<NLoadHandlerHelp::fCHUNK && (chunkNumber * NLoadHandlerHelp::fCHUNK + i)<size; ++i)
|
|
|
|
{
|
|
|
|
inx[i] = in[chunkNumber * NLoadHandlerHelp::fCHUNK + i];
|
|
|
|
++readBytes;
|
|
|
|
}
|
|
|
|
++chunkNumber;
|
|
|
|
strm.avail_in = readBytes;
|
|
|
|
//strm.avail_in = fread(inx, 1, NLoadHandlerHelp::fCHUNK, source);
|
|
|
|
/*if (in.bad())
|
|
|
|
{
|
|
|
|
(void)inflateEnd(&strm);
|
|
|
|
return Z_ERRNO;
|
|
|
|
}*/
|
|
|
|
if (strm.avail_in == 0)
|
|
|
|
break;
|
|
|
|
strm.next_in = inx;
|
|
|
|
|
|
|
|
/* run inflate() on input until output buffer not full */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
strm.avail_out = NLoadHandlerHelp::fCHUNK;
|
|
|
|
strm.next_out = outx;
|
|
|
|
ret = inflate(&strm, Z_NO_FLUSH);
|
|
|
|
//assert(ret != Z_STREAM_ERROR); /* state not clobbered */
|
|
|
|
switch (ret)
|
|
|
|
{
|
|
|
|
case Z_NEED_DICT:
|
|
|
|
ret = Z_DATA_ERROR; /* and fall through */
|
|
|
|
case Z_DATA_ERROR:
|
|
|
|
case Z_MEM_ERROR:
|
|
|
|
(void)inflateEnd(&strm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
have = NLoadHandlerHelp::fCHUNK - strm.avail_out;
|
|
|
|
/*if (fwrite(out, 1, have, dest) != have || ferror(dest))
|
|
|
|
{
|
|
|
|
(void)inflateEnd(&strm);
|
|
|
|
return Z_ERRNO;
|
|
|
|
}*/
|
|
|
|
out.write((char*)outx, have);
|
|
|
|
if(out.bad())
|
|
|
|
{
|
|
|
|
(void)inflateEnd(&strm);
|
|
|
|
return Z_ERRNO;
|
|
|
|
}
|
|
|
|
} while (strm.avail_out == 0);
|
|
|
|
|
|
|
|
/* done when inflate() says it's done */
|
|
|
|
} while (ret != Z_STREAM_END);
|
|
|
|
|
|
|
|
/* clean up and return */
|
|
|
|
(void)inflateEnd(&strm);
|
|
|
|
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
unsigned char inx[NLoadHandlerHelp::fCHUNK];
|
|
|
|
unsigned char outx[NLoadHandlerHelp::fCHUNK];
|
|
|
|
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-05-26 07:52:34 +03:00
|
|
|
int readBytes = 0;
|
|
|
|
for(int i=0; i<NLoadHandlerHelp::fCHUNK && (chunkNumber * NLoadHandlerHelp::fCHUNK + i)<size; ++i)
|
|
|
|
{
|
|
|
|
inx[i] = in[chunkNumber * NLoadHandlerHelp::fCHUNK + i];
|
|
|
|
++readBytes;
|
|
|
|
}
|
|
|
|
++chunkNumber;
|
|
|
|
strm.avail_in = readBytes;
|
|
|
|
if (strm.avail_in == 0)
|
|
|
|
break;
|
|
|
|
strm.next_in = inx;
|
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
|
|
|
|
{
|
|
|
|
strm.avail_out = NLoadHandlerHelp::fCHUNK;
|
|
|
|
strm.next_out = outx;
|
|
|
|
ret = inflate(&strm, Z_NO_FLUSH);
|
|
|
|
//assert(ret != Z_STREAM_ERROR); /* state not clobbered */
|
|
|
|
switch (ret)
|
|
|
|
{
|
|
|
|
case Z_NEED_DICT:
|
|
|
|
ret = Z_DATA_ERROR; /* and fall through */
|
|
|
|
case Z_DATA_ERROR:
|
|
|
|
case Z_MEM_ERROR:
|
|
|
|
(void)inflateEnd(&strm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
have = NLoadHandlerHelp::fCHUNK - strm.avail_out;
|
|
|
|
for(int oo=0; oo<have; ++oo)
|
|
|
|
{
|
|
|
|
out[latPosOut] = outx[oo];
|
|
|
|
++latPosOut;
|
|
|
|
}
|
|
|
|
} while (strm.avail_out == 0);
|
2007-07-07 14:09:25 +03:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-06-13 00:08:04 +03:00
|
|
|
void CLodHandler::extract(std::string FName)
|
2007-06-30 19:24:05 +03:00
|
|
|
{
|
|
|
|
std::ofstream FOut;
|
|
|
|
for (int i=0;i<totalFiles;i++)
|
|
|
|
{
|
2009-05-26 07:52:34 +03:00
|
|
|
fseek(FLOD, entries[i].offset, 0);
|
2009-08-02 18:18:35 +03:00
|
|
|
std::string bufff = (DATA_DIR + FName.substr(0, FName.size()-4) + PATHSEPARATOR + entries[i].nameStr);
|
2007-06-30 19:24:05 +03:00
|
|
|
unsigned char * outp;
|
|
|
|
if (entries[i].size==0) //file is not compressed
|
|
|
|
{
|
|
|
|
outp = new unsigned char[entries[i].realSize];
|
2009-05-26 07:52:34 +03:00
|
|
|
fread((char*)outp, 1, entries[i].realSize, FLOD);
|
2007-06-30 19:24:05 +03:00
|
|
|
std::ofstream out;
|
|
|
|
out.open(bufff.c_str(), std::ios::binary);
|
|
|
|
if(!out.is_open())
|
|
|
|
{
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog1<<"Unable to create "<<bufff;
|
2007-06-30 19:24:05 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(int hh=0; hh<entries[i].realSize; ++hh)
|
|
|
|
{
|
|
|
|
out<<*(outp+hh);
|
|
|
|
}
|
|
|
|
out.close();
|
|
|
|
}
|
|
|
|
}
|
2008-08-02 18:08:03 +03:00
|
|
|
else
|
2007-06-30 19:24:05 +03:00
|
|
|
{
|
|
|
|
outp = new unsigned char[entries[i].size];
|
2009-05-26 07:52:34 +03:00
|
|
|
fread((char*)outp, 1, entries[i].size, FLOD);
|
|
|
|
fseek(FLOD, 0, 0);
|
2007-07-07 14:09:25 +03:00
|
|
|
std::ofstream destin;
|
|
|
|
destin.open(bufff.c_str(), std::ios::binary);
|
|
|
|
//int decRes = decompress(outp, entries[i].size, entries[i].realSize, bufff);
|
|
|
|
int decRes = infs(outp, entries[i].size, entries[i].realSize, destin);
|
|
|
|
destin.close();
|
|
|
|
if(decRes!=0)
|
|
|
|
{
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog1<<"LOD Extraction error"<<" "<<decRes<<" while extracting to "<<bufff<<std::endl;
|
2007-07-07 14:09:25 +03:00
|
|
|
}
|
|
|
|
}
|
2007-12-23 18:46:33 +02:00
|
|
|
delete[] outp;
|
2007-07-07 14:09:25 +03:00
|
|
|
}
|
2009-05-26 07:52:34 +03:00
|
|
|
fclose(FLOD);
|
2007-07-07 14:09:25 +03:00
|
|
|
}
|
|
|
|
|
2008-06-13 00:08:04 +03:00
|
|
|
void CLodHandler::extractFile(std::string FName, std::string name)
|
2007-07-07 14:09:25 +03:00
|
|
|
{
|
|
|
|
std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper);
|
|
|
|
for (int i=0;i<totalFiles;i++)
|
|
|
|
{
|
2009-08-02 18:18:35 +03:00
|
|
|
std::string buf1 = entries[i].nameStr;
|
2007-07-07 14:09:25 +03:00
|
|
|
std::transform(buf1.begin(), buf1.end(), buf1.begin(), (int(*)(int))toupper);
|
|
|
|
if(buf1!=name)
|
|
|
|
continue;
|
2009-05-26 07:52:34 +03:00
|
|
|
fseek(FLOD, entries[i].offset, 0);
|
2008-02-26 01:26:50 +02:00
|
|
|
std::string bufff = (FName);
|
2007-07-07 14:09:25 +03:00
|
|
|
unsigned char * outp;
|
|
|
|
if (entries[i].size==0) //file is not compressed
|
|
|
|
{
|
|
|
|
outp = new unsigned char[entries[i].realSize];
|
2009-05-26 07:52:34 +03:00
|
|
|
fread((char*)outp, 1, entries[i].realSize, FLOD);
|
2007-07-07 14:09:25 +03:00
|
|
|
std::ofstream out;
|
|
|
|
out.open(bufff.c_str(), std::ios::binary);
|
|
|
|
if(!out.is_open())
|
|
|
|
{
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog1<<"Unable to create "<<bufff;
|
2007-07-07 14:09:25 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(int hh=0; hh<entries[i].realSize; ++hh)
|
|
|
|
{
|
|
|
|
out<<*(outp+hh);
|
|
|
|
}
|
|
|
|
out.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //we will decompressing file
|
|
|
|
{
|
|
|
|
outp = new unsigned char[entries[i].size];
|
2009-05-26 07:52:34 +03:00
|
|
|
fread((char*)outp, 1, entries[i].size, FLOD);
|
|
|
|
fseek(FLOD, 0, 0);
|
2007-07-07 14:09:25 +03:00
|
|
|
std::ofstream destin;
|
|
|
|
destin.open(bufff.c_str(), std::ios::binary);
|
|
|
|
//int decRes = decompress(outp, entries[i].size, entries[i].realSize, bufff);
|
|
|
|
int decRes = infs(outp, entries[i].size, entries[i].realSize, destin);
|
|
|
|
destin.close();
|
2007-06-30 19:24:05 +03:00
|
|
|
if(decRes!=0)
|
|
|
|
{
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog1<<"LOD Extraction error"<<" "<<decRes<<" while extracting to "<<bufff<<std::endl;
|
2007-06-30 19:24:05 +03:00
|
|
|
}
|
|
|
|
}
|
2007-12-23 18:46:33 +02:00
|
|
|
delete[] outp;
|
2007-06-30 19:24:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-26 07:52:34 +03:00
|
|
|
int CLodHandler::readNormalNr (unsigned char* bufor, int bytCon, bool cyclic)
|
2007-06-30 19:24:05 +03:00
|
|
|
{
|
|
|
|
int ret=0;
|
|
|
|
int amp=1;
|
|
|
|
for (int i=0; i<bytCon; i++)
|
|
|
|
{
|
|
|
|
ret+=bufor[i]*amp;
|
|
|
|
amp*=256;
|
|
|
|
}
|
|
|
|
if(cyclic && bytCon<4 && ret>=amp/2)
|
|
|
|
{
|
|
|
|
ret = ret-amp;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-05-26 07:52:34 +03:00
|
|
|
void CLodHandler::init(std::string lodFile, std::string dirName)
|
2007-06-30 19:24:05 +03:00
|
|
|
{
|
2008-10-03 18:15:23 +03:00
|
|
|
myDir = dirName;
|
2007-07-07 19:04:15 +03:00
|
|
|
std::string Ts;
|
2009-05-26 07:52:34 +03:00
|
|
|
FLOD = fopen(lodFile.c_str(), "rb");
|
|
|
|
if(!FLOD)
|
2009-02-14 17:00:29 +02:00
|
|
|
{
|
|
|
|
tlog1 << "Cannot open " << lodFile << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2009-05-26 07:52:34 +03:00
|
|
|
fseek(FLOD, 8, 0);
|
|
|
|
unsigned char temp[4];
|
|
|
|
fread((char*)temp, 1, 4, FLOD);
|
|
|
|
totalFiles = readNormalNr(temp,4);
|
|
|
|
fseek(FLOD, 0x5c, 0);
|
|
|
|
for (int i=0; i<totalFiles; i++)
|
2007-07-07 19:04:15 +03:00
|
|
|
{
|
2007-07-17 23:51:49 +03:00
|
|
|
Entry entry;
|
2009-06-23 11:14:49 +03:00
|
|
|
char bufc = -1;
|
2009-08-02 18:18:35 +03:00
|
|
|
bool valid = true;
|
|
|
|
|
|
|
|
entry.nameStr = "";
|
|
|
|
|
|
|
|
// Read name
|
|
|
|
for(int kk=0; kk<16; ++kk)
|
2009-05-26 07:52:34 +03:00
|
|
|
{
|
2009-06-23 11:14:49 +03:00
|
|
|
fread(&bufc, 1, 1, FLOD);
|
2009-08-02 18:18:35 +03:00
|
|
|
if (valid) {
|
|
|
|
if (bufc)
|
|
|
|
entry.nameStr+=toupper(bufc);
|
|
|
|
else
|
|
|
|
valid = false;
|
2009-05-26 07:52:34 +03:00
|
|
|
}
|
|
|
|
}
|
2009-08-02 18:18:35 +03:00
|
|
|
|
2009-05-26 07:52:34 +03:00
|
|
|
fread((char*)temp, 1, 4, FLOD);
|
|
|
|
entry.offset=readNormalNr(temp,4);
|
|
|
|
fread((char*)temp, 1, 4, FLOD);
|
|
|
|
entry.realSize=readNormalNr(temp,4);
|
2009-08-02 18:18:35 +03:00
|
|
|
fread((char*)temp, 1, 4, FLOD);
|
2009-05-26 07:52:34 +03:00
|
|
|
fread((char*)temp, 1, 4, FLOD);
|
|
|
|
entry.size=readNormalNr(temp,4);
|
2009-08-02 18:18:35 +03:00
|
|
|
|
2007-07-17 23:51:49 +03:00
|
|
|
entries.push_back(entry);
|
2007-07-07 19:04:15 +03:00
|
|
|
}
|
2008-06-14 13:20:18 +03:00
|
|
|
boost::filesystem::directory_iterator enddir;
|
|
|
|
if(boost::filesystem::exists(dirName))
|
|
|
|
{
|
|
|
|
for (boost::filesystem::directory_iterator dir(dirName);dir!=enddir;dir++)
|
|
|
|
{
|
|
|
|
if(boost::filesystem::is_regular(dir->status()))
|
|
|
|
{
|
|
|
|
std::string name = dir->path().leaf();
|
|
|
|
std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper);
|
|
|
|
boost::algorithm::replace_all(name,".BMP",".PCX");
|
|
|
|
Entry * e = entries.znajdz(name);
|
2008-11-12 20:26:23 +02:00
|
|
|
if(e) //file present in .lod - overwrite its entry
|
2008-06-14 13:20:18 +03:00
|
|
|
{
|
|
|
|
e->offset = -1;
|
|
|
|
e->realSize = e->size = boost::filesystem::file_size(dir->path());
|
|
|
|
}
|
2008-11-12 20:26:23 +02:00
|
|
|
else //file not present in lod - add entry for it
|
|
|
|
{
|
2008-12-08 00:38:04 +02:00
|
|
|
Entry e2;
|
|
|
|
e2.offset = -1;
|
|
|
|
e2.nameStr = name;
|
|
|
|
e2.realSize = e2.size = boost::filesystem::file_size(dir->path());
|
|
|
|
entries.push_back(e2);
|
2008-11-12 20:26:23 +02:00
|
|
|
}
|
2008-06-14 13:20:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2009-02-14 17:00:29 +02:00
|
|
|
{
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog1<<"Warning: No "+dirName+"/ folder!"<<std::endl;
|
2009-02-14 17:00:29 +02:00
|
|
|
}
|
2007-06-30 19:24:05 +03:00
|
|
|
}
|
2008-06-13 00:08:04 +03:00
|
|
|
std::string CLodHandler::getTextFile(std::string name)
|
2007-07-16 17:42:44 +03:00
|
|
|
{
|
2008-06-12 09:45:51 +03:00
|
|
|
int length=-1;
|
|
|
|
unsigned char* data = giveFile(name,&length);
|
|
|
|
std::string ret;
|
|
|
|
ret.reserve(length);
|
|
|
|
for(int i=0;i<length;i++)
|
|
|
|
ret+=data[i];
|
|
|
|
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;
|
|
|
|
FLOD = NULL;
|
|
|
|
totalFiles = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CLodHandler::~CLodHandler()
|
|
|
|
{
|
|
|
|
delete mutex;
|
2009-08-02 18:18:35 +03:00
|
|
|
}
|