mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +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.open()) {
|
||||
_errorString = "Error reading tar file";
|
||||
_errorString = "Error reading tar file: " + tar.errorString();
|
||||
return;
|
||||
}
|
||||
QString tbaFileName(tbaFile(tar.files()));
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user