From f26b7dedad70a46769b4c96122a7615b328a9fbb Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sun, 16 Feb 2014 12:08:39 +0100 Subject: [PATCH] Only show folders that really are worlds --- logic/BaseExternalTool.cpp | 30 ++++++++++++++++++++++++++++++ logic/BaseExternalTool.h | 1 + logic/MCEditTool.cpp | 12 +++--------- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/logic/BaseExternalTool.cpp b/logic/BaseExternalTool.cpp index 6dffb4d6..081c3ef0 100644 --- a/logic/BaseExternalTool.cpp +++ b/logic/BaseExternalTool.cpp @@ -1,10 +1,16 @@ #include "BaseExternalTool.h" #include +#include +#include + #ifdef Q_OS_WIN #include #endif +#include "BaseInstance.h" +#include "MultiMC.h" + BaseExternalTool::BaseExternalTool(BaseInstance *instance, QObject *parent) : QObject(parent), m_instance(instance) { @@ -24,6 +30,30 @@ qint64 BaseExternalTool::pid(QProcess *process) #endif } +QString BaseExternalTool::getSave() const +{ + QDir saves(m_instance->minecraftRoot() + "/saves"); + QStringList worlds = saves.entryList(QDir::Dirs | QDir::NoDotAndDotDot); + QMutableListIterator 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) diff --git a/logic/BaseExternalTool.h b/logic/BaseExternalTool.h index 184b1f80..e8965bfd 100644 --- a/logic/BaseExternalTool.h +++ b/logic/BaseExternalTool.h @@ -18,6 +18,7 @@ protected: BaseInstance *m_instance; qint64 pid(QProcess *process); + QString getSave() const; }; class BaseDetachedTool : public BaseExternalTool diff --git a/logic/MCEditTool.cpp b/logic/MCEditTool.cpp index 5694f654..c4edece5 100644 --- a/logic/MCEditTool.cpp +++ b/logic/MCEditTool.cpp @@ -2,8 +2,6 @@ #include #include -#include -#include #include "settingsobject.h" #include "logic/BaseInstance.h" @@ -17,12 +15,8 @@ MCEditTool::MCEditTool(BaseInstance *instance, QObject *parent) void MCEditTool::runImpl() { const QString mceditPath = MMC->settings()->get("MCEditPath").toString(); - const QDir saves = QDir(m_instance->minecraftRoot() + "/saves"); - bool ok = true; - const QString save = QInputDialog::getItem( - MMC->activeWindow(), tr("MCEdit"), tr("Choose which world to open:"), - saves.entryList(QDir::Dirs | QDir::NoDotAndDotDot), 0, false, &ok); - if (save.isEmpty() || !ok) + const QString save = getSave(); + if (save.isNull()) { return; } @@ -36,7 +30,7 @@ void MCEditTool::runImpl() { program = mceditDir.absoluteFilePath("mcedit.exe"); } - QProcess::startDetached(program, QStringList() << saves.absoluteFilePath(save), mceditPath); + QProcess::startDetached(program, QStringList() << save, mceditPath); } void MCEditFactory::registerSettings(SettingsObject *settings)