Skip to content

Commit ebacd77

Browse files
committed
Added Stable Branch Support
1 parent 3e3c96f commit ebacd77

File tree

6 files changed

+77
-55
lines changed

6 files changed

+77
-55
lines changed

configuration.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@
1111
#include <QAudioDeviceInfo>
1212
#endif
1313

14-
Configuration::Configuration(QString file, QWidget *parent) :
14+
Configuration::Configuration(QSettings *mainSettings, QString file, QWidget *parent) :
1515
QDialog(parent),
1616
ui(new Ui::Configuration),
17-
config(file, QSettings::IniFormat)
17+
config(file, QSettings::IniFormat),
18+
mainSettings(mainSettings)
1819
{
1920
ui->setupUi(this);
2021
setComboBoxData();
2122

22-
{
23-
QSettings main;
23+
ui->launcherVersionMsg->setText(tr("Launcher Version: ") + QStringLiteral(APP_VERSION));
2424

25-
ui->launcherVersionMsg->setText(tr("Launcher Version: ") + QStringLiteral(APP_VERSION));
25+
QVariant build = mainSettings->value(QStringLiteral("downloadId"));
26+
if (build.isValid()) ui->buildVersionMsg->setText(tr("OpenRCT2 Build: ") + build.toString());
2627

27-
QVariant build = main.value(QStringLiteral("downloadId"));
28-
if (build.isValid()) ui->buildVersionMsg->setText(tr("OpenRCT2 Build: ") + build.toString());
28+
QVariant hash = mainSettings->value(QStringLiteral("gitHash"));
29+
if (hash.isValid()) ui->buildHashMsg->setText(tr("OpenRCT2 Git Hash: ") + hash.toByteArray().left(4).toHex().left(7));
2930

30-
QVariant hash = main.value(QStringLiteral("gitHash"));
31-
if (build.isValid()) ui->buildHashMsg->setText(tr("OpenRCT2 Git Hash: ") + hash.toByteArray().left(4).toHex().left(7));
32-
}
31+
QVariant stable = mainSettings->value(QStringLiteral("stable"));
32+
if (stable.isValid() && stable.toBool()) ui->stableButton->setChecked(true);
3333

3434
for (QLineEdit *w : ui->tabWidget->findChildren<QLineEdit *>()) {
3535
QVariant setting = w->property("config");
@@ -247,6 +247,15 @@ Configuration::~Configuration()
247247
}
248248
}
249249

250+
QVariant stableVar = mainSettings->value(QStringLiteral("stable"));
251+
bool stable = stableVar.isValid() && stableVar.toBool();
252+
bool newStable = ui->stableButton->isChecked();
253+
if (stable != newStable) {
254+
mainSettings->setValue(QStringLiteral("stable"), newStable);
255+
mainSettings->sync();
256+
emit redownload();
257+
}
258+
250259
delete ui;
251260
}
252261

configuration.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ class Configuration : public QDialog
1414
Q_OBJECT
1515

1616
public:
17-
explicit Configuration(QString file, QWidget *parent = 0);
17+
explicit Configuration(QSettings *mainSettings, QString file, QWidget *parent = 0);
1818
~Configuration();
1919

20+
signals:
21+
void redownload();
22+
2023
public slots:
2124
void on_locateRCT2_clicked();
2225

2326
private:
2427
Ui::Configuration *ui;
2528
void setComboBoxData();
2629
QSettings config;
30+
QSettings *mainSettings;
2731
QMap<QString, QString> langEquiv;
2832
};
2933

configuration.ui

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,7 @@
102102
</spacer>
103103
</item>
104104
<item>
105-
<widget class="QRadioButton" name="radioButton_2">
106-
<property name="enabled">
107-
<bool>false</bool>
108-
</property>
109-
<property name="toolTip">
110-
<string>Stable is not currently avaiable through the launcher</string>
111-
</property>
105+
<widget class="QRadioButton" name="stableButton">
112106
<property name="text">
113107
<string>Stable</string>
114108
</property>
@@ -118,7 +112,7 @@
118112
</widget>
119113
</item>
120114
<item>
121-
<widget class="QRadioButton" name="radioButton">
115+
<widget class="QRadioButton" name="developButton">
122116
<property name="text">
123117
<string>Develop</string>
124118
</property>

