diff options
author | Petr Mrázek <peterix@gmail.com> | 2017-01-14 15:47:58 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2017-01-14 15:47:58 +0100 |
commit | a6ef0059cced7f2736d0800c54c238d4d6511575 (patch) | |
tree | 967355800e01119ddc5be5d9e979ae7427661131 /application | |
parent | 3e81e2cb5b5d00c8f73c479cf9190131a3041f35 (diff) | |
download | MultiMC-a6ef0059cced7f2736d0800c54c238d4d6511575.tar MultiMC-a6ef0059cced7f2736d0800c54c238d4d6511575.tar.gz MultiMC-a6ef0059cced7f2736d0800c54c238d4d6511575.tar.lz MultiMC-a6ef0059cced7f2736d0800c54c238d4d6511575.tar.xz MultiMC-a6ef0059cced7f2736d0800c54c238d4d6511575.zip |
GH-1665 attempt at workaround for MultiMC not starting on macOS Sierra
This tries to detect the issue and instructs the user to fix it by
moving the application to /Applications or ~/Applications.
In addition, several other previously poorly handled fatal errors
now show an error dialog.
Diffstat (limited to 'application')
-rw-r--r-- | application/MultiMC.cpp | 57 | ||||
-rw-r--r-- | application/MultiMC.h | 7 |
2 files changed, 54 insertions, 10 deletions
diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 4b4cd6a9..cec7eb37 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -25,11 +25,11 @@ #include <QNetworkAccessManager> #include <QTranslator> #include <QLibraryInfo> -#include <QMessageBox> #include <QStringList> #include <QDebug> #include <QStyleFactory> +#include "dialogs/CustomMessageBox.h" #include "InstanceList.h" #include "FolderInstanceProvider.h" #include "minecraft/ftb/FTBInstanceProvider.h" @@ -199,10 +199,26 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) adjustedBy += "Fallback to binary path " + dataPath; } - if (!FS::ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath)) + if (!FS::ensureFolderPathExists(dataPath)) { - // BAD STUFF. WHAT DO? - m_status = MultiMC::Failed; + showFatalErrorMessage( + "MultiMC data folder could not be created.", + "MultiMC data folder could not be created.\n" + "Make sure you have the right permissions to the MultiMC data folder and any folder needed to access it.\n" + "\n" + "MultiMC cannot continue until you fix this problem." + ); + return; + } + if (!QDir::setCurrent(dataPath)) + { + showFatalErrorMessage( + "MultiMC data folder could not be opened.", + "MultiMC data folder could not be opened.\n" + "Make sure you have the right permissions to the MultiMC data folder.\n" + "\n" + "MultiMC cannot continue until you fix this problem." + ); return; } auto appID = ApplicationId::fromPathAndVersion(QDir::currentPath(), BuildConfig.printableVersionString()); @@ -233,7 +249,19 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) #endif // init the logger - initLogger(); + if(!initLogger()) + { + showFatalErrorMessage( + "MultiMC data folder is not writable!", + "MultiMC couldn't create a log file - the MultiMC data folder is not writable.\n" + "If you are on macOS Sierra, you might have to move MultiMC.app to your /Applications or ~/Applications folder. " + "This usually fixes the problem and you can move the application elsewhere afterwards.\n" + "If you are using any other operating system, make sure you have write permissions to the MultiMC data folder.\n" + "\n" + "MultiMC cannot continue until you fix this problem." + ); + return; + } qDebug() << "MultiMC 5, (c) 2013-2017 MultiMC Contributors"; qDebug() << "Version : " << BuildConfig.printableVersionString(); @@ -354,6 +382,13 @@ void MultiMC::performMainStartupAction() } } +void MultiMC::showFatalErrorMessage(const QString& title, const QString& content) +{ + m_status = MultiMC::Failed; + auto dialog = CustomMessageBox::selectable(nullptr, title, content, QMessageBox::Critical); + dialog->exec(); +} + MultiMC::~MultiMC() { #if defined Q_OS_WIN32 @@ -471,7 +506,7 @@ static void moveFile(const QString &oldName, const QString &newName) QFile::remove(oldName); } -void MultiMC::initLogger() +bool MultiMC::initLogger() { static const QString logBase = "MultiMC-%0.log"; @@ -480,10 +515,14 @@ void MultiMC::initLogger() moveFile(logBase.arg(1), logBase.arg(2)); moveFile(logBase.arg(0), logBase.arg(1)); - qInstallMessageHandler(appDebugOutput); - logFile = std::unique_ptr<QFile>(new QFile(logBase.arg(0))); - logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate); + auto succeeded = logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate); + if(!succeeded) + { + return false; + } + qInstallMessageHandler(appDebugOutput); + return true; } void MultiMC::shutdownLogger() diff --git a/application/MultiMC.h b/application/MultiMC.h index 846bb152..7600a120 100644 --- a/application/MultiMC.h +++ b/application/MultiMC.h @@ -50,6 +50,8 @@ public: enum Status { StartingUp, + UnwritableLog, + FailedShowError, Failed, Succeeded, Initialized @@ -172,7 +174,7 @@ private slots: void setupWizardFinished(int status); private: - void initLogger(); + bool initLogger(); void shutdownLogger(); void initIcons(); void initThemes(); @@ -186,6 +188,9 @@ private: void shutdownAnalytics(); void performMainStartupAction(); + // sets the fatal error message and m_status to Failed. + void showFatalErrorMessage(const QString & title, const QString & content); + private: QDateTime startTime; |