Tools/VMAPs: Fix extractor crash when some .mpq files does not exist (#18130)

This commit is contained in:
Mikhail Redko
2016-10-23 23:44:07 +03:00
committed by Shauren
parent cdc5a36dbb
commit 3d7a86bf1e
2 changed files with 10 additions and 8 deletions

View File

@@ -19,6 +19,7 @@
#include "mpq_libmpq04.h"
#include <deque>
#include <cstdio>
#include <algorithm>
ArchiveSet gOpenArchives;
@@ -52,6 +53,11 @@ MPQArchive::MPQArchive(const char* filename)
gOpenArchives.push_front(this);
}
bool MPQArchive::isOpened() const
{
return std::find(gOpenArchives.begin(), gOpenArchives.end(), this) != gOpenArchives.end();
}
void MPQArchive::close()
{
//gOpenArchives.erase(erase(&mpq_a);

View File

@@ -34,7 +34,7 @@ public:
mpq_archive_s *mpq_a;
MPQArchive(const char* filename);
~MPQArchive() { close(); }
~MPQArchive() { if (isOpened()) close(); }
void GetFileListTo(std::vector<std::string>& filelist) {
uint32_t filenum;
@@ -66,6 +66,7 @@ public:
private:
void close();
bool isOpened() const;
};
typedef std::deque<MPQArchive*> ArchiveSet;
@@ -95,13 +96,8 @@ public:
inline void flipcc(char *fcc)
{
char t;
t=fcc[0];
fcc[0]=fcc[3];
fcc[3]=t;
t=fcc[1];
fcc[1]=fcc[2];
fcc[2]=t;
std::swap(fcc[0], fcc[3]);
std::swap(fcc[1], fcc[2]);
}
#endif