mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +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;
|
||||
}
|
||||
|
||||
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 {
|
||||
|
16
src/ozf.cpp
16
src/ozf.cpp
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user