NOISSUE MCEdit integration - remove old 'tool', replace with Worlds

This commit is contained in:
Petr Mrázek 2016-11-02 02:33:55 +01:00
parent 3a4304d89d
commit 85b64ad767
8 changed files with 109 additions and 193 deletions

View File

@ -8,117 +8,70 @@
#include "BaseInstance.h" #include "BaseInstance.h"
#include "minecraft/MinecraftInstance.h" #include "minecraft/MinecraftInstance.h"
MCEditTool::MCEditTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent) MCEditTool::MCEditTool(SettingsObjectPtr settings)
: BaseDetachedTool(settings, instance, parent)
{
}
QString MCEditTool::getSave() const
{
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;
// FIXME: mixing logic and UI!!!!
/*
const QString save = QInputDialog::getItem(QApplication::activeWindow(), tr("MCEdit"), tr("Choose which world to open:"),
worlds, 0, false, &ok);
if (ok)
{
return saves.absoluteFilePath(save);
}
*/
return QString();
}
void MCEditTool::runImpl()
{
const QString mceditPath = globalSettings->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;
#ifdef Q_OS_LINUX
if (mceditDir.exists("mcedit.sh"))
{
program = mceditDir.absoluteFilePath("mcedit.sh");
}
else if (mceditDir.exists("mcedit.py"))
{
program = mceditDir.absoluteFilePath("mcedit.py");
}
#elif defined(Q_OS_WIN32)
if (mceditDir.exists("mcedit.exe"))
{
program = mceditDir.absoluteFilePath("mcedit.exe");
}
else if (mceditDir.exists("mcedit2.exe"))
{
program = mceditDir.absoluteFilePath("mcedit2.exe");
}
#endif
/*
if(program.size())
{
DesktopServices::openFile(program, save, mceditPath);
}
*/
#endif
}
void MCEditFactory::registerSettings(SettingsObjectPtr settings)
{ {
settings->registerSetting("MCEditPath"); settings->registerSetting("MCEditPath");
globalSettings = settings; m_settings = settings;
} }
BaseExternalTool *MCEditFactory::createTool(InstancePtr instance, QObject *parent)
void MCEditTool::setPath(QString& path)
{ {
return new MCEditTool(globalSettings, instance, parent); m_settings->set("MCEditPath", path);
} }
bool MCEditFactory::check(QString *error)
QString MCEditTool::path() const
{ {
return check(globalSettings->get("MCEditPath").toString(), error); return m_settings->get("MCEditPath").toString();
} }
bool MCEditFactory::check(const QString &path, QString *error)
bool MCEditTool::check(const QString& toolPath, QString& error)
{ {
if (path.isEmpty()) if (toolPath.isEmpty())
{ {
*error = QObject::tr("Path is empty"); error = QObject::tr("Path is empty");
return false; return false;
} }
const QDir dir(path); const QDir dir(toolPath);
if (!dir.exists()) if (!dir.exists())
{ {
*error = QObject::tr("Path does not exist"); error = QObject::tr("Path does not exist");
return false; return false;
} }
if (!dir.exists("mcedit.sh") && !dir.exists("mcedit.py") && !dir.exists("mcedit.exe") && !dir.exists("Contents") && !dir.exists("mcedit2.exe")) if (!dir.exists("mcedit.sh") && !dir.exists("mcedit.py") && !dir.exists("mcedit.exe") && !dir.exists("Contents") && !dir.exists("mcedit2.exe"))
{ {
*error = QObject::tr("Path does not seem to be a MCEdit path"); error = QObject::tr("Path does not seem to be a MCEdit path");
return false; return false;
} }
return true; return true;
} }
QString MCEditTool::getProgramPath()
{
#ifdef Q_OS_OSX
return path();
#else
const QString mceditPath = path();
QDir mceditDir(mceditPath);
#ifdef Q_OS_LINUX
if (mceditDir.exists("mcedit.sh"))
{
return mceditDir.absoluteFilePath("mcedit.sh");
}
else if (mceditDir.exists("mcedit.py"))
{
return mceditDir.absoluteFilePath("mcedit.py");
}
return QString();
#elif defined(Q_OS_WIN32)
if (mceditDir.exists("mcedit.exe"))
{
return mceditDir.absoluteFilePath("mcedit.exe");
}
else if (mceditDir.exists("mcedit2.exe"))
{
return mceditDir.absoluteFilePath("mcedit2.exe");
}
return QString();
#endif
#endif
}

