GH-253 implement launching instances from command line
This commit is contained in:
parent
e993b1152d
commit
e2fd299fc5
@ -84,6 +84,10 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar
|
|||||||
parser.addShortOpt("dir", 'd');
|
parser.addShortOpt("dir", 'd');
|
||||||
parser.addDocumentation("dir", "use the supplied directory as MultiMC root instead of "
|
parser.addDocumentation("dir", "use the supplied directory as MultiMC root instead of "
|
||||||
"the binary location (use '.' for current)");
|
"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
|
// parse the arguments
|
||||||
try
|
try
|
||||||
@ -135,6 +139,8 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar
|
|||||||
adjustedBy += "Fallback to binary path " + dataPath;
|
adjustedBy += "Fallback to binary path " + dataPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
launchId = args["launch"].toString();
|
||||||
|
|
||||||
if (!ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath))
|
if (!ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath))
|
||||||
{
|
{
|
||||||
// BAD STUFF. WHAT DO?
|
// BAD STUFF. WHAT DO?
|
||||||
|
@ -180,5 +180,6 @@ private:
|
|||||||
|
|
||||||
Status m_status = MultiMC::Failed;
|
Status m_status = MultiMC::Failed;
|
||||||
public:
|
public:
|
||||||
|
QString launchId;
|
||||||
std::shared_ptr<QFile> logFile;
|
std::shared_ptr<QFile> logFile;
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#include "MultiMC.h"
|
#include "MultiMC.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
#include "LaunchInteraction.h"
|
||||||
|
#include <InstanceList.h>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
int main_gui(MultiMC &app)
|
int launchMainWindow(MultiMC &app)
|
||||||
{
|
{
|
||||||
// show main window
|
|
||||||
app.setIconTheme(MMC->settings()->get("IconTheme").toString());
|
|
||||||
MainWindow mainWin;
|
MainWindow mainWin;
|
||||||
mainWin.restoreState(QByteArray::fromBase64(MMC->settings()->get("MainWindowState").toByteArray()));
|
mainWin.restoreState(QByteArray::fromBase64(MMC->settings()->get("MainWindowState").toByteArray()));
|
||||||
mainWin.restoreGeometry(QByteArray::fromBase64(MMC->settings()->get("MainWindowGeometry").toByteArray()));
|
mainWin.restoreGeometry(QByteArray::fromBase64(MMC->settings()->get("MainWindowGeometry").toByteArray()));
|
||||||
@ -13,6 +14,29 @@ int main_gui(MultiMC &app)
|
|||||||
mainWin.checkInstancePathForProblems();
|
mainWin.checkInstancePathForProblems();
|
||||||
return app.exec();
|
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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
// initialize Qt
|
// initialize Qt
|
||||||
|
@ -362,23 +362,16 @@ int InstanceList::add(InstancePtr t)
|
|||||||
|
|
||||||
InstancePtr InstanceList::getInstanceById(QString instId) const
|
InstancePtr InstanceList::getInstanceById(QString instId) const
|
||||||
{
|
{
|
||||||
if (m_instances.isEmpty())
|
if(instId.isEmpty())
|
||||||
{
|
|
||||||
return InstancePtr();
|
return InstancePtr();
|
||||||
}
|
for(auto & inst: m_instances)
|
||||||
|
|
||||||
QListIterator<InstancePtr> iter(m_instances);
|
|
||||||
InstancePtr inst;
|
|
||||||
while (iter.hasNext())
|
|
||||||
{
|
{
|
||||||
inst = iter.next();
|
|
||||||
if (inst->id() == instId)
|
if (inst->id() == instId)
|
||||||
break;
|
{
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (inst->id() != instId)
|
return InstancePtr();
|
||||||
return InstancePtr();
|
|
||||||
else
|
|
||||||
return iter.peekPrevious();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex InstanceList::getInstanceIndexById(const QString &id) const
|
QModelIndex InstanceList::getInstanceIndexById(const QString &id) const
|
||||||
|
Loading…
Reference in New Issue
Block a user