Merge branch 'Loetkolben-pr_feature_warnProblematicInstPath' into develop

Closes #400
This commit is contained in:
Jan Dalheimer 2014-07-30 21:45:12 +02:00
commit 21597da33d
7 changed files with 116 additions and 52 deletions

View File

@ -54,8 +54,7 @@ static const int APPDATA_BUFFER_SIZE = 1024;
using namespace Util::Commandline; using namespace Util::Commandline;
MultiMC::MultiMC(int &argc, char **argv, bool root_override) MultiMC::MultiMC(int &argc, char **argv, bool root_override) : QApplication(argc, argv)
: QApplication(argc, argv)
{ {
setOrganizationName("MultiMC"); setOrganizationName("MultiMC");
setApplicationName("MultiMC5"); setApplicationName("MultiMC5");
@ -139,7 +138,7 @@ MultiMC::MultiMC(int &argc, char **argv, bool root_override)
adjustedBy += "Fallback to binary path " + dataPath; adjustedBy += "Fallback to binary path " + dataPath;
} }
if(!ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath)) if (!ensureFolderPathExists(dataPath) || !QDir::setCurrent(dataPath))
{ {
// BAD STUFF. WHAT DO? // BAD STUFF. WHAT DO?
initLogger(); initLogger();
@ -154,27 +153,27 @@ MultiMC::MultiMC(int &argc, char **argv, bool root_override)
} }
else else
{ {
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QDir foo(PathCombine(binPath, "..")); QDir foo(PathCombine(binPath, ".."));
rootPath = foo.absolutePath(); rootPath = foo.absolutePath();
#elif defined(Q_OS_WIN32) #elif defined(Q_OS_WIN32)
rootPath = binPath; rootPath = binPath;
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
QDir foo(PathCombine(binPath, "../..")); QDir foo(PathCombine(binPath, "../.."));
rootPath = foo.absolutePath(); rootPath = foo.absolutePath();
#endif #endif
} }
// static data paths... mostly just for translations // static data paths... mostly just for translations
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QDir foo(PathCombine(binPath, "..")); QDir foo(PathCombine(binPath, ".."));
staticDataPath = foo.absolutePath(); staticDataPath = foo.absolutePath();
#elif defined(Q_OS_WIN32) #elif defined(Q_OS_WIN32)
staticDataPath = binPath; staticDataPath = binPath;
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
QDir foo(PathCombine(rootPath, "Contents/Resources")); QDir foo(PathCombine(rootPath, "Contents/Resources"));
staticDataPath = foo.absolutePath(); staticDataPath = foo.absolutePath();
#endif #endif
// init the logger // init the logger
initLogger(); initLogger();
@ -216,6 +215,15 @@ MultiMC::MultiMC(int &argc, char **argv, bool root_override)
// and instances // and instances
auto InstDirSetting = m_settings->getSetting("InstanceDir"); auto InstDirSetting = m_settings->getSetting("InstanceDir");
// instance path: check for problems with '!' in instance path and warn the user in the log
// and rememer that we have to show him a dialog when the gui starts (if it does so)
QString instDir = MMC->settings()->get("InstanceDir").toString();
QLOG_INFO() << "Instance path : " << instDir;
if (checkProblemticPathJava(QDir(instDir)))
{
QLOG_WARN()
<< "Your instance path contains \'!\' and this is known to cause java problems";
}
m_instances.reset(new InstanceList(InstDirSetting->get().toString(), this)); m_instances.reset(new InstanceList(InstDirSetting->get().toString(), this));
QLOG_INFO() << "Loading Instances..."; QLOG_INFO() << "Loading Instances...";
m_instances->loadList(); m_instances->loadList();
@ -245,8 +253,7 @@ MultiMC::MultiMC(int &argc, char **argv, bool root_override)
{ {
profiler->registerSettings(m_settings.get()); profiler->registerSettings(m_settings.get());
} }
m_tools.insert("mcedit", m_tools.insert("mcedit", std::shared_ptr<BaseDetachedToolFactory>(new MCEditFactory()));
std::shared_ptr<BaseDetachedToolFactory>(new MCEditFactory()));
for (auto tool : m_tools.values()) for (auto tool : m_tools.values())
{ {
tool->registerSettings(m_settings.get()); tool->registerSettings(m_settings.get());
@ -374,7 +381,9 @@ void MultiMC::initGlobalSettings()
QString ftbDefault, newFtbDefault, oldFtbDefault; QString ftbDefault, newFtbDefault, oldFtbDefault;
if (!GetEnvironmentVariableW(L"LOCALAPPDATA", newBuf, APPDATA_BUFFER_SIZE)) if (!GetEnvironmentVariableW(L"LOCALAPPDATA", newBuf, APPDATA_BUFFER_SIZE))
{ {
QLOG_FATAL() << "Your LOCALAPPDATA folder is missing! If you are on windows, this means your system is broken. If you aren't on windows, how the **** are you running the windows build????"; QLOG_FATAL() << "Your LOCALAPPDATA folder is missing! If you are on windows, this "
"means your system is broken. If you aren't on windows, how the **** "
"are you running the windows build????";
} }
else else
{ {
@ -382,7 +391,9 @@ void MultiMC::initGlobalSettings()
} }
if (!GetEnvironmentVariableW(L"APPDATA", buf, APPDATA_BUFFER_SIZE)) if (!GetEnvironmentVariableW(L"APPDATA", buf, APPDATA_BUFFER_SIZE))
{ {
QLOG_FATAL() << "Your APPDATA folder is missing! If you are on windows, this means your system is broken. If you aren't on windows, how the **** are you running the windows build????"; QLOG_FATAL() << "Your APPDATA folder is missing! If you are on windows, this means "
"your system is broken. If you aren't on windows, how the **** are you "
"running the windows build????";
} }
else else
{ {
@ -405,10 +416,8 @@ void MultiMC::initGlobalSettings()
#endif #endif
m_settings->registerSetting("FTBLauncherDataRoot", ftbDataDefault); m_settings->registerSetting("FTBLauncherDataRoot", ftbDataDefault);
m_settings->registerSetting("FTBLauncherRoot", ftbDefault); m_settings->registerSetting("FTBLauncherRoot", ftbDefault);
QLOG_INFO() << "FTB Launcher paths:" QLOG_INFO() << "FTB Launcher paths:" << m_settings->get("FTBLauncherDataRoot").toString()
<< m_settings->get("FTBLauncherDataRoot").toString() << "and" << m_settings->get("FTBLauncherRoot").toString();
<< "and"
<< m_settings->get("FTBLauncherRoot").toString();
m_settings->registerSetting("FTBRoot"); m_settings->registerSetting("FTBRoot");
if (m_settings->get("FTBRoot").isNull()) if (m_settings->get("FTBRoot").isNull())
@ -544,11 +553,13 @@ void MultiMC::updateProxySettings()
// Set the application proxy settings. // Set the application proxy settings.
if (proxyTypeStr == "SOCKS5") if (proxyTypeStr == "SOCKS5")
{ {
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, addr, port, user, pass)); QNetworkProxy::setApplicationProxy(
QNetworkProxy(QNetworkProxy::Socks5Proxy, addr, port, user, pass));
} }
else if (proxyTypeStr == "HTTP") else if (proxyTypeStr == "HTTP")
{ {
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, addr, port, user, pass)); QNetworkProxy::setApplicationProxy(
QNetworkProxy(QNetworkProxy::HttpProxy, addr, port, user, pass));
} }
else if (proxyTypeStr == "None") else if (proxyTypeStr == "None")
{ {
@ -563,7 +574,8 @@ void MultiMC::updateProxySettings()
QLOG_INFO() << "Detecting proxy settings..."; QLOG_INFO() << "Detecting proxy settings...";
QNetworkProxy proxy = QNetworkProxy::applicationProxy(); QNetworkProxy proxy = QNetworkProxy::applicationProxy();
if (m_qnam.get()) m_qnam->setProxy(proxy); if (m_qnam.get())
m_qnam->setProxy(proxy);
QString proxyDesc; QString proxyDesc;
if (proxy.type() == QNetworkProxy::NoProxy) if (proxy.type() == QNetworkProxy::NoProxy)
{ {
@ -662,35 +674,34 @@ std::shared_ptr<URNResolver> MultiMC::resolver()
return m_resolver; return m_resolver;
} }
void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags) void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags)
{ {
// if we are going to update on exit, save the params now // if we are going to update on exit, save the params now
if(flags & OnExit) if (flags & OnExit)
{ {
m_updateOnExitPath = updateFilesDir; m_updateOnExitPath = updateFilesDir;
m_updateOnExitFlags = flags & ~OnExit; m_updateOnExitFlags = flags & ~OnExit;
return; return;
} }
// otherwise if there already were some params for on exit update, clear them and continue // otherwise if there already were some params for on exit update, clear them and continue
else if(m_updateOnExitPath.size()) else if (m_updateOnExitPath.size())
{ {
m_updateOnExitFlags = None; m_updateOnExitFlags = None;
m_updateOnExitPath.clear(); m_updateOnExitPath.clear();
} }
QLOG_INFO() << "Installing updates."; QLOG_INFO() << "Installing updates.";
#ifdef WINDOWS #ifdef WINDOWS
QString finishCmd = MMC->applicationFilePath(); QString finishCmd = MMC->applicationFilePath();
QString updaterBinary = PathCombine(bin(), "updater.exe"); QString updaterBinary = PathCombine(bin(), "updater.exe");
#elif LINUX #elif LINUX
QString finishCmd = PathCombine(root(), "MultiMC"); QString finishCmd = PathCombine(root(), "MultiMC");
QString updaterBinary = PathCombine(bin(), "updater"); QString updaterBinary = PathCombine(bin(), "updater");
#elif OSX #elif OSX
QString finishCmd = MMC->applicationFilePath(); QString finishCmd = MMC->applicationFilePath();
QString updaterBinary = PathCombine(bin(), "updater"); QString updaterBinary = PathCombine(bin(), "updater");
#else #else
#error Unsupported operating system. #error Unsupported operating system.
#endif #endif
QStringList args; QStringList args;
// ./updater --install-dir $INSTALL_DIR --package-dir $UPDATEFILES_DIR --script // ./updater --install-dir $INSTALL_DIR --package-dir $UPDATEFILES_DIR --script
@ -699,7 +710,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags)
args << "--package-dir" << updateFilesDir; args << "--package-dir" << updateFilesDir;
args << "--script" << PathCombine(updateFilesDir, "file_list.xml"); args << "--script" << PathCombine(updateFilesDir, "file_list.xml");
args << "--wait" << QString::number(MMC->applicationPid()); args << "--wait" << QString::number(MMC->applicationPid());
if(flags & DryRun) if (flags & DryRun)
args << "--dry-run"; args << "--dry-run";
if (flags & RestartOnFinish) if (flags & RestartOnFinish)
{ {
@ -709,7 +720,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags)
QLOG_INFO() << "Running updater with command" << updaterBinary << args.join(" "); QLOG_INFO() << "Running updater with command" << updaterBinary << args.join(" ");
QFile::setPermissions(updaterBinary, (QFileDevice::Permission)0x7755); QFile::setPermissions(updaterBinary, (QFileDevice::Permission)0x7755);
if (!QProcess::startDetached(updaterBinary, args/*, root()*/)) if (!QProcess::startDetached(updaterBinary, args /*, root()*/))
{ {
QLOG_ERROR() << "Failed to start the updater process!"; QLOG_ERROR() << "Failed to start the updater process!";
return; return;
@ -721,7 +732,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags)
void MultiMC::onExit() void MultiMC::onExit()
{ {
if(m_updateOnExitPath.size()) if (m_updateOnExitPath.size())
{ {
installUpdates(m_updateOnExitPath, m_updateOnExitFlags); installUpdates(m_updateOnExitPath, m_updateOnExitFlags);
} }

View File

@ -16,6 +16,7 @@
#pragma once #pragma once
#include <QString> #include <QString>
#include <QDir>
#include "libutil_config.h" #include "libutil_config.h"
@ -57,3 +58,6 @@ LIBUTIL_EXPORT void openFileInDefaultProgram(QString filename);
/// Opens the given directory in the default application. /// Opens the given directory in the default application.
LIBUTIL_EXPORT void openDirInDefaultProgram(QString dirpath, bool ensureExists = false); LIBUTIL_EXPORT void openDirInDefaultProgram(QString dirpath, bool ensureExists = false);
/// Checks if the a given Path contains "!"
LIBUTIL_EXPORT bool checkProblemticPathJava(QDir folder);

View File

@ -144,3 +144,11 @@ void openFileInDefaultProgram(QString filename)
{ {
QDesktopServices::openUrl(QUrl::fromLocalFile(filename)); QDesktopServices::openUrl(QUrl::fromLocalFile(filename));
} }
// Does the directory path contain any '!'? If yes, return true, otherwise false.
// (This is a problem for Java)
bool checkProblemticPathJava(QDir folder)
{
QString pathfoldername = folder.absolutePath();
return pathfoldername.contains("!", Qt::CaseInsensitive);
}

View File

@ -1533,3 +1533,21 @@ void MainWindow::checkSetDefaultJava()
MMC->settings()->set("JavaPath", QString("java")); MMC->settings()->set("JavaPath", QString("java"));
} }
} }
void MainWindow::checkInstancePathForProblems()
{
QString instanceFolder = MMC->settings()->get("InstanceDir").toString();
if (checkProblemticPathJava(QDir(instanceFolder)))
{
QMessageBox warning;
warning.setText(tr(
"Your instance folder contains \'!\' and this is known to cause Java problems!"));
warning.setInformativeText(
tr("You have now three options: <br/>"
" - ignore this warning <br/>"
" - change the instance dir in the settings <br/>"
" - move this installation of MultiMC5 to a different folder"));
warning.setDefaultButton(QMessageBox::Ok);
warning.exec();
}
}

View File

@ -52,6 +52,7 @@ public:
void checkSetDefaultJava(); void checkSetDefaultJava();
void checkMigrateLegacyAssets(); void checkMigrateLegacyAssets();
void checkInstancePathForProblems();
private private
slots: slots:

View File

@ -118,10 +118,31 @@ void MultiMCPage::on_instDirBrowseBtn_clicked()
// do not allow current dir - it's dirty. Do not allow dirs that don't exist // do not allow current dir - it's dirty. Do not allow dirs that don't exist
if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists())
{
if (checkProblemticPathJava(QDir(cooked_dir)))
{
QMessageBox warning;
warning.setText(tr("You're trying to specify an instance folder which\'s path "
"contains at least one \'!\'. "
"Java is known to cause problems if that is the case, your "
"instances (probably) won't start!"));
warning.setInformativeText(
tr("Do you really want to use this path? "
"Selecting \"No\" will close this and not alter your instance path."));
warning.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
int result = warning.exec();
if (result == QMessageBox::Yes)
{ {
ui->instDirTextBox->setText(cooked_dir); ui->instDirTextBox->setText(cooked_dir);
} }
}
else
{
ui->instDirTextBox->setText(cooked_dir);
}
}
} }
void MultiMCPage::on_iconsDirBrowseBtn_clicked() void MultiMCPage::on_iconsDirBrowseBtn_clicked()
{ {
QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Icons Directory"), QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Icons Directory"),

View File

@ -17,6 +17,7 @@ int main_gui(MultiMC &app)
mainWin.show(); mainWin.show();
mainWin.checkMigrateLegacyAssets(); mainWin.checkMigrateLegacyAssets();
mainWin.checkSetDefaultJava(); mainWin.checkSetDefaultJava();
mainWin.checkInstancePathForProblems();
return app.exec(); return app.exec();
} }