View File

@ -1,26 +1,17 @@
#pragma once #pragma once
#include "BaseExternalTool.h" #include <QString>
#include "settings/SettingsObject.h"
#include "multimc_logic_export.h" #include "multimc_logic_export.h"
class MULTIMC_LOGIC_EXPORT MCEditTool : public BaseDetachedTool class MULTIMC_LOGIC_EXPORT MCEditTool
{
Q_OBJECT
public:
explicit MCEditTool(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0);
protected:
QString getSave() const;
void runImpl() override;
};
class MULTIMC_LOGIC_EXPORT MCEditFactory : public BaseDetachedToolFactory
{ {
public: public:
QString name() const override { return "MCEdit"; } MCEditTool(SettingsObjectPtr settings);
void registerSettings(SettingsObjectPtr settings) override; void setPath(QString & path);
BaseExternalTool *createTool(InstancePtr instance, QObject *parent = 0) override; QString path() const;
bool check(QString *error) override; bool check(const QString &toolPath, QString &error);
bool check(const QString &path, QString *error) override; QString getProgramPath();
private:
SettingsObjectPtr m_settings;
}; };

View File

@ -110,6 +110,7 @@ public:
QAction *actionChangeInstIcon; QAction *actionChangeInstIcon;
QAction *actionEditInstNotes; QAction *actionEditInstNotes;
QAction *actionEditInstance; QAction *actionEditInstance;
QAction *actionWorlds;
QAction *actionViewSelectedInstFolder; QAction *actionViewSelectedInstFolder;
QAction *actionDeleteInstance; QAction *actionDeleteInstance;
QAction *actionConfig_Folder; QAction *actionConfig_Folder;
@ -187,6 +188,8 @@ public:
actionEditInstNotes->setObjectName(QStringLiteral("actionEditInstNotes")); actionEditInstNotes->setObjectName(QStringLiteral("actionEditInstNotes"));
actionEditInstance = new QAction(MainWindow); actionEditInstance = new QAction(MainWindow);
actionEditInstance->setObjectName(QStringLiteral("actionEditInstance")); actionEditInstance->setObjectName(QStringLiteral("actionEditInstance"));
actionWorlds = new QAction(MainWindow);
actionWorlds->setObjectName(QStringLiteral("actionWorlds"));
actionViewSelectedInstFolder = new QAction(MainWindow); actionViewSelectedInstFolder = new QAction(MainWindow);
actionViewSelectedInstFolder->setObjectName(QStringLiteral("actionViewSelectedInstFolder")); actionViewSelectedInstFolder->setObjectName(QStringLiteral("actionViewSelectedInstFolder"));
actionDeleteInstance = new QAction(MainWindow); actionDeleteInstance = new QAction(MainWindow);
@ -280,6 +283,7 @@ public:
instanceToolBar->addAction(actionEditInstance); instanceToolBar->addAction(actionEditInstance);
instanceToolBar->addAction(actionInstanceSettings); instanceToolBar->addAction(actionInstanceSettings);
instanceToolBar->addAction(actionEditInstNotes); instanceToolBar->addAction(actionEditInstNotes);
instanceToolBar->addAction(actionWorlds);
instanceToolBar->addAction(actionScreenshots); instanceToolBar->addAction(actionScreenshots);
instanceToolBar->addSeparator(); instanceToolBar->addSeparator();
instanceToolBar->addAction(actionViewSelectedInstFolder); instanceToolBar->addAction(actionViewSelectedInstFolder);
@ -330,6 +334,8 @@ public:
actionChangeInstIcon->setToolTip(tr("Change the selected instance's icon.")); actionChangeInstIcon->setToolTip(tr("Change the selected instance's icon."));
actionEditInstNotes->setText(tr("Edit Notes")); actionEditInstNotes->setText(tr("Edit Notes"));
actionEditInstNotes->setToolTip(tr("Edit the notes for the selected instance.")); actionEditInstNotes->setToolTip(tr("Edit the notes for the selected instance."));
actionWorlds->setText(tr("View Worlds"));
actionWorlds->setToolTip(tr("View the worlds of this instance."));
actionEditInstance->setText(tr("Edit Instance")); actionEditInstance->setText(tr("Edit Instance"));
actionEditInstance->setToolTip(tr("Change the instance settings, mods and versions.")); actionEditInstance->setToolTip(tr("Change the instance settings, mods and versions."));
actionViewSelectedInstFolder->setText(tr("Instance Folder")); actionViewSelectedInstFolder->setText(tr("Instance Folder"));
@ -690,24 +696,6 @@ void MainWindow::updateToolsMenu()
}); });
} }
} }
launchMenu->addSeparator()->setText(tr("Tools"));
for (auto tool : MMC->tools().values())
{
QAction *toolAction = launchMenu->addAction(tool->name());
QString error;
if (!tool->check(&error))
{
toolAction->setDisabled(true);
toolAction->setToolTip(tr("Tool not setup correctly. Go into settings, \"External Tools\"."));
}
else
{
connect(toolAction, &QAction::triggered, [this, tool]()
{
tool->createDetachedTool(m_selectedInstance, this)->run();
});
}
}
ui->actionLaunchInstance->setMenu(launchMenu); ui->actionLaunchInstance->setMenu(launchMenu);
} }
@ -1250,6 +1238,11 @@ void MainWindow::on_actionEditInstNotes_triggered()
MMC->showInstanceWindow(m_selectedInstance, "notes"); MMC->showInstanceWindow(m_selectedInstance, "notes");
} }
void MainWindow::on_actionWorlds_triggered()
{
MMC->showInstanceWindow(m_selectedInstance, "worlds");
}
void MainWindow::on_actionEditInstance_triggered() void MainWindow::on_actionEditInstance_triggered()
{ {
MMC->showInstanceWindow(m_selectedInstance); MMC->showInstanceWindow(m_selectedInstance);

View File

@ -115,6 +115,8 @@ private slots:
void on_actionEditInstNotes_triggered(); void on_actionEditInstNotes_triggered();
void on_actionWorlds_triggered();
void on_actionScreenshots_triggered(); void on_actionScreenshots_triggered();
void taskEnd(); void taskEnd();

View File

@ -271,12 +271,7 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
profiler->registerSettings(m_settings); profiler->registerSettings(m_settings);
} }
//FIXME: what to do with these? initMCEdit();
m_tools.insert("mcedit", std::shared_ptr<BaseDetachedToolFactory>(new MCEditFactory()));
for (auto tool : m_tools.values())
{
tool->registerSettings(m_settings);
}
connect(this, SIGNAL(aboutToQuit()), SLOT(onExit())); connect(this, SIGNAL(aboutToQuit()), SLOT(onExit()));
@ -628,6 +623,11 @@ void MultiMC::initGlobalSettings()
} }
} }
void MultiMC::initMCEdit()
{
m_mcedit.reset(new MCEditTool(m_settings));
}
std::shared_ptr<LWJGLVersionList> MultiMC::lwjgllist() std::shared_ptr<LWJGLVersionList> MultiMC::lwjgllist()
{ {
if (!m_lwjgllist) if (!m_lwjgllist)

View File

@ -33,6 +33,7 @@ class BaseProfilerFactory;
class BaseDetachedToolFactory; class BaseDetachedToolFactory;
class TranslationDownloader; class TranslationDownloader;
class ITheme; class ITheme;
class MCEditTool;
#if defined(MMC) #if defined(MMC)
#undef MMC #undef MMC
@ -105,6 +106,11 @@ public:
return m_icons; return m_icons;
} }
MCEditTool *mcedit() const
{
return m_mcedit.get();
}
std::shared_ptr<MojangAccountList> accounts() const std::shared_ptr<MojangAccountList> accounts() const
{ {
return m_accounts; return m_accounts;
@ -120,11 +126,6 @@ public:
return m_profilers; return m_profilers;
} }
const QMap<QString, std::shared_ptr<BaseDetachedToolFactory>> &tools() const
{
return m_tools;
}
/// this is the root of the 'installation'. Used for automatic updates /// this is the root of the 'installation'. Used for automatic updates
const QString &root() const QString &root()
{ {
@ -166,6 +167,7 @@ private:
void initNetwork(); void initNetwork();
void initInstances(); void initInstances();
void initAccounts(); void initAccounts();
void initMCEdit();
private: private:
QDateTime startTime; QDateTime startTime;
@ -186,9 +188,9 @@ private:
std::shared_ptr<TranslationDownloader> m_translationChecker; std::shared_ptr<TranslationDownloader> m_translationChecker;
std::shared_ptr<GenericPageProvider> m_globalSettingsProvider; std::shared_ptr<GenericPageProvider> m_globalSettingsProvider;
std::map<QString, std::unique_ptr<ITheme>> m_themes; std::map<QString, std::unique_ptr<ITheme>> m_themes;
std::unique_ptr<MCEditTool> m_mcedit;
QMap<QString, std::shared_ptr<BaseProfilerFactory>> m_profilers; QMap<QString, std::shared_ptr<BaseProfilerFactory>> m_profilers;
QMap<QString, std::shared_ptr<BaseDetachedToolFactory>> m_tools;
QString m_rootPath; QString m_rootPath;
Status m_status = MultiMC::Failed; Status m_status = MultiMC::Failed;

View File

@ -24,10 +24,11 @@
#include <QMessageBox> #include <QMessageBox>
#include <QTreeView> #include <QTreeView>
#include <QInputDialog> #include <QInputDialog>
#include <tools/MCEditTool.h>
#include "MultiMC.h" #include "MultiMC.h"
#include <GuiUtil.h> #include <GuiUtil.h>
#include <QProcess>
WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worlds, QString id, WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worlds, QString id,
QString iconName, QString displayName, QString helpPage, QString iconName, QString displayName, QString helpPage,
@ -148,7 +149,8 @@ void WorldListPage::on_copySeedBtn_clicked()
void WorldListPage::on_mcEditBtn_clicked() void WorldListPage::on_mcEditBtn_clicked()
{ {
const QString mceditPath = MMC->settings()->get("MCEditPath").toString(); auto mcedit = MMC->mcedit();
const QString mceditPath = mcedit->path();
QModelIndex index = getSelectedWorld(); QModelIndex index = getSelectedWorld();
@ -162,49 +164,27 @@ void WorldListPage::on_mcEditBtn_clicked()
auto fullPath = m_worlds->data(index, WorldList::FolderRole).toString(); auto fullPath = m_worlds->data(index, WorldList::FolderRole).toString();
#ifdef Q_OS_OSX auto program = mcedit->getProgramPath();
QProcess *process = new QProcess();
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), process, SLOT(deleteLater()));
process->setProgram(mceditPath);
process->setArguments(QStringList() << fullPath);
process->start();
#else
QDir mceditDir(mceditPath);
QString program;
#ifdef Q_OS_LINUX
if (mceditDir.exists("mcedit.sh"))
{
program = mceditDir.absoluteFilePath("mcedit.sh");
}
else if (mceditDir.exists("mcedit.py"))
{
program = mceditDir.absoluteFilePath("mcedit.py");
}
#elif defined(Q_OS_WIN32)
if (mceditDir.exists("mcedit.exe"))
{
program = mceditDir.absoluteFilePath("mcedit.exe");
}
else if (mceditDir.exists("mcedit2.exe"))
{
program = mceditDir.absoluteFilePath("mcedit2.exe");
}
#endif
if(program.size()) if(program.size())
{ {
qint64 pid = 0; qint64 pid;
if(!QProcess::startDetached(program, QStringList() << fullPath, mceditPath, &pid))
DesktopServices::openFile(program, fullPath, mceditPath, &pid);
if(pid == 0)
{ {
QMessageBox::warning(this->parentWidget(), tr("MCEdit failed to start!"), tr("MCEdit failed to start.\nIt may be necessary to reinstall it.")); QMessageBox::warning(
this->parentWidget(),
tr("MCEdit failed to start!"),
tr("MCEdit failed to start.\nIt may be necessary to reinstall it.")
);
} }
} }
else else
{ {
QMessageBox::warning(this->parentWidget(), tr("No MCEdit found or set up!"), tr("You do not have MCEdit set up or it was moved.\nYou can set it up in the global settings.")); QMessageBox::warning(
this->parentWidget(),
tr("No MCEdit found or set up!"),
tr("You do not have MCEdit set up or it was moved.\nYou can set it up in the global settings.")
);
} }
#endif
} }
void WorldListPage::worldChanged(const QModelIndex &current, const QModelIndex &previous) void WorldListPage::worldChanged(const QModelIndex &current, const QModelIndex &previous)

