2014-02-16 15:16:14 +05:30
|
|
|
#include "MCEditTool.h"
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QProcess>
|
2014-02-22 00:43:12 +05:30
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QUrl>
|
2014-02-16 15:16:14 +05:30
|
|
|
|
|
|
|
#include "settingsobject.h"
|
|
|
|
#include "logic/BaseInstance.h"
|
|
|
|
#include "MultiMC.h"
|
|
|
|
|
|
|
|
MCEditTool::MCEditTool(BaseInstance *instance, QObject *parent)
|
|
|
|
: BaseDetachedTool(instance, parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCEditTool::runImpl()
|
|
|
|
{
|
|
|
|
const QString mceditPath = MMC->settings()->get("MCEditPath").toString();
|
2014-02-16 16:38:39 +05:30
|
|
|
const QString save = getSave();
|
|
|
|
if (save.isNull())
|
2014-02-16 15:16:14 +05:30
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-22 00:43:12 +05:30
|
|
|
#ifdef Q_OS_OSX
|
|
|
|
QProcess *process = new QProcess();
|
|
|
|
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), process, SLOT(deleteLater()));
|
|
|
|
process->setProgram(mceditPath);
|
|
|
|
process->setArguments(QStringList() << save);
|
|
|
|
process->start();
|
|
|
|
#else
|
2014-02-16 16:19:55 +05:30
|
|
|
QDir mceditDir(mceditPath);
|
|
|
|
QString program;
|
|
|
|
if (mceditDir.exists("mcedit.py"))
|
|
|
|
{
|
|
|
|
program = mceditDir.absoluteFilePath("mcedit.py");
|
|
|
|
}
|
|
|
|
else if (mceditDir.exists("mcedit.exe"))
|
|
|
|
{
|
|
|
|
program = mceditDir.absoluteFilePath("mcedit.exe");
|
|
|
|
}
|
2014-02-16 16:38:39 +05:30
|
|
|
QProcess::startDetached(program, QStringList() << save, mceditPath);
|
2014-02-22 00:43:12 +05:30
|
|
|
#endif
|
2014-02-16 15:16:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void MCEditFactory::registerSettings(SettingsObject *settings)
|
|
|
|
{
|
|
|
|
settings->registerSetting("MCEditPath");
|
|
|
|
}
|
|
|
|
BaseExternalTool *MCEditFactory::createTool(BaseInstance *instance, QObject *parent)
|
|
|
|
{
|
|
|
|
return new MCEditTool(instance, parent);
|
|
|
|
}
|
|
|
|
bool MCEditFactory::check(QString *error)
|
|
|
|
{
|
|
|
|
return check(MMC->settings()->get("MCEditPath").toString(), error);
|
|
|
|
}
|
|
|
|
bool MCEditFactory::check(const QString &path, QString *error)
|
|
|
|
{
|
|
|
|
if (path.isEmpty())
|
|
|
|
{
|
|
|
|
*error = QObject::tr("Path is empty");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const QDir dir(path);
|
|
|
|
if (!dir.exists())
|
|
|
|
{
|
|
|
|
*error = QObject::tr("Path does not exist");
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-22 00:43:12 +05:30
|
|
|
if (!dir.exists("mcedit.py") && !dir.exists("mcedit.exe") && !dir.exists("Contents"))
|
2014-02-16 15:16:14 +05:30
|
|
|
{
|
2014-02-22 00:43:12 +05:30
|
|
|
*error = QObject::tr("Path does not seem to be a MCEdit path");
|
2014-02-16 15:16:14 +05:30
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|