diff --git a/src/ViewWidgets/LogDownloadController.cc b/src/ViewWidgets/LogDownloadController.cc index a4399e4f87ee82261f743acf6af815c22b394adc..7718d522437624f92d008ae8cca7a9ca8e0b8b09 100644 --- a/src/ViewWidgets/LogDownloadController.cc +++ b/src/ViewWidgets/LogDownloadController.cc @@ -282,16 +282,7 @@ LogDownloadController::_logData(UASInterface* uas, uint32_t ofs, uint16_t id, ui // Check for a gap qint64 pos = _downloadData->file.pos(); if (pos != ofs) { - // Check for a gap collision - if (_downloadData->gaps.contains(ofs)) { - // The gap is being filled. Shrink it - const int32_t gap = _downloadData->gaps.take(ofs) - count; - if (gap > 0) { - _downloadData->gaps[ofs+count] = qMax(static_cast(gap), _downloadData->gaps.value(ofs+count, 0)); - } else { - timeout_time = 20; - } - } else if (pos < ofs) { + if (pos < ofs) { // Mind the gap uint32_t gap = ofs - pos; _downloadData->gaps[pos] = gap; @@ -304,6 +295,17 @@ LogDownloadController::_logData(UASInterface* uas, uint32_t ofs, uint16_t id, ui } } + // Check for a gap collision + if (_downloadData->gaps.contains(ofs)) { + // The gap is being filled. Shrink it + const int32_t gap = _downloadData->gaps.take(ofs) - count; + if (gap > 0) { + _downloadData->gaps[ofs+count] = qMax(static_cast(gap), _downloadData->gaps.value(ofs+count, 0)); + } else { + timeout_time = 20; + } + } + //-- Write chunk to file if(_downloadData->file.write((const char*)data, count)) { _downloadData->written += count; @@ -378,9 +380,12 @@ LogDownloadController::_findMissingData() const qint64 pos = _downloadData->file.pos(), size = _downloadData->entry->size(); if (!_downloadData->gaps.isEmpty()) { - const uint32_t start = _downloadData->gaps.firstKey(); + auto keys = _downloadData->gaps.keys(); + qSort(keys); + const uint32_t start = keys.first(); const uint32_t count = _downloadData->gaps.value(start); + _downloadData->file.seek(start); //-- Request these log chunks again _requestLogData(_downloadData->ID, start, count); } else if (pos != size) { diff --git a/src/ViewWidgets/LogDownloadController.h b/src/ViewWidgets/LogDownloadController.h index d27c9dbea43b73478b3978aefd4054d05ec05664..40ba3b1256ce5dcb2ff44bdb82f3abc80e1136e7 100644 --- a/src/ViewWidgets/LogDownloadController.h +++ b/src/ViewWidgets/LogDownloadController.h @@ -125,13 +125,13 @@ private: //----------------------------------------------------------------------------- struct LogDownloadData { LogDownloadData(QGCLogEntry* entry); - QMap gaps; - QFile file; - QString filename; - uint ID; - QGCLogEntry* entry; - uint written; - QElapsedTimer elapsed; + QHash gaps; + QFile file; + QString filename; + uint ID; + QGCLogEntry* entry; + uint written; + QElapsedTimer elapsed; }; //-----------------------------------------------------------------------------