| 338 | } |
| 339 | |
| 340 | void Backend::saveConfig() |
| 341 | { |
| 342 | QString configDir = crConfigDir(); |
| 343 | QDir().mkpath(configDir); |
| 344 | |
| 345 | QString configPath = configDir + "/config.json"; |
| 346 | |
| 347 | // Read existing config to preserve keys not managed by this function |
| 348 | QJsonObject obj; |
| 349 | QFile existing(configPath); |
| 350 | if (existing.open(QIODevice::ReadOnly)) { |
| 351 | QJsonDocument doc = QJsonDocument::fromJson(existing.readAll()); |
| 352 | existing.close(); |
| 353 | if (doc.isObject()) |
| 354 | obj = doc.object(); |
| 355 | } |
| 356 | |
| 357 | obj["provider"] = m_providerName; |
| 358 | obj["sync_folder_path"] = m_syncFolderPath; |
| 359 | obj["notifications_enabled"] = m_notificationsEnabled; |
| 360 | obj["stats_sync_enabled"] = m_statsSyncEnabled; |
| 361 | obj["sync_achievements"] = m_syncAchievements; |
| 362 | obj["sync_playtime"] = m_syncPlaytime; |
| 363 | |
| 364 | // Atomic write: write to temp, then rename |
| 365 | QString tempPath = configPath + ".tmp"; |
| 366 | QFile f(tempPath); |
| 367 | if (f.open(QIODevice::WriteOnly)) { |
| 368 | f.write(QJsonDocument(obj).toJson()); |
| 369 | f.close(); |
| 370 | // rename() is atomic on POSIX if same filesystem; fallback to copy+delete |
| 371 | if (!QFile::rename(tempPath, configPath)) { |
| 372 | QFile::remove(configPath); |
| 373 | if (!QFile::rename(tempPath, configPath)) { |
| 374 | QFile::copy(tempPath, configPath); |
| 375 | QFile::remove(tempPath); |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | emit settingsChanged(); |
| 381 | } |
| 382 | |
| 383 | int Backend::managedAppCount() const { |
| 384 | int count = 0; |
nothing calls this directly
no test coverage detected