From e2fd299fc588962b19b91d3e11f7bf274080de84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 30 Sep 2015 00:11:00 +0200 Subject: GH-253 implement launching instances from command line --- application/MultiMC.cpp | 6 ++++++ application/MultiMC.h | 1 + application/main.cpp | 30 +++++++++++++++++++++++++++--- logic/InstanceList.cpp | 19 ++++++------------- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 86356cd1..3b2003e4 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -84,6 +84,10 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar parser.addShortOpt("dir", 'd'); parser.addDocumentation("dir", "use the supplied directory as MultiMC root instead of " "the binary location (use '.' for current)"); + // --launch + parser.addOption("launch"); + parser.addShortOpt("launch", 'l'); + parser.addDocumentation("launch", "launch the specified instance (by instance ID)"); // parse the arguments try @@ -135,6 +139,8 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar adjustedBy += "Fallback to binary path " + dataPath; } + launchId = args["launch"].toString(); + if (!ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath)) { // BAD STUFF. WHAT DO? diff --git a/application/MultiMC.h b/application/MultiMC.h index c1df1bb7..f32772ef 100644 --- a/application/MultiMC.h +++ b/application/MultiMC.h @@ -180,5 +180,6 @@ private: Status m_status = MultiMC::Failed; public: + QString launchId; std::shared_ptr logFile; }; diff --git a/application/main.cpp b/application/main.cpp index 12c97f09..c134facb 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -1,10 +1,11 @@ #include "MultiMC.h" #include "MainWindow.h" +#include "LaunchInteraction.h" +#include +#include -int main_gui(MultiMC &app) +int launchMainWindow(MultiMC &app) { - // show main window - app.setIconTheme(MMC->settings()->get("IconTheme").toString()); MainWindow mainWin; mainWin.restoreState(QByteArray::fromBase64(MMC->settings()->get("MainWindowState").toByteArray())); mainWin.restoreGeometry(QByteArray::fromBase64(MMC->settings()->get("MainWindowGeometry").toByteArray())); @@ -13,6 +14,29 @@ int main_gui(MultiMC &app) mainWin.checkInstancePathForProblems(); return app.exec(); } + +int launchInstance(MultiMC &app, InstancePtr inst) +{ + app.minecraftlist(); + LaunchController launchController; + launchController.setInstance(inst); + launchController.setOnline(true); + launchController.launch(); + return app.exec(); +} + +int main_gui(MultiMC &app) +{ + app.setIconTheme(MMC->settings()->get("IconTheme").toString()); + // show main window + auto inst = app.instances()->getInstanceById(app.launchId); + if(inst) + { + return launchInstance(app, inst); + } + return launchMainWindow(app); +} + int main(int argc, char *argv[]) { // initialize Qt diff --git a/logic/InstanceList.cpp b/logic/InstanceList.cpp index 2ff0c913..22b36748 100644 --- a/logic/InstanceList.cpp +++ b/logic/InstanceList.cpp @@ -362,23 +362,16 @@ int InstanceList::add(InstancePtr t) InstancePtr InstanceList::getInstanceById(QString instId) const { - if (m_instances.isEmpty()) - { + if(instId.isEmpty()) return InstancePtr(); - } - - QListIterator iter(m_instances); - InstancePtr inst; - while (iter.hasNext()) + for(auto & inst: m_instances) { - inst = iter.next(); if (inst->id() == instId) - break; + { + return inst; + } } - if (inst->id() != instId) - return InstancePtr(); - else - return iter.peekPrevious(); + return InstancePtr(); } QModelIndex InstanceList::getInstanceIndexById(const QString &id) const -- cgit v1.2.3