Some pre/post related stuff
Reload the onesix version config after the commands (addresses https://www.pivotaltracker.com/story/show/60360652) Add a few more variables and also substitute them in the command (fixes https://www.pivotaltracker.com/story/show/66994828)
This commit is contained in:
parent
737169d1d3
commit
44f21406e9
@ -169,6 +169,12 @@ bool BaseInstance::canLaunch() const
|
|||||||
return !(flags() & VersionBrokenFlag);
|
return !(flags() & VersionBrokenFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BaseInstance::reload()
|
||||||
|
{
|
||||||
|
// TODO reload the instance settings
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QString BaseInstance::baseJar() const
|
QString BaseInstance::baseJar() const
|
||||||
{
|
{
|
||||||
I_D(BaseInstance);
|
I_D(BaseInstance);
|
||||||
|
@ -190,6 +190,8 @@ public:
|
|||||||
|
|
||||||
bool canLaunch() const;
|
bool canLaunch() const;
|
||||||
|
|
||||||
|
virtual bool reload();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/*!
|
/*!
|
||||||
* \brief Signal emitted when properties relevant to the instance view change
|
* \brief Signal emitted when properties relevant to the instance view change
|
||||||
|
@ -49,9 +49,11 @@ MinecraftProcess::MinecraftProcess(BaseInstance *inst) : m_instance(inst)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// export some infos
|
// export some infos
|
||||||
env.insert("INST_NAME", inst->name());
|
auto variables = getVariables();
|
||||||
env.insert("INST_ID", inst->id());
|
for (auto it = variables.begin(); it != variables.end(); ++it)
|
||||||
env.insert("INST_DIR", QDir(inst->instanceRoot()).absolutePath());
|
{
|
||||||
|
env.insert(it.key(), it.value());
|
||||||
|
}
|
||||||
|
|
||||||
this->setProcessEnvironment(env);
|
this->setProcessEnvironment(env);
|
||||||
m_prepostlaunchprocess.setProcessEnvironment(env);
|
m_prepostlaunchprocess.setProcessEnvironment(env);
|
||||||
@ -63,10 +65,10 @@ MinecraftProcess::MinecraftProcess(BaseInstance *inst) : m_instance(inst)
|
|||||||
// Log prepost launch command output (can be disabled.)
|
// Log prepost launch command output (can be disabled.)
|
||||||
if (m_instance->settings().get("LogPrePostOutput").toBool())
|
if (m_instance->settings().get("LogPrePostOutput").toBool())
|
||||||
{
|
{
|
||||||
connect(&m_prepostlaunchprocess, &QProcess::readyReadStandardError,
|
connect(&m_prepostlaunchprocess, &QProcess::readyReadStandardError, this,
|
||||||
this, &MinecraftProcess::on_prepost_stdErr);
|
&MinecraftProcess::on_prepost_stdErr);
|
||||||
connect(&m_prepostlaunchprocess, &QProcess::readyReadStandardOutput,
|
connect(&m_prepostlaunchprocess, &QProcess::readyReadStandardOutput, this,
|
||||||
this, &MinecraftProcess::on_prepost_stdOut);
|
&MinecraftProcess::on_prepost_stdOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,17 +141,15 @@ MessageLevel::Enum MinecraftProcess::getLevel(const QString &levelName)
|
|||||||
return MessageLevel::Message;
|
return MessageLevel::Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinecraftProcess::logOutput(const QStringList &lines,
|
void MinecraftProcess::logOutput(const QStringList &lines, MessageLevel::Enum defaultLevel,
|
||||||
MessageLevel::Enum defaultLevel,
|
|
||||||
bool guessLevel, bool censor)
|
bool guessLevel, bool censor)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < lines.size(); ++i)
|
for (int i = 0; i < lines.size(); ++i)
|
||||||
logOutput(lines[i], defaultLevel, guessLevel, censor);
|
logOutput(lines[i], defaultLevel, guessLevel, censor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinecraftProcess::logOutput(QString line,
|
void MinecraftProcess::logOutput(QString line, MessageLevel::Enum defaultLevel, bool guessLevel,
|
||||||
MessageLevel::Enum defaultLevel,
|
bool censor)
|
||||||
bool guessLevel, bool censor)
|
|
||||||
{
|
{
|
||||||
MessageLevel::Enum level = defaultLevel;
|
MessageLevel::Enum level = defaultLevel;
|
||||||
|
|
||||||
@ -251,33 +251,7 @@ void MinecraftProcess::finish(int code, ExitStatus status)
|
|||||||
m_prepostlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(code));
|
m_prepostlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(code));
|
||||||
|
|
||||||
// run post-exit
|
// run post-exit
|
||||||
QString postlaunch_cmd = m_instance->settings().get("PostExitCommand").toString();
|
postLaunch();
|
||||||
if (!postlaunch_cmd.isEmpty())
|
|
||||||
{
|
|
||||||
emit log(tr("Running Post-Launch command: %1").arg(postlaunch_cmd));
|
|
||||||
m_prepostlaunchprocess.start(postlaunch_cmd);
|
|
||||||
m_prepostlaunchprocess.waitForFinished();
|
|
||||||
// Flush console window
|
|
||||||
if (!m_err_leftover.isEmpty())
|
|
||||||
{
|
|
||||||
logOutput(m_err_leftover, MessageLevel::PrePost);
|
|
||||||
m_err_leftover.clear();
|
|
||||||
}
|
|
||||||
if (!m_out_leftover.isEmpty())
|
|
||||||
{
|
|
||||||
logOutput(m_out_leftover, MessageLevel::PrePost);
|
|
||||||
m_out_leftover.clear();
|
|
||||||
}
|
|
||||||
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
|
|
||||||
{
|
|
||||||
emit log(tr("Post-Launch command failed with code %1.\n\n").arg(m_prepostlaunchprocess.exitCode()),
|
|
||||||
MessageLevel::Error);
|
|
||||||
emit postlaunch_failed(m_instance, m_prepostlaunchprocess.exitCode(),
|
|
||||||
m_prepostlaunchprocess.exitStatus());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
emit log(tr("Post-Launch command ran successfully.\n\n"));
|
|
||||||
}
|
|
||||||
m_instance->cleanupAfterRun();
|
m_instance->cleanupAfterRun();
|
||||||
emit ended(m_instance, code, status);
|
emit ended(m_instance, code, status);
|
||||||
}
|
}
|
||||||
@ -288,14 +262,12 @@ void MinecraftProcess::killMinecraft()
|
|||||||
kill();
|
kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinecraftProcess::arm()
|
bool MinecraftProcess::preLaunch()
|
||||||
{
|
{
|
||||||
emit log("MultiMC version: " + MMC->version().toString() + "\n\n");
|
|
||||||
emit log("Minecraft folder is:\n" + workingDirectory() + "\n\n");
|
|
||||||
|
|
||||||
QString prelaunch_cmd = m_instance->settings().get("PreLaunchCommand").toString();
|
QString prelaunch_cmd = m_instance->settings().get("PreLaunchCommand").toString();
|
||||||
if (!prelaunch_cmd.isEmpty())
|
if (!prelaunch_cmd.isEmpty())
|
||||||
{
|
{
|
||||||
|
prelaunch_cmd = substituteVariables(prelaunch_cmd);
|
||||||
// Launch
|
// Launch
|
||||||
emit log(tr("Running Pre-Launch command: %1").arg(prelaunch_cmd));
|
emit log(tr("Running Pre-Launch command: %1").arg(prelaunch_cmd));
|
||||||
m_prepostlaunchprocess.start(prelaunch_cmd);
|
m_prepostlaunchprocess.start(prelaunch_cmd);
|
||||||
@ -315,23 +287,88 @@ void MinecraftProcess::arm()
|
|||||||
// Process return values
|
// Process return values
|
||||||
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
|
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
|
||||||
{
|
{
|
||||||
emit log(tr("Pre-Launch command failed with code %1.\n\n").arg(m_prepostlaunchprocess.exitCode()),
|
emit log(tr("Pre-Launch command failed with code %1.\n\n")
|
||||||
|
.arg(m_prepostlaunchprocess.exitCode()),
|
||||||
MessageLevel::Fatal);
|
MessageLevel::Fatal);
|
||||||
m_instance->cleanupAfterRun();
|
m_instance->cleanupAfterRun();
|
||||||
emit prelaunch_failed(m_instance, m_prepostlaunchprocess.exitCode(),
|
emit prelaunch_failed(m_instance, m_prepostlaunchprocess.exitCode(),
|
||||||
m_prepostlaunchprocess.exitStatus());
|
m_prepostlaunchprocess.exitStatus());
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
emit log(tr("Pre-Launch command ran successfully.\n\n"));
|
emit log(tr("Pre-Launch command ran successfully.\n\n"));
|
||||||
|
|
||||||
|
return m_instance->reload();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool MinecraftProcess::postLaunch()
|
||||||
|
{
|
||||||
|
QString postlaunch_cmd = m_instance->settings().get("PostExitCommand").toString();
|
||||||
|
if (!postlaunch_cmd.isEmpty())
|
||||||
|
{
|
||||||
|
postlaunch_cmd = substituteVariables(postlaunch_cmd);
|
||||||
|
emit log(tr("Running Post-Launch command: %1").arg(postlaunch_cmd));
|
||||||
|
m_prepostlaunchprocess.start(postlaunch_cmd);
|
||||||
|
m_prepostlaunchprocess.waitForFinished();
|
||||||
|
// Flush console window
|
||||||
|
if (!m_err_leftover.isEmpty())
|
||||||
|
{
|
||||||
|
logOutput(m_err_leftover, MessageLevel::PrePost);
|
||||||
|
m_err_leftover.clear();
|
||||||
|
}
|
||||||
|
if (!m_out_leftover.isEmpty())
|
||||||
|
{
|
||||||
|
logOutput(m_out_leftover, MessageLevel::PrePost);
|
||||||
|
m_out_leftover.clear();
|
||||||
|
}
|
||||||
|
if (m_prepostlaunchprocess.exitStatus() != NormalExit)
|
||||||
|
{
|
||||||
|
emit log(tr("Post-Launch command failed with code %1.\n\n")
|
||||||
|
.arg(m_prepostlaunchprocess.exitCode()),
|
||||||
|
MessageLevel::Error);
|
||||||
|
emit postlaunch_failed(m_instance, m_prepostlaunchprocess.exitCode(),
|
||||||
|
m_prepostlaunchprocess.exitStatus());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
emit log(tr("Post-Launch command ran successfully.\n\n"));
|
||||||
|
|
||||||
|
return m_instance->reload();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_instance->setLastLaunch();
|
QMap<QString, QString> MinecraftProcess::getVariables() const
|
||||||
auto &settings = m_instance->settings();
|
|
||||||
|
|
||||||
//////////// java arguments ////////////
|
|
||||||
QStringList args;
|
|
||||||
{
|
{
|
||||||
|
QMap<QString, QString> out;
|
||||||
|
out.insert("INST_NAME", m_instance->name());
|
||||||
|
out.insert("INST_ID", m_instance->id());
|
||||||
|
out.insert("INST_DIR", QDir(m_instance->instanceRoot()).absolutePath());
|
||||||
|
out.insert("INST_MC_DIR", QDir(m_instance->minecraftRoot()).absolutePath());
|
||||||
|
out.insert("INST_JAVA", m_instance->settings().get("JavaPath").toString());
|
||||||
|
out.insert("INST_JAVA_ARGS", javaArguments().join(' '));
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
QString MinecraftProcess::substituteVariables(const QString &cmd) const
|
||||||
|
{
|
||||||
|
QString out = cmd;
|
||||||
|
auto variables = getVariables();
|
||||||
|
for (auto it = variables.begin(); it != variables.end(); ++it)
|
||||||
|
{
|
||||||
|
out.replace("$" + it.key(), it.value());
|
||||||
|
}
|
||||||
|
auto env = QProcessEnvironment::systemEnvironment();
|
||||||
|
for (auto var : env.keys())
|
||||||
|
{
|
||||||
|
out.replace("$" + var, env.value(var));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList MinecraftProcess::javaArguments() const
|
||||||
|
{
|
||||||
|
QStringList args;
|
||||||
|
|
||||||
// custom args go first. we want to override them if we have our own here.
|
// custom args go first. we want to override them if we have our own here.
|
||||||
args.append(m_instance->extraArguments());
|
args.append(m_instance->extraArguments());
|
||||||
|
|
||||||
@ -347,14 +384,31 @@ void MinecraftProcess::arm()
|
|||||||
"minecraft.exe.heapdump");
|
"minecraft.exe.heapdump");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
args << QString("-Xms%1m").arg(settings.get("MinMemAlloc").toInt());
|
args << QString("-Xms%1m").arg(m_instance->settings().get("MinMemAlloc").toInt());
|
||||||
args << QString("-Xmx%1m").arg(settings.get("MaxMemAlloc").toInt());
|
args << QString("-Xmx%1m").arg(m_instance->settings().get("MaxMemAlloc").toInt());
|
||||||
args << QString("-XX:PermSize=%1m").arg(settings.get("PermGen").toInt());
|
args << QString("-XX:PermSize=%1m").arg(m_instance->settings().get("PermGen").toInt());
|
||||||
if (!m_nativeFolder.isEmpty())
|
if (!m_nativeFolder.isEmpty())
|
||||||
args << QString("-Djava.library.path=%1").arg(m_nativeFolder);
|
args << QString("-Djava.library.path=%1").arg(m_nativeFolder);
|
||||||
args << "-jar" << PathCombine(MMC->bin(), "jars", "NewLaunch.jar");
|
args << "-jar" << PathCombine(MMC->bin(), "jars", "NewLaunch.jar");
|
||||||
|
|
||||||
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MinecraftProcess::arm()
|
||||||
|
{
|
||||||
|
emit log("MultiMC version: " + MMC->version().toString() + "\n\n");
|
||||||
|
emit log("Minecraft folder is:\n" + workingDirectory() + "\n\n");
|
||||||
|
|
||||||
|
if (!preLaunch())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_instance->setLastLaunch();
|
||||||
|
auto &settings = m_instance->settings();
|
||||||
|
|
||||||
|
QStringList args = javaArguments();
|
||||||
|
|
||||||
QString JavaPath = m_instance->settings().get("JavaPath").toString();
|
QString JavaPath = m_instance->settings().get("JavaPath").toString();
|
||||||
emit log("Java path is:\n" + JavaPath + "\n\n");
|
emit log("Java path is:\n" + JavaPath + "\n\n");
|
||||||
QString allArgs = args.join(", ");
|
QString allArgs = args.join(", ");
|
||||||
|
@ -131,6 +131,13 @@ protected:
|
|||||||
QString launchScript;
|
QString launchScript;
|
||||||
QString m_nativeFolder;
|
QString m_nativeFolder;
|
||||||
|
|
||||||
|
bool preLaunch();
|
||||||
|
bool postLaunch();
|
||||||
|
QMap<QString, QString> getVariables() const;
|
||||||
|
QString substituteVariables(const QString &cmd) const;
|
||||||
|
|
||||||
|
QStringList javaArguments() const;
|
||||||
|
|
||||||
protected
|
protected
|
||||||
slots:
|
slots:
|
||||||
void finish(int, QProcess::ExitStatus status);
|
void finish(int, QProcess::ExitStatus status);
|
||||||
|
@ -413,6 +413,11 @@ bool OneSixInstance::providesVersionFile() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OneSixInstance::reload()
|
||||||
|
{
|
||||||
|
return BaseInstance::reload() && reloadVersion();
|
||||||
|
}
|
||||||
|
|
||||||
QString OneSixInstance::loaderModsDir() const
|
QString OneSixInstance::loaderModsDir() const
|
||||||
{
|
{
|
||||||
return PathCombine(minecraftRoot(), "mods");
|
return PathCombine(minecraftRoot(), "mods");
|
||||||
|
@ -75,6 +75,8 @@ public:
|
|||||||
virtual QStringList externalPatches() const;
|
virtual QStringList externalPatches() const;
|
||||||
virtual bool providesVersionFile() const;
|
virtual bool providesVersionFile() const;
|
||||||
|
|
||||||
|
bool reload() override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void versionReloaded();
|
void versionReloaded();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user