summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-06-03 21:10:28 +0200
committerPetr Mrázek <peterix@gmail.com>2015-06-06 21:23:05 +0200
commit06a67fbd3852cdaa9bb4d8e2900543b47360f0fc (patch)
treec0f5e05661c1c31ae9815a8543157d45167100e3 /logic
parent3a8b238052163952831fb5924b2483a375e86ebd (diff)
downloadMultiMC-06a67fbd3852cdaa9bb4d8e2900543b47360f0fc.tar
MultiMC-06a67fbd3852cdaa9bb4d8e2900543b47360f0fc.tar.gz
MultiMC-06a67fbd3852cdaa9bb4d8e2900543b47360f0fc.tar.lz
MultiMC-06a67fbd3852cdaa9bb4d8e2900543b47360f0fc.tar.xz
MultiMC-06a67fbd3852cdaa9bb4d8e2900543b47360f0fc.zip
NOISSUE use FS a bit more
Diffstat (limited to 'logic')
-rw-r--r--logic/BaseConfigObject.cpp30
-rw-r--r--logic/Json.cpp1
-rw-r--r--logic/net/HttpMetaCache.cpp21
-rw-r--r--logic/settings/INIFile.cpp21
4 files changed, 24 insertions, 49 deletions
diff --git a/logic/BaseConfigObject.cpp b/logic/BaseConfigObject.cpp
index ff698ad0..3040ac2e 100644
--- a/logic/BaseConfigObject.cpp
+++ b/logic/BaseConfigObject.cpp
@@ -16,12 +16,12 @@
#include "BaseConfigObject.h"
#include <QTimer>
-#include <QSaveFile>
#include <QFile>
#include <QCoreApplication>
#include <QDebug>
#include "Exception.h"
+#include "FileSystem.h"
BaseConfigObject::BaseConfigObject(const QString &filename)
: m_filename(filename)
@@ -76,19 +76,13 @@ void BaseConfigObject::saveNow()
return;
}
- QSaveFile file(m_filename);
- if (!file.open(QFile::WriteOnly))
+ try
{
- qWarning() << "Couldn't open" << m_filename << "for writing:" << file.errorString();
- return;
+ FS::write(m_filename, doSave());
}
- // cppcheck-suppress pureVirtualCall
- file.write(doSave());
-
- if (!file.commit())
+ catch (Exception & e)
{
- qCritical() << "Unable to commit the file" << file.fileName() << ":" << file.errorString();
- file.cancelWriting();
+ qCritical() << e.cause();
}
}
void BaseConfigObject::loadNow()
@@ -98,21 +92,11 @@ void BaseConfigObject::loadNow()
saveNow();
}
- QFile file(m_filename);
- if (!file.exists())
- {
- return;
- }
- if (!file.open(QFile::ReadOnly))
- {
- qWarning() << "Couldn't open" << m_filename << "for reading:" << file.errorString();
- return;
- }
try
{
- doLoad(file.readAll());
+ doLoad(FS::read(m_filename));
}
- catch (Exception &e)
+ catch (Exception & e)
{
qWarning() << "Error loading" << m_filename << ":" << e.cause();
}
diff --git a/logic/Json.cpp b/logic/Json.cpp
index 46055909..97bab474 100644
--- a/logic/Json.cpp
+++ b/logic/Json.cpp
@@ -3,7 +3,6 @@
#include "Json.h"
#include <QFile>
-#include <QSaveFile>
#include "FileSystem.h"
#include <math.h>
diff --git a/logic/net/HttpMetaCache.cpp b/logic/net/HttpMetaCache.cpp
index bfd2cb42..977e3a90 100644
--- a/logic/net/HttpMetaCache.cpp
+++ b/logic/net/HttpMetaCache.cpp
@@ -15,12 +15,12 @@
#include "Env.h"
#include "HttpMetaCache.h"
+#include "FileSystem.h"
#include <pathutils.h>
#include <QFileInfo>
#include <QFile>
#include <QTemporaryFile>
-#include <QSaveFile>
#include <QDateTime>
#include <QCryptographicHash>
@@ -230,9 +230,6 @@ void HttpMetaCache::SaveEventually()
void HttpMetaCache::SaveNow()
{
- QSaveFile tfile(m_index_file);
- if (!tfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
- return;
QJsonObject toplevel;
toplevel.insert("version", QJsonValue(QString("1")));
QJsonArray entriesArr;
@@ -259,12 +256,14 @@ void HttpMetaCache::SaveNow()
}
}
toplevel.insert("entries", entriesArr);
+
QJsonDocument doc(toplevel);
- QByteArray jsonData = doc.toJson();
- qint64 result = tfile.write(jsonData);
- if (result == -1)
- return;
- if (result != jsonData.size())
- return;
- tfile.commit();
+ try
+ {
+ FS::write(m_index_file, doc.toJson());
+ }
+ catch (Exception & e)
+ {
+ qWarning() << e.what();
+ }
}
diff --git a/logic/settings/INIFile.cpp b/logic/settings/INIFile.cpp
index 5d9052e9..5f39f213 100644
--- a/logic/settings/INIFile.cpp
+++ b/logic/settings/INIFile.cpp
@@ -14,6 +14,7 @@
*/
#include "settings/INIFile.h"
+#include <FileSystem.h>
#include <QFile>
#include <QTextStream>
@@ -74,14 +75,7 @@ QString INIFile::escape(QString orig)
bool INIFile::saveFile(QString fileName)
{
- QSaveFile file(fileName);
- if(!file.open(QIODevice::WriteOnly))
- {
- qCritical() << "Unable to open INI config file" << fileName << "for saving";
- return false;
- }
QByteArray outArray;
-
for (Iterator iter = begin(); iter != end(); iter++)
{
QString value = iter.value().toString();
@@ -91,18 +85,17 @@ bool INIFile::saveFile(QString fileName)
outArray.append(value.toUtf8());
outArray.append('\n');
}
- if(file.write(outArray) != outArray.size())
+
+ try
{
- qCritical() << "Unable to write to the INI config file" << fileName;
- file.cancelWriting();
- return false;
+ FS::write(fileName, outArray);
}
- if(!file.commit())
+ catch (Exception & e)
{
- qCritical() << "Unable to commit the INI config file" << fileName;
- file.cancelWriting();
+ qCritical() << e.what();
return false;
}
+
return true;
}