MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / onReply

Method onReply

lib/QSimpleUpdater/src/Updater.cpp:410–462  ·  view source on GitHub ↗

* @brief Called when the download of the update definitions file is finished. * * Parses the JSON response, extracts platform-specific update information, * and determines whether an update is available. */

Source from the content-addressed store, hash-verified

408 * and determines whether an update is available.
409 */
410void Updater::onReply(QNetworkReply* reply)
411{
412 // Ensure the reply is cleaned up when we're done
413 reply->deleteLater();
414
415 // Check if we need to redirect
416 QUrl redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
417 if (!redirect.isEmpty()) {
418 setUrl(redirect.toString());
419 checkForUpdates();
420 return;
421 }
422
423 // There was a network error
424 if (reply->error() != QNetworkReply::NoError) {
425 setUpdateAvailable(false);
426 emit checkingFinished(url());
427 return;
428 }
429
430 // The application wants to interpret the appcast by itself
431 if (customAppcast()) {
432 emit appcastDownloaded(url(), reply->readAll());
433 emit checkingFinished(url());
434 return;
435 }
436
437 // Try to create a JSON document from downloaded data
438 QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
439
440 // JSON is invalid
441 if (document.isNull()) {
442 setUpdateAvailable(false);
443 emit checkingFinished(url());
444 return;
445 }
446
447 // Get the platform information
448 QJsonObject updates = document.object().value("updates").toObject();
449 QJsonObject platform = updates.value(platformKey()).toObject();
450
451 // Get update information
452 m_openUrl = platform.value("open-url").toString();
453 m_changelog = platform.value("changelog").toString();
454 m_downloadUrl = platform.value("download-url").toString();
455 m_latestVersion = platform.value("latest-version").toString();
456 if (platform.contains("mandatory-update"))
457 m_mandatoryUpdate = platform.value("mandatory-update").toBool();
458
459 // Compare latest and current version
460 setUpdateAvailable(compare(latestVersion(), moduleVersion()));
461 emit checkingFinished(url());
462}
463
464/**
465 * @brief Prompts the user based on the value of the @a available parameter and

Callers

nothing calls this directly

Calls 5

fromJsonFunction · 0.85
isEmptyMethod · 0.80
errorMethod · 0.80
valueMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected