aboutsummaryrefslogtreecommitdiff
path: root/contrib/extractor/loadlib/loadlib.cpp
diff options
context:
space:
mode:
authorXTZGZoReX <none@none>2009-04-13 16:24:19 +0200
committerXTZGZoReX <none@none>2009-04-13 16:24:19 +0200
commit83bc37cd375662dfb19aa2ae38132074ef39047c (patch)
tree072cb5c64eef1530fc082f7840d1da019b64fc62 /contrib/extractor/loadlib/loadlib.cpp
parent99e944f195ba6dc6bcbd0eaef08f33d127489535 (diff)
* Fixed extractor compile.
--HG-- branch : trunk
Diffstat (limited to 'contrib/extractor/loadlib/loadlib.cpp')
-rw-r--r--contrib/extractor/loadlib/loadlib.cpp64
1 files changed, 64 insertions, 0 deletions
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