From bc04d89c32142094eec161709cf3932b7213b058 Mon Sep 17 00:00:00 2001 From: OverMighty Date: Wed, 5 Feb 2020 00:29:23 +0100 Subject: [PATCH] feat: add --import command-line option When specified, opens the "Import from zip" dialog as soon as the main window is shown, with the URL field prefilled with the argument given to the option. Closes #2998 --- application/MainWindow.h | 4 ++-- application/MultiMC.cpp | 12 ++++++++++++ application/MultiMC.h | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/application/MainWindow.h b/application/MainWindow.h index a415b5e8..00b8e043 100644 --- a/application/MainWindow.h +++ b/application/MainWindow.h @@ -57,6 +57,8 @@ public: void checkInstancePathForProblems(); void updatesAllowedChanged(bool allowed); + + void droppedURLs(QList urls); signals: void isClosing(); @@ -180,8 +182,6 @@ private slots: */ void downloadUpdates(GoUpdate::Status status); - void droppedURLs(QList urls); - void konamiTriggered(); void globalSettingsClosed(); diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index c4e4392d..039fb11d 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -174,6 +175,10 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) parser.addSwitch("alive"); parser.addDocumentation("alive", "Write a small '" + liveCheckFile + "' file after MultiMC starts"); + parser.addOption("import"); + parser.addShortOpt("import", 'I'); + parser.addDocumentation("import", "Import instance from specified zip (local path or URL)"); + // parse the arguments try { @@ -207,6 +212,7 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) } m_instanceIdToLaunch = args["launch"].toString(); m_liveCheck = args["alive"].toBool(); + m_zipToImport = args["import"].toUrl(); QString origcwdPath = QDir::currentPath(); QString binPath = applicationDirPath(); @@ -812,6 +818,12 @@ void MultiMC::performMainStartupAction() showMainWindow(false); qDebug() << "<> Main window shown."; } + + if (!m_zipToImport.isEmpty()) { + qDebug() << "<> Importing instance from zip:" << m_zipToImport.toString(); + QList urls = { m_zipToImport }; + m_mainWindow->droppedURLs(urls); + } } void MultiMC::showFatalErrorMessage(const QString& title, const QString& content) diff --git a/application/MultiMC.h b/application/MultiMC.h index d7c727e0..e6588a14 100644 --- a/application/MultiMC.h +++ b/application/MultiMC.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -221,5 +222,6 @@ private: public: QString m_instanceIdToLaunch; bool m_liveCheck = false; + QUrl m_zipToImport; std::unique_ptr logFile; };