summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOverMighty <its.overmighty@gmail.com>2020-02-05 00:29:23 +0100
committerPetr Mrázek <peterix@gmail.com>2020-02-24 18:52:26 +0100
commit47fa7b3f8c7a92fa14aa50d6bd7d7a3c100a06f3 (patch)
tree297c4adaf4f596a54218cf68f0ff43957ae0d628
parentd58481e0de15ec4f1eb60de9a42c6cc9ec330d86 (diff)
downloadMultiMC-47fa7b3f8c7a92fa14aa50d6bd7d7a3c100a06f3.tar
MultiMC-47fa7b3f8c7a92fa14aa50d6bd7d7a3c100a06f3.tar.gz
MultiMC-47fa7b3f8c7a92fa14aa50d6bd7d7a3c100a06f3.tar.lz
MultiMC-47fa7b3f8c7a92fa14aa50d6bd7d7a3c100a06f3.tar.xz
MultiMC-47fa7b3f8c7a92fa14aa50d6bd7d7a3c100a06f3.zip
GH-2988 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
-rw-r--r--application/MainWindow.h4
-rw-r--r--application/MultiMC.cpp50
-rw-r--r--application/MultiMC.h2
3 files changed, 49 insertions, 7 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<QUrl> urls);
signals:
void isClosing();
@@ -180,8 +182,6 @@ private slots:
*/
void downloadUpdates(GoUpdate::Status status);
- void droppedURLs(QList<QUrl> urls);
-
void konamiTriggered();
void globalSettingsClosed();
diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp
index c4e4392d..393ea046 100644
--- a/application/MultiMC.cpp
+++ b/application/MultiMC.cpp
@@ -34,6 +34,7 @@
#include <QNetworkAccessManager>
#include <QTranslator>
#include <QLibraryInfo>
+#include <QList>
#include <QStringList>
#include <QDebug>
#include <QStyleFactory>
@@ -173,6 +174,10 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
// --alive
parser.addSwitch("alive");
parser.addDocumentation("alive", "Write a small '" + liveCheckFile + "' file after MultiMC starts");
+ // --import
+ 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();
@@ -278,13 +284,20 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
connect(m_peerInstance, &LocalPeer::messageReceived, this, &MultiMC::messageReceived);
if(m_peerInstance->isClient())
{
+ int timeout = 2000;
+
if(m_instanceIdToLaunch.isEmpty())
{
- m_peerInstance->sendMessage("activate", 2000);
+ m_peerInstance->sendMessage("activate", timeout);
+
+ if(!m_zipToImport.isEmpty())
+ {
+ m_peerInstance->sendMessage("import " + m_zipToImport.toString(), timeout);
+ }
}
else
{
- m_peerInstance->sendMessage(m_instanceIdToLaunch, 2000);
+ m_peerInstance->sendMessage("launch " + m_instanceIdToLaunch, timeout);
}
m_status = MultiMC::Succeeded;
return;
@@ -812,6 +825,11 @@ void MultiMC::performMainStartupAction()
showMainWindow(false);
qDebug() << "<> Main window shown.";
}
+ if(!m_zipToImport.isEmpty())
+ {
+ qDebug() << "<> Importing instance from zip:" << m_zipToImport;
+ m_mainWindow->droppedURLs({ m_zipToImport });
+ }
}
void MultiMC::showFatalErrorMessage(const QString& title, const QString& content)
@@ -848,18 +866,40 @@ void MultiMC::messageReceived(const QString& message)
qDebug() << "Received message" << message << "while still initializing. It will be ignored.";
return;
}
- if(message == "activate")
+
+ QStringList args = message.split(' ');
+ QString command = args.takeFirst();
+
+ if(command == "activate")
{
showMainWindow();
}
- else
+ else if(command == "import")
+ {
+ if(args.isEmpty())
+ {
+ qWarning() << "Received" << command << "message without a zip path/URL.";
+ return;
+ }
+ m_mainWindow->droppedURLs({ QUrl(args.takeFirst()) });
+ }
+ else if(command == "launch")
{
- auto inst = instances()->getInstanceById(message);
+ if(args.isEmpty())
+ {
+ qWarning() << "Received" << command << "message without an instance ID.";
+ return;
+ }
+ auto inst = instances()->getInstanceById(args.takeFirst());
if(inst)
{
launch(inst, true, nullptr);
}
}
+ else
+ {
+ qWarning() << "Received invalid message" << message;
+ }
}
void MultiMC::analyticsSettingChanged(const Setting&, QVariant value)
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 <QFlag>
#include <QIcon>
#include <QDateTime>
+#include <QUrl>
#include <updater/GoUpdate.h>
#include <BaseInstance.h>
@@ -221,5 +222,6 @@ private:
public:
QString m_instanceIdToLaunch;
bool m_liveCheck = false;
+ QUrl m_zipToImport;
std::unique_ptr<QFile> logFile;
};