1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Various code cleanup

This commit is contained in:
Martin Tůma 2019-08-12 22:20:12 +02:00
parent 680104fec3
commit f67eaa8dec
8 changed files with 26 additions and 27 deletions

View File

@ -91,7 +91,7 @@ IMG::IMG(const QString &fileName)
} }
QString fn(QByteArray(name, sizeof(name))); QString fn(QByteArray(name, sizeof(name)));
if (VectorTile::isTileFile(tt)) { if (SubFile::isTileFile(tt)) {
VectorTile *tile; VectorTile *tile;
QMap<QString, VectorTile*>::iterator it = tileMap.find(fn); QMap<QString, VectorTile*>::iterator it = tileMap.find(fn);
if (it == tileMap.end()) { if (it == tileMap.end()) {

View File

@ -54,15 +54,18 @@ bool LBLFile::init()
{ {
Handle hdl; Handle hdl;
quint16 codepage; quint16 codepage;
quint8 multiplier, poiMultiplier;
if (!(seek(hdl, 0x15) && readUInt32(hdl, _offset) if (!(seek(hdl, 0x15) && readUInt32(hdl, _offset)
&& readUInt32(hdl, _size) && readByte(hdl, _multiplier) && readUInt32(hdl, _size) && readByte(hdl, multiplier)
&& readByte(hdl, _encoding) && seek(hdl, 0x57) && readByte(hdl, _encoding) && seek(hdl, 0x57)
&& readUInt32(hdl, _poiOffset) && readUInt32(hdl, _poiSize) && readUInt32(hdl, _poiOffset) && readUInt32(hdl, _poiSize)
&& seek(hdl, 0xAA) && readUInt16(hdl, codepage))) && readByte(hdl, poiMultiplier) && seek(hdl, 0xAA)
&& readUInt16(hdl, codepage)))
return false; return false;
_multiplier = 1<<_multiplier; _multiplier = 1<<multiplier;
_poiMultiplier = 1<<poiMultiplier;
if (codepage == 65001) if (codepage == 65001)
_codec = QTextCodec::codecForName("UTF-8"); _codec = QTextCodec::codecForName("UTF-8");
@ -162,14 +165,15 @@ Label LBLFile::label8b(Handle &hdl, quint32 offset) const
Label LBLFile::label(Handle &hdl, quint32 offset, bool poi) Label LBLFile::label(Handle &hdl, quint32 offset, bool poi)
{ {
if (!_size && !init()) if (!_multiplier && !init())
return QString(); return QString();
quint32 labelOffset; quint32 labelOffset;
if (poi) { if (poi) {
quint32 poiOffset; quint32 poiOffset;
if (!(seek(hdl, _poiOffset + offset) && readUInt24(hdl, poiOffset) if (!(_poiSize >= offset * _poiMultiplier
&& (poiOffset & 0x3FFFFF))) && seek(hdl, _poiOffset + offset * _poiMultiplier)
&& readUInt24(hdl, poiOffset) && (poiOffset & 0x3FFFFF)))
return QString(); return QString();
labelOffset = _offset + (poiOffset & 0x3FFFFF) * _multiplier; labelOffset = _offset + (poiOffset & 0x3FFFFF) * _multiplier;
} else } else

View File

@ -10,8 +10,8 @@ class LBLFile : public SubFile
{ {
public: public:
LBLFile(IMG *img, quint32 size) LBLFile(IMG *img, quint32 size)
: SubFile(img, size), _offset(0), _size(0), _poiOffset(0), _poiSize(0), : SubFile(img, size), _codec(0), _offset(0), _size(0), _poiOffset(0),
_multiplier(0), _encoding(0), _codec(0) {} _poiSize(0), _poiMultiplier(0), _multiplier(0), _encoding(0) {}
Label label(Handle &hdl, quint32 offset, bool poi = false); Label label(Handle &hdl, quint32 offset, bool poi = false);
@ -21,13 +21,14 @@ private:
Label label6b(Handle &hdl, quint32 offset) const; Label label6b(Handle &hdl, quint32 offset) const;
Label label8b(Handle &hdl, quint32 offset) const; Label label8b(Handle &hdl, quint32 offset) const;
QTextCodec *_codec;
quint32 _offset; quint32 _offset;
quint32 _size; quint32 _size;
quint32 _poiOffset; quint32 _poiOffset;
quint32 _poiSize; quint32 _poiSize;
quint8 _poiMultiplier;
quint8 _multiplier; quint8 _multiplier;
quint8 _encoding; quint8 _encoding;
QTextCodec *_codec;
}; };
#endif // LBLFILE_H #endif // LBLFILE_H

View File

@ -3,22 +3,21 @@
bool NETFile::init() bool NETFile::init()
{ {
Handle hdl; Handle hdl;
quint8 multiplier;
if (!(seek(hdl, 0x15) && readUInt32(hdl, _offset) if (!(seek(hdl, 0x15) && readUInt32(hdl, _offset)
&& readUInt32(hdl, _size) && readByte(hdl, _multiplier))) && readUInt32(hdl, _size) && readByte(hdl, multiplier)))
return false; return false;
_multiplier = 1<<_multiplier; _multiplier = 1<<multiplier;
return true; return true;
} }
bool NETFile::lblOffset(Handle &hdl, quint32 netOffset, quint32 &lblOffset) bool NETFile::lblOffset(Handle &hdl, quint32 netOffset, quint32 &lblOffset)
{ {
if (!_init) { if (!_multiplier && !init())
if (!(_init = init())) return false;
return false;
}
if (!(seek(hdl, _offset + netOffset * _multiplier) if (!(seek(hdl, _offset + netOffset * _multiplier)
&& readUInt24(hdl, lblOffset))) && readUInt24(hdl, lblOffset)))

View File

@ -6,7 +6,8 @@
class NETFile : public SubFile class NETFile : public SubFile
{ {
public: public:
NETFile(IMG *img, quint32 size) : SubFile(img, size), _init(false) {} NETFile(IMG *img, quint32 size)
: SubFile(img, size), _offset(0), _size(0), _multiplier(0) {}
bool lblOffset(Handle &hdl, quint32 netOffset, quint32 &lblOffset); bool lblOffset(Handle &hdl, quint32 netOffset, quint32 &lblOffset);
@ -16,8 +17,6 @@ private:
quint32 _offset; quint32 _offset;
quint32 _size; quint32 _size;
quint8 _multiplier; quint8 _multiplier;
bool _init;
}; };
#endif // NETFILE_H #endif // NETFILE_H

View File

@ -76,12 +76,12 @@ bool SubFile::readByte(Handle &handle, quint8 &val) const
quint32 SubFile::size() const quint32 SubFile::size() const
{ {
return _img ? _size : (quint32)_file->size(); return _file ? (quint32)_file->size() : _size;
} }
QString SubFile::fileName() const QString SubFile::fileName() const
{ {
return _img ? _img->fileName() : _file->fileName(); return _file ? _file->fileName() : _img->fileName();
} }
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG

View File

@ -84,6 +84,8 @@ public:
QString fileName() const; QString fileName() const;
static Type type(const char str[3]); static Type type(const char str[3]);
static bool isTileFile(Type type)
{return (type == TRE || type == LBL || type == RGN || type == NET);}
friend QDebug operator<<(QDebug dbg, const SubFile &file); friend QDebug operator<<(QDebug dbg, const SubFile &file);

View File

@ -26,12 +26,6 @@ public:
friend QDebug operator<<(QDebug dbg, const VectorTile &tile); friend QDebug operator<<(QDebug dbg, const VectorTile &tile);
static bool isTileFile(SubFile::Type type)
{
return (type == SubFile::TRE || type == SubFile::LBL
|| type == SubFile::RGN || type == SubFile::NET);
}
private: private:
TREFile *_tre; TREFile *_tre;
RGNFile *_rgn; RGNFile *_rgn;