mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-30 22:51:16 +01:00
Fixed/improved error handling
This commit is contained in:
parent
1fb6aad50f
commit
54ed0ca9f6
@ -82,8 +82,9 @@ bool NODFile::init(Handle &hdl)
|
|||||||
|
|
||||||
if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen)))
|
if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen)))
|
||||||
return false;
|
return false;
|
||||||
|
if (hdrLen < 0x7b)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (hdrLen >= 0x7b) {
|
|
||||||
if (!(seek(hdl, _gmpOffset + 0x1d) && readUInt32(hdl, _flags)
|
if (!(seek(hdl, _gmpOffset + 0x1d) && readUInt32(hdl, _flags)
|
||||||
&& readUInt8(hdl, _blockShift) && readUInt8(hdl, _nodeShift)))
|
&& readUInt8(hdl, _blockShift) && readUInt8(hdl, _nodeShift)))
|
||||||
return false;
|
return false;
|
||||||
@ -93,25 +94,26 @@ bool NODFile::init(Handle &hdl)
|
|||||||
&& readUInt32(hdl, _indexOffset) && readUInt32(hdl, _indexSize)
|
&& readUInt32(hdl, _indexOffset) && readUInt32(hdl, _indexSize)
|
||||||
&& readUInt16(hdl, _indexRecordSize) && readUInt32(hdl, _indexFlags)))
|
&& readUInt16(hdl, _indexRecordSize) && readUInt32(hdl, _indexFlags)))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
if (!_indexRecordSize)
|
||||||
|
return false;
|
||||||
|
quint32 indexCount = _indexSize / _indexRecordSize;
|
||||||
|
if (indexCount <= 0x100)
|
||||||
|
_indexIdSize = 1;
|
||||||
|
else if (indexCount <= 0x1000)
|
||||||
|
_indexIdSize = 2;
|
||||||
|
else if (indexCount <= 0x1000000)
|
||||||
|
_indexIdSize = 3;
|
||||||
|
|
||||||
|
return (_indexIdSize > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 NODFile::indexIdSize(Handle &hdl)
|
quint32 NODFile::indexIdSize(Handle &hdl)
|
||||||
{
|
{
|
||||||
if (!_indexRecordSize && !init(hdl))
|
if (!_indexIdSize && !init(hdl))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
quint32 indexCount = _indexSize / _indexRecordSize;
|
return _indexIdSize;
|
||||||
if (indexCount <= 0x100)
|
|
||||||
return 1;
|
|
||||||
else if (indexCount <= 0x1000)
|
|
||||||
return 2;
|
|
||||||
else if (indexCount <= 0x1000000)
|
|
||||||
return 3;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NODFile::readBlock(Handle &hdl, quint32 blockOffset,
|
bool NODFile::readBlock(Handle &hdl, quint32 blockOffset,
|
||||||
@ -300,7 +302,7 @@ bool NODFile::absAdjInfo(Handle &hdl, AdjacencyInfo &adj) const
|
|||||||
quint32 m2p = 2;
|
quint32 m2p = 2;
|
||||||
quint32 skip = 8;
|
quint32 skip = 8;
|
||||||
quint32 flags;
|
quint32 flags;
|
||||||
quint32 nextOffset;
|
quint32 nextOffset = 0xFFFFFFFF;
|
||||||
bool extraBit = (adj.nodeInfo.flags >> 6) & 1;
|
bool extraBit = (adj.nodeInfo.flags >> 6) & 1;
|
||||||
bool linkIdValid = true;
|
bool linkIdValid = true;
|
||||||
bool firstLoop = true;
|
bool firstLoop = true;
|
||||||
@ -403,7 +405,7 @@ bool NODFile::relAdjInfo(Handle &hdl, AdjacencyInfo &adj) const
|
|||||||
quint32 skip = 8;
|
quint32 skip = 8;
|
||||||
quint32 flagsBits = 8;
|
quint32 flagsBits = 8;
|
||||||
quint32 flags;
|
quint32 flags;
|
||||||
quint32 nextOffset;
|
quint32 nextOffset = 0xFFFFFFFF;
|
||||||
bool extraBit = (adj.nodeInfo.flags >> 6) & 1;
|
bool extraBit = (adj.nodeInfo.flags >> 6) & 1;
|
||||||
bool linkIdValid = true;
|
bool linkIdValid = true;
|
||||||
bool firstLoop = true;
|
bool firstLoop = true;
|
||||||
@ -507,24 +509,21 @@ bool NODFile::linkType(Handle &hdl, const BlockInfo &blockInfo, quint8 linkId,
|
|||||||
+ blockInfo.hdr.s11 * 3;
|
+ blockInfo.hdr.s11 * 3;
|
||||||
quint32 low = 0;
|
quint32 low = 0;
|
||||||
quint32 high = blockInfo.hdr.s12 - 1;
|
quint32 high = blockInfo.hdr.s12 - 1;
|
||||||
quint32 pos;
|
quint32 pos = blockInfo.hdr.s12;
|
||||||
quint16 val;
|
quint16 val;
|
||||||
|
|
||||||
if (high > 1) {
|
if (high > 1) {
|
||||||
do {
|
do {
|
||||||
pos = (low + high) / 2;
|
pos = (low + high) / 2;
|
||||||
|
|
||||||
if (!seek(hdl, offset + _blockRecordSize * pos))
|
if (!(seek(hdl, offset + _blockRecordSize * pos)
|
||||||
return false;
|
&& readUInt16(hdl, val)))
|
||||||
if (!readUInt16(hdl, val))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
quint32 tmp = pos;
|
if ((val >> 8) <= linkId)
|
||||||
if ((val >> 8) <= linkId) {
|
|
||||||
low = pos;
|
low = pos;
|
||||||
tmp = high;
|
else
|
||||||
}
|
high = pos;
|
||||||
high = tmp;
|
|
||||||
} while (low + 1 < high);
|
} while (low + 1 < high);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,14 +535,12 @@ bool NODFile::linkType(Handle &hdl, const BlockInfo &blockInfo, quint8 linkId,
|
|||||||
type = val & 0x3f;
|
type = val & 0x3f;
|
||||||
|
|
||||||
if ((low < high) && (pos != high)) {
|
if ((low < high) && (pos != high)) {
|
||||||
if (!seek(hdl, offset + _blockRecordSize * high))
|
if (!(seek(hdl, offset + _blockRecordSize * high)
|
||||||
|
&& readUInt16(hdl, val)))
|
||||||
return false;
|
return false;
|
||||||
if (!readUInt16(hdl, val))
|
if ((val >> 8) <= linkId)
|
||||||
return false;
|
|
||||||
if ((val >> 8) <= linkId) {
|
|
||||||
type = (val & 0x3f);
|
type = (val & 0x3f);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
type <<= 8;
|
type <<= 8;
|
||||||
|
|
||||||
|
@ -56,14 +56,14 @@ public:
|
|||||||
|
|
||||||
NODFile(IMG *img) : SubFile(img), _indexOffset(0), _indexSize(0),
|
NODFile(IMG *img) : SubFile(img), _indexOffset(0), _indexSize(0),
|
||||||
_indexFlags(0), _blockOffset(0), _blockSize(0), _indexRecordSize(0),
|
_indexFlags(0), _blockOffset(0), _blockSize(0), _indexRecordSize(0),
|
||||||
_blockRecordSize(0), _blockShift(0), _nodeShift(0) {}
|
_blockRecordSize(0), _blockShift(0), _nodeShift(0), _indexIdSize(0) {}
|
||||||
NODFile(const QString &path) : SubFile(path), _indexOffset(0), _indexSize(0),
|
NODFile(const QString &path) : SubFile(path), _indexOffset(0), _indexSize(0),
|
||||||
_indexFlags(0), _blockOffset(0), _blockSize(0), _indexRecordSize(0),
|
_indexFlags(0), _blockOffset(0), _blockSize(0), _indexRecordSize(0),
|
||||||
_blockRecordSize(0), _blockShift(0), _nodeShift(0) {}
|
_blockRecordSize(0), _blockShift(0), _nodeShift(0), _indexIdSize(0) {}
|
||||||
NODFile(SubFile *gmp, quint32 offset) : SubFile(gmp, offset),
|
NODFile(SubFile *gmp, quint32 offset) : SubFile(gmp, offset),
|
||||||
_indexOffset(0), _indexSize(0),_indexFlags(0), _blockOffset(0),
|
_indexOffset(0), _indexSize(0),_indexFlags(0), _blockOffset(0),
|
||||||
_blockSize(0), _indexRecordSize(0), _blockRecordSize(0), _blockShift(0),
|
_blockSize(0), _indexRecordSize(0), _blockRecordSize(0), _blockShift(0),
|
||||||
_nodeShift(0) {}
|
_nodeShift(0), _indexIdSize(0) {}
|
||||||
|
|
||||||
quint32 indexIdSize(Handle &hdl);
|
quint32 indexIdSize(Handle &hdl);
|
||||||
bool blockInfo(Handle &hdl, quint32 blockId, BlockInfo &blockInfo) const;
|
bool blockInfo(Handle &hdl, quint32 blockId, BlockInfo &blockInfo) const;
|
||||||
@ -93,6 +93,7 @@ private:
|
|||||||
quint16 _indexRecordSize, _blockRecordSize;
|
quint16 _indexRecordSize, _blockRecordSize;
|
||||||
quint8 _blockShift, _nodeShift;
|
quint8 _blockShift, _nodeShift;
|
||||||
quint32 _flags;
|
quint32 _flags;
|
||||||
|
quint32 _indexIdSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NETFILE_H
|
#endif // NETFILE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user