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

#include "mpq_libmpq04.h"

Public Member Functions

 MPQArchive (const char *filename)
 
 ~MPQArchive ()
 
void close ()
 
void GetFileListTo (vector< string > &filelist)
 
 MPQArchive (const char *filename)
 
 ~MPQArchive ()
 
void GetFileListTo (vector< string > &filelist)
 

Public Attributes

mpq_archive_s * mpq_a
 

Private Member Functions

void close ()
 
bool isOpened () const
 

Detailed Description

Constructor & Destructor Documentation

◆ MPQArchive() [1/2]

MPQArchive::MPQArchive ( const char *  filename)
25{
26 int result = libmpq__archive_open(&mpq_a, filename, -1);
27 printf("Opening %s\n", filename);
28 if (result)
29 {
30 switch (result)
31 {
32 case LIBMPQ_ERROR_OPEN :
33 printf("Error opening archive '%s': Does file really exist?\n", filename);
34 break;
35 case LIBMPQ_ERROR_FORMAT : /* bad file format */
36 printf("Error opening archive '%s': Bad file format\n", filename);
37 break;
38 case LIBMPQ_ERROR_SEEK : /* seeking in file failed */
39 printf("Error opening archive '%s': Seeking in file failed\n", filename);
40 break;
41 case LIBMPQ_ERROR_READ : /* Read error in archive */
42 printf("Error opening archive '%s': Read error in archive\n", filename);
43 break;
44 case LIBMPQ_ERROR_MALLOC : /* maybe not enough memory? :) */
45 printf("Error opening archive '%s': Maybe not enough memory\n", filename);
46 break;
47 default:
48 printf("Error opening archive '%s': Unknown error\n", filename);
49 break;
50 }
51 return;
52 }
53 gOpenArchives.push_front(this);
54}
mpq_archive_s * mpq_a
Definition: mpq_libmpq04.h:34
ArchiveSet gOpenArchives
Definition: mpq_libmpq.cpp:22

References gOpenArchives, and mpq_a.

◆ ~MPQArchive() [1/2]

MPQArchive::~MPQArchive ( )
inline
37{ close(); }
void close()
Definition: mpq_libmpq.cpp:56

References close().

◆ MPQArchive() [2/2]

MPQArchive::MPQArchive ( const char *  filename)

◆ ~MPQArchive() [2/2]

MPQArchive::~MPQArchive ( )
inline
36{ if (isOpened()) close(); }
bool isOpened() const
Definition: mpq_libmpq.cpp:57

References close(), and isOpened().

Member Function Documentation

◆ close() [1/2]

void MPQArchive::close ( )
57{
58 //gOpenArchives.erase(erase(&mpq_a);
59 libmpq__archive_close(mpq_a);
60}

References mpq_a.

Referenced by ~MPQArchive().

◆ close() [2/2]

void MPQArchive::close ( )
private

◆ GetFileListTo() [1/2]

void MPQArchive::GetFileListTo ( vector< string > &  filelist)
inline
41 {
42 uint32_t filenum;
43 if (libmpq__file_number(mpq_a, "(listfile)", &filenum)) return;
44 libmpq__off_t size, transferred;
45 libmpq__file_unpacked_size(mpq_a, filenum, &size);
46
47 char* buffer = new char[size + 1];
48 buffer[size] = '\0';
49
50 libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred);
51
52 char seps[] = "\n";
53 char* token;
54
55 token = strtok( buffer, seps );
56 uint32 counter = 0;
57 while ((token != nullptr) && (counter < size))
58 {
59 //cout << token << endl;
60 token[strlen(token) - 1] = 0;
61 string s = token;
62 filelist.push_back(s);
63 counter += strlen(token) + 2;
64 token = strtok(nullptr, seps);
65 }
66
67 delete[] buffer;
68 }
std::uint32_t uint32
Definition: Define.h:107

References mpq_a.

◆ GetFileListTo() [2/2]

void MPQArchive::GetFileListTo ( vector< string > &  filelist)
inline
39 {
40 uint32_t filenum;
41 if (libmpq__file_number(mpq_a, "(listfile)", &filenum)) return;
42 libmpq__off_t size, transferred;
43 libmpq__file_unpacked_size(mpq_a, filenum, &size);
44
45 char* buffer = new char[size + 1];
46 buffer[size] = '\0';
47
48 libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred);
49
50 char seps[] = "\n";
51 char* token;
52
53 token = strtok( buffer, seps );
54 uint32 counter = 0;
55 while ((token != nullptr) && (counter < size))
56 {
57 //cout << token << endl;
58 token[strlen(token) - 1] = 0;
59 string s = token;
60 filelist.push_back(s);
61 counter += strlen(token) + 2;
62 token = strtok(nullptr, seps);
63 }
64
65 delete[] buffer;
66 }

References mpq_a.

◆ isOpened()

bool MPQArchive::isOpened ( ) const
private
58{
59 return std::find(gOpenArchives.begin(), gOpenArchives.end(), this) != gOpenArchives.end();
60}

References gOpenArchives.

Referenced by ~MPQArchive().

Member Data Documentation

◆ mpq_a

mpq_archive_s * MPQArchive::mpq_a

Referenced by close(), GetFileListTo(), and MPQArchive().