Fix problem with instance list not using the instance folder path
This commit is contained in:
parent
9233477295
commit
6ecb833dbf
@ -139,9 +139,12 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
|
||||
initGlobalSettings();
|
||||
|
||||
// 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...";
|
||||
m_instances->loadList();
|
||||
connect(InstDirSetting, SIGNAL(settingChanged(const Setting &, QVariant)),
|
||||
m_instances.get(), SLOT(on_InstFolderChanged(const Setting &, QVariant)));
|
||||
|
||||
// init the http meta cache
|
||||
initHttpMetaCache();
|
||||
|
@ -25,6 +25,16 @@ LIBUTIL_EXPORT QString PathCombine(QString path1, QString path2, QString path3);
|
||||
|
||||
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 DirNameFromString(QString string, QString inDir = ".");
|
||||
|
@ -39,6 +39,30 @@ QString AbsolutePath(QString path)
|
||||
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 RemoveInvalidFilenameChars(QString string, QChar replaceWith)
|
||||
|
@ -22,12 +22,12 @@
|
||||
#include "logic/lists/JavaVersionList.h"
|
||||
|
||||
#include <settingsobject.h>
|
||||
#include <pathutils.h>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QDir>
|
||||
|
||||
SettingsDialog::SettingsDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::SettingsDialog)
|
||||
SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog)
|
||||
{
|
||||
MultiMCPlatform::fixWM_CLASS(this);
|
||||
ui->setupUi(this);
|
||||
@ -40,7 +40,7 @@ SettingsDialog::~SettingsDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
void SettingsDialog::showEvent ( QShowEvent* ev )
|
||||
void SettingsDialog::showEvent(QShowEvent *ev)
|
||||
{
|
||||
QDialog::showEvent(ev);
|
||||
adjustSize();
|
||||
@ -49,15 +49,20 @@ void SettingsDialog::showEvent ( QShowEvent* ev )
|
||||
void SettingsDialog::updateCheckboxStuff()
|
||||
{
|
||||
ui->windowWidthSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked());
|
||||
ui->windowHeightSpinBox->setEnabled(! ui->maximizedCheckBox->isChecked());
|
||||
ui->windowHeightSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked());
|
||||
}
|
||||
|
||||
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());
|
||||
if (!dir.isEmpty())
|
||||
ui->instDirTextBox->setText(dir);
|
||||
QString cooked_dir = NormalizePath(raw_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()
|
||||
@ -65,7 +70,9 @@ void SettingsDialog::on_modsDirBrowseBtn_clicked()
|
||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Mods Directory"),
|
||||
ui->modsDirTextBox->text());
|
||||
if (!dir.isEmpty())
|
||||
{
|
||||
ui->modsDirTextBox->setText(dir);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::on_lwjglDirBrowseBtn_clicked()
|
||||
@ -73,7 +80,9 @@ void SettingsDialog::on_lwjglDirBrowseBtn_clicked()
|
||||
QString dir = QFileDialog::getExistingDirectory(this, tr("LWJGL Directory"),
|
||||
ui->lwjglDirTextBox->text());
|
||||
if (!dir.isEmpty())
|
||||
{
|
||||
ui->lwjglDirTextBox->setText(dir);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::on_compatModeCheckBox_clicked(bool checked)
|
||||
@ -104,7 +113,8 @@ void SettingsDialog::applySettings(SettingsObject *s)
|
||||
}
|
||||
else if (!s->get("UseDevBuilds").toBool())
|
||||
{
|
||||
int response = QMessageBox::question(this, tr("Development builds"),
|
||||
int response = QMessageBox::question(
|
||||
this, tr("Development builds"),
|
||||
tr("Development builds contain experimental features "
|
||||
"and may be unstable. Are you sure you want to enable them?"));
|
||||
if (response == QMessageBox::Yes)
|
||||
@ -113,7 +123,6 @@ void SettingsDialog::applySettings(SettingsObject *s)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Updates
|
||||
s->set("AutoUpdate", ui->autoUpdateCheckBox->isChecked());
|
||||
|
||||
@ -204,7 +213,7 @@ void SettingsDialog::on_pushButton_clicked()
|
||||
void SettingsDialog::on_btnBrowse_clicked()
|
||||
{
|
||||
QString dir = QFileDialog::getOpenFileName(this, tr("Find Java executable"));
|
||||
if(!dir.isNull())
|
||||
if (!dir.isNull())
|
||||
{
|
||||
ui->javaPathTextBox->setText(dir);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@
|
||||
const static int GROUP_FILE_FORMAT_VERSION = 1;
|
||||
|
||||
InstanceList::InstanceList(const QString &instDir, QObject *parent)
|
||||
: QAbstractListModel(parent), m_instDir("instances")
|
||||
: QAbstractListModel(parent), m_instDir(instDir)
|
||||
{
|
||||
}
|
||||
|
||||
@ -269,7 +269,8 @@ InstanceList::InstListError InstanceList::loadList()
|
||||
|
||||
m_instances.clear();
|
||||
QDir dir(m_instDir);
|
||||
QDirIterator iter(dir);
|
||||
QDirIterator iter(m_instDir, QDir::Dirs | QDir::NoDot | QDir::NoDotDot | QDir::Readable,
|
||||
QDirIterator::FollowSymlinks);
|
||||
while (iter.hasNext())
|
||||
{
|
||||
QString subDir = iter.next();
|
||||
@ -340,7 +341,12 @@ void InstanceList::clear()
|
||||
endResetModel();
|
||||
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
|
||||
int InstanceList::add(InstancePtr t)
|
||||
|
@ -29,7 +29,7 @@ class InstanceList : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
void loadGroupList(QMap<QString, QString> & groupList);
|
||||
void loadGroupList(QMap<QString, QString> &groupList);
|
||||
void saveGroupList();
|
||||
|
||||
public:
|
||||
@ -37,10 +37,10 @@ public:
|
||||
virtual ~InstanceList();
|
||||
|
||||
public:
|
||||
QModelIndex index ( int row, int column = 0, const QModelIndex& parent = QModelIndex() ) const;
|
||||
int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
|
||||
QVariant data ( const QModelIndex& index, int role ) const;
|
||||
Qt::ItemFlags flags ( const QModelIndex& index ) const;
|
||||
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
||||
enum AdditionalRoles
|
||||
{
|
||||
@ -57,7 +57,10 @@ public:
|
||||
UnknownError
|
||||
};
|
||||
|
||||
QString instDir() const { return m_instDir; }
|
||||
QString instDir() const
|
||||
{
|
||||
return m_instDir;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the instance list. Triggers notifications.
|
||||
@ -70,7 +73,8 @@ public:
|
||||
InstancePtr at(int i) const
|
||||
{
|
||||
return m_instances.at(i);
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
/*!
|
||||
* \brief Get the count of loaded instances
|
||||
@ -78,7 +82,8 @@ public:
|
||||
int count() const
|
||||
{
|
||||
return m_instances.count();
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
/// Clear all instances. Triggers notifications.
|
||||
void clear();
|
||||
@ -87,27 +92,33 @@ public:
|
||||
int add(InstancePtr t);
|
||||
|
||||
/// Get an instance by ID
|
||||
InstancePtr getInstanceById (QString id);
|
||||
InstancePtr getInstanceById(QString id);
|
||||
signals:
|
||||
void dataIsInvalid();
|
||||
|
||||
private slots:
|
||||
void propertiesChanged(BaseInstance * inst);
|
||||
void instanceNuked(BaseInstance * inst);
|
||||
public
|
||||
slots:
|
||||
void on_InstFolderChanged(const Setting & setting, QVariant value);
|
||||
|
||||
private
|
||||
slots:
|
||||
void propertiesChanged(BaseInstance *inst);
|
||||
void instanceNuked(BaseInstance *inst);
|
||||
void groupChanged();
|
||||
|
||||
private:
|
||||
int getInstIndex(BaseInstance * inst);
|
||||
int getInstIndex(BaseInstance *inst);
|
||||
|
||||
protected:
|
||||
QString m_instDir;
|
||||
QList< InstancePtr > m_instances;
|
||||
QList<InstancePtr> m_instances;
|
||||
};
|
||||
|
||||
class InstanceProxyModel : public KCategorizedSortFilterProxyModel
|
||||
{
|
||||
public:
|
||||
explicit InstanceProxyModel ( QObject *parent = 0 );
|
||||
explicit InstanceProxyModel(QObject *parent = 0);
|
||||
|
||||
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