blob: c4edece52d25447d6da99c8e68882c2e4dd6251a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#include "MCEditTool.h"
#include <QDir>
#include <QProcess>
#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();
const QString save = getSave();
if (save.isNull())
{
return;
}
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");
}
QProcess::startDetached(program, QStringList() << save, mceditPath);
}
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;
}
if (!dir.exists("mcedit.py") && !dir.exists("mcedit.exe"))
{
*error = QObject::tr("Path does not contain mcedit.py");
return false;
}
return true;
}
|