summaryrefslogtreecommitdiffstats
path: root/application/MultiMC.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-01-14 15:47:58 +0100
committerPetr Mrázek <peterix@gmail.com>2017-01-14 15:47:58 +0100
commita6ef0059cced7f2736d0800c54c238d4d6511575 (patch)
tree967355800e01119ddc5be5d9e979ae7427661131 /application/MultiMC.cpp
parent3e81e2cb5b5d00c8f73c479cf9190131a3041f35 (diff)
downloadMultiMC-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/MultiMC.cpp')
-rw-r--r--application/MultiMC.cpp57
1 files changed, 48 insertions, 9 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()