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:35
ArchiveSet gOpenArchives
Definition: mpq_libmpq.cpp:22

References gOpenArchives, and mpq_a.

◆ ~MPQArchive() [1/2]

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

References close().

◆ MPQArchive() [2/2]

MPQArchive::MPQArchive ( const char *  filename)

◆ ~MPQArchive() [2/2]

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

References mpq_a.

◆ GetFileListTo() [2/2]

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

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().