summaryrefslogtreecommitdiffstats
path: root/logic/tools/MCEditTool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'logic/tools/MCEditTool.cpp')
-rw-r--r--logic/tools/MCEditTool.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/logic/tools/MCEditTool.cpp b/logic/tools/MCEditTool.cpp
new file mode 100644
index 00000000..e22a5d4a
--- /dev/null
+++ b/logic/tools/MCEditTool.cpp
@@ -0,0 +1,77 @@
+#include "MCEditTool.h"
+
+#include <QDir>
+#include <QProcess>
+#include <QDesktopServices>
+#include <QUrl>
+
+#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;
+ }
+#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
+ 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);
+#endif
+}
+
+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") && !dir.exists("Contents"))
+ {
+ *error = QObject::tr("Path does not seem to be a MCEdit path");
+ return false;
+ }
+ return true;
+}