mainwindow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ void MainWindow::on_optionsButton_clicked() {
4242
dir.cd(QStringLiteral(OPENRCT2_BASE));
4343
}
4444

45-
Configuration config(dir.filePath(QStringLiteral("config.ini")));
45+
Configuration config(&updater.settings, dir.filePath(QStringLiteral("config.ini")));
46+
connect(&config, &Configuration::redownload, [this]{ ui->launchButton->setEnabled(false); updater.download(); });
4647
config.exec();
4748
}
4849

updater.cpp

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,49 @@
1818
#include <QMessageBox>
1919
#include <QNetworkRequest>
2020
#include <QProcess>
21-
#include <QSettings>
2221
#include <QStringBuilder>
2322
#include <QTemporaryFile>
2423
#include <QUrlQuery>
2524

2625
Updater::Updater(QObject *parent) : QObject(parent), url(QStringLiteral("https://openrct2.org/altapi/"))
2726
{
2827
connect(&net, &QNetworkAccessManager::sslErrors, [](QNetworkReply * reply, const QList<QSslError> & errors){Q_UNUSED(reply); qDebug() << errors;});
28+
}
29+
30+
void Updater::download() {
31+
if (update != nullptr) update->abort(), update = nullptr;
32+
if (api != nullptr) api->abort(), api = nullptr;
33+
if (bundle != nullptr) bundle->abort(), bundle = nullptr;
2934

3035
QUrlQuery query;
3136
query.addQueryItem(QStringLiteral("command"), QStringLiteral("get-latest-download"));
3237
query.addQueryItem(QStringLiteral("flavourId"), QStringLiteral(OPENRCT2_FLAVOR));
33-
query.addQueryItem(QStringLiteral("gitBranch"), QStringLiteral("develop"));
38+
39+
QVariant stableVar = settings.value(QStringLiteral("stable"));
40+
bool stable = stableVar.isValid() && stableVar.toBool();
41+
query.addQueryItem(QStringLiteral("gitBranch"), stable ? QStringLiteral("master") : QStringLiteral("develop"));
3442

3543
url.setQuery(query.query());
36-
}
3744

38-
void Updater::download() {
3945
QNetworkRequest urequest(QStringLiteral("https://api.github.com/repos/LRFLEW/OpenRCT2Launcher/releases/latest"));
40-
QNetworkReply *ureply = net.get(urequest);
41-
connect(ureply, &QNetworkReply::finished, [this, ureply]() { receivedUpdate(ureply); });
46+
update = net.get(urequest);
47+
connect(update, &QNetworkReply::finished, this, &Updater::receivedUpdate);
4248

4349
QNetworkRequest request(url);
44-
QNetworkReply *reply = net.get(request);
45-
connect(reply, &QNetworkReply::finished, [this, reply]() { receivedAPI(reply); });
50+
api = net.get(request);
51+
connect(api, &QNetworkReply::finished, this, &Updater::receivedAPI);
4652
}
4753

