2014-09-02 08:21:17 +00:00
|
|
|
|
|
|
|
#include "runner.hpp"
|
|
|
|
|
2014-09-03 17:56:52 +00:00
|
|
|
#include "operation.hpp"
|
2014-09-02 08:21:17 +00:00
|
|
|
|
2014-09-02 09:56:35 +00:00
|
|
|
CSMDoc::Runner::Runner() : mRunning (false)
|
2014-09-02 08:21:17 +00:00
|
|
|
{
|
|
|
|
connect (&mProcess, SIGNAL (finished (int, QProcess::ExitStatus)),
|
|
|
|
this, SLOT (finished (int, QProcess::ExitStatus)));
|
|
|
|
}
|
|
|
|
|
2014-09-03 18:06:49 +00:00
|
|
|
CSMDoc::Runner::~Runner()
|
|
|
|
{
|
|
|
|
if (mRunning)
|
|
|
|
{
|
|
|
|
disconnect (&mProcess, 0, this, 0);
|
|
|
|
mProcess.kill();
|
|
|
|
mProcess.waitForFinished();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-03 17:56:52 +00:00
|
|
|
void CSMDoc::Runner::start (bool delayed)
|
2014-09-02 08:21:17 +00:00
|
|
|
{
|
2014-09-03 17:56:52 +00:00
|
|
|
if (!delayed)
|
|
|
|
{
|
|
|
|
QString path = "openmw";
|
2014-09-02 08:21:17 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2014-09-03 17:56:52 +00:00
|
|
|
path.append(QString(".exe"));
|
2014-09-02 08:21:17 +00:00
|
|
|
#elif defined(Q_OS_MAC)
|
2014-09-03 17:56:52 +00:00
|
|
|
QDir dir(QCoreApplication::applicationDirPath());
|
|
|
|
path = dir.absoluteFilePath(name);
|
2014-09-02 08:21:17 +00:00
|
|
|
#else
|
2014-09-03 17:56:52 +00:00
|
|
|
path.prepend(QString("./"));
|
2014-09-02 08:21:17 +00:00
|
|
|
#endif
|
|
|
|
|
2014-09-03 17:56:52 +00:00
|
|
|
mProcess.start (path);
|
|
|
|
}
|
|
|
|
|
2014-09-02 09:56:35 +00:00
|
|
|
mRunning = true;
|
|
|
|
emit runStateChanged();
|
2014-09-02 08:21:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMDoc::Runner::stop()
|
|
|
|
{
|
2014-09-03 17:56:52 +00:00
|
|
|
if (mProcess.state()==QProcess::NotRunning)
|
|
|
|
{
|
|
|
|
mRunning = false;
|
|
|
|
emit runStateChanged();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mProcess.kill();
|
2014-09-02 08:21:17 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 09:56:35 +00:00
|
|
|
bool CSMDoc::Runner::isRunning() const
|
|
|
|
{
|
|
|
|
return mRunning;
|
|
|
|
}
|
|
|
|
|
2014-09-02 08:21:17 +00:00
|
|
|
void CSMDoc::Runner::finished (int exitCode, QProcess::ExitStatus exitStatus)
|
|
|
|
{
|
2014-09-02 09:56:35 +00:00
|
|
|
mRunning = false;
|
|
|
|
emit runStateChanged();
|
2014-09-02 08:21:17 +00:00
|
|
|
}
|
2014-09-03 17:56:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
CSMDoc::SaveWatcher::SaveWatcher (Runner *runner, Operation *operation)
|
|
|
|
: QObject (runner), mRunner (runner)
|
|
|
|
{
|
|
|
|
connect (operation, SIGNAL (done (int, bool)), this, SLOT (saveDone (int, bool)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSMDoc::SaveWatcher::saveDone (int type, bool failed)
|
|
|
|
{
|
|
|
|
if (failed)
|
|
|
|
mRunner->stop();
|
|
|
|
else
|
|
|
|
mRunner->start();
|
|
|
|
|
|
|
|
deleteLater();
|
|
|
|
}
|