From 8140aae006ba5386f3495887ec32caa08ec6d371 Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Tue, 7 Jul 2020 13:23:28 -0700 Subject: [PATCH] New QGCFileDownload support for bit.ly style redirects and file name --- .../APM/APMAirframeComponentController.cc | 72 +++--- .../APM/APMAirframeComponentController.h | 6 +- src/FirmwarePlugin/FirmwarePlugin.cc | 18 +- src/QGCApplication.cc | 50 ++-- src/QGCApplication.h | 19 +- src/QGCFileDownload.cc | 68 +++-- src/QGCFileDownload.h | 13 +- src/VehicleSetup/FirmwareUpgradeController.cc | 240 +++++++++--------- src/VehicleSetup/FirmwareUpgradeController.h | 39 ++- 9 files changed, 239 insertions(+), 286 deletions(-) diff --git a/src/AutoPilotPlugins/APM/APMAirframeComponentController.cc b/src/AutoPilotPlugins/APM/APMAirframeComponentController.cc index 84cce217f..6df3e4256 100644 --- a/src/AutoPilotPlugins/APM/APMAirframeComponentController.cc +++ b/src/AutoPilotPlugins/APM/APMAirframeComponentController.cc @@ -219,56 +219,48 @@ void APMAirframeComponentController::loadParameters(const QString& paramFile) QString paramFileUrl = QStringLiteral("https://api.github.com/repos/ArduPilot/ardupilot/contents/Tools/Frame_params/%1?ref=master"); QGCFileDownload* downloader = new QGCFileDownload(this); - connect(downloader, &QGCFileDownload::downloadFinished, this, &APMAirframeComponentController::_githubJsonDownloadFinished); - connect(downloader, &QGCFileDownload::error, this, &APMAirframeComponentController::_githubJsonDownloadError); + connect(downloader, &QGCFileDownload::downloadComplete, this, &APMAirframeComponentController::_githubJsonDownloadComplete); downloader->download(paramFileUrl.arg(paramFile)); } -void APMAirframeComponentController::_githubJsonDownloadFinished(QString remoteFile, QString localFile) +void APMAirframeComponentController::_githubJsonDownloadComplete(QString /*remoteFile*/, QString localFile, QString errorMsg) { - Q_UNUSED(remoteFile); - - QFile jsonFile(localFile); - if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - qWarning() << "Unable to open github json file" << localFile << jsonFile.errorString(); - qgcApp()->restoreOverrideCursor(); - return; - } - QByteArray bytes = jsonFile.readAll(); - jsonFile.close(); + if (errorMsg.isEmpty()) { + QFile jsonFile(localFile); + if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning() << "Unable to open github json file" << localFile << jsonFile.errorString(); + qgcApp()->restoreOverrideCursor(); + return; + } + QByteArray bytes = jsonFile.readAll(); + jsonFile.close(); + + QJsonParseError jsonParseError; + QJsonDocument doc = QJsonDocument::fromJson(bytes, &jsonParseError); + if (jsonParseError.error != QJsonParseError::NoError) { + qWarning() << "Unable to open json document" << localFile << jsonParseError.errorString(); + qgcApp()->restoreOverrideCursor(); + return; + } + QJsonObject json = doc.object(); - QJsonParseError jsonParseError; - QJsonDocument doc = QJsonDocument::fromJson(bytes, &jsonParseError); - if (jsonParseError.error != QJsonParseError::NoError) { - qWarning() << "Unable to open json document" << localFile << jsonParseError.errorString(); + QGCFileDownload* downloader = new QGCFileDownload(this); + connect(downloader, &QGCFileDownload::downloadComplete, this, &APMAirframeComponentController::_paramFileDownloadComplete); + downloader->download(json[QLatin1Literal("download_url")].toString()); + } else { + qgcApp()->showAppMessage(tr("Param file github json download failed: %1").arg(errorMsg)); qgcApp()->restoreOverrideCursor(); - return; } - QJsonObject json = doc.object(); - - QGCFileDownload* downloader = new QGCFileDownload(this); - connect(downloader, &QGCFileDownload::downloadFinished, this, &APMAirframeComponentController::_paramFileDownloadFinished); - connect(downloader, &QGCFileDownload::error, this, &APMAirframeComponentController::_paramFileDownloadError); - downloader->download(json[QLatin1Literal("download_url")].toString()); -} - -void APMAirframeComponentController::_githubJsonDownloadError(QString errorMsg) -{ - qgcApp()->showAppMessage(tr("Param file github json download failed: %1").arg(errorMsg)); - qgcApp()->restoreOverrideCursor(); } -void APMAirframeComponentController::_paramFileDownloadFinished(QString remoteFile, QString localFile) +void APMAirframeComponentController::_paramFileDownloadComplete(QString /*remoteFile*/, QString localFile, QString errorMsg) { - Q_UNUSED(remoteFile); - - _loadParametersFromDownloadFile(localFile); -} - -void APMAirframeComponentController::_paramFileDownloadError(QString errorMsg) -{ - qgcApp()->showAppMessage(tr("Param file download failed: %1").arg(errorMsg)); - qgcApp()->restoreOverrideCursor(); + if (errorMsg.isEmpty()) { + _loadParametersFromDownloadFile(localFile); + } else { + qgcApp()->showAppMessage(tr("Param file download failed: %1").arg(errorMsg)); + qgcApp()->restoreOverrideCursor(); + } } APMFrameClass::APMFrameClass(const QString& name, bool copter, int frameClass, Fact* frameTypeFact, QObject* parent) diff --git a/src/AutoPilotPlugins/APM/APMAirframeComponentController.h b/src/AutoPilotPlugins/APM/APMAirframeComponentController.h index c5290e391..102a75778 100644 --- a/src/AutoPilotPlugins/APM/APMAirframeComponentController.h +++ b/src/AutoPilotPlugins/APM/APMAirframeComponentController.h @@ -35,10 +35,8 @@ public: Q_INVOKABLE void loadParameters(const QString& paramFile); private slots: - void _githubJsonDownloadFinished(QString remoteFile, QString localFile); - void _githubJsonDownloadError(QString errorMsg); - void _paramFileDownloadFinished(QString remoteFile, QString localFile); - void _paramFileDownloadError(QString errorMsg); + void _githubJsonDownloadComplete(QString remoteFile, QString localFile, QString errorMsg); + void _paramFileDownloadComplete(QString remoteFile, QString localFile, QString errorMsg); private: void _fillFrameClasses(void); diff --git a/src/FirmwarePlugin/FirmwarePlugin.cc b/src/FirmwarePlugin/FirmwarePlugin.cc index 0a1096fa2..a3dbab588 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.cc +++ b/src/FirmwarePlugin/FirmwarePlugin.cc @@ -831,20 +831,16 @@ void FirmwarePlugin::checkIfIsLatestStable(Vehicle* vehicle) QGCFileDownload* downloader = new QGCFileDownload(this); connect( downloader, - &QGCFileDownload::downloadFinished, + &QGCFileDownload::downloadComplete, this, - [vehicle, this](QString remoteFile, QString localFile) { - _versionFileDownloadFinished(remoteFile, localFile, vehicle); + [vehicle, this](QString remoteFile, QString localFile, QString errorMsg) { + if (errorMsg.isEmpty()) { + _versionFileDownloadFinished(remoteFile, localFile, vehicle); + } else { + qCDebug(FirmwarePluginLog) << "Failed to download the latest fw version file. Error: " << errorMsg; + } sender()->deleteLater(); }); - connect( - downloader, - &QGCFileDownload::error, - this, - [=](QString errorMsg) { - qCDebug(FirmwarePluginLog) << "Failed to download the latest fw version file. Error: " << errorMsg; - downloader->deleteLater(); - }); downloader->download(versionFile); } diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 43ed421cd..c3b8356e5 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -866,48 +866,46 @@ void QGCApplication::_checkForNewVersion() if (_parseVersionText(applicationVersion(), _majorVersion, _minorVersion, _buildVersion)) { QString versionCheckFile = toolbox()->corePlugin()->stableVersionCheckFileUrl(); if (!versionCheckFile.isEmpty()) { - _currentVersionDownload = new QGCFileDownload(this); - connect(_currentVersionDownload, &QGCFileDownload::downloadFinished, this, &QGCApplication::_currentVersionDownloadFinished); - connect(_currentVersionDownload, &QGCFileDownload::error, this, &QGCApplication::_currentVersionDownloadError); - _currentVersionDownload->download(versionCheckFile); + QGCFileDownload* download = new QGCFileDownload(this); + connect(download, &QGCFileDownload::downloadComplete, this, &QGCApplication::_qgcCurrentStableVersionDownloadComplete); + download->download(versionCheckFile); } } } #endif } -void QGCApplication::_currentVersionDownloadFinished(QString /*remoteFile*/, QString localFile) +void QGCApplication::_qgcCurrentStableVersionDownloadComplete(QString /*remoteFile*/, QString localFile, QString errorMsg) { #ifdef __mobile__ - Q_UNUSED(localFile); + Q_UNUSED(localFile) + Q_UNUSED(errorMsg) #else - QFile versionFile(localFile); - if (versionFile.open(QIODevice::ReadOnly)) { - QTextStream textStream(&versionFile); - QString version = textStream.readLine(); - - qDebug() << version; - - int majorVersion, minorVersion, buildVersion; - if (_parseVersionText(version, majorVersion, minorVersion, buildVersion)) { - if (_majorVersion < majorVersion || - (_majorVersion == majorVersion && _minorVersion < minorVersion) || - (_majorVersion == majorVersion && _minorVersion == minorVersion && _buildVersion < buildVersion)) { - //-- TODO - ///QGCMessageBox::information(tr("New Version Available"), tr("There is a newer version of %1 available. You can download it from %2.").arg(applicationName()).arg(toolbox()->corePlugin()->stableDownloadLocation())); + if (errorMsg.isEmpty()) { + QFile versionFile(localFile); + if (versionFile.open(QIODevice::ReadOnly)) { + QTextStream textStream(&versionFile); + QString version = textStream.readLine(); + + qDebug() << version; + + int majorVersion, minorVersion, buildVersion; + if (_parseVersionText(version, majorVersion, minorVersion, buildVersion)) { + if (_majorVersion < majorVersion || + (_majorVersion == majorVersion && _minorVersion < minorVersion) || + (_majorVersion == majorVersion && _minorVersion == minorVersion && _buildVersion < buildVersion)) { + showAppMessage(tr("There is a newer version of %1 available. You can download it from %2.").arg(applicationName()).arg(toolbox()->corePlugin()->stableDownloadLocation()), tr("New Version Available")); + } } } + } else { + qDebug() << "Download QGC stable version failed" << errorMsg; } - _currentVersionDownload->deleteLater(); + sender()->deleteLater(); #endif } -void QGCApplication::_currentVersionDownloadError(QString /*errorMsg*/) -{ - _currentVersionDownload->deleteLater(); -} - bool QGCApplication::_parseVersionText(const QString& versionString, int& majorVersion, int& minorVersion, int& buildVersion) { QRegularExpression regExp("v(\\d+)\\.(\\d+)\\.(\\d+)"); diff --git a/src/QGCApplication.h b/src/QGCApplication.h index faba95c48..f66f8b149 100644 --- a/src/QGCApplication.h +++ b/src/QGCApplication.h @@ -41,7 +41,6 @@ class QQmlApplicationEngine; class QGCSingleton; class QGCToolbox; -class QGCFileDownload; /** * @brief The main application and management class. @@ -166,15 +165,14 @@ public: bool _checkTelemetrySavePath(bool useMessageBox); private slots: - void _missingParamsDisplay (void); - void _currentVersionDownloadFinished(QString remoteFile, QString localFile); - void _currentVersionDownloadError (QString errorMsg); - bool _parseVersionText (const QString& versionString, int& majorVersion, int& minorVersion, int& buildVersion); - void _onGPSConnect (void); - void _onGPSDisconnect (void); - void _gpsSurveyInStatus (float duration, float accuracyMM, double latitude, double longitude, float altitude, bool valid, bool active); - void _gpsNumSatellites (int numSatellites); - void _showDelayedAppMessages (void); + void _missingParamsDisplay (void); + void _qgcCurrentStableVersionDownloadComplete (QString remoteFile, QString localFile, QString errorMsg); + bool _parseVersionText (const QString& versionString, int& majorVersion, int& minorVersion, int& buildVersion); + void _onGPSConnect (void); + void _onGPSDisconnect (void); + void _gpsSurveyInStatus (float duration, float accuracyMM, double latitude, double longitude, float altitude, bool valid, bool active); + void _gpsNumSatellites (int numSatellites); + void _showDelayedAppMessages (void); private: QObject* _rootQmlObject (); @@ -194,7 +192,6 @@ private: int _majorVersion = 0; int _minorVersion = 0; int _buildVersion = 0; - QGCFileDownload* _currentVersionDownload = nullptr; GPSRTKFactGroup* _gpsRtkFactGroup = nullptr; QGCToolbox* _toolbox = nullptr; QQuickItem* _mainRootWindow = nullptr; diff --git a/src/QGCFileDownload.cc b/src/QGCFileDownload.cc index 62a0301cb..8a9a50135 100644 --- a/src/QGCFileDownload.cc +++ b/src/QGCFileDownload.cc @@ -31,29 +31,6 @@ bool QGCFileDownload::download(const QString& remoteFile, bool redirect) return false; } - // Split out filename from path - QString remoteFileName = QFileInfo(remoteFile).fileName(); - if (remoteFileName.isEmpty()) { - qWarning() << "Unabled to parse filename from downloadFile" << remoteFile; - return false; - } - - // Strip out parameters from remote filename - int parameterIndex = remoteFileName.indexOf("?"); - if (parameterIndex != -1) { - remoteFileName = remoteFileName.left(parameterIndex); - } - - // Determine location to download file to - QString localFile = QStandardPaths::writableLocation(QStandardPaths::TempLocation); - if (localFile.isEmpty()) { - localFile = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); - if (localFile.isEmpty()) { - qDebug() << "Unabled to find writable download location. Tried downloads and temp directory."; - return false; - } - } - localFile += "/" + remoteFileName; QUrl remoteUrl; if (remoteFile.startsWith("http:") || remoteFile.startsWith("https:")) { @@ -72,9 +49,6 @@ bool QGCFileDownload::download(const QString& remoteFile, bool redirect) tProxy.setType(QNetworkProxy::DefaultProxy); setProxy(tProxy); - // Store local file location in user attribute so we can retrieve when the download finishes - networkRequest.setAttribute(QNetworkRequest::User, localFile); - QNetworkReply* networkReply = get(networkRequest); if (!networkReply) { qWarning() << "QNetworkAccessManager::get failed"; @@ -84,8 +58,7 @@ bool QGCFileDownload::download(const QString& remoteFile, bool redirect) connect(networkReply, &QNetworkReply::downloadProgress, this, &QGCFileDownload::downloadProgress); connect(networkReply, &QNetworkReply::finished, this, &QGCFileDownload::_downloadFinished); #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) - connect(networkReply, static_cast(&QNetworkReply::error), - this, &QGCFileDownload::_downloadError); + connect(networkReply, static_cast(&QNetworkReply::error), this, &QGCFileDownload::_downloadError); #else connect(networkReply, &QNetworkReply::errorOccurred, this, &QGCFileDownload::_downloadError); #endif @@ -95,10 +68,10 @@ bool QGCFileDownload::download(const QString& remoteFile, bool redirect) void QGCFileDownload::_downloadFinished(void) { QNetworkReply* reply = qobject_cast(QObject::sender()); - + // When an error occurs or the user cancels the download, we still end up here. So bail out in // those cases. - if (reply->error() != QNetworkReply::NoError) { + if (reply->error() != QNetworkReply::NoError) { reply->deleteLater(); return; } @@ -112,25 +85,46 @@ void QGCFileDownload::_downloadFinished(void) return; } - // Download file location is in user attribute - QString downloadFilename = reply->request().attribute(QNetworkRequest::User).toString(); + // Split out filename from path + QString remoteFileName = QFileInfo(reply->url().toString()).fileName(); + if (remoteFileName.isEmpty()) { + qWarning() << "Unabled to parse filename from remote url" << reply->url().toString(); + remoteFileName = "DownloadedFile"; + } + + // Strip out http parameters from remote filename + int parameterIndex = remoteFileName.indexOf("?"); + if (parameterIndex != -1) { + remoteFileName = remoteFileName.left(parameterIndex); + } + + // Determine location to download file to + QString downloadFilename = QStandardPaths::writableLocation(QStandardPaths::TempLocation); + if (downloadFilename.isEmpty()) { + downloadFilename = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); + if (downloadFilename.isEmpty()) { + emit downloadComplete(_originalRemoteFile, QString(), tr("Unabled to find writable download location. Tried downloads and temp directory.")); + return; + } + } + downloadFilename += "/" + remoteFileName; if (!downloadFilename.isEmpty()) { // Store downloaded file in download location QFile file(downloadFilename); - if (!file.open(QIODevice::WriteOnly)) { - emit error(tr("Could not save downloaded file to %1. Error: %2").arg(downloadFilename).arg(file.errorString())); + if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + emit downloadComplete(_originalRemoteFile, downloadFilename, tr("Could not save downloaded file to %1. Error: %2").arg(downloadFilename).arg(file.errorString())); return; } file.write(reply->readAll()); file.close(); - emit downloadFinished(_originalRemoteFile, downloadFilename); + emit downloadComplete(_originalRemoteFile, downloadFilename, QString()); } else { QString errorMsg = "Internal error"; qWarning() << errorMsg; - emit error(errorMsg); + emit downloadComplete(_originalRemoteFile, downloadFilename, errorMsg); } reply->deleteLater(); @@ -151,5 +145,5 @@ void QGCFileDownload::_downloadError(QNetworkReply::NetworkError code) errorMsg = tr("Error during download. Error: %1").arg(code); } - emit error(errorMsg); + emit downloadComplete(_originalRemoteFile, QString(), errorMsg); } diff --git a/src/QGCFileDownload.h b/src/QGCFileDownload.h index ac67381f1..62d04a98a 100644 --- a/src/QGCFileDownload.h +++ b/src/QGCFileDownload.h @@ -7,9 +7,7 @@ * ****************************************************************************/ - -#ifndef QGCFileDownload_H -#define QGCFileDownload_H +#pragma once #include @@ -21,15 +19,14 @@ public: QGCFileDownload(QObject* parent = nullptr); /// Download the specified remote file. - /// @param remoteFile File to download. Can be http address or file system path. - /// @param redirect true: call is internal due to redirect + /// @param remoteFile File to download. Can be http address or file system path. + /// @param redirect true: call is internal due to redirect /// @return true: Asynchronous download has started, false: Download initialization failed bool download(const QString& remoteFile, bool redirect = false); signals: void downloadProgress(qint64 curr, qint64 total); - void downloadFinished(QString remoteFile, QString localFile); - void error(QString errorMsg); + void downloadComplete(QString remoteFile, QString localFile, QString errorMsg); private: void _downloadFinished(void); @@ -37,5 +34,3 @@ private: QString _originalRemoteFile; }; - -#endif diff --git a/src/VehicleSetup/FirmwareUpgradeController.cc b/src/VehicleSetup/FirmwareUpgradeController.cc index e2b697cc0..934d81e58 100644 --- a/src/VehicleSetup/FirmwareUpgradeController.cc +++ b/src/VehicleSetup/FirmwareUpgradeController.cc @@ -582,9 +582,8 @@ void FirmwareUpgradeController::_downloadFirmware(void) _appendStatusLog(tr(" From: %1").arg(_firmwareFilename)); QGCFileDownload* downloader = new QGCFileDownload(this); - connect(downloader, &QGCFileDownload::downloadFinished, this, &FirmwareUpgradeController::_firmwareDownloadFinished); + connect(downloader, &QGCFileDownload::downloadComplete, this, &FirmwareUpgradeController::_firmwareDownloadComplete); connect(downloader, &QGCFileDownload::downloadProgress, this, &FirmwareUpgradeController::_firmwareDownloadProgress); - connect(downloader, &QGCFileDownload::error, this, &FirmwareUpgradeController::_firmwareDownloadError); downloader->download(_firmwareFilename); } @@ -598,10 +597,9 @@ void FirmwareUpgradeController::_firmwareDownloadProgress(qint64 curr, qint64 to } /// @brief Called when the firmware download completes. -void FirmwareUpgradeController::_firmwareDownloadFinished(QString remoteFile, QString localFile) +void FirmwareUpgradeController::_firmwareDownloadComplete(QString /*remoteFile*/, QString localFile, QString errorMsg) { - Q_UNUSED(remoteFile); - + if (errorMsg.isEmpty()) { _appendStatusLog(tr("Download complete")); FirmwareImage* image = new FirmwareImage(this); @@ -626,12 +624,9 @@ void FirmwareUpgradeController::_firmwareDownloadFinished(QString remoteFile, QS } _threadController->flash(image); -} - -/// @brief Called when an error occurs during download -void FirmwareUpgradeController::_firmwareDownloadError(QString errorMsg) -{ - _errorCancel(errorMsg); + } else { + _errorCancel(errorMsg); + } } /// @brief returns firmware type as a string @@ -809,161 +804,152 @@ FirmwareUpgradeController::FirmwareVehicleType_t FirmwareUpgradeController::vehi void FirmwareUpgradeController::_determinePX4StableVersion(void) { QGCFileDownload* downloader = new QGCFileDownload(this); - connect(downloader, &QGCFileDownload::downloadFinished, this, &FirmwareUpgradeController::_px4ReleasesGithubDownloadFinished); - connect(downloader, &QGCFileDownload::error, this, &FirmwareUpgradeController::_px4ReleasesGithubDownloadError); + connect(downloader, &QGCFileDownload::downloadComplete, this, &FirmwareUpgradeController::_px4ReleasesGithubDownloadComplete); downloader->download(QStringLiteral("https://api.github.com/repos/PX4/Firmware/releases")); } -void FirmwareUpgradeController::_px4ReleasesGithubDownloadFinished(QString remoteFile, QString localFile) +void FirmwareUpgradeController::_px4ReleasesGithubDownloadComplete(QString /*remoteFile*/, QString localFile, QString errorMsg) { - Q_UNUSED(remoteFile); - - QFile jsonFile(localFile); - if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - qCWarning(FirmwareUpgradeLog) << "Unable to open github px4 releases json file" << localFile << jsonFile.errorString(); - return; - } - QByteArray bytes = jsonFile.readAll(); - jsonFile.close(); + if (errorMsg.isEmpty()) { + QFile jsonFile(localFile); + if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + qCWarning(FirmwareUpgradeLog) << "Unable to open github px4 releases json file" << localFile << jsonFile.errorString(); + return; + } + QByteArray bytes = jsonFile.readAll(); + jsonFile.close(); - QJsonParseError jsonParseError; - QJsonDocument doc = QJsonDocument::fromJson(bytes, &jsonParseError); - if (jsonParseError.error != QJsonParseError::NoError) { - qCWarning(FirmwareUpgradeLog) << "Unable to open px4 releases json document" << localFile << jsonParseError.errorString(); - return; - } + QJsonParseError jsonParseError; + QJsonDocument doc = QJsonDocument::fromJson(bytes, &jsonParseError); + if (jsonParseError.error != QJsonParseError::NoError) { + qCWarning(FirmwareUpgradeLog) << "Unable to open px4 releases json document" << localFile << jsonParseError.errorString(); + return; + } - // Json should be an array of release objects - if (!doc.isArray()) { - qCWarning(FirmwareUpgradeLog) << "px4 releases json document is not an array" << localFile; - return; - } - QJsonArray releases = doc.array(); - - // The first release marked prerelease=false is stable - // The first release marked prerelease=true is beta - bool foundStable = false; - bool foundBeta = false; - for (int i=0; idownload(QStringLiteral("http://firmware.ardupilot.org/manifest.json.gz")); } -void FirmwareUpgradeController::_ardupilotManifestDownloadFinished(QString remoteFile, QString localFile) +void FirmwareUpgradeController::_ardupilotManifestDownloadComplete(QString remoteFile, QString localFile, QString errorMsg) { - Q_UNUSED(remoteFile); + if (errorMsg.isEmpty()) { + // Delete the QGCFileDownload object + sender()->deleteLater(); - // Delete the QGCFileDownload object - sender()->deleteLater(); + qCDebug(FirmwareUpgradeLog) << "_ardupilotManifestDownloadFinished" << remoteFile << localFile; - qCDebug(FirmwareUpgradeLog) << "_ardupilotManifestDownloadFinished" << remoteFile << localFile; + QString jsonFileName(QDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).absoluteFilePath("ArduPilot.Manifest.json")); + if (!QGCZlib::inflateGzipFile(localFile, jsonFileName)) { + qCWarning(FirmwareUpgradeLog) << "Inflate of compressed manifest failed" << localFile; + return; + } - QString jsonFileName(QDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).absoluteFilePath("ArduPilot.Manifest.json")); - if (!QGCZlib::inflateGzipFile(localFile, jsonFileName)) { - qCWarning(FirmwareUpgradeLog) << "Inflate of compressed manifest failed" << localFile; - return; - } + QString errorString; + QJsonDocument doc; + if (!JsonHelper::isJsonFile(jsonFileName, doc, errorString)) { + qCWarning(FirmwareUpgradeLog) << "Json file read failed" << errorString; + return; + } - QString errorString; - QJsonDocument doc; - if (!JsonHelper::isJsonFile(jsonFileName, doc, errorString)) { - qCWarning(FirmwareUpgradeLog) << "Json file read failed" << errorString; - return; - } + QJsonObject json = doc.object(); + QJsonArray rgFirmware = json[_manifestFirmwareJsonKey].toArray(); - QJsonObject json = doc.object(); - QJsonArray rgFirmware = json[_manifestFirmwareJsonKey].toArray(); + for (int i=0; i(firmwareJson[_manifestBoardIdJsonKey].toInt()); + firmwareInfo.firmwareBuildType = firmwareBuildType; + firmwareInfo.vehicleType = firmwareVehicleType; + firmwareInfo.url = firmwareJson[_manifestUrlJsonKey].toString(); + firmwareInfo.version = firmwareJson[_manifestMavFirmwareVersionJsonKey].toString(); + firmwareInfo.chibios = format == QStringLiteral("apj"); firmwareInfo.fmuv2 = platform.contains(QStringLiteral("fmuv2")); - firmwareInfo.boardId = static_cast(firmwareJson[_manifestBoardIdJsonKey].toInt()); - firmwareInfo.firmwareBuildType = firmwareBuildType; - firmwareInfo.vehicleType = firmwareVehicleType; - firmwareInfo.url = firmwareJson[_manifestUrlJsonKey].toString(); - firmwareInfo.version = firmwareJson[_manifestMavFirmwareVersionJsonKey].toString(); - firmwareInfo.chibios = format == QStringLiteral("apj"); - firmwareInfo.fmuv2 = platform.contains(QStringLiteral("fmuv2")); + QJsonArray bootloaderArray = firmwareJson[_manifestBootloaderStrJsonKey].toArray(); + for (int j=0; j* _firmwareHashForBoardId(int boardId); - void _getFirmwareFile(FirmwareIdentifier firmwareId); + void _getFirmwareFile (FirmwareIdentifier firmwareId); void _initFirmwareHash (void); void _downloadFirmware (void); void _appendStatusLog (const QString& text, bool critical = false); -- 2.22.0