summaryrefslogtreecommitdiffstats
path: root/logic/tools/MCEditTool.cpp
diff options
context:
space:
mode:
authorJan Dalheimer <jan@dalheimer.de>2014-02-16 12:52:35 +0100
committerJan Dalheimer <jan@dalheimer.de>2014-02-16 12:52:35 +0100
commit9c87bc6c4b99f0c93f2b18039208dcf9f3fb4d79 (patch)
treecac60e920a67584cf90805382db4464c0e23b03e /logic/tools/MCEditTool.cpp
parentf26b7dedad70a46769b4c96122a7615b328a9fbb (diff)
downloadMultiMC-9c87bc6c4b99f0c93f2b18039208dcf9f3fb4d79.tar
MultiMC-9c87bc6c4b99f0c93f2b18039208dcf9f3fb4d79.tar.gz
MultiMC-9c87bc6c4b99f0c93f2b18039208dcf9f3fb4d79.tar.lz
MultiMC-9c87bc6c4b99f0c93f2b18039208dcf9f3fb4d79.tar.xz
MultiMC-9c87bc6c4b99f0c93f2b18039208dcf9f3fb4d79.zip
Restructure
Diffstat (limited to 'logic/tools/MCEditTool.cpp')
-rw-r--r--logic/tools/MCEditTool.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/logic/tools/MCEditTool.cpp b/logic/tools/MCEditTool.cpp
new file mode 100644
index 00000000..c4edece5
--- /dev/null
+++ b/logic/tools/MCEditTool.cpp
@@ -0,0 +1,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;
+}