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

Improved error handling

This commit is contained in:
Martin Tůma 2022-02-06 11:53:43 +01:00
parent 6564c61b00
commit 36220dbc9c
3 changed files with 31 additions and 30 deletions

View File

@ -180,8 +180,8 @@ Label LBLFile::str2label(const QVector<quint8> &str, bool capitalize,
Shield(shieldType, _codec.toString(shieldLabel))); Shield(shieldType, _codec.toString(shieldLabel)));
} }
Label LBLFile::label6b(const SubFile *file, Handle &fileHdl, bool capitalize, Label LBLFile::label6b(const SubFile *file, Handle &fileHdl, quint32 size,
bool convert) const bool capitalize, bool convert) const
{ {
Shield::Type shieldType = Shield::None; Shield::Type shieldType = Shield::None;
QByteArray label, shieldLabel; QByteArray label, shieldLabel;
@ -190,7 +190,7 @@ Label LBLFile::label6b(const SubFile *file, Handle &fileHdl, bool capitalize,
quint8 b1, b2, b3; quint8 b1, b2, b3;
int split = -1; int split = -1;
while (true) { for (quint32 i = 0; i < size; i = i + 3) {
if (!(file->readByte(fileHdl, &b1) && file->readByte(fileHdl, &b2) if (!(file->readByte(fileHdl, &b1) && file->readByte(fileHdl, &b2)
&& file->readByte(fileHdl, &b3))) && file->readByte(fileHdl, &b3)))
return Label(); return Label();
@ -242,29 +242,33 @@ Label LBLFile::label6b(const SubFile *file, Handle &fileHdl, bool capitalize,
} }
} }
} }
return Label();
} }
Label LBLFile::label8b(const SubFile *file, Handle &fileHdl, bool capitalize, Label LBLFile::label8b(const SubFile *file, Handle &fileHdl, quint32 size,
bool convert) const bool capitalize, bool convert) const
{ {
QVector<quint8> str; QVector<quint8> str;
quint8 c; quint8 c;
do { for (quint32 i = 0; i < size; i++) {
if (!file->readByte(fileHdl, &c)) if (!file->readByte(fileHdl, &c))
return Label(); break;
str.append(c); str.append(c);
} while (c); if (!c)
return str2label(str, capitalize, convert);
}
return str2label(str, capitalize, convert); return Label();
} }
Label LBLFile::labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl, Label LBLFile::labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl,
bool capitalize, bool convert) const quint32 size, bool capitalize, bool convert) const
{ {
QVector<quint8> str; QVector<quint8> str;
if (!_huffmanText->decode(file, fileHdl, 0xFFFFFFFF, str)) if (!_huffmanText->decode(file, fileHdl, size, str))
return Label(); return Label();
if (!_table) if (!_table)
return str2label(str, capitalize, convert); return str2label(str, capitalize, convert);
@ -319,20 +323,21 @@ Label LBLFile::label(Handle &hdl, quint32 offset, bool poi, bool capitalize,
if (!seek(hdl, labelOffset)) if (!seek(hdl, labelOffset))
return Label(); return Label();
return label(hdl, this, hdl, capitalize, convert); return label(hdl, this, hdl, _offset + _size - labelOffset, capitalize,
convert);
} }
Label LBLFile::label(Handle &hdl, const SubFile *file, Handle &fileHdl, Label LBLFile::label(Handle &hdl, const SubFile *file, Handle &fileHdl,
bool capitalize, bool convert) const quint32 size, bool capitalize, bool convert) const
{ {
switch (_encoding) { switch (_encoding) {
case 6: case 6:
return label6b(file, fileHdl, capitalize, convert); return label6b(file, fileHdl, size, capitalize, convert);
case 9: case 9:
case 10: case 10:
return label8b(file, fileHdl, capitalize, convert); return label8b(file, fileHdl, size, capitalize, convert);
case 11: case 11:
return labelHuffman(hdl, file, fileHdl, capitalize, convert); return labelHuffman(hdl, file, fileHdl, size, capitalize, convert);
default: default:
return Label(); return Label();
} }

View File

@ -34,7 +34,7 @@ public:
Label label(Handle &hdl, quint32 offset, bool poi = false, Label label(Handle &hdl, quint32 offset, bool poi = false,
bool capitalize = true, bool convert = false) const; bool capitalize = true, bool convert = false) const;
Label label(Handle &hdl, const SubFile *file, Handle &fileHdl, Label label(Handle &hdl, const SubFile *file, Handle &fileHdl,
bool capitalize = true, bool convert = false) const; quint32 size, bool capitalize = true, bool convert = false) const;
quint8 imageIdSize() const {return _imgOffsetIdSize;} quint8 imageIdSize() const {return _imgOffsetIdSize;}
QPixmap image(Handle &hdl, quint32 id) const; QPixmap image(Handle &hdl, quint32 id) const;
@ -47,12 +47,12 @@ private:
Label str2label(const QVector<quint8> &str, bool capitalize, Label str2label(const QVector<quint8> &str, bool capitalize,
bool convert) const; bool convert) const;
Label label6b(const SubFile *file, Handle &fileHdl, bool capitalize, Label label6b(const SubFile *file, Handle &fileHdl, quint32 size,
bool convert) const;
Label label8b(const SubFile *file, Handle &fileHdl, bool capitalize,
bool convert) const;
Label labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl,
bool capitalize, bool convert) const; bool capitalize, bool convert) const;
Label label8b(const SubFile *file, Handle &fileHdl, quint32 size,
bool capitalize, bool convert) const;
Label labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl,
quint32 size, bool capitalize, bool convert) const;
bool loadRasterTable(Handle &hdl, quint32 offset, quint32 size, bool loadRasterTable(Handle &hdl, quint32 offset, quint32 size,
quint32 recordSize); quint32 recordSize);

View File

@ -64,6 +64,8 @@ bool RGNFile::readClassFields(Handle &hdl, SegmentType segmentType,
break; break;
} }
quint32 off = pos(hdl);
if (poly && Style::isRaster(poly->type) && lbl && lbl->imageIdSize()) { if (poly && Style::isRaster(poly->type) && lbl && lbl->imageIdSize()) {
quint32 id; quint32 id;
quint32 top, right, bottom, left; quint32 top, right, bottom, left;
@ -77,20 +79,14 @@ bool RGNFile::readClassFields(Handle &hdl, SegmentType segmentType,
poly->raster = Raster(lbl, id, QRect(QPoint(left, top), QPoint(right, poly->raster = Raster(lbl, id, QRect(QPoint(left, top), QPoint(right,
bottom))); bottom)));
rs -= lbl->imageIdSize() + 16;
} }
if (point && (flags & 1) && lbl) { if (point && (flags & 1) && lbl) {
quint32 p = pos(hdl); point->label = lbl->label(lblHdl, this, hdl, rs);
point->label = lbl->label(lblHdl, this, hdl);
point->classLabel = true; point->classLabel = true;
Q_ASSERT(pos(hdl) - p <= rs + 4);
seek(hdl, p);
} }
return seek(hdl, pos(hdl) + rs); return seek(hdl, off + rs);
} }
bool RGNFile::skipLclFields(Handle &hdl, const quint32 flags[3]) const bool RGNFile::skipLclFields(Handle &hdl, const quint32 flags[3]) const