|
11 | 11 | #include <QJsonArray> |
12 | 12 | #include <QFile> |
13 | 13 | #include <QDir> |
| 14 | +#include <QUrlQuery> |
14 | 15 |
|
15 | 16 | IndexDownloadWorker::IndexDownloadWorker(QObject* parent) |
16 | 17 | : QThread(parent) |
@@ -84,6 +85,61 @@ void IndexDownloadWorker::run() { |
84 | 85 | games.append({obj["id"].toString(), obj["name"].toString()}); |
85 | 86 | } |
86 | 87 |
|
| 88 | + // Client-side Fallback: Check for missing/unknown names and fetch from Store API |
| 89 | + int missingCount = 0; |
| 90 | + for (const auto& game : games) { |
| 91 | + if (game.name.isEmpty() || game.name.startsWith("Unknown Game") || game.name == game.id) { |
| 92 | + missingCount++; |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + if (missingCount > 0 && missingCount < 50) { // Limit to avoid massive delays if everything is broken |
| 97 | + emit progress(QString("Fetching details for %1 games...").arg(missingCount)); |
| 98 | + QNetworkAccessManager storeMgr; |
| 99 | + |
| 100 | + for (auto& game : games) { |
| 101 | + if (game.name.isEmpty() || game.name.startsWith("Unknown Game") || game.name == game.id) { |
| 102 | + QUrl storeUrl("https://store.steampowered.com/api/appdetails"); |
| 103 | + QUrlQuery query; |
| 104 | + query.addQueryItem("appids", game.id); |
| 105 | + query.addQueryItem("filters", "basic"); |
| 106 | + storeUrl.setQuery(query); |
| 107 | + |
| 108 | + QNetworkRequest req(storeUrl); |
| 109 | + req.setHeader(QNetworkRequest::UserAgentHeader, "SteamLuaPatcher/2.0"); |
| 110 | + |
| 111 | + QEventLoop storeLoop; |
| 112 | + QNetworkReply* storeReply = storeMgr.get(req); |
| 113 | + // Simple timeout to prevent hanging forever |
| 114 | + QTimer storeTimer; |
| 115 | + storeTimer.setSingleShot(true); |
| 116 | + connect(&storeTimer, &QTimer::timeout, &storeLoop, &QEventLoop::quit); |
| 117 | + connect(storeReply, &QNetworkReply::finished, &storeLoop, &QEventLoop::quit); |
| 118 | + storeTimer.start(5000); |
| 119 | + |
| 120 | + storeLoop.exec(); |
| 121 | + |
| 122 | + if (storeReply->error() == QNetworkReply::NoError) { |
| 123 | + QJsonDocument storeDoc = QJsonDocument::fromJson(storeReply->readAll()); |
| 124 | + QJsonObject storeRoot = storeDoc.object(); |
| 125 | + if (storeRoot.contains(game.id)) { |
| 126 | + QJsonObject appData = storeRoot[game.id].toObject(); |
| 127 | + if (appData["success"].toBool()) { |
| 128 | + QString newName = appData["data"].toObject()["name"].toString(); |
| 129 | + if (!newName.isEmpty()) { |
| 130 | + game.name = newName; |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + storeReply->deleteLater(); |
| 136 | + |
| 137 | + // Polite delay |
| 138 | + QThread::msleep(200); |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + |
87 | 143 | emit finished(games); |
88 | 144 |
|
89 | 145 |
|
|
0 commit comments