summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-10-05 23:48:38 +0200
committerPetr Mrázek <peterix@gmail.com>2015-10-05 23:48:38 +0200
commit439c6b43a3432e604afbcef74c36ae5fb73de12b (patch)
tree863283bb9615c02167d48e68d0560720bb127b81
parentdb926a546e2c58227ab1dcb129b056213d33d6f5 (diff)
downloadMultiMC-439c6b43a3432e604afbcef74c36ae5fb73de12b.tar
MultiMC-439c6b43a3432e604afbcef74c36ae5fb73de12b.tar.gz
MultiMC-439c6b43a3432e604afbcef74c36ae5fb73de12b.tar.lz
MultiMC-439c6b43a3432e604afbcef74c36ae5fb73de12b.tar.xz
MultiMC-439c6b43a3432e604afbcef74c36ae5fb73de12b.zip
GH-1268 simplify and fix instance group file IO
-rw-r--r--logic/InstanceList.cpp32
1 files changed, 9 insertions, 23 deletions
diff --git a/logic/InstanceList.cpp b/logic/InstanceList.cpp
index c3a6a9c4..3644e828 100644
--- a/logic/InstanceList.cpp
+++ b/logic/InstanceList.cpp
@@ -135,16 +135,6 @@ QStringList InstanceList::getGroups()
void InstanceList::saveGroupList()
{
QString groupFileName = m_instDir + "/instgroups.json";
- QFile groupFile(groupFileName);
-
- // if you can't open the file, fail
- if (!groupFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
- {
- // An error occurred. Ignore it.
- qCritical() << "Failed to save instance group file.";
- return;
- }
- QTextStream out(&groupFile);
QMap<QString, QSet<QString>> groupMap;
for (auto instance : m_instances)
{
@@ -187,8 +177,7 @@ void InstanceList::saveGroupList()
}
toplevel.insert("groups", groupsArr);
QJsonDocument doc(toplevel);
- groupFile.write(doc.toJson());
- groupFile.close();
+ FS::write(groupFileName, doc.toJson());
}
void InstanceList::loadGroupList(QMap<QString, QString> &groupMap)
@@ -199,22 +188,19 @@ void InstanceList::loadGroupList(QMap<QString, QString> &groupMap)
if (!QFileInfo(groupFileName).exists())
return;
- QFile groupFile(groupFileName);
-
- // if you can't open the file, fail
- if (!groupFile.open(QIODevice::ReadOnly))
+ QByteArray jsonData;
+ try
+ {
+ jsonData = FS::read(groupFileName);
+ }
+ catch (FS::FileSystemException & e)
{
- // An error occurred. Ignore it.
- qCritical() << "Failed to read instance group file.";
+ qCritical() << "Failed to read instance group file :" << e.cause();
return;
}
- QTextStream in(&groupFile);
- QString jsonStr = in.readAll();
- groupFile.close();
-
QJsonParseError error;
- QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonStr.toUtf8(), &error);
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &error);
// if the json was bad, fail
if (error.error != QJsonParseError::NoError)