From 83bc37cd375662dfb19aa2ae38132074ef39047c Mon Sep 17 00:00:00 2001 From: XTZGZoReX Date: Mon, 13 Apr 2009 16:24:19 +0200 Subject: * Fixed extractor compile. --HG-- branch : trunk --- contrib/extractor/loadlib/loadlib.cpp | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 contrib/extractor/loadlib/loadlib.cpp (limited to 'contrib/extractor/loadlib/loadlib.cpp') diff --git a/contrib/extractor/loadlib/loadlib.cpp b/contrib/extractor/loadlib/loadlib.cpp new file mode 100644 index 00000000000..ed5bd9acb71 --- /dev/null +++ b/contrib/extractor/loadlib/loadlib.cpp @@ -0,0 +1,64 @@ +#define _CRT_SECURE_NO_DEPRECATE + +#include "loadlib.h" +#include "../mpq_libmpq.h" + +class MPQFile; + +FileLoader::FileLoader() +{ + data = 0; + data_size = 0; + version = 0; +} + +FileLoader::~FileLoader() +{ + free(); +} + +bool FileLoader::loadFile(char *filename, bool log) +{ + free(); + MPQFile mf(filename); + if(mf.isEof()) + { + if (log) + printf("No such file %s\n", filename); + return false; + } + + data_size = mf.getSize(); + + data = new uint8 [data_size]; + if (data) + { + mf.read(data, data_size); + mf.close(); + if (prepareLoadedData()) + return true; + } + printf("Error loading %s", filename); + mf.close(); + free(); + return false; +} + +bool FileLoader::prepareLoadedData() +{ + // Check version + version = (file_MVER *) data; + if (version->fcc != 'MVER') + return false; + if (version->ver != FILE_FORMAT_VERSION) + return false; + return true; +} + +void FileLoader::free() +{ + if (data) delete[] data; + data = 0; + data_size = 0; + version = 0; +} \ No newline at end of file -- cgit v1.2.3