48-
void Updater::receivedUpdate(QNetworkReply *reply) {
49-
if (reply->error() != QNetworkReply::NoError) {
50-
emit error(reply->errorString());
54+
void Updater::receivedUpdate() {
55+
if (update->error() != QNetworkReply::NoError) {
56+
emit error(update->errorString());
5157
return;
5258
}
5359

54-
QByteArray data = reply->readAll();
55-
reply->close();
56-
reply->deleteLater();
60+
QByteArray data = update->readAll();
61+
update->close();
62+
update->deleteLater();
63+
update = nullptr;
5764

5865
QJsonDocument response = QJsonDocument::fromJson(data);
5966
QJsonObject robj = response.object();
@@ -87,15 +94,16 @@ void Updater::receivedUpdate(QNetworkReply *reply) {
8794
}
8895
}
8996

90-
void Updater::receivedAPI(QNetworkReply *reply) {
91-
if (reply->error() != QNetworkReply::NoError) {
92-
emit error(reply->errorString());
97+
void Updater::receivedAPI() {
98+
if (api->error() != QNetworkReply::NoError) {
99+
emit error(api->errorString());
93100
return;
94101
}
95102

96-
QByteArray data = reply->readAll();
97-
reply->close();
98-
reply->deleteLater();
103+
QByteArray data = api->readAll();
104+
api->close();
105+
api->deleteLater();
106+
api = nullptr;
99107

100108
QJsonDocument response = QJsonDocument::fromJson(data);
101109
QJsonObject robj = response.object();
@@ -104,7 +112,6 @@ void Updater::receivedAPI(QNetworkReply *reply) {
104112
return;
105113
}
106114

107-
QSettings settings;
108115
QString have = settings.value(QStringLiteral("downloadId")).toString();
109116
version = robj[QStringLiteral("downloadId")].toString();
110117

@@ -116,21 +123,22 @@ void Updater::receivedAPI(QNetworkReply *reply) {
116123
githash = QByteArray::fromHex(robj[QStringLiteral("gitHash")].toString().toLatin1());
117124

118125
QNetworkRequest request(robj[QStringLiteral("url")].toString());
119-
QNetworkReply *dreply = net.get(request);
120-
connect(dreply, &QNetworkReply::finished, [this, dreply]() { this->receivedBundle(dreply); });
121-
connect(dreply, &QNetworkReply::downloadProgress, this, &Updater::downloadProgress);
126+
bundle = net.get(request);
127+
connect(bundle, &QNetworkReply::finished, this, &Updater::receivedBundle);
128+
connect(bundle, &QNetworkReply::downloadProgress, this, &Updater::downloadProgress);
122129
}
123130
}
124131

125-
void Updater::receivedBundle(QNetworkReply *reply) {
126-
if (reply->error() != QNetworkReply::NoError) {
127-
emit error(reply->errorString());
132+
void Updater::receivedBundle() {
133+
if (bundle->error() != QNetworkReply::NoError) {
134+
emit error(bundle->errorString());
128135
return;
129136
}
130137

131-
QByteArray data = reply->readAll();
132-
reply->close();
133-
reply->deleteLater();
138+
QByteArray data = bundle->readAll();
139+
bundle->close();
140+
bundle->deleteLater();
141+
bundle = nullptr;
134142

135143
if (data.size() != size) {
136144
emit error(tr("Invalid Download"));
@@ -161,9 +169,9 @@ void Updater::receivedBundle(QNetworkReply *reply) {
161169
if (extract(data, bin)) {
162170
emit installed();
163171

164-
QSettings settings;
165172
settings.setValue(QStringLiteral("downloadId"), version);
166173
settings.setValue(QStringLiteral("gitHash"), githash);
174+
settings.sync();
167175
} else {
168176
emit error(tr("Error extracting archive"));
169177
}

updater.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
#include <QByteArray>
66
#include <QNetworkAccessManager>
77
#include <QNetworkReply>
8+
#include <QSettings>
89
#include <QUrl>
910

1011
class Updater : public QObject
1112
{
1213
Q_OBJECT
1314
public:
1415
explicit Updater(QObject *parent = 0);
16+
QSettings settings;
1517

1618
signals:
1719
void installed();
@@ -21,10 +23,10 @@ class Updater : public QObject
2123
public slots:
2224
void download();
2325

24-
private:
25-
void receivedUpdate(QNetworkReply *reply);
26-
void receivedAPI(QNetworkReply *reply);
27-
void receivedBundle(QNetworkReply *reply);
26+
private slots:
27+
void receivedUpdate();
28+
void receivedAPI();
29+
void receivedBundle();
2830

2931
private:
3032
bool extract(QByteArray &data, QDir &bin);
@@ -35,6 +37,10 @@ public slots:
3537
QByteArray hash;
3638
QByteArray githash;
3739
QString version;
40+
41+
QNetworkReply *update = nullptr;
42+
QNetworkReply *api = nullptr;
43+
QNetworkReply *bundle = nullptr;
3844
};
3945

4046
#endif // UPDATER_H

0 commit comments

Comments
 (0)