summaryrefslogtreecommitdiffstats
path: root/MultiMC.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'MultiMC.cpp')
-rw-r--r--MultiMC.cpp82
1 files changed, 77 insertions, 5 deletions
diff --git a/MultiMC.cpp b/MultiMC.cpp
index 1792f587..bf0d9d99 100644
--- a/MultiMC.cpp
+++ b/MultiMC.cpp
@@ -2,14 +2,16 @@
#include "MultiMC.h"
#include <iostream>
#include <QDir>
+#include <QFileInfo>
#include <QNetworkAccessManager>
#include <QTranslator>
#include <QLibraryInfo>
#include <QMessageBox>
+#include <QStringList>
#include "gui/dialogs/VersionSelectDialog.h"
#include "logic/lists/InstanceList.h"
-#include "logic/lists/MojangAccountList.h"
+#include "logic/auth/MojangAccountList.h"
#include "logic/lists/IconList.h"
#include "logic/lists/LwjglVersionList.h"
#include "logic/lists/MinecraftVersionList.h"
@@ -20,6 +22,8 @@
#include "logic/JavaUtils.h"
+#include "logic/updater/UpdateChecker.h"
+
#include "pathutils.h"
#include "cmdutils.h"
#include <inisettingsobject.h>
@@ -31,7 +35,7 @@
using namespace Util::Commandline;
MultiMC::MultiMC(int &argc, char **argv, const QString &root) : 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");
@@ -73,11 +77,13 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &root) : QApplication(arg
parser.addShortOpt("quietupdate", 'U');
parser.addDocumentation("quietupdate",
"doesn't restart MultiMC after installing updates");
+ // WARNING: disabled until further notice
+ /*
// --launch
parser.addOption("launch");
parser.addShortOpt("launch", 'l');
parser.addDocumentation("launch", "tries to launch the given instance", "<inst>");
-
+*/
// parse the arguments
try
{
@@ -139,6 +145,9 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &root) : QApplication(arg
// load settings
initGlobalSettings();
+ // initialize the updater
+ m_updateChecker.reset(new UpdateChecker());
+
// and instances
auto InstDirSetting = m_settings->getSetting("InstanceDir");
m_instances.reset(new InstanceList(InstDirSetting->get().toString(), this));
@@ -206,6 +215,8 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &root) : QApplication(arg
m_qnam.reset(new QNetworkAccessManager(this));
// launch instance, if that's what should be done
+ // WARNING: disabled until further notice
+ /*
if (!args["launch"].isNull())
{
if (InstanceLauncher(args["launch"].toString()).launch())
@@ -214,7 +225,7 @@ MultiMC::MultiMC(int &argc, char **argv, const QString &root) : QApplication(arg
m_status = MultiMC::Failed;
return;
}
-
+*/
m_status = MultiMC::Initialized;
}
@@ -352,7 +363,8 @@ void MultiMC::initGlobalSettings()
void MultiMC::initHttpMetaCache()
{
m_metacache.reset(new HttpMetaCache("metacache"));
- m_metacache->addBase("assets", QDir("assets").absolutePath());
+ m_metacache->addBase("asset_indexes", QDir("assets/indexes").absolutePath());
+ m_metacache->addBase("asset_objects", QDir("assets/objects").absolutePath());
m_metacache->addBase("versions", QDir("versions").absolutePath());
m_metacache->addBase("libraries", QDir("libraries").absolutePath());
m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
@@ -405,4 +417,64 @@ std::shared_ptr<JavaVersionList> 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;
+}
+
+
#include "MultiMC.moc"