| 266 | } |
| 267 | |
| 268 | void Backend::loadConfig() |
| 269 | { |
| 270 | QString configPath = crConfigDir() + "/config.json"; |
| 271 | fprintf(stderr, "[Backend] loadConfig from: %s\n", configPath.toUtf8().constData()); |
| 272 | QFile f(configPath); |
| 273 | if (!f.open(QIODevice::ReadOnly)) { |
| 274 | fprintf(stderr, "[Backend] loadConfig: file not found or cannot open\n"); |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | QJsonDocument doc = QJsonDocument::fromJson(f.readAll()); |
| 279 | f.close(); |
| 280 | if (!doc.isObject()) { |
| 281 | fprintf(stderr, "[Backend] loadConfig: invalid JSON\n"); |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | QJsonObject obj = doc.object(); |
| 286 | m_providerName = obj.value("provider").toString("local"); |
| 287 | m_syncFolderPath = obj.value("sync_folder_path").toString(); |
| 288 | m_notificationsEnabled = obj.value("notifications_enabled").toBool(true); |
| 289 | m_statsSyncEnabled = obj.value("stats_sync_enabled").toBool(true); |
| 290 | m_syncAchievements = obj.value("sync_achievements").toBool(false); |
| 291 | m_syncPlaytime = obj.value("sync_playtime").toBool(false); |
| 292 | fprintf(stderr, "[Backend] loadConfig: provider=%s syncFolder=%s notifications=%s\n", |
| 293 | m_providerName.toUtf8().constData(), m_syncFolderPath.toUtf8().constData(), |
| 294 | m_notificationsEnabled ? "true" : "false"); |
| 295 | |
| 296 | m_providerAuthenticated = false; |
| 297 | if (m_providerName == "gdrive" || m_providerName == "onedrive") { |
| 298 | QString tokenPath = defaultTokenPath(m_providerName); |
| 299 | if (QFile::exists(tokenPath)) { |
| 300 | m_providerAuthenticated = true; |
| 301 | } |
| 302 | } else if (m_providerName == "folder" && !m_syncFolderPath.isEmpty()) { |
| 303 | m_providerAuthenticated = QDir(m_syncFolderPath).exists(); |
| 304 | } |
| 305 | |
| 306 | // Load store cache (names and header URLs) |
| 307 | QString cachePath = crConfigDir() + "/store_cache.json"; |
| 308 | QFile cacheFile(cachePath); |
| 309 | if (cacheFile.open(QIODevice::ReadOnly)) { |
| 310 | QJsonDocument cacheDoc = QJsonDocument::fromJson(cacheFile.readAll()); |
| 311 | cacheFile.close(); |
| 312 | if (cacheDoc.isObject()) { |
| 313 | QJsonObject cacheObj = cacheDoc.object(); |
| 314 | for (auto it = cacheObj.begin(); it != cacheObj.end(); ++it) { |
| 315 | uint appId = it.key().toUInt(); |
| 316 | QJsonObject entry = it.value().toObject(); |
| 317 | QString name = entry["name"].toString(); |
| 318 | QString headerUrl = entry["headerUrl"].toString(); |
| 319 | if (!name.isEmpty()) { |
| 320 | m_nameCache[appId] = name; |
| 321 | } |
| 322 | if (!headerUrl.isEmpty()) { |
| 323 | m_headerCache[appId] = headerUrl; |
| 324 | } |
| 325 | } |
nothing calls this directly
no test coverage detected