Skip to content

Commit 7f396fd

Browse files
committed
read versions from current.json file
1 parent a931f83 commit 7f396fd

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

currentversionfetcher.cpp

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,50 @@ void CurrentVersionFetcher::fetchCurrentVersion(QString url)
2020

2121
void CurrentVersionFetcher::reply(QNetworkReply* reply)
2222
{
23-
QString game;
24-
QString updater;
23+
QString gameVersion;
24+
QString updaterVersion;
25+
2526
if (reply->error() != QNetworkReply::NoError) {
2627
qDebug() << "CurrentVersionFetcher: network error";
27-
emit onCurrentVersions(updater, game);
28+
emit onCurrentVersions(updaterVersion, gameVersion);
2829
return;
2930
}
31+
3032
QJsonParseError error;
3133
QJsonDocument json = QJsonDocument::fromJson(reply->readAll(), &error);
3234
if (error.error != QJsonParseError::NoError) {
3335
qDebug() << "CurrentVersionFetcher: JSON parsing error";
34-
emit onCurrentVersions(updater, game);
36+
emit onCurrentVersions(updaterVersion, gameVersion);
3537
return;
3638
}
37-
QJsonValue value = json.object().value("updater");
38-
if (value != QJsonValue::Undefined) {
39-
updater = value.toString();
39+
QJsonObject jsonObject = json.object();
40+
41+
QJsonObject updaterObject = jsonObject["updater"].toObject();
42+
if (!updaterObject.isEmpty()) {
43+
QJsonValue version = updaterObject.value("version");
44+
if (version != QJsonValue::Undefined) {
45+
updaterVersion = version.toString();
46+
} else {
47+
qDebug() << "CurrentVersionFetcher: undefined “version” updater value";
48+
}
4049
} else {
41-
qDebug() << "CurrentVersionFetcher: undefined “updater” value";
50+
qDebug() << "CurrentVersionFetcher: undefined “updater” key";
4251
}
43-
value = json.object().value("unvanquished");
44-
if (value != QJsonValue::Undefined) {
45-
game = value.toString();
52+
53+
QJsonObject gameObject = jsonObject["game"].toObject();
54+
if (!gameObject.isEmpty()) {
55+
QJsonValue version = gameObject.value("version");
56+
if (version != QJsonValue::Undefined) {
57+
gameVersion = version.toString();
58+
} else {
59+
qDebug() << "CurrentVersionFetcher: undefined “version” game value";
60+
}
4661
} else {
47-
qDebug() << "CurrentVersionFetcher: undefined “unvanquished” value";
62+
qDebug() << "CurrentVersionFetcher: undefined “game” key";
4863
}
49-
qDebug() << "CurrentVersionFetcher: fetched versions: updater =" << updater << "game =" << game;
50-
emit onCurrentVersions(updater, game);
64+
65+
qDebug() << "CurrentVersionFetcher: fetched versions: updater =" << updaterVersion << "game =" << gameVersion;
66+
67+
emit onCurrentVersions(updaterVersion, gameVersion);
5168
}
5269

currentversionfetcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CurrentVersionFetcher : public QObject
1414
void fetchCurrentVersion(QString url);
1515

1616
signals:
17-
void onCurrentVersions(QString updater, QString game);
17+
void onCurrentVersions(QString updaterVersion, QString gameVersion);
1818

1919
private slots:
2020
void reply(QNetworkReply* reply);

qmldownloader.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@ void QmlDownloader::stopAria()
200200
void QmlDownloader::checkForUpdate()
201201
{
202202
connect(&fetcher_, SIGNAL(onCurrentVersions(QString, QString)), this, SLOT(onCurrentVersions(QString, QString)));
203-
fetcher_.fetchCurrentVersion("https://dl.unvanquished.net/versions.json");
203+
fetcher_.fetchCurrentVersion("https://cdn.unvanquished.net/current.json");
204204
}
205205

206206
// Receives the results of the checkForUpdate request.
207-
void QmlDownloader::onCurrentVersions(QString updater, QString game)
207+
void QmlDownloader::onCurrentVersions(QString updaterVersion, QString gameVersion)
208208
{
209-
latestUpdaterVersion_ = updater;
210-
latestGameVersion_ = game;
209+
latestUpdaterVersion_ = updaterVersion;
210+
latestGameVersion_ = gameVersion;
211211
}
212212

213213
// This runs after the splash screen has been displayed for the programmed amount of time (and the
@@ -216,9 +216,10 @@ void QmlDownloader::onCurrentVersions(QString updater, QString game)
216216
void QmlDownloader::autoLaunchOrUpdate()
217217
{
218218
qDebug() << "Previously-installed game version:" << settings_.currentVersion();
219-
if (!latestUpdaterVersion_.isEmpty() && latestUpdaterVersion_ != QString(GIT_VERSION)) {
219+
QString gitUpdaterVersion = "v" + latestUpdaterVersion_;
220+
if (!latestUpdaterVersion_.isEmpty() && gitUpdaterVersion != QString(GIT_VERSION)) {
220221
qDebug() << "Updater update to version" << latestUpdaterVersion_ << "required";
221-
QString url = UPDATER_BASE_URL + "/" + latestUpdaterVersion_ + "/" + Sys::updaterArchiveName();
222+
QString url = UPDATER_BASE_URL + "/" + gitUpdaterVersion + "/" + Sys::updaterArchiveName();
222223
temp_dir_.reset(new QTemporaryDir());
223224
worker_ = new DownloadWorker(ariaLogFilename_);
224225
worker_->setDownloadDirectory(QDir(temp_dir_->path()).canonicalPath().toStdString());

qmldownloader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public slots:
6464
void setTotalSize(int size);
6565
void setCompletedSize(int size);
6666
void onDownloadEvent(int event);
67-
void onCurrentVersions(QString updater, QString game);
67+
void onCurrentVersions(QString updaterVersion, QString gameVersion);
6868

6969
Q_INVOKABLE void startUpdate();
7070
Q_INVOKABLE void toggleDownload();

0 commit comments

Comments
 (0)