forked from Hellfire-Core/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadlib.cpp
More file actions
63 lines (55 loc) · 1.05 KB
/
Copy pathloadlib.cpp
File metadata and controls
63 lines (55 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#define _CRT_SECURE_NO_DEPRECATE
#include "loadlib.h"
#include <libmpq/mpq_libmpq.h>
#include <stdio.h>
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;
}