Skip to content

Commit 99319ea

Browse files
Add manual game file updating and optional automatic update on startup.
1 parent 6b1fd23 commit 99319ea

File tree

3 files changed

+131
-67
lines changed

3 files changed

+131
-67
lines changed

launcherwindow.cpp

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ LauncherWindow::LauncherWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui
3737
gameInstances = 0;
3838

3939
ui->setupUi(this);
40+
connect(this, SIGNAL(enableUpdate(bool)), ui->updateButton, SLOT(setEnabled(bool)));
41+
connect(ui->updatesCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleAutoUpdates()));
42+
connect(ui->updateButton, SIGNAL(clicked(bool)), this, SLOT(updateFiles()));
4043

4144
//read the previous settings
4245
readSettings();
@@ -66,7 +69,15 @@ LauncherWindow::LauncherWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui
6669
emit enableLogin(false);
6770
loginIsReady = false;
6871

69-
updateFiles();
72+
if(autoUpdate)
73+
{
74+
updateFiles();
75+
}
76+
else
77+
{
78+
loginReady();
79+
ui->progressBar->hide();
80+
}
7081
}
7182

7283
LauncherWindow::~LauncherWindow()
@@ -94,10 +105,20 @@ void LauncherWindow::relayHideProgressBar()
94105
emit hideProgressBar();
95106
}
96107

108+
void LauncherWindow::updatesReady()
109+
{
110+
if(gameInstances == 0)
111+
{
112+
emit enableUpdate(true);
113+
}
114+
}
115+
97116
void LauncherWindow::loginReady()
98117
{
99118
emit enableLogin(true);
100119
loginIsReady = true;
120+
121+
emit sendMessage("Logins are ready!");
101122
}
102123

103124
void LauncherWindow::initiateLogin()
@@ -128,6 +149,9 @@ void LauncherWindow::initiateLogin()
128149

129150
void LauncherWindow::gameHasStarted()
130151
{
152+
//disable updates while an instance is running
153+
emit enableUpdate(false);
154+
131155
//check whether to save the credentials or not
132156
if(ui->saveCredentialsBox->isChecked())
133157
{
@@ -183,6 +207,9 @@ void LauncherWindow::gameHasFinished(int exitCode, QByteArray gameOutput)
183207
"Looks like Toontown Rewritten has crashed. The engine's error message is:\n" + gameOutput,
184208
QMessageBox::Ok);
185209
}
210+
211+
//re-enable updates (checks to see if no other instances are running as well)
212+
updatesReady();
186213
}
187214

188215
void LauncherWindow::authenticationFailed()
@@ -232,13 +259,28 @@ void LauncherWindow::newsViewLoaded()
232259
ui->newsWebview->page()->runJavaScript(QString("document.body.style.backgroundColor = \"#141618\";"));
233260
}
234261

262+
void LauncherWindow::toggleAutoUpdates()
263+
{
264+
if(ui->updatesCheckBox->isChecked())
265+
{
266+
autoUpdate = true;
267+
}
268+
else
269+
{
270+
autoUpdate = false;
271+
}
272+
273+
writeSettings();
274+
}
275+
235276
void LauncherWindow::writeSettings()
236277
{
237278
QSettings settings("Shticker-Book-Rewritten", "Shticker-Book-Rewritten");
238279

239280
settings.beginGroup("LauncherWindow");
240281
settings.setValue("size", size());
241282
settings.setValue("pos", pos());
283+
settings.setValue("update", autoUpdate);
242284
settings.endGroup();
243285

244286
settings.beginGroup("Logins");
@@ -254,13 +296,19 @@ void LauncherWindow::readSettings()
254296
settings.beginGroup("LauncherWindow");
255297
resize(settings.value("size", QSize(400, 400)).toSize());
256298
move(settings.value("pos", QPoint(200, 200)).toPoint());
299+
autoUpdate = settings.value("update", true).toBool();
257300
settings.endGroup();
258301

259302
settings.beginGroup("Logins");
260303
savedUsers = settings.value("username").toStringList();
261304
savedPasses = settings.value("pass").toStringList();
262305
settings.endGroup();
263306

307+
if(autoUpdate)
308+
{
309+
ui->updatesCheckBox->setChecked(true);
310+
}
311+
264312
readSettingsPath();
265313
}
266314

@@ -298,6 +346,10 @@ void LauncherWindow::fillCredentials(QString username)
298346

299347
void LauncherWindow::updateFiles()
300348
{
349+
ui->progressBar->show();
350+
351+
emit enableUpdate(false);
352+
301353
//check to make sure the cache directory exists and make it if it doesn't
302354
if(!QDir(filePath).exists())
303355
{
@@ -323,6 +375,7 @@ void LauncherWindow::updateFiles()
323375
connect(updateWorker, SIGNAL(showProgressBar()), this, SLOT(relayShowProgressBar()));
324376
connect(updateWorker, SIGNAL(hideProgressBar()), this, SLOT(relayHideProgressBar()));
325377
connect(updateWorker, SIGNAL(updateComplete()), this, SLOT(loginReady()));
378+
connect(updateWorker, SIGNAL(updateComplete()), this, SLOT(updatesReady()));
326379

327380
updateThread->start();
328381
}

launcherwindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,16 @@ private slots:
5353
void fillCredentials(QString);
5454
void changeFilePath();
5555
void updateFiles();
56+
void updatesReady();
57+
void toggleAutoUpdates();
5658

5759
signals:
5860
void sendMessage(QString);
5961
void sendProgressBarReceived(int);
6062
void showProgressBar();
6163
void hideProgressBar();
6264
void enableLogin(bool);
65+
void enableUpdate(bool);
6366

6467
private:
6568
Ui::LauncherWindow *ui;
@@ -71,6 +74,7 @@ private slots:
7174
QStringList savedPasses;
7275
QString filePath;
7376
QString cachePath;
77+
bool autoUpdate;
7478

7579
void readSettings();
7680
void readSettingsPath();

0 commit comments

Comments
 (0)