mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 13:41:16 +01:00
Detect OZF files by contents rather than by file extension
This commit is contained in:
parent
81e1664a9b
commit
5b8d41afb7
@ -342,13 +342,7 @@ bool OfflineMap::getImageInfo(const QString &path)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString suffix = ii.suffix().toLower();
|
if (OZF::isOZF(_imgPath)) {
|
||||||
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") {
|
|
||||||
_ozf.load(_imgPath);
|
_ozf.load(_imgPath);
|
||||||
_size = _ozf.size();
|
_size = _ozf.size();
|
||||||
} else {
|
} else {
|
||||||
|
16
src/ozf.cpp
16
src/ozf.cpp
@ -232,3 +232,19 @@ QPixmap OZF::tile(int x, int y)
|
|||||||
|
|
||||||
return QPixmap::fromImage(img.mirrored());
|
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;
|
||||||
|
}
|
||||||
|
@ -22,6 +22,8 @@ public:
|
|||||||
QSize tileSize() const {return QSize(64, 64);}
|
QSize tileSize() const {return QSize(64, 64);}
|
||||||
QPixmap tile(int x, int y);
|
QPixmap tile(int x, int y);
|
||||||
|
|
||||||
|
static bool isOZF(const QString &path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<class T> bool readValue(T &val);
|
template<class T> bool readValue(T &val);
|
||||||
bool read(void *data, size_t size);
|
bool read(void *data, size_t size);
|
||||||
|
Loading…
Reference in New Issue
Block a user