Skip to content

Commit 6e6430f

Browse files
committed
read game url from current.json file
1 parent 9cb7551 commit 6e6430f

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

currentversionfetcher.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,38 +78,29 @@ void CurrentVersionFetcher::reply(QNetworkReply* reply)
7878
{
7979
QString updaterVersion;
8080
QString updaterUrl;
81-
QString gameVersion;
81+
QString productVersion;
82+
QString productUrl;
8283

8384
if (reply->error() != QNetworkReply::NoError) {
8485
qDebug() << "CurrentVersionFetcher: network error";
85-
emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion);
86+
emit onCurrentVersions(updaterVersion, updaterUrl, productVersion, productUrl);
8687
return;
8788
}
8889

8990
QJsonParseError error;
9091
QJsonDocument json = QJsonDocument::fromJson(reply->readAll(), &error);
9192
if (error.error != QJsonParseError::NoError) {
9293
qDebug() << "CurrentVersionFetcher: JSON parsing error";
93-
emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion);
94+
emit onCurrentVersions(updaterVersion, updaterUrl, productVersion, productUrl);
9495
return;
9596
}
9697

9798
QJsonObject jsonObject = json.object();
9899

99100
ComponentVersionFetcher(jsonObject, "updater", Sys::updaterSystem(), &updaterVersion, &updaterUrl);
100101

101-
QJsonObject gameObject = jsonObject["game"].toObject();
102-
if (!gameObject.isEmpty()) {
103-
QJsonValue version = gameObject.value("version");
104-
if (version != QJsonValue::Undefined) {
105-
gameVersion = version.toString();
106-
} else {
107-
qDebug() << "CurrentVersionFetcher: undefined “version” game value";
108-
}
109-
} else {
110-
qDebug() << "CurrentVersionFetcher: undefined “game” key";
111-
}
102+
ComponentVersionFetcher(jsonObject, "product", "all-all", &productVersion, &productUrl);
112103

113-
emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion);
104+
emit onCurrentVersions(updaterVersion, updaterUrl, productVersion, productUrl);
114105
}
115106

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 updaterVersion, QString updaterUrl, QString gameVersion);
17+
void onCurrentVersions(QString updaterVersion, QString updaterUrl, QString productVersion, QString productUrl);
1818

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

qmldownloader.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ void QmlDownloader::onDownloadEvent(int event)
7979
}
8080
qDebug() << "Calling Sys::install";
8181
Sys::install();
82-
// FIXME: latestGameVersion_ could be empty if CurrentVersionFetcher didn't succeed
83-
settings_.setCurrentVersion(latestGameVersion_);
82+
// FIXME: latestProductVersion_ could be empty if CurrentVersionFetcher didn't succeed
83+
settings_.setCurrentVersion(latestProductVersion_);
8484
settings_.setInstallFinished(true);
8585
setState(COMPLETED);
8686
setDownloadSpeed(0);
@@ -142,7 +142,7 @@ void QmlDownloader::startUpdate()
142142

143143
worker_ = new DownloadWorker(ariaLogFilename_);
144144
worker_->setDownloadDirectory(dir.canonicalPath().toStdString());
145-
worker_->addTorrent("https://cdn.unvanquished.net/current.torrent");
145+
worker_->addTorrent(latestProductUrl_.toStdString());
146146
worker_->moveToThread(&thread_);
147147
connect(&thread_, SIGNAL(finished()), worker_, SLOT(deleteLater()));
148148
connect(worker_, SIGNAL(onDownloadEvent(int)), this, SLOT(onDownloadEvent(int)));
@@ -198,16 +198,17 @@ void QmlDownloader::stopAria()
198198
// Initiates an asynchronous request for the latest available versions.
199199
void QmlDownloader::checkForUpdate()
200200
{
201-
connect(&fetcher_, SIGNAL(onCurrentVersions(QString, QString, QString)), this, SLOT(onCurrentVersions(QString, QString, QString)));
201+
connect(&fetcher_, SIGNAL(onCurrentVersions(QString, QString, QString, QString)), this, SLOT(onCurrentVersions(QString, QString, QString, QString)));
202202
fetcher_.fetchCurrentVersion("https://cdn.unvanquished.net/current.json");
203203
}
204204

205205
// Receives the results of the checkForUpdate request.
206-
void QmlDownloader::onCurrentVersions(QString updaterVersion, QString updaterUrl, QString gameVersion)
206+
void QmlDownloader::onCurrentVersions(QString updaterVersion, QString updaterUrl, QString productVersion, QString productUrl)
207207
{
208208
latestUpdaterVersion_ = updaterVersion;
209209
latestUpdaterUrl_ = updaterUrl;
210-
latestGameVersion_ = gameVersion;
210+
latestProductVersion_ = productVersion;
211+
latestProductUrl_ = productUrl;
211212
}
212213

213214
// This runs after the splash screen has been displayed for the programmed amount of time (and the
@@ -233,7 +234,7 @@ void QmlDownloader::autoLaunchOrUpdate()
233234
connect(&thread_, SIGNAL(started()), worker_, SLOT(download()));
234235
thread_.start();
235236
} else if (settings_.currentVersion().isEmpty() ||
236-
(!latestGameVersion_.isEmpty() && settings_.currentVersion() != latestGameVersion_)) {
237+
(!latestProductVersion_.isEmpty() && settings_.currentVersion() != latestProductVersion_)) {
237238
qDebug() << "Game update required.";
238239
emit updateNeeded(true);
239240
} else {

qmldownloader.h

Lines changed: 3 additions & 2 deletions
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 updaterVersion, QString updaterUrl, QString gameVersion);
67+
void onCurrentVersions(QString updaterVersion, QString updaterUrl, QString productVersion, QString productUrl);
6868

6969
Q_INVOKABLE void startUpdate();
7070
Q_INVOKABLE void toggleDownload();
@@ -89,7 +89,8 @@ public slots:
8989
Settings settings_;
9090
QString latestUpdaterVersion_;
9191
QString latestUpdaterUrl_;
92-
QString latestGameVersion_;
92+
QString latestProductVersion_;
93+
QString latestProductUrl_;
9394
DownloadState state_;
9495
std::unique_ptr<QTemporaryDir> temp_dir_;
9596

0 commit comments

Comments
 (0)