Skip to content

Commit ea954c4

Browse files
committed
Iterate current.json mirrors
1 parent 4016854 commit ea954c4

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

currentversionfetcher.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,27 @@ CurrentVersionFetcher::CurrentVersionFetcher(QObject* parent) : QObject(parent),
3131
connect(manager_.get(), SIGNAL(finished(QNetworkReply*)), this, SLOT(reply(QNetworkReply*)));
3232
}
3333

34-
void CurrentVersionFetcher::fetchCurrentVersion(QString url)
34+
static const QString versionMirrors[] = {
35+
"https://cdn.unvanquished.net/",
36+
"https://cdn.illwieckz.net/unvanquished/",
37+
"https://webseed.unv.kangz.net/",
38+
nullptr,
39+
};
40+
41+
static const QString *versionMirror = &versionMirrors[0];
42+
43+
void CurrentVersionFetcher::fetchCurrentVersion()
3544
{
36-
QNetworkRequest request = QNetworkRequest(QUrl(url));
37-
manager_->get(request);
45+
static const QString versionFile = "current.json";
46+
47+
if (versionMirror)
48+
{
49+
QString versionURL = versionMirror + versionFile;
50+
qDebug() << "Fetching" << versionURL;
51+
QNetworkRequest request = QNetworkRequest(QUrl(versionURL));
52+
manager_->get(request);
53+
versionMirror++;
54+
}
3855
}
3956

4057
void ComponentVersionFetcher(QJsonObject jsonObject, QString componentSlug, QString componentSystem, QString *componentVersion, QString *componentUrl)
@@ -117,7 +134,12 @@ void CurrentVersionFetcher::reply(QNetworkReply* reply)
117134

118135
if (reply->error() != QNetworkReply::NoError) {
119136
qDebug() << "CurrentVersionFetcher: network error";
120-
emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion, gameUrl, newsUrl);
137+
138+
if (versionMirror) {
139+
fetchCurrentVersion();
140+
} else {
141+
emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion, gameUrl, newsUrl);
142+
}
121143
return;
122144
}
123145

currentversionfetcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CurrentVersionFetcher : public QObject
2828
Q_OBJECT
2929
public:
3030
explicit CurrentVersionFetcher(QObject *parent = nullptr);
31-
void fetchCurrentVersion(QString url);
31+
void fetchCurrentVersion();
3232

3333
signals:
3434
void onCurrentVersions(QString updaterVersion, QString updaterUrl, QString gameVersion, QString gameUrl, QString newsUrl);

splashcontroller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void SplashController::checkForUpdate()
4848
connect(&fetcher_, SIGNAL(onCurrentVersions(QString, QString, QString, QString, QString)),
4949
this, SLOT(onCurrentVersions(QString, QString, QString, QString, QString)));
5050

51-
fetcher_.fetchCurrentVersion("https://cdn.unvanquished.net/current.json");
51+
fetcher_.fetchCurrentVersion();
5252
}
5353

5454
QString SplashController::gameUrl() const {

0 commit comments

Comments
 (0)