TrinityCore
Loading...
Searching...
No Matches
loadlib.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#define _CRT_SECURE_NO_DEPRECATE
19
20#include "loadlib.h"
21#include "mpq_libmpq.h"
22#include <cstdio>
23
24class MPQFile;
25
26u_map_fcc MverMagic = { {'R','E','V','M'} };
27
29{
30 data = 0;
31 data_size = 0;
32 version = 0;
33}
34
39
40bool FileLoader::loadFile(std::string const& fileName, bool log)
41{
42 free();
43 MPQFile mf(fileName.c_str());
44 if(mf.isEof())
45 {
46 if (log)
47 printf("No such file %s\n", fileName.c_str());
48 return false;
49 }
50
51 data_size = mf.getSize();
52
53 data = new uint8 [data_size];
54 mf.read(data, data_size);
55 mf.close();
57 return true;
58
59 printf("Error loading %s", fileName.c_str());
60 mf.close();
61 free();
62 return false;
63}
64
66{
67 // Check version
69 if (version->fcc != MverMagic.fcc)
70 return false;
72 return false;
73 return true;
74}
75
77{
78 delete[] data;
79 data = 0;
80 data_size = 0;
81 version = 0;
82}
uint8_t uint8
Definition Define.h:135
bool loadFile(std::string const &fileName, bool log=true)
Definition loadlib.cpp:40
uint32 data_size
Definition loadlib.h:50
file_MVER * version
Definition loadlib.h:56
virtual void free()
Definition loadlib.cpp:76
virtual bool prepareLoadedData()
Definition loadlib.cpp:65
uint8 * data
Definition loadlib.h:49
size_t getSize()
Definition mpq_libmpq.h:87
size_t read(void *dest, size_t bytes)
bool isEof()
Definition mpq_libmpq.h:91
void close()
u_map_fcc MverMagic
Definition loadlib.cpp:26
uint32 ver
Definition loadlib.h:45
uint32 fcc
Definition loadlib.h:41
uint32 fcc
Definition loadlib.h:32
#define FILE_FORMAT_VERSION
Definition loadlib.h:23