2020-01-05 00:50:02 +01:00
|
|
|
#include <cstring>
|
2019-10-25 22:30:12 +02:00
|
|
|
#include <QDataStream>
|
|
|
|
#include <QtEndian>
|
|
|
|
#include <QUrl>
|
2019-11-06 23:23:05 +01:00
|
|
|
#include <QIODevice>
|
|
|
|
#include <QApplication>
|
2019-11-01 19:07:21 +01:00
|
|
|
#include <QBuffer>
|
2019-11-06 23:23:05 +01:00
|
|
|
#include <QImageReader>
|
2019-11-07 23:23:25 +01:00
|
|
|
#include <QCryptographicHash>
|
2019-11-06 23:23:05 +01:00
|
|
|
#include <QTemporaryDir>
|
2019-11-10 16:46:31 +01:00
|
|
|
#include "common/garmin.h"
|
2020-12-22 22:09:09 +01:00
|
|
|
#include "common/textcodec.h"
|
2021-10-10 08:38:38 +02:00
|
|
|
#include "common/color.h"
|
2021-05-12 21:58:46 +02:00
|
|
|
#include "address.h"
|
2019-10-25 22:30:12 +02:00
|
|
|
#include "gpiparser.h"
|
|
|
|
|
2021-09-20 21:43:17 +02:00
|
|
|
using namespace Garmin;
|
2019-10-25 22:30:12 +02:00
|
|
|
|
|
|
|
struct RecordHeader {
|
|
|
|
quint16 type;
|
|
|
|
quint16 flags;
|
|
|
|
quint32 size;
|
|
|
|
quint32 extra;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TranslatedString {
|
|
|
|
public:
|
|
|
|
TranslatedString() {}
|
|
|
|
TranslatedString(const QString &lang, const QString &str)
|
|
|
|
: _lang(lang), _str(str) {}
|
|
|
|
|
|
|
|
const QString &str() const {return _str;}
|
|
|
|
const QString &lang() const {return _lang;}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _lang;
|
|
|
|
QString _str;
|
|
|
|
};
|
|
|
|
|
2021-10-10 08:38:38 +02:00
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
QDebug operator<<(QDebug dbg, const TranslatedString &ts)
|
|
|
|
{
|
|
|
|
dbg.nospace() << "TS(" << ts.lang() << ", " << ts.str() << ")";
|
|
|
|
return dbg.space();
|
|
|
|
}
|
|
|
|
#endif // QT_NO_DEBUG
|
|
|
|
|
2019-11-06 23:23:05 +01:00
|
|
|
class CryptDevice : public QIODevice
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CryptDevice(QIODevice *device, quint32 key, quint32 blockSize,
|
|
|
|
QObject *parent = 0);
|
|
|
|
bool isSequential() const {return true;}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
qint64 readData(char *data, qint64 maxSize);
|
|
|
|
qint64 writeData(const char *, qint64) {return -1;}
|
2019-11-01 19:07:21 +01:00
|
|
|
|
2019-11-06 23:23:05 +01:00
|
|
|
private:
|
|
|
|
QIODevice *_device;
|
|
|
|
quint32 _key;
|
|
|
|
QByteArray _block;
|
|
|
|
int _available;
|
|
|
|
};
|
2019-11-01 19:07:21 +01:00
|
|
|
|
2019-11-06 23:23:05 +01:00
|
|
|
static void demangle(quint8 *data, quint32 size, quint32 key)
|
2019-11-01 19:07:21 +01:00
|
|
|
{
|
|
|
|
static const unsigned char shuf[] = {
|
|
|
|
0xb, 0xc, 0xa, 0x0,
|
|
|
|
0x8, 0xf, 0x2, 0x1,
|
|
|
|
0x6, 0x4, 0x9, 0x3,
|
|
|
|
0xd, 0x5, 0x7, 0xe
|
|
|
|
};
|
|
|
|
|
|
|
|
int hiCnt = 0, loCnt;
|
2019-11-05 19:31:52 +01:00
|
|
|
quint8 sum = shuf[((key >> 24) + (key >> 16) + (key >> 8) + key) & 0xf];
|
2019-11-01 19:07:21 +01:00
|
|
|
|
|
|
|
for (quint32 i = 0; i < size; i++) {
|
|
|
|
quint8 hiAdd = shuf[key >> (hiCnt << 2) & 0xf] + sum;
|
|
|
|
loCnt = (hiCnt > 6) ? 0 : hiCnt + 1;
|
|
|
|
quint8 loAdd = shuf[key >> (loCnt << 2) & 0xf] + sum;
|
2019-11-05 19:31:52 +01:00
|
|
|
quint8 hi = data[i] - (hiAdd << 4);
|
2019-11-01 19:07:21 +01:00
|
|
|
quint8 lo = data[i] - loAdd;
|
|
|
|
data[i] = (hi & 0xf0) | (lo & 0x0f);
|
|
|
|
hiCnt = (loCnt > 6) ? 0 : loCnt + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 23:23:05 +01:00
|
|
|
CryptDevice::CryptDevice(QIODevice *device, quint32 key, quint32 blockSize,
|
|
|
|
QObject *parent) : QIODevice(parent), _device(device), _key(key), _available(0)
|
|
|
|
{
|
|
|
|
_block.resize(blockSize);
|
|
|
|
setOpenMode(_device->openMode());
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 CryptDevice::readData(char *data, qint64 maxSize)
|
|
|
|
{
|
|
|
|
qint64 rs, ts = 0;
|
|
|
|
int cs;
|
|
|
|
|
|
|
|
if (_available) {
|
|
|
|
cs = qMin(maxSize, (qint64)_available);
|
|
|
|
memcpy(data, _block.constData() + _block.size() - _available, cs);
|
|
|
|
_available -= cs;
|
|
|
|
maxSize -= cs;
|
|
|
|
ts = cs;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (maxSize) {
|
|
|
|
if ((rs = _device->read(_block.data(), _block.size())) < 0)
|
|
|
|
return -1;
|
|
|
|
else if (!rs)
|
|
|
|
break;
|
|
|
|
_available = rs;
|
|
|
|
demangle((quint8*)_block.data(), _available, _key);
|
|
|
|
cs = qMin(maxSize, (qint64)_available);
|
|
|
|
memcpy(data + ts, _block.constData(), cs);
|
|
|
|
_available -= cs;
|
|
|
|
maxSize -= cs;
|
|
|
|
ts += cs;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
2019-11-10 16:46:31 +01:00
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
class DataStream : public QDataStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DataStream(QIODevice *d) : QDataStream(d) {}
|
|
|
|
|
|
|
|
void setCodepage(quint16 codepage) {_codec = TextCodec(codepage);}
|
|
|
|
|
|
|
|
quint16 readString(QString &str);
|
|
|
|
qint32 readInt24();
|
|
|
|
quint8 readRecordHeader(RecordHeader &hdr);
|
|
|
|
quint32 readTranslatedObjects(QList<TranslatedString> &objects);
|
|
|
|
|
|
|
|
quint32 skipRecord();
|
|
|
|
quint16 nextHeaderType();
|
|
|
|
|
|
|
|
private:
|
|
|
|
TextCodec _codec;
|
|
|
|
};
|
|
|
|
|
|
|
|
quint16 DataStream::readString(QString &str)
|
|
|
|
{
|
|
|
|
quint16 len;
|
|
|
|
*this >> len;
|
|
|
|
QByteArray ba;
|
|
|
|
ba.resize(len);
|
|
|
|
readRawData(ba.data(), len);
|
|
|
|
str = _codec.toString(ba);
|
|
|
|
|
|
|
|
return len + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
qint32 DataStream::readInt24()
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
2019-11-10 16:46:31 +01:00
|
|
|
unsigned char data[3];
|
|
|
|
quint32 val;
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
readRawData((char*)data, sizeof(data));
|
2019-11-10 16:46:31 +01:00
|
|
|
val = data[0] | ((quint32)data[1]) << 8 | ((quint32)data[2]) << 16;
|
|
|
|
return (val > 0x7FFFFF) ? (val & 0x7FFFFF) - 0x800000 : val;
|
2019-10-25 22:30:12 +02:00
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
quint16 DataStream::nextHeaderType()
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
|
|
|
quint16 type = 0;
|
2019-11-07 23:23:25 +01:00
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
if (device()->peek((char*)&type, sizeof(type)) < (qint64)sizeof(type)) {
|
|
|
|
setStatus(QDataStream::ReadCorruptData);
|
2019-11-07 23:23:25 +01:00
|
|
|
return 0xFFFF;
|
|
|
|
} else
|
|
|
|
return qFromLittleEndian(type);
|
2019-10-25 22:30:12 +02:00
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
quint8 DataStream::readRecordHeader(RecordHeader &hdr)
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
2020-12-22 22:09:09 +01:00
|
|
|
*this >> hdr.type >> hdr.flags >> hdr.size;
|
2019-10-25 22:30:12 +02:00
|
|
|
if (hdr.flags & 0xA)
|
2020-12-22 22:09:09 +01:00
|
|
|
*this >> hdr.extra;
|
2019-10-25 22:30:12 +02:00
|
|
|
return (hdr.flags & 0xA) ? 12 : 8;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
quint32 DataStream::skipRecord()
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
2020-12-22 22:09:09 +01:00
|
|
|
quint8 rs = readRecordHeader(rh);
|
|
|
|
skipRawData(rh.size);
|
2019-10-25 22:30:12 +02:00
|
|
|
|
|
|
|
return rs + rh.size;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
quint32 DataStream::readTranslatedObjects(QList<TranslatedString> &objects)
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
|
|
|
qint32 size = 0, ret;
|
2020-01-05 00:50:02 +01:00
|
|
|
char lang[3];
|
2019-10-25 22:30:12 +02:00
|
|
|
|
2020-01-05 00:50:02 +01:00
|
|
|
memset(lang, 0, sizeof(lang));
|
2019-10-25 22:30:12 +02:00
|
|
|
objects.clear();
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
*this >> size;
|
2019-10-25 22:30:12 +02:00
|
|
|
ret = size + 4;
|
2020-12-22 22:09:09 +01:00
|
|
|
while (status() == QDataStream::Ok && size > 0) {
|
2019-10-25 22:30:12 +02:00
|
|
|
QString str;
|
2020-12-22 22:09:09 +01:00
|
|
|
readRawData(lang, sizeof(lang) - 1);
|
|
|
|
size -= readString(str) + 2;
|
2019-10-25 22:30:12 +02:00
|
|
|
objects.append(TranslatedString(lang, str));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size < 0)
|
2020-12-22 22:09:09 +01:00
|
|
|
setStatus(QDataStream::ReadCorruptData);
|
2019-10-25 22:30:12 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
|
|
|
|
static quint32 readFprsRecord(DataStream &stream)
|
2019-11-07 23:23:25 +01:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
|
|
|
quint16 s1;
|
|
|
|
quint8 rs, s2, s3, s4;
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
rs = stream.readRecordHeader(rh);
|
2019-11-07 23:23:25 +01:00
|
|
|
stream >> s1 >> s2 >> s3 >> s4;
|
|
|
|
|
|
|
|
return rs + 5;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
static quint32 readFileDataRecord(DataStream &stream)
|
2019-11-07 23:23:25 +01:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
2021-10-11 22:02:24 +02:00
|
|
|
quint32 ds, flags;
|
2019-11-07 23:23:25 +01:00
|
|
|
quint16 s2, s3;
|
|
|
|
quint8 rs;
|
|
|
|
QList<TranslatedString> obj;
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
rs = stream.readRecordHeader(rh);
|
2021-10-11 22:02:24 +02:00
|
|
|
stream >> flags >> s2 >> s3;
|
2019-11-07 23:23:25 +01:00
|
|
|
ds = 8;
|
2021-10-11 22:02:24 +02:00
|
|
|
// name
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readTranslatedObjects(obj);
|
2021-10-11 22:02:24 +02:00
|
|
|
// copyright
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readTranslatedObjects(obj);
|
2021-10-11 22:02:24 +02:00
|
|
|
// additional stuff depending on flags
|
|
|
|
// ...
|
2019-11-07 23:23:25 +01:00
|
|
|
|
|
|
|
if (ds > rh.size)
|
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
|
|
|
else if (ds < rh.size)
|
|
|
|
stream.skipRawData(rh.size - ds);
|
|
|
|
|
|
|
|
return rs + rh.size;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
static quint32 readDescription(DataStream &stream, Waypoint &waypoint)
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
|
|
|
quint8 rs;
|
|
|
|
quint32 ds;
|
|
|
|
QList<TranslatedString> obj;
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
rs = stream.readRecordHeader(rh);
|
|
|
|
ds = stream.readTranslatedObjects(obj);
|
2019-10-25 22:30:12 +02:00
|
|
|
if (!obj.isEmpty())
|
|
|
|
waypoint.setDescription(obj.first().str());
|
|
|
|
|
|
|
|
if (ds != rh.size)
|
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
|
|
|
|
|
|
|
return rs + rh.size;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
static quint32 readNotes(DataStream &stream, Waypoint &waypoint)
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
2021-10-11 22:02:24 +02:00
|
|
|
quint8 rs, flags;
|
2019-10-25 22:30:12 +02:00
|
|
|
quint32 ds = 1;
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
rs = stream.readRecordHeader(rh);
|
2021-10-11 22:02:24 +02:00
|
|
|
stream >> flags;
|
|
|
|
if (flags & 0x1) {
|
2019-10-25 22:30:12 +02:00
|
|
|
QList<TranslatedString> obj;
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readTranslatedObjects(obj);
|
2020-03-09 20:04:13 +01:00
|
|
|
if (!obj.isEmpty())
|
|
|
|
waypoint.setComment(obj.first().str());
|
2019-10-25 22:30:12 +02:00
|
|
|
}
|
2021-10-11 22:02:24 +02:00
|
|
|
if (flags & 0x2) {
|
2019-10-25 22:30:12 +02:00
|
|
|
QString str;
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readString(str);
|
2020-03-09 20:04:13 +01:00
|
|
|
if (!str.isEmpty())
|
|
|
|
waypoint.setComment(str);
|
2019-10-25 22:30:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ds != rh.size)
|
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
|
|
|
|
|
|
|
return rs + rh.size;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
static quint32 readContact(DataStream &stream, Waypoint &waypoint)
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
|
|
|
quint8 rs;
|
2019-11-08 21:00:59 +01:00
|
|
|
quint16 flags;
|
2019-10-25 22:30:12 +02:00
|
|
|
quint32 ds = 2;
|
|
|
|
QString str;
|
|
|
|
QList<TranslatedString> obj;
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
rs = stream.readRecordHeader(rh);
|
2019-11-08 21:00:59 +01:00
|
|
|
stream >> flags;
|
2019-10-25 22:30:12 +02:00
|
|
|
|
2021-05-12 21:58:46 +02:00
|
|
|
if (flags & 0x1) {
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readString(str);
|
2021-05-12 21:58:46 +02:00
|
|
|
waypoint.setPhone(str);
|
|
|
|
}
|
2019-11-08 21:00:59 +01:00
|
|
|
if (flags & 0x2) // phone2
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readString(str);
|
2019-11-08 21:00:59 +01:00
|
|
|
if (flags & 0x4) // fax
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readString(str);
|
2021-05-12 21:58:46 +02:00
|
|
|
if (flags & 0x8) {
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readString(str);
|
2021-05-12 21:58:46 +02:00
|
|
|
waypoint.addLink(Link("mailto:" + str, str));
|
|
|
|
}
|
|
|
|
if (flags & 0x10) {
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readString(str);
|
2019-10-25 22:30:12 +02:00
|
|
|
QUrl url(str);
|
|
|
|
waypoint.addLink(Link(url.scheme().isEmpty()
|
|
|
|
? "http://" + str : str, str));
|
|
|
|
}
|
2019-11-08 21:00:59 +01:00
|
|
|
if (flags & 0x20) // unknown
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readTranslatedObjects(obj);
|
2019-11-08 21:00:59 +01:00
|
|
|
|
|
|
|
if (ds != rh.size)
|
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
|
|
|
|
|
|
|
return rs + rh.size;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
static quint32 readAddress(DataStream &stream, Waypoint &waypoint)
|
2019-11-08 21:00:59 +01:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
|
|
|
quint8 rs;
|
|
|
|
quint16 flags;
|
|
|
|
quint32 ds = 2;
|
|
|
|
QList<TranslatedString> obj;
|
|
|
|
QString str;
|
|
|
|
Address addr;
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
rs = stream.readRecordHeader(rh);
|
2019-11-08 21:00:59 +01:00
|
|
|
stream >> flags;
|
|
|
|
|
|
|
|
if (flags & 0x1) {
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readTranslatedObjects(obj);
|
2019-11-08 21:00:59 +01:00
|
|
|
if (!obj.isEmpty())
|
|
|
|
addr.setCity(obj.first().str());
|
|
|
|
}
|
|
|
|
if (flags & 0x2) {
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readTranslatedObjects(obj);
|
2019-11-08 21:00:59 +01:00
|
|
|
if (!obj.isEmpty())
|
|
|
|
addr.setCountry(obj.first().str());
|
|
|
|
}
|
|
|
|
if (flags & 0x4) {
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readTranslatedObjects(obj);
|
2019-11-08 21:00:59 +01:00
|
|
|
if (!obj.isEmpty())
|
|
|
|
addr.setState(obj.first().str());
|
|
|
|
}
|
|
|
|
if (flags & 0x8) {
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readString(str);
|
2019-11-08 21:00:59 +01:00
|
|
|
addr.setPostalCode(str);
|
|
|
|
}
|
|
|
|
if (flags & 0x10) {
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readTranslatedObjects(obj);
|
2019-11-08 21:00:59 +01:00
|
|
|
if (!obj.isEmpty())
|
|
|
|
addr.setStreet(obj.first().str());
|
|
|
|
}
|
|
|
|
if (flags & 0x20) // unknown
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readString(str);
|
2019-11-08 21:00:59 +01:00
|
|
|
|
2021-05-12 21:58:46 +02:00
|
|
|
if (addr.isValid())
|
|
|
|
waypoint.setAddress(addr.address());
|
2019-10-25 22:30:12 +02:00
|
|
|
|
|
|
|
if (ds != rh.size)
|
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
|
|
|
|
|
|
|
return rs + rh.size;
|
|
|
|
}
|
|
|
|
|
2019-11-08 01:04:17 +01:00
|
|
|
static const QTemporaryDir &tempDir()
|
|
|
|
{
|
|
|
|
static QTemporaryDir dir;
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
static quint32 readImageInfo(DataStream &stream, Waypoint &waypoint,
|
2019-11-07 23:23:25 +01:00
|
|
|
const QString &fileName, int &imgId)
|
2019-11-06 23:23:05 +01:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
|
|
|
quint8 rs, s1;
|
|
|
|
quint32 size;
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
rs = stream.readRecordHeader(rh);
|
2019-11-06 23:23:05 +01:00
|
|
|
stream >> s1 >> size;
|
|
|
|
|
|
|
|
QByteArray ba;
|
|
|
|
ba.resize(size);
|
|
|
|
stream.readRawData(ba.data(), ba.size());
|
|
|
|
|
2019-11-15 23:41:30 +01:00
|
|
|
if (tempDir().isValid()) {
|
|
|
|
QBuffer buf(&ba);
|
|
|
|
QImageReader ir(&buf);
|
|
|
|
|
|
|
|
QByteArray id(fileName.toUtf8() + QByteArray::number(imgId++));
|
|
|
|
QFile imgFile(tempDir().path() + "/" + QString("%0.%1").arg(
|
|
|
|
QCryptographicHash::hash(id, QCryptographicHash::Sha1).toHex(),
|
|
|
|
QString(ir.format())));
|
|
|
|
imgFile.open(QIODevice::WriteOnly);
|
|
|
|
imgFile.write(ba);
|
|
|
|
imgFile.close();
|
|
|
|
|
2021-10-04 21:00:29 +02:00
|
|
|
waypoint.addImage(imgFile.fileName());
|
2019-11-15 23:41:30 +01:00
|
|
|
}
|
2019-11-06 23:23:05 +01:00
|
|
|
|
|
|
|
if (size + 5 != rh.size)
|
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
|
|
|
|
|
|
|
return rs + rh.size;
|
|
|
|
}
|
|
|
|
|
2019-11-10 16:46:31 +01:00
|
|
|
static int speed(quint8 flags)
|
|
|
|
{
|
|
|
|
switch (flags >> 4) {
|
|
|
|
case 0x8:
|
|
|
|
return 40;
|
|
|
|
case 0x9:
|
|
|
|
return 30;
|
|
|
|
case 0xA:
|
|
|
|
return 50;
|
|
|
|
case 0xB:
|
|
|
|
return 70;
|
|
|
|
case 0xC:
|
|
|
|
return 80;
|
|
|
|
case 0xD:
|
|
|
|
return 90;
|
|
|
|
case 0xE:
|
|
|
|
return 100;
|
2019-11-13 19:21:41 +01:00
|
|
|
case 0xF:
|
|
|
|
return 120;
|
2019-11-10 16:46:31 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
static quint32 readCamera(DataStream &stream, QVector<Waypoint> &waypoints,
|
2019-11-10 16:46:31 +01:00
|
|
|
QList<Area> &polygons)
|
|
|
|
{
|
|
|
|
RecordHeader rh;
|
|
|
|
quint8 flags, type, s7, rs;
|
2019-11-14 22:55:06 +01:00
|
|
|
qint32 top, right, bottom, left, lat, lon;
|
2019-11-10 19:20:25 +01:00
|
|
|
quint32 ds = 15;
|
2019-11-10 16:46:31 +01:00
|
|
|
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
rs = stream.readRecordHeader(rh);
|
|
|
|
top = stream.readInt24();
|
|
|
|
right = stream.readInt24();
|
|
|
|
bottom = stream.readInt24();
|
|
|
|
left = stream.readInt24();
|
2019-11-10 16:46:31 +01:00
|
|
|
stream >> flags >> type >> s7;
|
|
|
|
|
|
|
|
if (s7) {
|
2019-11-10 19:20:25 +01:00
|
|
|
quint32 skip = s7 + 2 + s7/4;
|
2019-11-10 16:46:31 +01:00
|
|
|
stream.skipRawData(skip);
|
2020-12-22 22:09:09 +01:00
|
|
|
lat = stream.readInt24();
|
|
|
|
lon = stream.readInt24();
|
2019-11-10 19:20:25 +01:00
|
|
|
ds += skip + 6;
|
2019-11-14 22:55:06 +01:00
|
|
|
} else {
|
|
|
|
quint8 s8;
|
|
|
|
stream.skipRawData(9);
|
|
|
|
stream >> s8;
|
|
|
|
quint32 skip = 3 + s8 + s8/4;
|
|
|
|
stream.skipRawData(skip);
|
2020-12-22 22:09:09 +01:00
|
|
|
lat = stream.readInt24();
|
|
|
|
lon = stream.readInt24();
|
2019-11-14 22:55:06 +01:00
|
|
|
ds += skip + 16;
|
2019-11-10 19:20:25 +01:00
|
|
|
}
|
2019-11-10 16:46:31 +01:00
|
|
|
|
2019-11-14 22:55:06 +01:00
|
|
|
waypoints.append(Coordinates(toWGS24(lon), toWGS24(lat)));
|
|
|
|
|
2020-12-02 23:58:11 +01:00
|
|
|
Area area(RectC(Coordinates(toWGS24(left), toWGS24(top)),
|
|
|
|
Coordinates(toWGS24(right), toWGS24(bottom))));
|
2019-11-10 16:46:31 +01:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 8:
|
|
|
|
area.setDescription(QString("%1 mi/h")
|
|
|
|
.arg(speed(flags)));
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
area.setDescription(QString("%1 km/h")
|
|
|
|
.arg(speed(flags)));
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
case 11:
|
|
|
|
area.setDescription("Red light camera");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
polygons.append(area);
|
|
|
|
|
2019-11-10 19:20:25 +01:00
|
|
|
if (ds > rh.size)
|
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
|
|
|
else if (ds < rh.size)
|
|
|
|
stream.skipRawData(rh.size - ds);
|
|
|
|
|
2019-11-10 16:46:31 +01:00
|
|
|
return rs + rh.size;
|
|
|
|
}
|
|
|
|
|
2021-10-10 08:38:38 +02:00
|
|
|
static quint32 readIconId(DataStream &stream, quint16 &id)
|
|
|
|
{
|
|
|
|
RecordHeader rh;
|
|
|
|
quint8 rs;
|
|
|
|
|
|
|
|
rs = stream.readRecordHeader(rh);
|
|
|
|
stream >> id;
|
|
|
|
|
|
|
|
if (2 != rh.size)
|
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
|
|
|
|
|
|
|
return rs + rh.size;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
static quint32 readPOI(DataStream &stream, QVector<Waypoint> &waypoints,
|
2021-10-10 08:38:38 +02:00
|
|
|
const QString &fileName, int &imgId, QVector<QPair<int, quint16> > &icons)
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
|
|
|
quint8 rs;
|
|
|
|
quint32 ds;
|
2019-11-09 21:43:07 +01:00
|
|
|
qint32 lat, lon;
|
2021-10-18 23:10:09 +02:00
|
|
|
quint16 s3, iconId = 0;
|
2019-10-25 22:30:12 +02:00
|
|
|
QList<TranslatedString> obj;
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
rs = stream.readRecordHeader(rh);
|
2019-11-09 21:43:07 +01:00
|
|
|
stream >> lat >> lon >> s3;
|
2019-10-25 22:30:12 +02:00
|
|
|
stream.skipRawData(s3);
|
|
|
|
ds = 10 + s3;
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.readTranslatedObjects(obj);
|
2019-10-25 22:30:12 +02:00
|
|
|
|
2019-11-10 16:46:31 +01:00
|
|
|
waypoints.append(Waypoint(Coordinates(toWGS32(lon), toWGS32(lat))));
|
2019-10-25 22:30:12 +02:00
|
|
|
if (!obj.isEmpty())
|
|
|
|
waypoints.last().setName(obj.first().str());
|
|
|
|
|
2019-11-07 23:23:25 +01:00
|
|
|
while (stream.status() == QDataStream::Ok && ds < rh.size) {
|
2021-10-11 22:02:24 +02:00
|
|
|
switch (stream.nextHeaderType()) {
|
2021-10-10 08:38:38 +02:00
|
|
|
case 4:
|
2021-10-18 23:10:09 +02:00
|
|
|
ds += readIconId(stream, iconId);
|
2021-10-10 08:38:38 +02:00
|
|
|
break;
|
2019-10-25 22:30:12 +02:00
|
|
|
case 10:
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += readDescription(stream, waypoints.last());
|
2019-10-25 22:30:12 +02:00
|
|
|
break;
|
2019-11-08 21:00:59 +01:00
|
|
|
case 11:
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += readAddress(stream, waypoints.last());
|
2019-11-08 21:00:59 +01:00
|
|
|
break;
|
2019-10-25 22:30:12 +02:00
|
|
|
case 12:
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += readContact(stream, waypoints.last());
|
2019-10-25 22:30:12 +02:00
|
|
|
break;
|
2019-11-06 23:23:05 +01:00
|
|
|
case 13:
|
2019-11-07 23:23:25 +01:00
|
|
|
ds += readImageInfo(stream, waypoints.last(), fileName, imgId);
|
2019-11-06 23:23:05 +01:00
|
|
|
break;
|
2019-10-25 22:30:12 +02:00
|
|
|
case 14:
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += readNotes(stream, waypoints.last());
|
2019-10-25 22:30:12 +02:00
|
|
|
break;
|
|
|
|
default:
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.skipRecord();
|
2019-10-25 22:30:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 23:10:09 +02:00
|
|
|
icons.append(QPair<int, quint16>(waypoints.size() - 1, iconId));
|
|
|
|
|
2019-10-25 22:30:12 +02:00
|
|
|
if (ds != rh.size)
|
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
|
|
|
|
|
|
|
return rs + rh.size;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
static quint32 readSpatialIndex(DataStream &stream, QVector<Waypoint> &waypoints,
|
2021-10-10 08:38:38 +02:00
|
|
|
QList<Area> &polygons, const QString &fileName, int &imgId,
|
|
|
|
QVector<QPair<int, quint16> > &icons)
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
|
|
|
quint32 ds, s5;
|
|
|
|
qint32 top, right, bottom, left;
|
|
|
|
quint16 s6;
|
|
|
|
quint8 rs;
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
rs = stream.readRecordHeader(rh);
|
2019-10-25 22:30:12 +02:00
|
|
|
stream >> top >> right >> bottom >> left >> s5 >> s6;
|
|
|
|
stream.skipRawData(s6);
|
|
|
|
ds = 22 + s6;
|
|
|
|
if (rh.flags & 0x8) {
|
2019-11-07 23:23:25 +01:00
|
|
|
while (stream.status() == QDataStream::Ok && ds < rh.size) {
|
2021-10-11 22:02:24 +02:00
|
|
|
switch (stream.nextHeaderType()) {
|
2019-10-25 22:30:12 +02:00
|
|
|
case 2:
|
2021-10-11 22:02:24 +02:00
|
|
|
ds += readPOI(stream, waypoints, fileName, imgId, icons);
|
2019-10-25 22:30:12 +02:00
|
|
|
break;
|
|
|
|
case 8:
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += readSpatialIndex(stream, waypoints, polygons,
|
2021-10-10 08:38:38 +02:00
|
|
|
fileName, imgId, icons);
|
2019-11-10 16:46:31 +01:00
|
|
|
break;
|
|
|
|
case 19:
|
|
|
|
ds += readCamera(stream, waypoints, polygons);
|
2019-10-25 22:30:12 +02:00
|
|
|
break;
|
|
|
|
default:
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.skipRecord();
|
2019-10-25 22:30:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ds != rh.size)
|
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
|
|
|
|
|
|
|
return rs + rh.size;
|
|
|
|
}
|
|
|
|
|
2021-10-10 08:38:38 +02:00
|
|
|
static quint32 readSymbol(DataStream &stream, QPixmap &pixmap)
|
|
|
|
{
|
|
|
|
RecordHeader rh;
|
|
|
|
quint8 rs, u8, bpp, transparent;
|
|
|
|
quint32 ds = 36, u32, imageSize, paletteSize, bgColor;
|
|
|
|
quint16 id, height, width, lineSize;
|
|
|
|
QByteArray data;
|
|
|
|
QVector<QRgb> palette;
|
|
|
|
QImage img;
|
|
|
|
|
|
|
|
rs = stream.readRecordHeader(rh);
|
|
|
|
stream >> id >> height >> width >> lineSize >> bpp >> u8 >> u8 >> u8
|
|
|
|
>> imageSize >> u32 >> paletteSize >> bgColor >> transparent >> u8 >> u8
|
|
|
|
>> u8 >> u32;
|
|
|
|
if (imageSize) {
|
|
|
|
data.resize(imageSize);
|
|
|
|
stream.readRawData(data.data(), data.size());
|
|
|
|
ds += data.size();
|
|
|
|
}
|
|
|
|
if (paletteSize) {
|
|
|
|
quint32 rgb;
|
|
|
|
palette.resize(paletteSize);
|
|
|
|
for (quint32 i = 0; i < paletteSize; i++) {
|
|
|
|
stream >> rgb;
|
|
|
|
palette[i] = (transparent && rgb == bgColor)
|
|
|
|
? QRgb(0)
|
|
|
|
: Color::rgb((rgb & 0x000000FF), (rgb & 0x0000FF00) >> 8,
|
|
|
|
(rgb & 0x00FF0000) >> 16);
|
|
|
|
}
|
|
|
|
ds += paletteSize * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (paletteSize) {
|
|
|
|
img = QImage((uchar*)data.data(), width, height, lineSize,
|
|
|
|
QImage::Format_Indexed8);
|
|
|
|
img.setColorTable(palette);
|
|
|
|
} else
|
|
|
|
img = QImage((uchar*)data.data(), width, height, lineSize,
|
2021-10-18 23:10:09 +02:00
|
|
|
QImage::Format_RGBX8888).rgbSwapped();
|
2021-10-10 08:38:38 +02:00
|
|
|
pixmap = QPixmap::fromImage(img);
|
|
|
|
|
2021-10-18 23:10:09 +02:00
|
|
|
/* There should be no more data left in the record, but broken GPI files
|
|
|
|
generated by pinns.co.uk tools exist in the wild so we read out
|
|
|
|
the record as a workaround for such files. */
|
|
|
|
if (ds > rh.size)
|
2021-10-10 08:38:38 +02:00
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
2021-10-18 23:10:09 +02:00
|
|
|
else if (ds < rh.size)
|
|
|
|
stream.skipRawData(rh.size - ds);
|
2021-10-10 08:38:38 +02:00
|
|
|
|
|
|
|
return rs + rh.size;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
static void readPOIDatabase(DataStream &stream, QVector<Waypoint> &waypoints,
|
|
|
|
QList<Area> &polygons, const QString &fileName, int &imgId)
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
|
|
|
QList<TranslatedString> obj;
|
2019-11-07 23:23:25 +01:00
|
|
|
quint32 ds;
|
2021-10-10 08:38:38 +02:00
|
|
|
QVector<QPair<int, quint16> > il;
|
|
|
|
QVector<QPixmap> icons;
|
2019-10-25 22:30:12 +02:00
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
stream.readRecordHeader(rh);
|
|
|
|
ds = stream.readTranslatedObjects(obj);
|
2021-10-10 08:38:38 +02:00
|
|
|
ds += readSpatialIndex(stream, waypoints, polygons, fileName, imgId, il);
|
2019-11-07 23:23:25 +01:00
|
|
|
if (rh.flags & 0x8) {
|
|
|
|
while (stream.status() == QDataStream::Ok && ds < rh.size) {
|
2021-10-11 22:02:24 +02:00
|
|
|
switch (stream.nextHeaderType()) {
|
2021-10-10 08:38:38 +02:00
|
|
|
case 5:
|
|
|
|
icons.append(QPixmap());
|
|
|
|
ds += readSymbol(stream, icons.last());
|
|
|
|
break;
|
2021-04-24 05:17:12 +02:00
|
|
|
case 8:
|
|
|
|
ds += readSpatialIndex(stream, waypoints, polygons,
|
2021-10-10 08:38:38 +02:00
|
|
|
fileName, imgId, il);
|
2021-04-24 05:17:12 +02:00
|
|
|
break;
|
2019-11-07 23:23:25 +01:00
|
|
|
default:
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += stream.skipRecord();
|
2019-11-07 23:23:25 +01:00
|
|
|
}
|
|
|
|
}
|
2019-10-25 22:30:12 +02:00
|
|
|
}
|
|
|
|
|
2021-10-10 08:38:38 +02:00
|
|
|
for (int i = 0; i < il.size(); i++) {
|
|
|
|
const QPair<int, quint16> &e = il.at(i);
|
|
|
|
if (e.second < icons.size())
|
|
|
|
waypoints[e.first].setIcon(icons.at(e.second));
|
|
|
|
}
|
|
|
|
|
2019-11-07 23:23:25 +01:00
|
|
|
if (ds != rh.size)
|
2019-10-25 22:30:12 +02:00
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
bool GPIParser::readData(DataStream &stream, QVector<Waypoint> &waypoints,
|
|
|
|
QList<Area> &polygons, const QString &fileName)
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
2019-11-26 08:15:01 +01:00
|
|
|
int imgId = 0;
|
|
|
|
|
2019-11-07 23:23:25 +01:00
|
|
|
while (stream.status() == QDataStream::Ok) {
|
2020-12-22 22:09:09 +01:00
|
|
|
switch (stream.nextHeaderType()) {
|
2021-10-10 08:38:38 +02:00
|
|
|
case 0x09:
|
2020-12-22 22:09:09 +01:00
|
|
|
readPOIDatabase(stream, waypoints, polygons, fileName,
|
2019-11-10 16:46:31 +01:00
|
|
|
imgId);
|
2019-11-07 23:23:25 +01:00
|
|
|
break;
|
|
|
|
case 0xffff: // EOF
|
2020-12-22 22:09:09 +01:00
|
|
|
stream.skipRecord();
|
2019-11-07 23:23:25 +01:00
|
|
|
if (stream.status() == QDataStream::Ok)
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
default:
|
2020-12-22 22:09:09 +01:00
|
|
|
stream.skipRecord();
|
2019-11-07 23:23:25 +01:00
|
|
|
}
|
2019-10-25 22:30:12 +02:00
|
|
|
}
|
|
|
|
|
2019-11-07 23:23:25 +01:00
|
|
|
_errorString = "Invalid/corrupted GPI data";
|
2019-10-25 22:30:12 +02:00
|
|
|
|
2019-11-07 23:23:25 +01:00
|
|
|
return false;
|
2019-10-25 22:30:12 +02:00
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
bool GPIParser::readGPIHeader(DataStream &stream)
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
|
|
|
char m1[6], m2[2];
|
|
|
|
quint16 codepage = 0;
|
|
|
|
quint8 s2, s3;
|
|
|
|
quint32 ds;
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
stream.readRecordHeader(rh);
|
2019-10-25 22:30:12 +02:00
|
|
|
stream.readRawData(m1, sizeof(m1));
|
|
|
|
stream.readRawData(m2, sizeof(m2));
|
|
|
|
stream >> codepage >> s2 >> s3;
|
|
|
|
ds = sizeof(m1) + sizeof(m2) + 4;
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
stream.setCodepage(codepage);
|
2019-10-25 22:30:12 +02:00
|
|
|
|
|
|
|
if (s2 & 0x10)
|
2020-12-22 22:09:09 +01:00
|
|
|
ds += readFileDataRecord(stream);
|
2019-10-25 22:30:12 +02:00
|
|
|
|
|
|
|
if (stream.status() != QDataStream::Ok || ds != rh.size) {
|
|
|
|
_errorString = "Invalid GPI header";
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
bool GPIParser::readFileHeader(DataStream &stream, quint32 &ebs)
|
2019-10-25 22:30:12 +02:00
|
|
|
{
|
|
|
|
RecordHeader rh;
|
2019-11-07 23:23:25 +01:00
|
|
|
quint32 ds, s7;
|
|
|
|
quint16 s10;
|
|
|
|
quint8 s5, s6, s8, s9;
|
|
|
|
char magic[6];
|
2019-10-25 22:30:12 +02:00
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
stream.readRecordHeader(rh);
|
2019-11-07 23:23:25 +01:00
|
|
|
stream.readRawData(magic, sizeof(magic));
|
|
|
|
if (memcmp(magic, "GRMREC", sizeof(magic))) {
|
|
|
|
_errorString = "Not a GPI file";
|
|
|
|
return false;
|
2019-10-25 22:30:12 +02:00
|
|
|
}
|
2019-11-07 23:23:25 +01:00
|
|
|
stream >> s5 >> s6 >> s7 >> s8 >> s9 >> s10;
|
|
|
|
stream.skipRawData(s10);
|
|
|
|
ds = sizeof(magic) + 10 + s10;
|
|
|
|
if (rh.flags & 8)
|
|
|
|
ds += readFprsRecord(stream);
|
2019-10-25 22:30:12 +02:00
|
|
|
|
2019-11-07 23:23:25 +01:00
|
|
|
ebs = (s8 & 0x4) ? s9 * 8 + 8 : 0;
|
2019-10-27 16:34:53 +01:00
|
|
|
|
2019-11-07 23:23:25 +01:00
|
|
|
if (stream.status() != QDataStream::Ok || ds != rh.size) {
|
|
|
|
_errorString = "Invalid file header";
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
return true;
|
2019-10-27 16:34:53 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 22:30:12 +02:00
|
|
|
bool GPIParser::parse(QFile *file, QList<TrackData> &tracks,
|
|
|
|
QList<RouteData> &routes, QList<Area> &polygons, QVector<Waypoint> &waypoints)
|
|
|
|
{
|
|
|
|
Q_UNUSED(tracks);
|
|
|
|
Q_UNUSED(routes);
|
2020-12-22 22:09:09 +01:00
|
|
|
DataStream stream(file);
|
2019-11-01 19:07:21 +01:00
|
|
|
quint32 ebs;
|
2019-10-25 22:30:12 +02:00
|
|
|
|
|
|
|
stream.setByteOrder(QDataStream::LittleEndian);
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
if (!readFileHeader(stream, ebs) || !readGPIHeader(stream))
|
2019-10-25 22:30:12 +02:00
|
|
|
return false;
|
|
|
|
|
2019-11-01 19:07:21 +01:00
|
|
|
if (ebs) {
|
2019-11-06 23:23:05 +01:00
|
|
|
CryptDevice dev(stream.device(), 0xf870b5, ebs);
|
2020-12-22 22:09:09 +01:00
|
|
|
DataStream cryptStream(&dev);
|
2019-11-06 23:23:05 +01:00
|
|
|
cryptStream.setByteOrder(QDataStream::LittleEndian);
|
2020-12-22 22:09:09 +01:00
|
|
|
return readData(cryptStream, waypoints, polygons, file->fileName());
|
2019-10-25 22:30:12 +02:00
|
|
|
} else
|
2020-12-22 22:09:09 +01:00
|
|
|
return readData(stream, waypoints, polygons, file->fileName());
|
2019-10-25 22:30:12 +02:00
|
|
|
}
|