1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Detect OZF files by contents rather than by file extension

This commit is contained in:
Martin Tůma 2017-07-29 22:19:03 +02:00
parent 81e1664a9b
commit 5b8d41afb7
3 changed files with 19 additions and 7 deletions

View File

@ -342,13 +342,7 @@ bool OfflineMap::getImageInfo(const QString &path)
return false;
}
QString suffix = ii.suffix().toLower();
if (suffix == "ozf4" || suffix == "ozfx4") {
_errorString = QString("%1: OZF4 image files not supported")
.arg(QFileInfo(_imgPath).fileName());
return false;
} else if (suffix == "ozf2" || suffix == "ozfx2" || suffix == "ozf3"
|| suffix == "ozfx3") {
if (OZF::isOZF(_imgPath)) {
_ozf.load(_imgPath);
_size = _ozf.size();
} else {

View File

@ -232,3 +232,19 @@ QPixmap OZF::tile(int x, int y)
return QPixmap::fromImage(img.mirrored());
}
bool OZF::isOZF(const QString &path)
{
QFile file(path);
quint16 magic;
if (!file.open(QIODevice::ReadOnly))
return false;
if (file.read((char*)&magic, sizeof(magic)) < (qint64)sizeof(magic))
return false;
if (magic == OZF2_MAGIC || magic == OZF3_MAGIC)
return true;
return false;
}

View File

@ -22,6 +22,8 @@ public:
QSize tileSize() const {return QSize(64, 64);}
QPixmap tile(int x, int y);
static bool isOZF(const QString &path);
private:
template<class T> bool readValue(T &val);
bool read(void *data, size_t size);