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 <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QSaveFile>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
@ -201,7 +202,10 @@ void RunnerManagerDaemon::loadRegistry()
|
||||||
bool RunnerManagerDaemon::saveRegistry() const
|
bool RunnerManagerDaemon::saveRegistry() const
|
||||||
{
|
{
|
||||||
const QString path = registryPath();
|
const QString path = registryPath();
|
||||||
QDir().mkpath(QFileInfo(path).absolutePath());
|
const QString dirPath = QFileInfo(path).absolutePath();
|
||||||
|
if (!QDir().mkpath(dirPath)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonArray arr;
|
QJsonArray arr;
|
||||||
|
|
||||||
|
|
@ -221,13 +225,17 @@ bool RunnerManagerDaemon::saveRegistry() const
|
||||||
QJsonObject root;
|
QJsonObject root;
|
||||||
root.insert(QStringLiteral("runners"), arr);
|
root.insert(QStringLiteral("runners"), arr);
|
||||||
|
|
||||||
QFile f(path);
|
QSaveFile f(path);
|
||||||
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
f.write(QJsonDocument(root).toJson(QJsonDocument::Indented));
|
const QByteArray payload = QJsonDocument(root).toJson(QJsonDocument::Indented);
|
||||||
return true;
|
if (f.write(payload) != payload.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return f.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString RunnerManagerDaemon::gameProfilesPath() const
|
QString RunnerManagerDaemon::gameProfilesPath() const
|
||||||
|
|
@ -267,7 +275,10 @@ void RunnerManagerDaemon::loadGameProfiles()
|
||||||
bool RunnerManagerDaemon::saveGameProfiles() const
|
bool RunnerManagerDaemon::saveGameProfiles() const
|
||||||
{
|
{
|
||||||
const QString path = gameProfilesPath();
|
const QString path = gameProfilesPath();
|
||||||
QDir().mkpath(QFileInfo(path).absolutePath());
|
const QString dirPath = QFileInfo(path).absolutePath();
|
||||||
|
if (!QDir().mkpath(dirPath)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonArray arr;
|
QJsonArray arr;
|
||||||
for (auto it = m_gameProfiles.constBegin(); it != m_gameProfiles.constEnd(); ++it) {
|
for (auto it = m_gameProfiles.constBegin(); it != m_gameProfiles.constEnd(); ++it) {
|
||||||
|
|
@ -281,13 +292,17 @@ bool RunnerManagerDaemon::saveGameProfiles() const
|
||||||
QJsonObject root;
|
QJsonObject root;
|
||||||
root.insert(QStringLiteral("profiles"), arr);
|
root.insert(QStringLiteral("profiles"), arr);
|
||||||
|
|
||||||
QFile f(path);
|
QSaveFile f(path);
|
||||||
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
f.write(QJsonDocument(root).toJson(QJsonDocument::Indented));
|
const QByteArray payload = QJsonDocument(root).toJson(QJsonDocument::Indented);
|
||||||
return true;
|
if (f.write(payload) != payload.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return f.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap RunnerManagerDaemon::gameProfileForGameId(const QString &gameId) const
|
QVariantMap RunnerManagerDaemon::gameProfileForGameId(const QString &gameId) const
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue