mirror of
https://invent.kde.org/marcoa/a-la-karte.git
synced 2026-03-26 17:03:08 +00:00
runnerd: save registry and profiles atomically
This commit is contained in:
parent
c6f3e645f4
commit
9160076aa2
1 changed files with 23 additions and 8 deletions
|
|
@ -22,6 +22,7 @@
|
|||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QProcess>
|
||||
#include <QSaveFile>
|
||||
#include <QSet>
|
||||
#include <QStandardPaths>
|
||||
#include <QTimer>
|
||||
|
|
@ -201,7 +202,10 @@ void RunnerManagerDaemon::loadRegistry()
|
|||
bool RunnerManagerDaemon::saveRegistry() const
|
||||
{
|
||||
const QString path = registryPath();
|
||||
QDir().mkpath(QFileInfo(path).absolutePath());
|
||||
const QString dirPath = QFileInfo(path).absolutePath();
|
||||
if (!QDir().mkpath(dirPath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonArray arr;
|
||||
|
||||
|
|
@ -221,13 +225,17 @@ bool RunnerManagerDaemon::saveRegistry() const
|
|||
QJsonObject root;
|
||||
root.insert(QStringLiteral("runners"), arr);
|
||||
|
||||
QFile f(path);
|
||||
QSaveFile f(path);
|
||||
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
f.write(QJsonDocument(root).toJson(QJsonDocument::Indented));
|
||||
return true;
|
||||
const QByteArray payload = QJsonDocument(root).toJson(QJsonDocument::Indented);
|
||||
if (f.write(payload) != payload.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return f.commit();
|
||||
}
|
||||
|
||||
QString RunnerManagerDaemon::gameProfilesPath() const
|
||||
|
|
@ -267,7 +275,10 @@ void RunnerManagerDaemon::loadGameProfiles()
|
|||
bool RunnerManagerDaemon::saveGameProfiles() const
|
||||
{
|
||||
const QString path = gameProfilesPath();
|
||||
QDir().mkpath(QFileInfo(path).absolutePath());
|
||||
const QString dirPath = QFileInfo(path).absolutePath();
|
||||
if (!QDir().mkpath(dirPath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonArray arr;
|
||||
for (auto it = m_gameProfiles.constBegin(); it != m_gameProfiles.constEnd(); ++it) {
|
||||
|
|
@ -281,13 +292,17 @@ bool RunnerManagerDaemon::saveGameProfiles() const
|
|||
QJsonObject root;
|
||||
root.insert(QStringLiteral("profiles"), arr);
|
||||
|
||||
QFile f(path);
|
||||
QSaveFile f(path);
|
||||
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
f.write(QJsonDocument(root).toJson(QJsonDocument::Indented));
|
||||
return true;
|
||||
const QByteArray payload = QJsonDocument(root).toJson(QJsonDocument::Indented);
|
||||
if (f.write(payload) != payload.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return f.commit();
|
||||
}
|
||||
|
||||
QVariantMap RunnerManagerDaemon::gameProfileForGameId(const QString &gameId) const
|
||||
|
|
|
|||
Loading…
Reference in a new issue