From 6aa9bd0f77dcb5128167fae62e32aa5252fe85c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 2 Dec 2013 00:55:24 +0100 Subject: Renew the updater branch Now with some actual consensus on what the updater will do! --- MultiMC.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'MultiMC.cpp') diff --git a/MultiMC.cpp b/MultiMC.cpp index e10292ab..3df73c18 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -20,6 +20,7 @@ #include "logic/net/HttpMetaCache.h" #include "logic/JavaUtils.h" +#include "logic/GoUpdate.h" #include "pathutils.h" #include "cmdutils.h" @@ -138,6 +139,9 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv), // load settings initGlobalSettings(); + // initialize the updater + m_go_update.reset(new GoUpdate()); + // and instances auto InstDirSetting = m_settings->getSetting("InstanceDir"); m_instances.reset(new InstanceList(InstDirSetting->get().toString(), this)); -- cgit v1.2.3 From bf94aaea7527a8f5b9f3b8c1ab6ff4e88cbd748f Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 4 Dec 2013 12:34:12 -0600 Subject: Rework the update checking system --- MultiMC.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'MultiMC.cpp') diff --git a/MultiMC.cpp b/MultiMC.cpp index 3df73c18..128e71f3 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -20,7 +20,8 @@ #include "logic/net/HttpMetaCache.h" #include "logic/JavaUtils.h" -#include "logic/GoUpdate.h" + +#include "logic/updater/UpdateChecker.h" #include "pathutils.h" #include "cmdutils.h" @@ -33,7 +34,7 @@ using namespace Util::Commandline; MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv), - m_version{VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_BUILD_TYPE} + m_version{VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_CHANNEL, VERSION_BUILD_TYPE} { setOrganizationName("MultiMC"); setApplicationName("MultiMC5"); @@ -140,7 +141,7 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv), initGlobalSettings(); // initialize the updater - m_go_update.reset(new GoUpdate()); + m_updateChecker.reset(new UpdateChecker()); // and instances auto InstDirSetting = m_settings->getSetting("InstanceDir"); -- cgit v1.2.3 From 6ac94ddcb6f64ffae3948bed778bccc33a92f0fd Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 6 Dec 2013 12:59:58 -0600 Subject: Finish implementing update installation. Also add the option to update on exit. --- MultiMC.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) (limited to 'MultiMC.cpp') diff --git a/MultiMC.cpp b/MultiMC.cpp index 128e71f3..e3107ac4 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -2,10 +2,12 @@ #include "MultiMC.h" #include #include +#include #include #include #include #include +#include #include "gui/MainWindow.h" #include "gui/dialogs/VersionSelectDialog.h" @@ -409,6 +411,65 @@ std::shared_ptr MultiMC::javalist() return m_javalist; } +#ifdef WINDOWS +#define UPDATER_BIN "updater.exe" +#elif LINUX +#define UPDATER_BIN "updater" +#elif OSX +#define UPDATER_BIN "updater" +#else +#error Unsupported operating system. +#endif + +void MultiMC::installUpdates(const QString& updateFilesDir, bool restartOnFinish) +{ + QLOG_INFO() << "Installing updates."; +#if LINUX + // On Linux, the MultiMC executable file is actually in the bin folder inside the installation directory. + // This means that MultiMC's *actual* install path is the parent folder. + // We need to tell the updater to run with this directory as the install path, rather than the bin folder where the executable is. + // On other operating systems, we'll just use the path to the executable. + QString appDir = QFileInfo(MMC->applicationDirPath()).dir().path(); + + // On Linux, we also need to set the finish command to the launch script, rather than the binary. + QString finishCmd = PathCombine(appDir, "MultiMC"); +#else + QString appDir = MMC->applicationDirPath(); + QString finishCmd = MMC->applicationFilePath(); +#endif + + // Build the command we'll use to run the updater. + // Note, the above comment about the app dir path on Linux is irrelevant here because the updater binary is always in the + // same folder as the main binary. + QString updaterBinary = PathCombine(MMC->applicationDirPath(), UPDATER_BIN); + QStringList args; + // ./updater --install-dir $INSTALL_DIR --package-dir $UPDATEFILES_DIR --script $UPDATEFILES_DIR/file_list.xml --wait $PID --mode main + args << "--install-dir" << appDir; + args << "--package-dir" << updateFilesDir; + args << "--script" << PathCombine(updateFilesDir, "file_list.xml"); + args << "--wait" << QString::number(MMC->applicationPid()); + + if (restartOnFinish) + args << "--finish-cmd" << finishCmd; + + QLOG_INFO() << "Running updater with command" << updaterBinary << args.join(" "); + + QProcess::startDetached(updaterBinary, args); + + // Now that we've started the updater, quit MultiMC. + MMC->quit(); +} + +void MultiMC::setUpdateOnExit(const QString& updateFilesDir) +{ + m_updateOnExitPath = updateFilesDir; +} + +QString MultiMC::getExitUpdatePath() const +{ + return m_updateOnExitPath; +} + int main_gui(MultiMC &app) { // show main window @@ -417,7 +478,13 @@ int main_gui(MultiMC &app) mainWin.restoreGeometry(QByteArray::fromBase64(MMC->settings()->get("MainWindowGeometry").toByteArray())); mainWin.show(); mainWin.checkSetDefaultJava(); - return app.exec(); + auto exitCode = app.exec(); + + // Update if necessary. + if (!app.getExitUpdatePath().isEmpty()) + app.installUpdates(app.getExitUpdatePath(), false); + + return exitCode; } int main(int argc, char *argv[]) -- cgit v1.2.3