mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-02-26 04:00:49 +01:00
Improved error reporting
This commit is contained in:
parent
cbca92513b
commit
6d03834167
@ -112,7 +112,7 @@ Atlas::Atlas(const QString &fileName, bool TAR, const Projection &proj,
|
|||||||
|
|
||||||
if (TAR) {
|
if (TAR) {
|
||||||
if (!tar.open()) {
|
if (!tar.open()) {
|
||||||
_errorString = "Error reading tar file";
|
_errorString = "Error reading tar file: " + tar.errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString tbaFileName(tbaFile(tar.files()));
|
QString tbaFileName(tbaFile(tar.files()));
|
||||||
|
@ -179,20 +179,22 @@ bool OZF::readTileTable()
|
|||||||
|
|
||||||
bool OZF::open()
|
bool OZF::open()
|
||||||
{
|
{
|
||||||
if (!_file.open(QIODevice::ReadOnly))
|
if (!_file.open(QIODevice::ReadOnly)) {
|
||||||
|
_error = _file.errorString();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_zooms.isEmpty())
|
if (!_zooms.isEmpty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!readHeaders()) {
|
if (!readHeaders()) {
|
||||||
qWarning("%s: Invalid header", qPrintable(_file.fileName()));
|
_error = "Invalid header";
|
||||||
_file.close();
|
_file.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!readTileTable()) {
|
if (!readTileTable()) {
|
||||||
qWarning("%s: Invalid tile table", qPrintable(_file.fileName()));
|
_error = "Invalid tile table";
|
||||||
_file.close();
|
_file.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ public:
|
|||||||
|
|
||||||
bool open();
|
bool open();
|
||||||
void close() {_file.close();}
|
void close() {_file.close();}
|
||||||
|
const QString &errorString() const {return _error;}
|
||||||
|
|
||||||
QString fileName() const {return _file.fileName();}
|
QString fileName() const {return _file.fileName();}
|
||||||
bool isOpen() const {return _file.isOpen();}
|
bool isOpen() const {return _file.isOpen();}
|
||||||
@ -49,6 +50,7 @@ private:
|
|||||||
quint8 _key;
|
quint8 _key;
|
||||||
QList<Zoom> _zooms;
|
QList<Zoom> _zooms;
|
||||||
QFile _file;
|
QFile _file;
|
||||||
|
QString _error;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // OZF_H
|
#endif // OZF_H
|
||||||
|
@ -66,7 +66,7 @@ OziMap::OziMap(const QString &fileName, const Projection &proj, QObject *parent)
|
|||||||
|
|
||||||
_tar = new Tar(fileName);
|
_tar = new Tar(fileName);
|
||||||
if (!_tar->open()) {
|
if (!_tar->open()) {
|
||||||
_errorString = "Error reading tar file";
|
_errorString = "Error reading tar file: " + _tar->errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QStringList files(_tar->files());
|
QStringList files(_tar->files());
|
||||||
@ -202,7 +202,7 @@ OziMap::OziMap(const QString &dirName, Tar &tar, const Projection &proj,
|
|||||||
}
|
}
|
||||||
_tar = new Tar(tf);
|
_tar = new Tar(tf);
|
||||||
if (!_tar->open()) {
|
if (!_tar->open()) {
|
||||||
_errorString = _tar->fileName() + ": error reading tar file";
|
_errorString = _tar->fileName() + ": " + _tar->errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!setTileInfo(_tar->files())) {
|
if (!setTileInfo(_tar->files())) {
|
||||||
@ -245,8 +245,8 @@ bool OziMap::setImageInfo(const QString &path)
|
|||||||
|
|
||||||
if (OZF::isOZF(_map.path)) {
|
if (OZF::isOZF(_map.path)) {
|
||||||
_ozf = new OZF(_map.path);
|
_ozf = new OZF(_map.path);
|
||||||
if (!_ozf || !_ozf->open()) {
|
if (!_ozf->open()) {
|
||||||
_errorString = QString("%1: Error loading OZF file").arg(_map.path);
|
_errorString = QString("%1: %2").arg(_map.path, _ozf->errorString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_scale = _ozf->scale(_zoom);
|
_scale = _ozf->scale(_zoom);
|
||||||
@ -312,19 +312,24 @@ void OziMap::load(const Projection &in, const Projection &out,
|
|||||||
|
|
||||||
if (_tar) {
|
if (_tar) {
|
||||||
Q_ASSERT(!_tar->isOpen());
|
Q_ASSERT(!_tar->isOpen());
|
||||||
if (!_tar->open())
|
if (!_tar->open()) {
|
||||||
|
qWarning("%s: %s", qPrintable(_tar->fileName()),
|
||||||
|
qPrintable(_tar->errorString()));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (_ozf) {
|
if (_ozf) {
|
||||||
Q_ASSERT(!_ozf->isOpen());
|
Q_ASSERT(!_ozf->isOpen());
|
||||||
if (!_ozf->open())
|
if (!_ozf->open()) {
|
||||||
|
qWarning("%s: %s", qPrintable(_ozf->fileName()),
|
||||||
|
qPrintable(_ozf->errorString()));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!_tile.isValid() && !_ozf) {
|
if (!_tile.isValid() && !_ozf) {
|
||||||
Q_ASSERT(!_img);
|
Q_ASSERT(!_img);
|
||||||
_img = new Image(_map.path);
|
_img = new Image(_map.path);
|
||||||
if (_img)
|
_img->setDevicePixelRatio(_mapRatio);
|
||||||
_img->setDevicePixelRatio(_mapRatio);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +46,10 @@ static quint64 number(const char* data, size_t size, int base = 8)
|
|||||||
|
|
||||||
bool Tar::open()
|
bool Tar::open()
|
||||||
{
|
{
|
||||||
if (!_file.open(QIODevice::ReadOnly))
|
if (!_file.open(QIODevice::ReadOnly)) {
|
||||||
|
_error = _file.errorString();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_index.isEmpty())
|
if (!_index.isEmpty())
|
||||||
return true;
|
return true;
|
||||||
@ -72,6 +74,7 @@ bool Tar::loadTar()
|
|||||||
if (ret < BLOCKSIZE) {
|
if (ret < BLOCKSIZE) {
|
||||||
_file.close();
|
_file.close();
|
||||||
_index.clear();
|
_index.clear();
|
||||||
|
_error = "Error reading header block";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
size = number(hdr->size, sizeof(hdr->size));
|
size = number(hdr->size, sizeof(hdr->size));
|
||||||
@ -79,6 +82,7 @@ bool Tar::loadTar()
|
|||||||
if (!_file.seek(_file.pos() + BLOCKCOUNT(size) * BLOCKSIZE)) {
|
if (!_file.seek(_file.pos() + BLOCKCOUNT(size) * BLOCKSIZE)) {
|
||||||
_file.close();
|
_file.close();
|
||||||
_index.clear();
|
_index.clear();
|
||||||
|
_error = "Error skipping data blocks";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ public:
|
|||||||
|
|
||||||
bool open();
|
bool open();
|
||||||
void close() {_file.close();}
|
void close() {_file.close();}
|
||||||
|
const QString &errorString() const {return _error;}
|
||||||
|
|
||||||
QStringList files() const {return _index.keys();}
|
QStringList files() const {return _index.keys();}
|
||||||
QByteArray file(const QString &name);
|
QByteArray file(const QString &name);
|
||||||
@ -26,6 +27,7 @@ private:
|
|||||||
|
|
||||||
QFile _file;
|
QFile _file;
|
||||||
QMap<QString, quint64> _index;
|
QMap<QString, quint64> _index;
|
||||||
|
QString _error;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TAR_H
|
#endif // TAR_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user