summaryrefslogtreecommitdiffstats
path: root/logic/tools/BaseExternalTool.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-02-24 00:29:13 +0100
committerPetr Mrázek <peterix@gmail.com>2014-02-24 00:29:13 +0100
commitf7c97efcf3785f597417895945b24c2e7476cba8 (patch)
treec0ad8ba4b59bf9be441c2037ae7592585c3cbe58 /logic/tools/BaseExternalTool.cpp
parente3d2e5fd7405baa8137e300e8cc817e70df172b7 (diff)
parenta354e8bfae812b23b85b65c4a5b7e860cb18080c (diff)
downloadMultiMC-f7c97efcf3785f597417895945b24c2e7476cba8.tar
MultiMC-f7c97efcf3785f597417895945b24c2e7476cba8.tar.gz
MultiMC-f7c97efcf3785f597417895945b24c2e7476cba8.tar.lz
MultiMC-f7c97efcf3785f597417895945b24c2e7476cba8.tar.xz
MultiMC-f7c97efcf3785f597417895945b24c2e7476cba8.zip
Merge branch 'feature_profiling' into integration_json_and_tools
Diffstat (limited to 'logic/tools/BaseExternalTool.cpp')
-rw-r--r--logic/tools/BaseExternalTool.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/logic/tools/BaseExternalTool.cpp b/logic/tools/BaseExternalTool.cpp
new file mode 100644
index 00000000..69cddd00
--- /dev/null
+++ b/logic/tools/BaseExternalTool.cpp
@@ -0,0 +1,77 @@
+#include "BaseExternalTool.h"
+
+#include <QProcess>
+#include <QDir>
+#include <QInputDialog>
+
+#ifdef Q_OS_WIN
+#include <windows.h>
+#endif
+
+#include "logic/BaseInstance.h"
+#include "MultiMC.h"
+
+BaseExternalTool::BaseExternalTool(BaseInstance *instance, QObject *parent)
+ : QObject(parent), m_instance(instance)
+{
+}
+
+BaseExternalTool::~BaseExternalTool()
+{
+}
+
+qint64 BaseExternalTool::pid(QProcess *process)
+{
+#ifdef Q_OS_WIN
+ struct _PROCESS_INFORMATION *procinfo = process->pid();
+ return procinfo->dwProcessId;
+#else
+ return process->pid();
+#endif
+}
+
+QString BaseExternalTool::getSave() const
+{
+ QDir saves(m_instance->minecraftRoot() + "/saves");
+ QStringList worlds = saves.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
+ QMutableListIterator<QString> it(worlds);
+ while (it.hasNext())
+ {
+ it.next();
+ if (!QDir(saves.absoluteFilePath(it.value())).exists("level.dat"))
+ {
+ it.remove();
+ }
+ }
+ bool ok = true;
+ const QString save = QInputDialog::getItem(
+ MMC->activeWindow(), tr("MCEdit"), tr("Choose which world to open:"),
+ worlds, 0, false, &ok);
+ if (ok)
+ {
+ return saves.absoluteFilePath(save);
+ }
+ return QString();
+}
+
+
+BaseDetachedTool::BaseDetachedTool(BaseInstance *instance, QObject *parent)
+ : BaseExternalTool(instance, parent)
+{
+
+}
+
+void BaseDetachedTool::run()
+{
+ runImpl();
+}
+
+
+BaseExternalToolFactory::~BaseExternalToolFactory()
+{
+}
+
+BaseDetachedTool *BaseDetachedToolFactory::createDetachedTool(BaseInstance *instance, QObject *parent)
+{
+ return qobject_cast<BaseDetachedTool *>(createTool(instance, parent));
+}