2014-02-16 09:46:14 +00:00
|
|
|
#include "MCEditTool.h"
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QProcess>
|
2014-02-21 19:13:12 +00:00
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QUrl>
|
2015-01-27 21:31:07 +00:00
|
|
|
// FIXME: mixing logic and UI!!!!
|
|
|
|
#include <QInputDialog>
|
2014-02-16 09:46:14 +00:00
|
|
|
|
2014-07-01 00:48:09 +01:00
|
|
|
#include "logic/settings/SettingsObject.h"
|
2014-02-16 09:46:14 +00:00
|
|
|
#include "logic/BaseInstance.h"
|
2015-01-27 21:31:07 +00:00
|
|
|
#include "logic/minecraft/MinecraftInstance.h"
|
2014-02-16 09:46:14 +00:00
|
|
|
#include "MultiMC.h"
|
|
|
|
|
2014-03-30 19:11:05 +01:00
|
|
|
MCEditTool::MCEditTool(InstancePtr instance, QObject *parent)
|
2014-02-16 09:46:14 +00:00
|
|
|
: BaseDetachedTool(instance, parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
QString MCEditTool::getSave() const
|
|
|
|
{
|
|
|
|
// FIXME: mixing logic and UI!!!!
|
|
|
|
auto mcInstance = std::dynamic_pointer_cast<MinecraftInstance>(m_instance);
|
|
|
|
if(!mcInstance)
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
QDir saves(mcInstance->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();
|
|
|
|
}
|
|
|
|
|
2014-02-16 09:46:14 +00:00
|
|
|
void MCEditTool::runImpl()
|
|
|
|
{
|
|
|
|
const QString mceditPath = MMC->settings()->get("MCEditPath").toString();
|
2014-02-16 11:08:39 +00:00
|
|
|
const QString save = getSave();
|
|
|
|
if (save.isNull())
|
2014-02-16 09:46:14 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-21 19:13:12 +00:00
|
|
|
#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
|
2014-02-16 10:49:55 +00:00
|
|
|
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");
|
|
|
|
}
|
2015-04-01 21:43:18 +01:00
|
|
|
else if (mceditDir.exists("mcedit2.exe"))
|
|
|
|
{
|
|
|
|
program = mceditDir.absoluteFilePath("mcedit2.exe");
|
|
|
|
}
|
2014-02-16 11:08:39 +00:00
|
|
|
QProcess::startDetached(program, QStringList() << save, mceditPath);
|
2014-02-21 19:13:12 +00:00
|
|
|
#endif
|
2014-02-16 09:46:14 +00:00
|
|
|
}
|
|
|
|
|
2014-09-06 17:16:56 +01:00
|
|
|
void MCEditFactory::registerSettings(std::shared_ptr<SettingsObject> settings)
|
2014-02-16 09:46:14 +00:00
|
|
|
{
|
|
|
|
settings->registerSetting("MCEditPath");
|
|
|
|
}
|
2014-03-30 19:11:05 +01:00
|
|
|
BaseExternalTool *MCEditFactory::createTool(InstancePtr instance, QObject *parent)
|
2014-02-16 09:46:14 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2015-04-01 21:43:18 +01:00
|
|
|
if (!dir.exists("mcedit.py") && !dir.exists("mcedit.exe") && !dir.exists("Contents") && !dir.exists("mcedit2.exe"))
|
2014-02-16 09:46:14 +00:00
|
|
|
{
|
2014-02-21 19:13:12 +00:00
|
|
|
*error = QObject::tr("Path does not seem to be a MCEdit path");
|
2014-02-16 09:46:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|