27#include <simgear/io/HTTPMemoryRequest.hxx>
28#include <simgear/props/props_io.hxx>
29#include <simgear/structure/exception.hxx>
38class UpdateXMLRequest :
public simgear::HTTP::MemoryRequest
41 UpdateXMLRequest(UpdateChecker* u,
const std::string& uri) :
42 simgear::HTTP::MemoryRequest(uri),
48 requestHeader(
"FlightGear-Version") = FLIGHTGEAR_VERSION;
51 void onFail()
override
56 void onDone()
override
58 int response = responseCode();
59 if (response == 200) {
61 QMetaObject::invokeMethod(_owner,
"receivedUpdateXML", Qt::QueuedConnection,
62 Q_ARG(QByteArray, QByteArray::fromStdString(responseBody())));
73 const QDate n = QDate::currentDate().addDays(1);
74 settings.setValue(
"next-update-check", n);
77 UpdateChecker* _owner;
85 QDate nextCheck = settings.value(
"next-update-check").toDate();
86 if (!nextCheck.isValid()) {
88 const QDate n = QDate::currentDate().addDays(1);
89 settings.setValue(
"next-update-check", n);
94 if (nextCheck <= QDate::currentDate()) {
101 const string_list versionParts = simgear::strutils::split(FLIGHTGEAR_VERSION,
".");
102 _majorMinorVersion = versionParts[0] +
"." + versionParts[1];
105 std::string uri =
"https://download.flightgear.org/builds/" + _majorMinorVersion +
"/updates.xml";
106 m_request =
new UpdateXMLRequest(
this, uri);
107 http->makeRequest(m_request);
117 http->
client()->cancelRequest(m_request);
126 settings.setValue(
"ignored-point-release", _currentUpdateVersion);
128 settings.setValue(
"ignored-major-release", _currentUpdateVersion);
135 _currentUpdateVersion.clear();
139void UpdateChecker::receivedUpdateXML(QByteArray body)
141 SGPropertyNode_ptr props(
new SGPropertyNode);
142 const auto s = body.toStdString();
148 const char* buffer = s.c_str();
149 readProperties(buffer, s.size(), props,
true);
151 const QDate n = QDate::currentDate().addDays(7);
152 settings.setValue(
"next-update-check", n);
154 const std::string newMajorVersion = props->getStringValue(
"current-major-release");
155 if (simgear::strutils::compare_versions(FLIGHTGEAR_VERSION, newMajorVersion) < 0) {
157 _currentUpdateVersion = QString::fromStdString(newMajorVersion);
158 if (settings.value(
"ignored-major-release") == _currentUpdateVersion) {
163 const std::string newVersionUri = props->getStringValue(
"upgrade-uri");
164 m_updateUri = QUrl(QString::fromStdString(newVersionUri));
167 nc->postNotification(
"flightgear-update-major", QUrl{
"qrc:///qml/NewVersionNotification.qml"});
174 const std::string newPointVersion = props->getStringValue(
"current-point-release");
175 if (simgear::strutils::compare_versions(FLIGHTGEAR_VERSION, newPointVersion) < 0) {
177 _currentUpdateVersion = QString::fromStdString(newPointVersion);
178 if (settings.value(
"ignored-point-release") == _currentUpdateVersion) {
182 const std::string newVersionUri = props->getStringValue(
"download-uri");
183 m_updateUri = QUrl(QString::fromStdString(newVersionUri));
186 nc->postNotification(
"flightgear-update-point", QUrl{
"qrc:///qml/NewVersionNotification.qml"});
189 }
catch (
const sg_exception &e) {
190 SG_LOG(SG_IO, SG_WARN,
"parsing update XML failed: " << e.getFormattedMessage());
simgear::HTTP::Client * client()
static LauncherNotificationsController * instance()
UpdateChecker(QObject *parent=nullptr)
void statusChanged(Status status)
std::vector< std::string > string_list