Merge pull request #952 from Scrumplex/fix-pre-post-launch
Fix variable substitution in pre launch/post exit hooks
This commit is contained in:
commit
4596e78df0
@ -282,35 +282,22 @@ void LaunchTask::emitFailed(QString reason)
|
|||||||
Task::emitFailed(reason);
|
Task::emitFailed(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchTask::substituteVariables(const QStringList &args) const
|
void LaunchTask::substituteVariables(QStringList &args) const
|
||||||
{
|
{
|
||||||
auto variables = m_instance->getVariables();
|
auto env = m_instance->createEnvironment();
|
||||||
auto envVariables = QProcessEnvironment::systemEnvironment();
|
|
||||||
|
|
||||||
for (auto arg : args) {
|
for (auto key : env.keys())
|
||||||
for (auto key : variables)
|
|
||||||
{
|
{
|
||||||
arg.replace("$" + key, variables.value(key));
|
args.replaceInStrings("$" + key, env.value(key));
|
||||||
}
|
|
||||||
for (auto env : envVariables.keys())
|
|
||||||
{
|
|
||||||
arg.replace("$" + env, envVariables.value(env));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LaunchTask::substituteVariables(const QString &cmd) const
|
void LaunchTask::substituteVariables(QString &cmd) const
|
||||||
{
|
{
|
||||||
QString out = cmd;
|
auto env = m_instance->createEnvironment();
|
||||||
auto variables = m_instance->getVariables();
|
|
||||||
for (auto it = variables.begin(); it != variables.end(); ++it)
|
for (auto key : env.keys())
|
||||||
{
|
{
|
||||||
out.replace("$" + it.key(), it.value());
|
cmd.replace("$" + key, env.value(key));
|
||||||
}
|
}
|
||||||
auto env = QProcessEnvironment::systemEnvironment();
|
|
||||||
for (auto var : env.keys())
|
|
||||||
{
|
|
||||||
out.replace("$" + var, env.value(var));
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,8 @@ public: /* methods */
|
|||||||
shared_qobject_ptr<LogModel> getLogModel();
|
shared_qobject_ptr<LogModel> getLogModel();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void substituteVariables(const QStringList &args) const;
|
void substituteVariables(QStringList &args) const;
|
||||||
QString substituteVariables(const QString &cmd) const;
|
void substituteVariables(QString &cmd) const;
|
||||||
QString censorPrivateInfo(QString in);
|
QString censorPrivateInfo(QString in);
|
||||||
|
|
||||||
protected: /* methods */
|
protected: /* methods */
|
||||||
|
@ -56,9 +56,10 @@ void PostLaunchCommand::executeTask()
|
|||||||
const QString program = args.takeFirst();
|
const QString program = args.takeFirst();
|
||||||
m_process.start(program, args);
|
m_process.start(program, args);
|
||||||
#else
|
#else
|
||||||
QString postlaunch_cmd = m_parent->substituteVariables(m_command);
|
m_parent->substituteVariables(m_command);
|
||||||
emit logLine(tr("Running Post-Launch command: %1").arg(postlaunch_cmd), MessageLevel::Launcher);
|
|
||||||
m_process.start(postlaunch_cmd);
|
emit logLine(tr("Running Post-Launch command: %1").arg(m_command), MessageLevel::Launcher);
|
||||||
|
m_process.start(m_command);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,9 +56,10 @@ void PreLaunchCommand::executeTask()
|
|||||||
const QString program = args.takeFirst();
|
const QString program = args.takeFirst();
|
||||||
m_process.start(program, args);
|
m_process.start(program, args);
|
||||||
#else
|
#else
|
||||||
QString prelaunch_cmd = m_parent->substituteVariables(m_command);
|
m_parent->substituteVariables(m_command);
|
||||||
emit logLine(tr("Running Pre-Launch command: %1").arg(prelaunch_cmd), MessageLevel::Launcher);
|
|
||||||
m_process.start(prelaunch_cmd);
|
emit logLine(tr("Running Pre-Launch command: %1").arg(m_command), MessageLevel::Launcher);
|
||||||
|
m_process.start(m_command);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user