diff options
author | Andrew <forkk@forkk.net> | 2013-12-09 12:04:05 -0600 |
---|---|---|
committer | Andrew <forkk@forkk.net> | 2013-12-09 12:04:05 -0600 |
commit | 7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c (patch) | |
tree | 52097b57dc7d18ec4e35ef3a8e554af2d91545e8 /gui/MainWindow.cpp | |
parent | 9410dd042ea62224fa3e0eb3b525abbdf0c316ee (diff) | |
parent | 220e07aef4a34dca9f31ae0c5bb994e5c594125d (diff) | |
download | MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.tar MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.tar.gz MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.tar.lz MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.tar.xz MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.zip |
Merge branch 'feature_updater' into develop
Diffstat (limited to 'gui/MainWindow.cpp')
-rw-r--r-- | gui/MainWindow.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index fd35e94e..94527b93 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -59,6 +59,7 @@ #include "gui/dialogs/CopyInstanceDialog.h" #include "gui/dialogs/AccountListDialog.h" #include "gui/dialogs/AccountSelectDialog.h" +#include "gui/dialogs/UpdateDialog.h" #include "gui/dialogs/EditAccountDialog.h" #include "gui/ConsoleWindow.h" @@ -69,6 +70,12 @@ #include "logic/lists/IconList.h" #include "logic/lists/JavaVersionList.h" +#include "logic/auth/flows/AuthenticateTask.h" +#include "logic/auth/flows/RefreshTask.h" +#include "logic/auth/flows/ValidateTask.h" + +#include "logic/updater/DownloadUpdateTask.h" + #include "logic/BaseInstance.h" #include "logic/InstanceFactory.h" #include "logic/MinecraftProcess.h" @@ -80,6 +87,8 @@ #include "logic/LegacyInstance.h" +#include <logic/updater/UpdateChecker.h> + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { MultiMCPlatform::fixWM_CLASS(this); @@ -232,6 +241,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi MMC->lwjgllist()->loadList(); } + // set up the updater object. + auto updater = MMC->updateChecker(); + QObject::connect(updater.get(), &UpdateChecker::updateAvailable, this, &MainWindow::updateAvailable); + // if automatic update checks are allowed, start one. + if(MMC->settings()->get("AutoUpdate").toBool()) + on_actionCheckUpdate_triggered(); + assets_downloader = new OneSixAssets(); connect(assets_downloader, SIGNAL(indexStarted()), SLOT(assetsIndexStarted())); connect(assets_downloader, SIGNAL(filesStarted()), SLOT(assetsFilesStarted())); @@ -413,6 +429,41 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *ev) return QMainWindow::eventFilter(obj, ev); } +void MainWindow::updateAvailable(QString repo, QString versionName, int versionId) +{ + UpdateDialog dlg; + UpdateAction action = (UpdateAction) dlg.exec(); + switch(action) + { + case UPDATE_LATER: + QLOG_INFO() << "Update will be installed later."; + break; + case UPDATE_NOW: + downloadUpdates(repo, versionId); + break; + case UPDATE_ONEXIT: + downloadUpdates(repo, versionId, true); + break; + } +} + +void MainWindow::downloadUpdates(QString repo, int versionId, bool installOnExit) +{ + QLOG_INFO() << "Downloading updates."; + // TODO: If the user chooses to update on exit, we should download updates in the background. + // Doing so is a bit complicated, because we'd have to make sure it finished downloading before actually exiting MultiMC. + ProgressDialog updateDlg(this); + DownloadUpdateTask updateTask(repo, versionId, &updateDlg); + // If the task succeeds, install the updates. + if (updateDlg.exec(&updateTask)) + { + if (installOnExit) + MMC->setUpdateOnExit(updateTask.updateFilesDir()); + else + MMC->installUpdates(updateTask.updateFilesDir()); + } +} + void MainWindow::onCatToggled(bool state) { setCatBackground(state); @@ -600,6 +651,8 @@ void MainWindow::on_actionConfig_Folder_triggered() void MainWindow::on_actionCheckUpdate_triggered() { + auto updater = MMC->updateChecker(); + updater->checkForUpdate(); } void MainWindow::on_actionSettings_triggered() |