AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
MPQFile Class Reference

#include "mpq_libmpq04.h"

Public Member Functions

 MPQFile (const char *filename)
 
 ~MPQFile ()
 
size_t read (void *dest, size_t bytes)
 
size_t getSize ()
 
size_t getPos ()
 
char * getBuffer ()
 
char * getPointer ()
 
bool isEof ()
 
void seek (int offset)
 
void seekRelative (int offset)
 
void close ()
 
 MPQFile (const char *filename)
 
 ~MPQFile ()
 
size_t read (void *dest, size_t bytes)
 
size_t getSize ()
 
size_t getPos ()
 
char * getBuffer ()
 
char * getPointer ()
 
bool isEof ()
 
void seek (int offset)
 
void seekRelative (int offset)
 
void close ()
 

Private Member Functions

 MPQFile (const MPQFile &)
 
void operator= (const MPQFile &)
 
 MPQFile (const MPQFile &)
 
void operator= (const MPQFile &)
 

Private Attributes

bool eof
 
char * buffer
 
libmpq__off_t pointer
 
libmpq__off_t size
 

Detailed Description

Constructor & Destructor Documentation

◆ MPQFile() [1/4]

MPQFile::MPQFile ( const MPQFile )
inlineprivate
82{}

◆ MPQFile() [2/4]

MPQFile::MPQFile ( const char *  filename)
62 :
63 eof(false),
64 buffer(nullptr),
65 pointer(0),
66 size(0)
67{
68 for (auto & gOpenArchive : gOpenArchives)
69 {
70 mpq_archive* mpq_a = gOpenArchive->mpq_a;
71
72 uint32_t filenum;
73 if (libmpq__file_number(mpq_a, filename, &filenum)) continue;
74 libmpq__off_t transferred;
75 libmpq__file_unpacked_size(mpq_a, filenum, &size);
76
77 // HACK: in patch.mpq some files don't want to open and give 1 for filesize
78 if (size <= 1)
79 {
80 // printf("warning: file %s has size %d; cannot read.\n", filename, size);
81 eof = true;
82 buffer = nullptr;
83 return;
84 }
85 buffer = new char[size];
86
87 //libmpq_file_getdata
88 libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred);
89 /*libmpq_file_getdata(&mpq_a, hash, fileno, (unsigned char*)buffer);*/
90 return;
91 }
92 eof = true;
93 buffer = nullptr;
94}
char * buffer
Definition: mpq_libmpq04.h:78
libmpq__off_t size
Definition: mpq_libmpq04.h:79
libmpq__off_t pointer
Definition: mpq_libmpq04.h:79
bool eof
Definition: mpq_libmpq04.h:77
ArchiveSet gOpenArchives
Definition: mpq_libmpq.cpp:22

References buffer, eof, gOpenArchives, and size.

◆ ~MPQFile() [1/2]

MPQFile::~MPQFile ( )
inline
87{ close(); }
void close()
Definition: mpq_libmpq.cpp:126

References close().

◆ MPQFile() [3/4]

MPQFile::MPQFile ( const MPQFile )
inlineprivate
83{}

◆ MPQFile() [4/4]

MPQFile::MPQFile ( const char *  filename)

◆ ~MPQFile() [2/2]

MPQFile::~MPQFile ( )
inline
88{ close(); }

References close().

Member Function Documentation

◆ close() [1/2]

void MPQFile::close ( )

◆ close() [2/2]

void MPQFile::close ( )

◆ getBuffer() [1/2]

char * MPQFile::getBuffer ( )
inline
91{ return buffer; }

References buffer.

Referenced by Model::open().

◆ getBuffer() [2/2]

char * MPQFile::getBuffer ( )
inline
92{ return buffer; }

References buffer.

◆ getPointer() [1/2]

char * MPQFile::getPointer ( )
inline
92{ return buffer + pointer; }

References buffer, and pointer.

Referenced by ExtractFile(), WMORoot::open(), and ReadBuild().

◆ getPointer() [2/2]

char * MPQFile::getPointer ( )
inline
93{ return buffer + pointer; }

References buffer, and pointer.

◆ getPos() [1/2]

size_t MPQFile::getPos ( )
inline
90{ return pointer; }

References pointer.

Referenced by ADTFile::init(), WDTFile::init(), WMORoot::open(), and WMOGroup::open().

◆ getPos() [2/2]

size_t MPQFile::getPos ( )
inline
91{ return pointer; }

References pointer.

◆ getSize() [1/2]

size_t MPQFile::getSize ( )
inline
89{ return size; }

References size.

Referenced by ExtractFile(), FileLoader::loadFile(), and ReadBuild().

◆ getSize() [2/2]

size_t MPQFile::getSize ( )
inline
90{ return size; }

References size.

◆ isEof() [1/2]

bool MPQFile::isEof ( )
inline

◆ isEof() [2/2]

bool MPQFile::isEof ( )
inline
94{ return eof; }

References eof.

◆ operator=() [1/2]

void MPQFile::operator= ( const MPQFile )
inlineprivate
83{}

◆ operator=() [2/2]

void MPQFile::operator= ( const MPQFile )
inlineprivate
84{}

◆ read() [1/2]

size_t MPQFile::read ( void *  dest,
size_t  bytes 
)
97{
98 if (eof) return 0;
99
100 size_t rpos = pointer + bytes;
101 if (rpos > size_t(size))
102 {
103 bytes = size - pointer;
104 eof = true;
105 }
106
107 memcpy(dest, &(buffer[pointer]), bytes);
108
109 pointer = rpos;
110
111 return bytes;
112}

References buffer, eof, pointer, and size.

Referenced by ADTFile::init(), WDTFile::init(), FileLoader::loadFile(), DBCFile::open(), Model::open(), WMORoot::open(), and WMOGroup::open().

◆ read() [2/2]

size_t MPQFile::read ( void *  dest,
size_t  bytes 
)

◆ seek() [1/2]

void MPQFile::seek ( int  offset)
115{
116 pointer = offset;
117 eof = (pointer >= size);
118}

References eof, pointer, and size.

Referenced by ADTFile::init(), WDTFile::init(), Model::open(), WMORoot::open(), and WMOGroup::open().

◆ seek() [2/2]

void MPQFile::seek ( int  offset)

◆ seekRelative() [1/2]

void MPQFile::seekRelative ( int  offset)
121{
122 pointer += offset;
123 eof = (pointer >= size);
124}

References eof, pointer, and size.

Referenced by Model::open().

◆ seekRelative() [2/2]

void MPQFile::seekRelative ( int  offset)

Member Data Documentation

◆ buffer

char * MPQFile::buffer
private

◆ eof

bool MPQFile::eof
private

◆ pointer

libmpq__off_t MPQFile::pointer
private

◆ size

libmpq__off_t MPQFile::size
private