From f0b71f989ea798495ad80d1f059ae0a28514f9a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 3 Nov 2016 01:10:16 +0100 Subject: [PATCH] NOISSUE use LoggedProcess to work around issues with QProcess on macOS --- api/logic/BaseInstance.h | 2 +- api/logic/CMakeLists.txt | 8 +-- api/logic/{launch => }/LoggedProcess.cpp | 0 api/logic/{launch => }/LoggedProcess.h | 3 +- api/logic/{launch => }/MessageLevel.cpp | 0 api/logic/{launch => }/MessageLevel.h | 0 api/logic/java/launch/CheckJava.h | 2 +- api/logic/launch/steps/PostLaunchCommand.h | 2 +- api/logic/launch/steps/PreLaunchCommand.h | 4 +- api/logic/launch/steps/TextPrint.h | 2 +- api/logic/launch/steps/Update.h | 2 +- .../launch/CreateServerResourcePacksFolder.h | 2 +- api/logic/minecraft/launch/DirectJavaLaunch.h | 2 +- .../minecraft/launch/LauncherPartLaunch.h | 2 +- application/ColorCache.h | 2 +- application/pages/WorldListPage.cpp | 50 +++++++++++++++---- application/pages/WorldListPage.h | 4 ++ 17 files changed, 62 insertions(+), 25 deletions(-) rename api/logic/{launch => }/LoggedProcess.cpp (100%) rename api/logic/{launch => }/LoggedProcess.h (94%) rename api/logic/{launch => }/MessageLevel.cpp (100%) rename api/logic/{launch => }/MessageLevel.h (100%) diff --git a/api/logic/BaseInstance.h b/api/logic/BaseInstance.h index 56d3d6cba..669bad791 100644 --- a/api/logic/BaseInstance.h +++ b/api/logic/BaseInstance.h @@ -27,7 +27,7 @@ #include "settings/INIFile.h" #include "BaseVersionList.h" #include "minecraft/auth/MojangAccount.h" -#include "launch/MessageLevel.h" +#include "MessageLevel.h" #include "pathmatcher/IPathMatcher.h" #include "multimc_logic_export.h" diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index 0741fb1a0..6d0f78f93 100644 --- a/api/logic/CMakeLists.txt +++ b/api/logic/CMakeLists.txt @@ -16,6 +16,10 @@ set(CORE_SOURCES InstanceImportTask.cpp InstanceList.h InstanceList.cpp + LoggedProcess.h + LoggedProcess.cpp + MessageLevel.cpp + MessageLevel.h BaseInstanceProvider.h FolderInstanceProvider.h FolderInstanceProvider.cpp @@ -126,12 +130,8 @@ set(LAUNCH_SOURCES launch/LaunchStep.h launch/LaunchTask.cpp launch/LaunchTask.h - launch/LoggedProcess.cpp - launch/LoggedProcess.h launch/LogModel.cpp launch/LogModel.h - launch/MessageLevel.cpp - launch/MessageLevel.h ) # Old update system diff --git a/api/logic/launch/LoggedProcess.cpp b/api/logic/LoggedProcess.cpp similarity index 100% rename from api/logic/launch/LoggedProcess.cpp rename to api/logic/LoggedProcess.cpp diff --git a/api/logic/launch/LoggedProcess.h b/api/logic/LoggedProcess.h similarity index 94% rename from api/logic/launch/LoggedProcess.h rename to api/logic/LoggedProcess.h index c4e5c52c4..e19286894 100644 --- a/api/logic/launch/LoggedProcess.h +++ b/api/logic/LoggedProcess.h @@ -17,12 +17,13 @@ #include #include "MessageLevel.h" +#include "multimc_logic_export.h" /* * This is a basic process. * It has line-based logging support and hides some of the nasty bits. */ -class LoggedProcess : public QProcess +class MULTIMC_LOGIC_EXPORT LoggedProcess : public QProcess { Q_OBJECT public: diff --git a/api/logic/launch/MessageLevel.cpp b/api/logic/MessageLevel.cpp similarity index 100% rename from api/logic/launch/MessageLevel.cpp rename to api/logic/MessageLevel.cpp diff --git a/api/logic/launch/MessageLevel.h b/api/logic/MessageLevel.h similarity index 100% rename from api/logic/launch/MessageLevel.h rename to api/logic/MessageLevel.h diff --git a/api/logic/java/launch/CheckJava.h b/api/logic/java/launch/CheckJava.h index 118da2256..7126f4c44 100644 --- a/api/logic/java/launch/CheckJava.h +++ b/api/logic/java/launch/CheckJava.h @@ -16,7 +16,7 @@ #pragma once #include -#include +#include #include class CheckJava: public LaunchStep diff --git a/api/logic/launch/steps/PostLaunchCommand.h b/api/logic/launch/steps/PostLaunchCommand.h index 4d5b0a52f..2b68ee86f 100644 --- a/api/logic/launch/steps/PostLaunchCommand.h +++ b/api/logic/launch/steps/PostLaunchCommand.h @@ -16,7 +16,7 @@ #pragma once #include -#include +#include class PostLaunchCommand: public LaunchStep { diff --git a/api/logic/launch/steps/PreLaunchCommand.h b/api/logic/launch/steps/PreLaunchCommand.h index 077bdfca9..eb7bc0b6a 100644 --- a/api/logic/launch/steps/PreLaunchCommand.h +++ b/api/logic/launch/steps/PreLaunchCommand.h @@ -15,8 +15,8 @@ #pragma once -#include -#include +#include "launch/LaunchStep.h" +#include "LoggedProcess.h" class PreLaunchCommand: public LaunchStep { diff --git a/api/logic/launch/steps/TextPrint.h b/api/logic/launch/steps/TextPrint.h index fdd9014a7..5b82aff84 100644 --- a/api/logic/launch/steps/TextPrint.h +++ b/api/logic/launch/steps/TextPrint.h @@ -16,7 +16,7 @@ #pragma once #include -#include +#include #include #include "multimc_logic_export.h" diff --git a/api/logic/launch/steps/Update.h b/api/logic/launch/steps/Update.h index 1739de476..ad7cfa69b 100644 --- a/api/logic/launch/steps/Update.h +++ b/api/logic/launch/steps/Update.h @@ -17,7 +17,7 @@ #include #include -#include +#include #include // FIXME: stupid. should be defined by the instance type? or even completely abstracted away... diff --git a/api/logic/minecraft/launch/CreateServerResourcePacksFolder.h b/api/logic/minecraft/launch/CreateServerResourcePacksFolder.h index d35ccc69d..46a3a974c 100644 --- a/api/logic/minecraft/launch/CreateServerResourcePacksFolder.h +++ b/api/logic/minecraft/launch/CreateServerResourcePacksFolder.h @@ -16,7 +16,7 @@ #pragma once #include -#include +#include #include // HACK: this is a workaround for MCL-3732 - 'server-resource-packs' folder is created. diff --git a/api/logic/minecraft/launch/DirectJavaLaunch.h b/api/logic/minecraft/launch/DirectJavaLaunch.h index 0e3d66ccc..eff13f16e 100644 --- a/api/logic/minecraft/launch/DirectJavaLaunch.h +++ b/api/logic/minecraft/launch/DirectJavaLaunch.h @@ -16,7 +16,7 @@ #pragma once #include -#include +#include #include class DirectJavaLaunch: public LaunchStep diff --git a/api/logic/minecraft/launch/LauncherPartLaunch.h b/api/logic/minecraft/launch/LauncherPartLaunch.h index 209902e01..dfa08f7a8 100644 --- a/api/logic/minecraft/launch/LauncherPartLaunch.h +++ b/api/logic/minecraft/launch/LauncherPartLaunch.h @@ -16,7 +16,7 @@ #pragma once #include -#include +#include #include class LauncherPartLaunch: public LaunchStep diff --git a/application/ColorCache.h b/application/ColorCache.h index 9d5ad02b5..1ce1c211a 100644 --- a/application/ColorCache.h +++ b/application/ColorCache.h @@ -1,7 +1,7 @@ #pragma once #include #include -#include +#include #include class ColorCache diff --git a/application/pages/WorldListPage.cpp b/application/pages/WorldListPage.cpp index a4f177449..365da4a43 100644 --- a/application/pages/WorldListPage.cpp +++ b/application/pages/WorldListPage.cpp @@ -29,6 +29,7 @@ #include "MultiMC.h" #include #include +#include WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr worlds, QString id, QString iconName, QString displayName, QString helpPage, @@ -149,7 +150,11 @@ void WorldListPage::on_copySeedBtn_clicked() void WorldListPage::on_mcEditBtn_clicked() { + if(m_mceditStarting) + return; + auto mcedit = MMC->mcedit(); + const QString mceditPath = mcedit->path(); QModelIndex index = getSelectedWorld(); @@ -167,15 +172,11 @@ void WorldListPage::on_mcEditBtn_clicked() auto program = mcedit->getProgramPath(); if(program.size()) { - qint64 pid; - if(!QProcess::startDetached(program, QStringList() << fullPath, mceditPath, &pid)) - { - QMessageBox::warning( - this->parentWidget(), - tr("MCEdit failed to start!"), - tr("MCEdit failed to start.\nIt may be necessary to reinstall it.") - ); - } + m_mceditProcess.reset(new LoggedProcess()); + m_mceditProcess->setDetachable(true); + connect(m_mceditProcess.get(), &LoggedProcess::stateChanged, this, &WorldListPage::mceditState); + m_mceditProcess->start(program, {fullPath}); + m_mceditStarting = true; } else { @@ -187,6 +188,37 @@ void WorldListPage::on_mcEditBtn_clicked() } } +void WorldListPage::mceditState(LoggedProcess::State state) +{ + bool failed = false; + switch(state) + { + case LoggedProcess::NotRunning: + case LoggedProcess::Starting: + return; + case LoggedProcess::FailedToStart: + case LoggedProcess::Crashed: + case LoggedProcess::Aborted: + { + failed = true; + } + case LoggedProcess::Running: + case LoggedProcess::Finished: + { + m_mceditStarting = false; + break; + } + } + if(failed) + { + QMessageBox::warning( + this->parentWidget(), + tr("MCEdit failed to start!"), + tr("MCEdit failed to start.\nIt may be necessary to reinstall it.") + ); + } +} + void WorldListPage::worldChanged(const QModelIndex ¤t, const QModelIndex &previous) { QModelIndex index = getSelectedWorld(); diff --git a/application/pages/WorldListPage.h b/application/pages/WorldListPage.h index 8a9fc16ff..0a09764e7 100644 --- a/application/pages/WorldListPage.h +++ b/application/pages/WorldListPage.h @@ -20,6 +20,7 @@ #include "minecraft/onesix/OneSixInstance.h" #include "BasePage.h" #include +#include class WorldList; namespace Ui @@ -73,6 +74,8 @@ private: private: Ui::WorldListPage *ui; std::shared_ptr m_worlds; + unique_qobject_ptr m_mceditProcess; + bool m_mceditStarting = false; QString m_iconName; QString m_id; QString m_displayName; @@ -88,4 +91,5 @@ private slots: void on_refreshBtn_clicked(); void on_viewFolderBtn_clicked(); void worldChanged(const QModelIndex ¤t, const QModelIndex &previous); + void mceditState(LoggedProcess::State state); };