TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mpqfile.h
Go to the documentation of this file.
1 #define _CRT_SECURE_NO_DEPRECATE
2 #ifndef _CRT_SECURE_NO_WARNINGS // fuck the police^Wwarnings
3 #define _CRT_SECURE_NO_WARNINGS
4 #endif
5 
6 #ifndef MPQ_H
7 #define MPQ_H
8 
9 #include <string.h>
10 #include <ctype.h>
11 #include <vector>
12 #include <iostream>
13 #include <deque>
14 #include <cstdint>
15 #include "CascLib.h"
16 
17 typedef int64_t int64;
18 typedef int32_t int32;
19 typedef int16_t int16;
20 typedef int8_t int8;
21 typedef uint64_t uint64;
22 typedef uint32_t uint32;
23 typedef uint16_t uint16;
24 typedef uint8_t uint8;
25 
26 #ifdef _WIN32
27 #include <Windows.h> // mainly only HANDLE definition is required
28 #else
29 int GetLastError();
30 #endif
31 
32 class MPQFile
33 {
34  //MPQHANDLE handle;
35  bool eof;
36  char *buffer;
37  size_t pointer,size;
38 
39  // disable copying
40  MPQFile(const MPQFile &f);
41  void operator=(const MPQFile &f);
42 
43 public:
44  MPQFile(HANDLE mpq, const char* filename, bool warnNoExist = true); // filenames are not case sensitive
45  ~MPQFile() { close(); }
46  size_t read(void* dest, size_t bytes);
47  size_t getSize() { return size; }
48  size_t getPos() { return pointer; }
49  char* getBuffer() { return buffer; }
50  char* getPointer() { return buffer + pointer; }
51  bool isEof() { return eof; }
52  void seek(int offset);
53  void seekRelative(int offset);
54  void close();
55 };
56 
57 inline void flipcc(char *fcc)
58 {
59  char t;
60  t=fcc[0];
61  fcc[0]=fcc[3];
62  fcc[3]=t;
63  t=fcc[1];
64  fcc[1]=fcc[2];
65  fcc[2]=t;
66 }
67 
68 #endif
void flipcc(char *fcc)
Definition: mpqfile.h:57
void * HANDLE
Definition: CascPort.h:146
MPQFile(const MPQFile &f)
uint32_t uint32
Definition: mpqfile.h:22
signed short int16_t
Definition: stdint.h:76
size_t getPos()
Definition: mpqfile.h:48
~MPQFile()
Definition: mpqfile.h:45
void close()
Definition: mpqfile.cpp:81
uint16_t uint16
Definition: mpqfile.h:23
char * getBuffer()
Definition: mpqfile.h:49
bool isEof()
Definition: mpqfile.h:51
size_t getSize()
Definition: mpqfile.h:47
signed __int64 int64_t
Definition: stdint.h:89
bool eof
Definition: mpqfile.h:35
Definition: mpqfile.h:32
unsigned int uint32_t
Definition: stdint.h:80
unsigned __int64 uint64_t
Definition: stdint.h:90
void seekRelative(int offset)
Definition: mpqfile.cpp:75
char * buffer
Definition: mpqfile.h:36
void operator=(const MPQFile &f)
int64_t int64
Definition: mpqfile.h:17
int8_t int8
Definition: mpqfile.h:20
size_t pointer
Definition: mpqfile.h:37
int16_t int16
Definition: mpqfile.h:19
int GetLastError()
Definition: Common.cpp:70
char * getPointer()
Definition: mpqfile.h:50
unsigned char uint8_t
Definition: stdint.h:78
size_t read(void *dest, size_t bytes)
Definition: mpqfile.cpp:52
signed char int8_t
Definition: stdint.h:75
uint64_t uint64
Definition: mpqfile.h:21
signed int int32_t
Definition: stdint.h:77
size_t size
Definition: mpqfile.h:37
int32_t int32
Definition: mpqfile.h:18
uint8_t uint8
Definition: mpqfile.h:24
void seek(int offset)
Definition: mpqfile.cpp:69
unsigned short uint16_t
Definition: stdint.h:79