View File

@ -24,6 +24,7 @@
#include "tools/BaseProfiler.h" #include "tools/BaseProfiler.h"
#include <FileSystem.h> #include <FileSystem.h>
#include "MultiMC.h" #include "MultiMC.h"
#include <tools/MCEditTool.h>
ExternalToolsPage::ExternalToolsPage(QWidget *parent) : ExternalToolsPage::ExternalToolsPage(QWidget *parent) :
QWidget(parent), QWidget(parent),
@ -93,8 +94,7 @@ void ExternalToolsPage::on_jprofilerPathBtn_clicked()
QString cooked_dir = FS::NormalizePath(raw_dir); QString cooked_dir = FS::NormalizePath(raw_dir);
if (!MMC->profilers()["jprofiler"]->check(cooked_dir, &error)) if (!MMC->profilers()["jprofiler"]->check(cooked_dir, &error))
{ {
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"), tr("Error while checking JProfiler install:\n%1").arg(error));
tr("Error while checking JProfiler install:\n%1").arg(error));
continue; continue;
} }
else else
@ -109,8 +109,7 @@ void ExternalToolsPage::on_jprofilerCheckBtn_clicked()
QString error; QString error;
if (!MMC->profilers()["jprofiler"]->check(ui->jprofilerPathEdit->text(), &error)) if (!MMC->profilers()["jprofiler"]->check(ui->jprofilerPathEdit->text(), &error))
{ {
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"), tr("Error while checking JProfiler install:\n%1").arg(error));
tr("Error while checking JProfiler install:\n%1").arg(error));
} }
else else
{ {
@ -132,8 +131,7 @@ void ExternalToolsPage::on_jvisualvmPathBtn_clicked()
QString cooked_dir = FS::NormalizePath(raw_dir); QString cooked_dir = FS::NormalizePath(raw_dir);
if (!MMC->profilers()["jvisualvm"]->check(cooked_dir, &error)) if (!MMC->profilers()["jvisualvm"]->check(cooked_dir, &error))
{ {
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"), tr("Error while checking JVisualVM install:\n%1").arg(error));
tr("Error while checking JVisualVM install:\n%1").arg(error));
continue; continue;
} }
else else
@ -148,8 +146,7 @@ void ExternalToolsPage::on_jvisualvmCheckBtn_clicked()
QString error; QString error;
if (!MMC->profilers()["jvisualvm"]->check(ui->jvisualvmPathEdit->text(), &error)) if (!MMC->profilers()["jvisualvm"]->check(ui->jvisualvmPathEdit->text(), &error))
{ {
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"), tr("Error while checking JVisualVM install:\n%1").arg(error));
tr("Error while checking JVisualVM install:\n%1").arg(error));
} }
else else
{ {
@ -174,10 +171,9 @@ void ExternalToolsPage::on_mceditPathBtn_clicked()
break; break;
} }
QString cooked_dir = FS::NormalizePath(raw_dir); QString cooked_dir = FS::NormalizePath(raw_dir);
if (!MMC->tools()["mcedit"]->check(cooked_dir, &error)) if (!MMC->mcedit()->check(cooked_dir, error))
{ {
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"), tr("Error while checking MCEdit install:\n%1").arg(error));
tr("Error while checking MCEdit install:\n%1").arg(error));
continue; continue;
} }
else else
@ -190,10 +186,9 @@ void ExternalToolsPage::on_mceditPathBtn_clicked()
void ExternalToolsPage::on_mceditCheckBtn_clicked() void ExternalToolsPage::on_mceditCheckBtn_clicked()
{ {
QString error; QString error;
if (!MMC->tools()["mcedit"]->check(ui->mceditPathEdit->text(), &error)) if (!!MMC->mcedit()->check(ui->mceditPathEdit->text(), error))
{ {
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"), tr("Error while checking MCEdit install:\n%1").arg(error));
tr("Error while checking MCEdit install:\n%1").arg(error));
} }
else else
{ {