create startup script when running from OpenCS

This commit is contained in:
Marc Zinnschlag 2014-09-05 11:40:01 +02:00
parent 61a92da374
commit 5e022195b8
3 changed files with 40 additions and 4 deletions

View file

@ -2375,7 +2375,8 @@ bool CSMDoc::Document::isBlacklisted (const CSMWorld::UniversalId& id)
void CSMDoc::Document::startRunning (const std::string& profile,
const std::string& startupInstruction)
{
mRunner.configure (getData().getDebugProfiles().getRecord (profile).get());
mRunner.configure (getData().getDebugProfiles().getRecord (profile).get(),
startupInstruction);
int state = getState();

View file

@ -1,9 +1,12 @@
#include "runner.hpp"
#include <QTemporaryFile>
#include <QTextStream>
#include "operation.hpp"
CSMDoc::Runner::Runner() : mRunning (false)
CSMDoc::Runner::Runner() : mRunning (false), mStartup (0)
{
connect (&mProcess, SIGNAL (finished (int, QProcess::ExitStatus)),
this, SLOT (finished (int, QProcess::ExitStatus)));
@ -23,6 +26,12 @@ CSMDoc::Runner::~Runner()
void CSMDoc::Runner::start (bool delayed)
{
if (mStartup)
{
delete mStartup;
mStartup = 0;
}
if (!delayed)
{
QString path = "openmw";
@ -35,6 +44,20 @@ void CSMDoc::Runner::start (bool delayed)
path.prepend(QString("./"));
#endif
mStartup = new QTemporaryFile (this);
mStartup->open();
{
QTextStream stream (mStartup);
if (!mStartupInstruction.empty())
stream << QString::fromUtf8 (mStartupInstruction.c_str()) << '\n';
stream << QString::fromUtf8 (mProfile.mScriptText.c_str());
}
mStartup->close();
QStringList arguments;
arguments << "--skip-menu";
@ -43,6 +66,8 @@ void CSMDoc::Runner::start (bool delayed)
else
arguments << "--new-game=1";
arguments << ("--script-run="+mStartup->fileName());
mProcess.start (path, arguments);
}
@ -52,6 +77,9 @@ void CSMDoc::Runner::start (bool delayed)
void CSMDoc::Runner::stop()
{
delete mStartup;
mStartup = 0;
if (mProcess.state()==QProcess::NotRunning)
{
mRunning = false;
@ -66,9 +94,11 @@ bool CSMDoc::Runner::isRunning() const
return mRunning;
}
void CSMDoc::Runner::configure (const ESM::DebugProfile& profile)
void CSMDoc::Runner::configure (const ESM::DebugProfile& profile,
const std::string& startupInstruction)
{
mProfile = profile;
mStartupInstruction = startupInstruction;
}
void CSMDoc::Runner::finished (int exitCode, QProcess::ExitStatus exitStatus)

View file

@ -6,6 +6,8 @@
#include <components/esm/debugprofile.hpp>
class QTemporaryFile;
namespace CSMDoc
{
class Runner : public QObject
@ -15,6 +17,8 @@ namespace CSMDoc
QProcess mProcess;
bool mRunning;
ESM::DebugProfile mProfile;
std::string mStartupInstruction;
QTemporaryFile *mStartup;
public:
@ -32,7 +36,8 @@ namespace CSMDoc
/// is not necessarily identical to the moment the child process is started.
bool isRunning() const;
void configure (const ESM::DebugProfile& profile);
void configure (const ESM::DebugProfile& profile,
const std::string& startupInstruction);
signals: