Skip to content

Commit 97ec403

Browse files
committed
Iterate current.json mirrors
1 parent edf9302 commit 97ec403

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

currentversionfetcher.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,26 @@ 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+
QString versionURL = versionMirror + versionFile;
49+
qDebug() << "Fetching" << versionURL;
50+
QNetworkRequest request = QNetworkRequest(QUrl(versionURL));
51+
manager_->get(request);
52+
versionMirror++;
53+
}
3854
}
3955

4056
void ComponentVersionFetcher(QJsonObject components, QString name, QString system, QString *version, QString *url)
@@ -101,7 +117,12 @@ void CurrentVersionFetcher::reply(QNetworkReply* reply)
101117

102118
if (reply->error() != QNetworkReply::NoError) {
103119
qDebug() << "CurrentVersionFetcher: network error";
104-
emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion, gameUrl, newsUrl);
120+
121+
if (versionMirror) {
122+
fetchCurrentVersion();
123+
} else {
124+
emit onCurrentVersions(updaterVersion, updaterUrl, gameVersion, gameUrl, newsUrl);
125+
}
105126
return;
106127
}
107128

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)