1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Compare commits

...

2 Commits

Author SHA1 Message Date
6d03834167 Improved error reporting 2023-11-26 10:51:37 +01:00
cbca92513b Fixed crash on empty MBTiles files 2023-11-26 09:07:08 +01:00
7 changed files with 33 additions and 13 deletions

View File

@ -112,7 +112,7 @@ Atlas::Atlas(const QString &fileName, bool TAR, const Projection &proj,
if (TAR) {
if (!tar.open()) {
_errorString = "Error reading tar file";
_errorString = "Error reading tar file: " + tar.errorString();
return;
}
QString tbaFileName(tbaFile(tar.files()));

View File

@ -82,6 +82,11 @@ bool MBTilesMap::getZooms()
_zooms.append(i);
}
if (!_zooms.size()) {
_errorString = "Empty tile set";
return false;
}
_zi = _zooms.size() - 1;
return true;

View File

@ -179,20 +179,22 @@ bool OZF::readTileTable()
bool OZF::open()
{
if (!_file.open(QIODevice::ReadOnly))
if (!_file.open(QIODevice::ReadOnly)) {
_error = _file.errorString();
return false;
}
if (!_zooms.isEmpty())
return true;
if (!readHeaders()) {
qWarning("%s: Invalid header", qPrintable(_file.fileName()));
_error = "Invalid header";
_file.close();
return false;
}
if (!readTileTable()) {
qWarning("%s: Invalid tile table", qPrintable(_file.fileName()));
_error = "Invalid tile table";
_file.close();
return false;
}

View File

@ -17,6 +17,7 @@ public:
bool open();
void close() {_file.close();}
const QString &errorString() const {return _error;}
QString fileName() const {return _file.fileName();}
bool isOpen() const {return _file.isOpen();}
@ -49,6 +50,7 @@ private:
quint8 _key;
QList<Zoom> _zooms;
QFile _file;
QString _error;
};
#endif // OZF_H

View File

@ -66,7 +66,7 @@ OziMap::OziMap(const QString &fileName, const Projection &proj, QObject *parent)
_tar = new Tar(fileName);
if (!_tar->open()) {
_errorString = "Error reading tar file";
_errorString = "Error reading tar file: " + _tar->errorString();
return;
}
QStringList files(_tar->files());
@ -202,7 +202,7 @@ OziMap::OziMap(const QString &dirName, Tar &tar, const Projection &proj,
}
_tar = new Tar(tf);
if (!_tar->open()) {
_errorString = _tar->fileName() + ": error reading tar file";
_errorString = _tar->fileName() + ": " + _tar->errorString();
return;
}
if (!setTileInfo(_tar->files())) {
@ -245,8 +245,8 @@ bool OziMap::setImageInfo(const QString &path)
if (OZF::isOZF(_map.path)) {
_ozf = new OZF(_map.path);
if (!_ozf || !_ozf->open()) {
_errorString = QString("%1: Error loading OZF file").arg(_map.path);
if (!_ozf->open()) {
_errorString = QString("%1: %2").arg(_map.path, _ozf->errorString());
return false;
}
_scale = _ozf->scale(_zoom);
@ -312,19 +312,24 @@ void OziMap::load(const Projection &in, const Projection &out,
if (_tar) {
Q_ASSERT(!_tar->isOpen());
if (!_tar->open())
if (!_tar->open()) {
qWarning("%s: %s", qPrintable(_tar->fileName()),
qPrintable(_tar->errorString()));
return;
}
}
if (_ozf) {
Q_ASSERT(!_ozf->isOpen());
if (!_ozf->open())
if (!_ozf->open()) {
qWarning("%s: %s", qPrintable(_ozf->fileName()),
qPrintable(_ozf->errorString()));
return;
}
}
if (!_tile.isValid() && !_ozf) {
Q_ASSERT(!_img);
_img = new Image(_map.path);
if (_img)
_img->setDevicePixelRatio(_mapRatio);
_img->setDevicePixelRatio(_mapRatio);
}
}

View File

@ -46,8 +46,10 @@ static quint64 number(const char* data, size_t size, int base = 8)
bool Tar::open()
{
if (!_file.open(QIODevice::ReadOnly))
if (!_file.open(QIODevice::ReadOnly)) {
_error = _file.errorString();
return false;
}
if (!_index.isEmpty())
return true;
@ -72,6 +74,7 @@ bool Tar::loadTar()
if (ret < BLOCKSIZE) {
_file.close();
_index.clear();
_error = "Error reading header block";
return false;
}
size = number(hdr->size, sizeof(hdr->size));
@ -79,6 +82,7 @@ bool Tar::loadTar()
if (!_file.seek(_file.pos() + BLOCKCOUNT(size) * BLOCKSIZE)) {
_file.close();
_index.clear();
_error = "Error skipping data blocks";
return false;
}
}

View File

@ -12,6 +12,7 @@ public:
bool open();
void close() {_file.close();}
const QString &errorString() const {return _error;}
QStringList files() const {return _index.keys();}
QByteArray file(const QString &name);
@ -26,6 +27,7 @@ private:
QFile _file;
QMap<QString, quint64> _index;
QString _error;
};
#endif // TAR_H