GH-2059 fix instance directory not being created on first launch

This commit is contained in:
Petr Mrázek 2017-12-05 09:52:04 +01:00
parent 44475350eb
commit 6d034bda82
4 changed files with 10 additions and 14 deletions

View File

@ -34,12 +34,13 @@ struct WatchLock
FolderInstanceProvider::FolderInstanceProvider(SettingsObjectPtr settings, const QString& instDir) FolderInstanceProvider::FolderInstanceProvider(SettingsObjectPtr settings, const QString& instDir)
: BaseInstanceProvider(settings) : BaseInstanceProvider(settings)
{ {
// Normalize path // Create aand normalize path
m_instDir = QDir(instDir).canonicalPath(); if (!QDir::current().exists(instDir))
if (!QDir::current().exists(m_instDir))
{ {
QDir::current().mkpath(m_instDir); QDir::current().mkpath(instDir);
} }
// NOTE: canonicalPath requires the path to exist. Do not move this above the creation block!
m_instDir = QDir(instDir).canonicalPath();
m_watcher = new QFileSystemWatcher(this); m_watcher = new QFileSystemWatcher(this);
connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &FolderInstanceProvider::instanceDirContentsChanged); connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &FolderInstanceProvider::instanceDirContentsChanged);
m_watcher->addPath(m_instDir); m_watcher->addPath(m_instDir);

View File

@ -26,10 +26,9 @@
#include "FolderInstanceProvider.h" #include "FolderInstanceProvider.h"
InstanceList::InstanceList(SettingsObjectPtr globalSettings, const QString &instDir, QObject *parent) InstanceList::InstanceList(QObject *parent)
: QAbstractListModel(parent), m_instDir(instDir) : QAbstractListModel(parent)
{ {
m_globalSettings = globalSettings;
resumeWatch(); resumeWatch();
} }

View File

@ -27,16 +27,14 @@
#include "QObjectPtr.h" #include "QObjectPtr.h"
class QFileSystemWatcher;
class BaseInstance; class BaseInstance;
class QDir;
class MULTIMC_LOGIC_EXPORT InstanceList : public QAbstractListModel class MULTIMC_LOGIC_EXPORT InstanceList : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit InstanceList(SettingsObjectPtr globalSettings, const QString &instDir, QObject *parent = 0); explicit InstanceList(QObject *parent = 0);
virtual ~InstanceList(); virtual ~InstanceList();
public: public:
@ -101,9 +99,7 @@ private:
protected: protected:
int m_watchLevel = 0; int m_watchLevel = 0;
QSet<BaseInstanceProvider *> m_updatedProviders; QSet<BaseInstanceProvider *> m_updatedProviders;
QString m_instDir;
QList<InstancePtr> m_instances; QList<InstancePtr> m_instances;
QSet<QString> m_groups; QSet<QString> m_groups;
SettingsObjectPtr m_globalSettings;
QVector<shared_qobject_ptr<BaseInstanceProvider>> m_providers; QVector<shared_qobject_ptr<BaseInstanceProvider>> m_providers;
}; };

View File

@ -584,13 +584,13 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
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 // 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) // and rememer that we have to show him a dialog when the gui starts (if it does so)
QString instDir = m_settings->get("InstanceDir").toString(); QString instDir = InstDirSetting->get().toString();
qDebug() << "Instance path : " << instDir; qDebug() << "Instance path : " << instDir;
if (FS::checkProblemticPathJava(QDir(instDir))) if (FS::checkProblemticPathJava(QDir(instDir)))
{ {
qWarning() << "Your instance path contains \'!\' and this is known to cause java problems"; qWarning() << "Your instance path contains \'!\' and this is known to cause java problems";
} }
m_instances.reset(new InstanceList(m_settings, InstDirSetting->get().toString(), this)); m_instances.reset(new InstanceList(this));
m_instanceFolder = new FolderInstanceProvider(m_settings, instDir); m_instanceFolder = new FolderInstanceProvider(m_settings, instDir);
connect(InstDirSetting.get(), &Setting::SettingChanged, m_instanceFolder, &FolderInstanceProvider::on_InstFolderChanged); connect(InstDirSetting.get(), &Setting::SettingChanged, m_instanceFolder, &FolderInstanceProvider::on_InstFolderChanged);
m_instances->addInstanceProvider(m_instanceFolder); m_instances->addInstanceProvider(m_instanceFolder);