diff options
Diffstat (limited to 'logic/lists/InstanceList.cpp')
-rw-r--r-- | logic/lists/InstanceList.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp index b9595578..15fd10ba 100644 --- a/logic/lists/InstanceList.cpp +++ b/logic/lists/InstanceList.cpp @@ -36,11 +36,16 @@ const static int GROUP_FILE_FORMAT_VERSION = 1; InstanceList::InstanceList(const QString &instDir, QObject *parent) : QAbstractListModel(parent), m_instDir(instDir) { + connect(MMC, &MultiMC::aboutToQuit, this, &InstanceList::saveGroupList); + + if (!QDir::current().exists(m_instDir)) + { + QDir::current().mkpath(m_instDir); + } } InstanceList::~InstanceList() { - saveGroupList(); } int InstanceList::rowCount(const QModelIndex &parent) const @@ -112,6 +117,11 @@ void InstanceList::groupChanged() saveGroupList(); } +QStringList InstanceList::getGroups() +{ + return m_groups.toList(); +} + void InstanceList::saveGroupList() { QString groupFileName = m_instDir + "/instgroups.json"; @@ -121,7 +131,7 @@ void InstanceList::saveGroupList() if (!groupFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { // An error occurred. Ignore it. - QLOG_ERROR() << "Failed to read instance group file."; + QLOG_ERROR() << "Failed to save instance group file."; return; } QTextStream out(&groupFile); @@ -132,6 +142,10 @@ void InstanceList::saveGroupList() QString group = instance->group(); if (group.isEmpty()) continue; + + // keep a list/set of groups for choosing + m_groups.insert(group); + if (!groupMap.count(group)) { QSet<QString> set; @@ -248,6 +262,9 @@ void InstanceList::loadGroupList(QMap<QString, QString> &groupMap) continue; } + // keep a list/set of groups for choosing + m_groups.insert(groupName); + // Iterate through the list of instances in the group. QJsonArray instancesArray = groupObj.value("instances").toArray(); |