Fix problem with instance list not using the instance folder path
This commit is contained in:
parent
9233477295
commit
6ecb833dbf
@ -32,8 +32,8 @@ using namespace Util::Commandline;
|
|||||||
|
|
||||||
MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
|
MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
|
||||||
{
|
{
|
||||||
setOrganizationName("MultiMC");
|
setOrganizationName("MultiMC");
|
||||||
setApplicationName("MultiMC5");
|
setApplicationName("MultiMC5");
|
||||||
|
|
||||||
initTranslations();
|
initTranslations();
|
||||||
|
|
||||||
@ -139,9 +139,12 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
initGlobalSettings();
|
initGlobalSettings();
|
||||||
|
|
||||||
// and instances
|
// and instances
|
||||||
m_instances.reset(new InstanceList(m_settings->get("InstanceDir").toString(), this));
|
auto InstDirSetting = m_settings->getSetting("InstanceDir");
|
||||||
|
m_instances.reset(new InstanceList(InstDirSetting->get().toString(), this));
|
||||||
QLOG_INFO() << "Loading Instances...";
|
QLOG_INFO() << "Loading Instances...";
|
||||||
m_instances->loadList();
|
m_instances->loadList();
|
||||||
|
connect(InstDirSetting, SIGNAL(settingChanged(const Setting &, QVariant)),
|
||||||
|
m_instances.get(), SLOT(on_InstFolderChanged(const Setting &, QVariant)));
|
||||||
|
|
||||||
// init the http meta cache
|
// init the http meta cache
|
||||||
initHttpMetaCache();
|
initHttpMetaCache();
|
||||||
|
@ -25,6 +25,16 @@ LIBUTIL_EXPORT QString PathCombine(QString path1, QString path2, QString path3);
|
|||||||
|
|
||||||
LIBUTIL_EXPORT QString AbsolutePath(QString path);
|
LIBUTIL_EXPORT QString AbsolutePath(QString path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize path
|
||||||
|
*
|
||||||
|
* Any paths inside the current directory will be normalized to relative paths (to current)
|
||||||
|
* Other paths will be made absolute
|
||||||
|
*
|
||||||
|
* Returns false if the path logic somehow filed (and normalizedPath in invalid)
|
||||||
|
*/
|
||||||
|
QString NormalizePath(QString path);
|
||||||
|
|
||||||
LIBUTIL_EXPORT QString RemoveInvalidFilenameChars(QString string, QChar replaceWith = '-');
|
LIBUTIL_EXPORT QString RemoveInvalidFilenameChars(QString string, QChar replaceWith = '-');
|
||||||
|
|
||||||
LIBUTIL_EXPORT QString DirNameFromString(QString string, QString inDir = ".");
|
LIBUTIL_EXPORT QString DirNameFromString(QString string, QString inDir = ".");
|
||||||
|
@ -39,6 +39,30 @@ QString AbsolutePath(QString path)
|
|||||||
return QFileInfo(path).absolutePath();
|
return QFileInfo(path).absolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize path
|
||||||
|
*
|
||||||
|
* Any paths inside the current directory will be normalized to relative paths (to current)
|
||||||
|
* Other paths will be made absolute
|
||||||
|
*/
|
||||||
|
QString NormalizePath(QString path)
|
||||||
|
{
|
||||||
|
QDir a = QDir::currentPath();
|
||||||
|
QString currentAbsolute = a.absolutePath();
|
||||||
|
|
||||||
|
QDir b(path);
|
||||||
|
QString newAbsolute = b.absolutePath();
|
||||||
|
|
||||||
|
if (newAbsolute.startsWith(currentAbsolute))
|
||||||
|
{
|
||||||
|
return a.relativeFilePath(newAbsolute);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return newAbsolute;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString badFilenameChars = "\"\\/?<>:*|!";
|
QString badFilenameChars = "\"\\/?<>:*|!";
|
||||||
|
|
||||||
QString RemoveInvalidFilenameChars(QString string, QChar replaceWith)
|
QString RemoveInvalidFilenameChars(QString string, QChar replaceWith)
|
||||||
|
@ -22,14 +22,14 @@
|
|||||||
#include "logic/lists/JavaVersionList.h"
|
#include "logic/lists/JavaVersionList.h"
|
||||||
|
|
||||||
#include <settingsobject.h>
|
#include <settingsobject.h>
|
||||||
|
#include <pathutils.h>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
SettingsDialog::SettingsDialog(QWidget *parent) :
|
SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog)
|
||||||
QDialog(parent),
|
|
||||||
ui(new Ui::SettingsDialog)
|
|
||||||
{
|
{
|
||||||
MultiMCPlatform::fixWM_CLASS(this);
|
MultiMCPlatform::fixWM_CLASS(this);
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
loadSettings(MMC->settings().get());
|
loadSettings(MMC->settings().get());
|
||||||
@ -40,7 +40,7 @@ SettingsDialog::~SettingsDialog()
|
|||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
void SettingsDialog::showEvent ( QShowEvent* ev )
|
void SettingsDialog::showEvent(QShowEvent *ev)
|
||||||
{
|
{
|
||||||
QDialog::showEvent(ev);
|
QDialog::showEvent(ev);
|
||||||
adjustSize();
|
adjustSize();
|
||||||
@ -49,15 +49,20 @@ void SettingsDialog::showEvent ( QShowEvent* ev )
|
|||||||
void SettingsDialog::updateCheckboxStuff()
|
void SettingsDialog::updateCheckboxStuff()
|
||||||
{
|
{
|
||||||
ui->windowWidthSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked());
|
ui->windowWidthSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked());
|
||||||
ui->windowHeightSpinBox->setEnabled(! ui->maximizedCheckBox->isChecked());
|
ui->windowHeightSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::on_instDirBrowseBtn_clicked()
|
void SettingsDialog::on_instDirBrowseBtn_clicked()
|
||||||
{
|
{
|
||||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Instance Directory"),
|
QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Instance Directory"),
|
||||||
ui->instDirTextBox->text());
|
ui->instDirTextBox->text());
|
||||||
if (!dir.isEmpty())
|
QString cooked_dir = NormalizePath(raw_dir);
|
||||||
ui->instDirTextBox->setText(dir);
|
|
||||||
|
// do not allow current dir - it's dirty. Do not allow dirs that don't exist
|
||||||
|
if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists())
|
||||||
|
{
|
||||||
|
ui->instDirTextBox->setText(cooked_dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::on_modsDirBrowseBtn_clicked()
|
void SettingsDialog::on_modsDirBrowseBtn_clicked()
|
||||||
@ -65,7 +70,9 @@ void SettingsDialog::on_modsDirBrowseBtn_clicked()
|
|||||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Mods Directory"),
|
QString dir = QFileDialog::getExistingDirectory(this, tr("Mods Directory"),
|
||||||
ui->modsDirTextBox->text());
|
ui->modsDirTextBox->text());
|
||||||
if (!dir.isEmpty())
|
if (!dir.isEmpty())
|
||||||
|
{
|
||||||
ui->modsDirTextBox->setText(dir);
|
ui->modsDirTextBox->setText(dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::on_lwjglDirBrowseBtn_clicked()
|
void SettingsDialog::on_lwjglDirBrowseBtn_clicked()
|
||||||
@ -73,7 +80,9 @@ void SettingsDialog::on_lwjglDirBrowseBtn_clicked()
|
|||||||
QString dir = QFileDialog::getExistingDirectory(this, tr("LWJGL Directory"),
|
QString dir = QFileDialog::getExistingDirectory(this, tr("LWJGL Directory"),
|
||||||
ui->lwjglDirTextBox->text());
|
ui->lwjglDirTextBox->text());
|
||||||
if (!dir.isEmpty())
|
if (!dir.isEmpty())
|
||||||
|
{
|
||||||
ui->lwjglDirTextBox->setText(dir);
|
ui->lwjglDirTextBox->setText(dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::on_compatModeCheckBox_clicked(bool checked)
|
void SettingsDialog::on_compatModeCheckBox_clicked(bool checked)
|
||||||
@ -104,16 +113,16 @@ void SettingsDialog::applySettings(SettingsObject *s)
|
|||||||
}
|
}
|
||||||
else if (!s->get("UseDevBuilds").toBool())
|
else if (!s->get("UseDevBuilds").toBool())
|
||||||
{
|
{
|
||||||
int response = QMessageBox::question(this, tr("Development builds"),
|
int response = QMessageBox::question(
|
||||||
tr("Development builds contain experimental features "
|
this, tr("Development builds"),
|
||||||
"and may be unstable. Are you sure you want to enable them?"));
|
tr("Development builds contain experimental features "
|
||||||
|
"and may be unstable. Are you sure you want to enable them?"));
|
||||||
if (response == QMessageBox::Yes)
|
if (response == QMessageBox::Yes)
|
||||||
{
|
{
|
||||||
s->set("UseDevBuilds", true);
|
s->set("UseDevBuilds", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Updates
|
// Updates
|
||||||
s->set("AutoUpdate", ui->autoUpdateCheckBox->isChecked());
|
s->set("AutoUpdate", ui->autoUpdateCheckBox->isChecked());
|
||||||
|
|
||||||
@ -204,7 +213,7 @@ void SettingsDialog::on_pushButton_clicked()
|
|||||||
void SettingsDialog::on_btnBrowse_clicked()
|
void SettingsDialog::on_btnBrowse_clicked()
|
||||||
{
|
{
|
||||||
QString dir = QFileDialog::getOpenFileName(this, tr("Find Java executable"));
|
QString dir = QFileDialog::getOpenFileName(this, tr("Find Java executable"));
|
||||||
if(!dir.isNull())
|
if (!dir.isNull())
|
||||||
{
|
{
|
||||||
ui->javaPathTextBox->setText(dir);
|
ui->javaPathTextBox->setText(dir);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
const static int GROUP_FILE_FORMAT_VERSION = 1;
|
const static int GROUP_FILE_FORMAT_VERSION = 1;
|
||||||
|
|
||||||
InstanceList::InstanceList(const QString &instDir, QObject *parent)
|
InstanceList::InstanceList(const QString &instDir, QObject *parent)
|
||||||
: QAbstractListModel(parent), m_instDir("instances")
|
: QAbstractListModel(parent), m_instDir(instDir)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,8 +196,8 @@ void InstanceList::loadGroupList(QMap<QString, QString> &groupMap)
|
|||||||
if (error.error != QJsonParseError::NoError)
|
if (error.error != QJsonParseError::NoError)
|
||||||
{
|
{
|
||||||
QLOG_ERROR() << QString("Failed to parse instance group file: %1 at offset %2")
|
QLOG_ERROR() << QString("Failed to parse instance group file: %1 at offset %2")
|
||||||
.arg(error.errorString(), QString::number(error.offset))
|
.arg(error.errorString(), QString::number(error.offset))
|
||||||
.toUtf8();
|
.toUtf8();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,7 +269,8 @@ InstanceList::InstListError InstanceList::loadList()
|
|||||||
|
|
||||||
m_instances.clear();
|
m_instances.clear();
|
||||||
QDir dir(m_instDir);
|
QDir dir(m_instDir);
|
||||||
QDirIterator iter(dir);
|
QDirIterator iter(m_instDir, QDir::Dirs | QDir::NoDot | QDir::NoDotDot | QDir::Readable,
|
||||||
|
QDirIterator::FollowSymlinks);
|
||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
QString subDir = iter.next();
|
QString subDir = iter.next();
|
||||||
@ -340,7 +341,12 @@ void InstanceList::clear()
|
|||||||
endResetModel();
|
endResetModel();
|
||||||
emit dataIsInvalid();
|
emit dataIsInvalid();
|
||||||
}
|
}
|
||||||
;
|
|
||||||
|
void InstanceList::on_InstFolderChanged(const Setting &setting, QVariant value)
|
||||||
|
{
|
||||||
|
m_instDir = value.toString();
|
||||||
|
loadList();
|
||||||
|
}
|
||||||
|
|
||||||
/// Add an instance. Triggers notifications, returns the new index
|
/// Add an instance. Triggers notifications, returns the new index
|
||||||
int InstanceList::add(InstancePtr t)
|
int InstanceList::add(InstancePtr t)
|
||||||
|
@ -29,7 +29,7 @@ class InstanceList : public QAbstractListModel
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
void loadGroupList(QMap<QString, QString> & groupList);
|
void loadGroupList(QMap<QString, QString> &groupList);
|
||||||
void saveGroupList();
|
void saveGroupList();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -37,10 +37,10 @@ public:
|
|||||||
virtual ~InstanceList();
|
virtual ~InstanceList();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QModelIndex index ( int row, int column = 0, const QModelIndex& parent = QModelIndex() ) const;
|
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
|
||||||
int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
QVariant data ( const QModelIndex& index, int role ) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
Qt::ItemFlags flags ( const QModelIndex& index ) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
|
||||||
enum AdditionalRoles
|
enum AdditionalRoles
|
||||||
{
|
{
|
||||||
@ -57,7 +57,10 @@ public:
|
|||||||
UnknownError
|
UnknownError
|
||||||
};
|
};
|
||||||
|
|
||||||
QString instDir() const { return m_instDir; }
|
QString instDir() const
|
||||||
|
{
|
||||||
|
return m_instDir;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Loads the instance list. Triggers notifications.
|
* \brief Loads the instance list. Triggers notifications.
|
||||||
@ -70,7 +73,8 @@ public:
|
|||||||
InstancePtr at(int i) const
|
InstancePtr at(int i) const
|
||||||
{
|
{
|
||||||
return m_instances.at(i);
|
return m_instances.at(i);
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Get the count of loaded instances
|
* \brief Get the count of loaded instances
|
||||||
@ -78,7 +82,8 @@ public:
|
|||||||
int count() const
|
int count() const
|
||||||
{
|
{
|
||||||
return m_instances.count();
|
return m_instances.count();
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
/// Clear all instances. Triggers notifications.
|
/// Clear all instances. Triggers notifications.
|
||||||
void clear();
|
void clear();
|
||||||
@ -87,27 +92,33 @@ public:
|
|||||||
int add(InstancePtr t);
|
int add(InstancePtr t);
|
||||||
|
|
||||||
/// Get an instance by ID
|
/// Get an instance by ID
|
||||||
InstancePtr getInstanceById (QString id);
|
InstancePtr getInstanceById(QString id);
|
||||||
signals:
|
signals:
|
||||||
void dataIsInvalid();
|
void dataIsInvalid();
|
||||||
|
|
||||||
private slots:
|
public
|
||||||
void propertiesChanged(BaseInstance * inst);
|
slots:
|
||||||
void instanceNuked(BaseInstance * inst);
|
void on_InstFolderChanged(const Setting & setting, QVariant value);
|
||||||
|
|
||||||
|
private
|
||||||
|
slots:
|
||||||
|
void propertiesChanged(BaseInstance *inst);
|
||||||
|
void instanceNuked(BaseInstance *inst);
|
||||||
void groupChanged();
|
void groupChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int getInstIndex(BaseInstance * inst);
|
int getInstIndex(BaseInstance *inst);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_instDir;
|
QString m_instDir;
|
||||||
QList< InstancePtr > m_instances;
|
QList<InstancePtr> m_instances;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InstanceProxyModel : public KCategorizedSortFilterProxyModel
|
class InstanceProxyModel : public KCategorizedSortFilterProxyModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit InstanceProxyModel ( QObject *parent = 0 );
|
explicit InstanceProxyModel(QObject *parent = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool subSortLessThan ( const QModelIndex& left, const QModelIndex& right ) const;
|
virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user