diff options
-rw-r--r-- | application/dialogs/ExportInstanceDialog.cpp | 14 | ||||
-rw-r--r-- | logic/BaseConfigObject.cpp | 30 | ||||
-rw-r--r-- | logic/Json.cpp | 1 | ||||
-rw-r--r-- | logic/net/HttpMetaCache.cpp | 21 | ||||
-rw-r--r-- | logic/settings/INIFile.cpp | 21 |
5 files changed, 32 insertions, 55 deletions
diff --git a/application/dialogs/ExportInstanceDialog.cpp b/application/dialogs/ExportInstanceDialog.cpp index ec376b1d..ec46b6ba 100644 --- a/application/dialogs/ExportInstanceDialog.cpp +++ b/application/dialogs/ExportInstanceDialog.cpp @@ -30,6 +30,7 @@ #include "SeparatorPrefixTree.h" #include "Env.h" #include <icons/IconList.h> +#include <FileSystem.h> class PackIgnoreProxy : public QSortFilterProxyModel { @@ -469,15 +470,16 @@ void ExportInstanceDialog::loadPackIgnore() void ExportInstanceDialog::savePackIgnore() { + auto data = proxyModel->blockedPaths().toStringList().join('\n').toUtf8(); auto filename = ignoreFileName(); - QSaveFile ignoreFile(filename); - if(!ignoreFile.open(QIODevice::WriteOnly)) + try { - ignoreFile.cancelWriting(); + FS::write(filename, data); + } + catch (Exception & e) + { + qWarning() << e.cause(); } - auto data = proxyModel->blockedPaths().toStringList().join('\n').toUtf8(); - ignoreFile.write(data); - ignoreFile.commit(); } #include "ExportInstanceDialog.moc" 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; } |