forked from LRFLEW/OpenRCT2Launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
56 lines (46 loc) · 1.82 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "platform.h"
#include "configuration.h"
#include <QDebug>
#include <QDir>
#include <QProcess>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->progressBar->setHidden(true);
connect(ui->launchButton, &QPushButton::clicked, this, &MainWindow::launch);
#ifndef Q_OS_OSX
ui->splash->setScaledContents(true);
#endif
connect(&updater, &Updater::installed, [this]{ ui->progressBar->setHidden(true); ui->launchButton->setEnabled(true); });
connect(&updater, &Updater::error, [this](QString error){ qDebug() << error; ui->errorLabel->setText(error); ui->launchButton->setEnabled(true); });
connect(&updater, &Updater::downloadProgress, [this](qint64 bytesReceived, qint64 bytesTotal){
ui->progressBar->setHidden(false); ui->progressBar->setMaximum(bytesTotal); ui->progressBar->setValue(bytesReceived); });
updater.download();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_optionsButton_clicked() {
QDir dir = OPENRCT2_HOMEDIR;
if (dir.cd(QStringLiteral(OPENRCT2_BASE))) {
if (!dir.exists()) dir.mkpath(QStringLiteral(OPENRCT2_BASE));
} else {
dir.mkpath(QStringLiteral(OPENRCT2_BASE));
dir.cd(QStringLiteral(OPENRCT2_BASE));
}
Configuration config(&updater.settings, dir.filePath(QStringLiteral("config.ini")));
connect(&config, &Configuration::redownload, [this]{ ui->launchButton->setEnabled(false); updater.download(); });
config.exec();
}
void MainWindow::launch() {
if (QProcess::startDetached(OPENRCT2_HOMEDIR.filePath(QStringLiteral(OPENRCT2_EXEC_LOCATION)), QStringList(), OPENRCT2_HOMEPATH)) {
QApplication::quit();
} else {
ui->errorLabel->setText(tr("Unable to Launch Game"));
}
}