game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
steamgriddb_service.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// steamgriddb_service.cpp
4// ==============================================================================
5// SteamGridDB API integration implementation
6// ==============================================================================
7
9#include "logger.h"
10#include "shell_utils.h"
11
12#include <algorithm>
13#include <array>
14#include <cctype>
15#include <cstdio>
16#include <filesystem>
17#include <future>
18#include <iomanip>
19#include <memory>
20#include <mutex>
21#include <sstream>
22#include <sys/wait.h>
23#include <vector>
24
25namespace fs = std::filesystem;
26
27// ==============================================================================
28// Async Future Management
29// ==============================================================================
30
31namespace
32{
33std::vector<std::shared_ptr<std::future<void>>> activeFutures_;
34std::mutex futuresMutex_;
35
36void storeFuture(std::shared_ptr<std::future<void>> f)
37{
38 std::lock_guard<std::mutex> lock(futuresMutex_);
39 activeFutures_.erase(std::remove_if(activeFutures_.begin(), activeFutures_.end(),
40 [](const std::shared_ptr<std::future<void>>& fu)
41 {
42 return fu->wait_for(std::chrono::seconds(0)) ==
43 std::future_status::ready;
44 }),
45 activeFutures_.end());
46 activeFutures_.push_back(std::move(f));
47}
48} // namespace
49
50// ==============================================================================
51// Static Members
52// ==============================================================================
53
54std::string SteamGridDBService::apiKey_;
55std::mutex SteamGridDBService::apiKeyMutex_;
56
57// ==============================================================================
58// Configuration
59// ==============================================================================
60
61void SteamGridDBService::setApiKey(const std::string& key)
62{
63 std::lock_guard<std::mutex> lock(apiKeyMutex_);
64 apiKey_ = key;
65 Logger::info("SteamGridDB: API key configured");
66}
67
69{
70 std::lock_guard<std::mutex> lock(apiKeyMutex_);
71 return !apiKey_.empty();
72}
73
75{
76 const char* home = std::getenv("HOME");
77 if (!home)
78 return "";
79
80 fs::path cacheDir = fs::path(home) / ".cache" / "gamelauncher" / "steamgriddb";
81
82 try
83 {
84 if (!fs::exists(cacheDir))
85 {
86 fs::create_directories(cacheDir);
87 }
88 }
89 catch (const std::exception& e)
90 {
91 Logger::warn("SteamGridDB: Failed to create cache directory: {}", e.what());
92 return "";
93 }
94
95 return cacheDir.string();
96}
97
98// ==============================================================================
99// HTTP Helpers
100// ==============================================================================
101
102std::string SteamGridDBService::httpGet(const std::string& url,
103 const std::map<std::string, std::string>& headers)
104{
105 std::ostringstream cmd;
106 cmd << "curl -s -L --connect-timeout 10 --max-time 30 --max-redirs 10 ";
107
108 // Add headers
109 for (const auto& [key, value] : headers)
110 {
111 cmd << "-H " << ShellUtils::escapeArg(key + ": " + value) << " ";
112 }
113
114 cmd << ShellUtils::escapeArg(url) << " 2>/dev/null";
115
116 std::array<char, 4096> buffer;
117 std::string result;
118
119 std::unique_ptr<FILE, int (*)(FILE*)> pipe(popen(cmd.str().c_str(), "r"), pclose);
120 if (!pipe)
121 {
122 Logger::error("SteamGridDB: Failed to execute curl command");
123 return "";
124 }
125
126 constexpr size_t kMaxResponse = 16u * 1024 * 1024; // 16 MB
127 while (fgets(buffer.data(), static_cast<int>(buffer.size()), pipe.get()) != nullptr)
128 {
129 result += buffer.data();
130 if (result.size() > kMaxResponse)
131 {
132 Logger::warn("[SteamGridDB] HTTP response too large, truncating");
133 break;
134 }
135 }
136
137 return result;
138}
139
140bool SteamGridDBService::downloadFile(const std::string& url, const std::string& localPath)
141{
142 // Only allow http/https schemes to prevent file://, ftp://, etc.
143 if (url.compare(0, 8, "https://") != 0 && url.compare(0, 7, "http://") != 0)
144 {
145 Logger::warn("SteamGridDB: Rejected URL with disallowed scheme: {}", url);
146 return false;
147 }
148
149 std::string cmd =
150 "curl -s -L --proto =https,http --connect-timeout 10 --max-time 60 --max-redirs 10 -o " +
151 ShellUtils::escapeArg(localPath) + " " + ShellUtils::escapeArg(url) + " 2>/dev/null";
152
153 int rawStatus = std::system(cmd.c_str());
154 if (rawStatus == -1 || !WIFEXITED(rawStatus) || WEXITSTATUS(rawStatus) != 0)
155 {
156 Logger::warn("SteamGridDB: Failed to download file from {}", url);
157 return false;
158 }
159
160 // Verify file was created
161 if (!fs::exists(localPath) || fs::file_size(localPath) == 0)
162 {
163 Logger::warn("SteamGridDB: Downloaded file is empty or missing");
164 fs::remove(localPath);
165 return false;
166 }
167
168 return true;
169}
170
171std::string SteamGridDBService::urlEncode(const std::string& str)
172{
173 std::ostringstream encoded;
174 encoded.fill('0');
175 encoded << std::hex;
176
177 for (char c : str)
178 {
179 if (std::isalnum(static_cast<unsigned char>(c)) || c == '-' || c == '_' || c == '.' ||
180 c == '~')
181 {
182 encoded << c;
183 }
184 else
185 {
186 encoded << std::uppercase;
187 encoded << '%' << std::setw(2) << static_cast<int>(static_cast<unsigned char>(c));
188 encoded << std::nouppercase;
189 }
190 }
191
192 return encoded.str();
193}
194
195// ==============================================================================
196// JSON Parsing Helpers
197// ==============================================================================
198
199namespace
200{
201
202std::string jsonGetString(const std::string& json, const std::string& key)
203{
204 std::string searchKey = "\"" + key + "\"";
205 size_t pos = json.find(searchKey);
206 if (pos == std::string::npos)
207 return "";
208
209 pos = json.find(':', pos);
210 if (pos == std::string::npos)
211 return "";
212
213 pos++;
214 while (pos < json.size() && std::isspace(static_cast<unsigned char>(json[pos])))
215 pos++;
216
217 if (pos >= json.size())
218 return "";
219
220 // Handle null values
221 if (json.substr(pos, 4) == "null")
222 return "";
223
224 if (json[pos] != '"')
225 return "";
226
227 pos++; // Skip opening quote
228 size_t end = pos;
229
230 while (end < json.size())
231 {
232 if (json[end] == '"')
233 {
234 // Count preceding backslashes: even count → quote is unescaped
235 size_t numBackslashes = 0;
236 size_t check = end;
237 while (check > 0 && json[check - 1] == '\\')
238 {
239 ++numBackslashes;
240 --check;
241 }
242 if (numBackslashes % 2 == 0)
243 break;
244 }
245 end++;
246 }
247
248 return json.substr(pos, end - pos);
249}
250
251int jsonGetInt(const std::string& json, const std::string& key)
252{
253 std::string searchKey = "\"" + key + "\"";
254 size_t pos = json.find(searchKey);
255 if (pos == std::string::npos)
256 return 0;
257
258 pos = json.find(':', pos);
259 if (pos == std::string::npos)
260 return 0;
261
262 pos++;
263 while (pos < json.size() && std::isspace(static_cast<unsigned char>(json[pos])))
264 pos++;
265
266 try
267 {
268 return std::stoi(json.substr(pos));
269 }
270 catch (...)
271 {
272 return 0;
273 }
274}
275
276bool jsonGetBool(const std::string& json, const std::string& key)
277{
278 std::string searchKey = "\"" + key + "\"";
279 size_t pos = json.find(searchKey);
280 if (pos == std::string::npos)
281 return false;
282
283 pos = json.find(':', pos);
284 if (pos == std::string::npos)
285 return false;
286
287 pos++;
288 while (pos < json.size() && std::isspace(static_cast<unsigned char>(json[pos])))
289 pos++;
290
291 return json.substr(pos, 4) == "true";
292}
293
294std::vector<std::string> jsonSplitArray(const std::string& json, const std::string& arrayKey = "")
295{
296 std::vector<std::string> elements;
297
298 size_t start;
299 if (arrayKey.empty())
300 {
301 start = json.find('[');
302 }
303 else
304 {
305 std::string searchKey = "\"" + arrayKey + "\"";
306 size_t keyPos = json.find(searchKey);
307 if (keyPos == std::string::npos)
308 return elements;
309 start = json.find('[', keyPos);
310 }
311
312 if (start == std::string::npos)
313 return elements;
314
315 start++;
316 int braceCount = 0;
317 bool inString = false;
318 bool escaped = false;
319 size_t elementStart = start;
320
321 for (size_t i = start; i < json.size(); i++)
322 {
323 char c = json[i];
324
325 // Track JSON string state so structural characters inside a quoted
326 // value are not miscounted as braces or delimiters (M4).
327 if (inString)
328 {
329 if (escaped)
330 escaped = false;
331 else if (c == '\\')
332 escaped = true;
333 else if (c == '"')
334 inString = false;
335 continue;
336 }
337 if (c == '"')
338 {
339 inString = true;
340 continue;
341 }
342
343 if (c == '{')
344 braceCount++;
345 else if (c == '}')
346 braceCount--;
347 else if ((c == ',' || c == ']') && braceCount == 0)
348 {
349 std::string element = json.substr(elementStart, i - elementStart);
350 size_t first = element.find_first_not_of(" \t\n\r");
351 size_t last = element.find_last_not_of(" \t\n\r");
352 if (first != std::string::npos && last != std::string::npos)
353 {
354 element = element.substr(first, last - first + 1);
355 if (!element.empty() && element[0] == '{')
356 {
357 elements.push_back(element);
358 }
359 }
360 elementStart = i + 1;
361 }
362
363 if (c == ']' && braceCount == 0)
364 break;
365 }
366
367 return elements;
368}
369
370} // anonymous namespace
371
372// ==============================================================================
373// JSON Parsing Implementation
374// ==============================================================================
375
376std::vector<SteamGridDBGame> SteamGridDBService::parseGamesJson(const std::string& json)
377{
378 std::vector<SteamGridDBGame> games;
379
380 // Check for success
381 if (json.find("\"success\":true") == std::string::npos &&
382 json.find("\"success\": true") == std::string::npos)
383 {
384 Logger::warn("SteamGridDB: API returned unsuccessful response");
385 return games;
386 }
387
388 auto elements = jsonSplitArray(json, "data");
389 for (const auto& elem : elements)
390 {
391 SteamGridDBGame game;
392 game.id = jsonGetInt(elem, "id");
393 game.name = jsonGetString(elem, "name");
394 game.releaseDate = jsonGetString(elem, "release_date");
395 game.verified = jsonGetBool(elem, "verified");
396
397 // Try to get Steam App ID from external_platform_data or types
398 // The API structure may vary, try multiple locations
399 size_t steamPos = elem.find("\"steam\"");
400 if (steamPos != std::string::npos)
401 {
402 size_t idPos = elem.find("\"id\"", steamPos);
403 if (idPos != std::string::npos && idPos < steamPos + 100)
404 {
405 game.steamAppId = jsonGetInt(elem.substr(steamPos, 100), "id");
406 }
407 }
408
409 if (game.id > 0)
410 {
411 games.push_back(game);
412 }
413 }
414
415 return games;
416}
417
418std::vector<SteamGridDBImage> SteamGridDBService::parseImagesJson(const std::string& json)
419{
420 std::vector<SteamGridDBImage> images;
421
422 if (json.find("\"success\":true") == std::string::npos &&
423 json.find("\"success\": true") == std::string::npos)
424 {
425 return images;
426 }
427
428 auto elements = jsonSplitArray(json, "data");
429 for (const auto& elem : elements)
430 {
431 SteamGridDBImage image;
432 image.id = jsonGetInt(elem, "id");
433 image.url = jsonGetString(elem, "url");
434 image.thumbUrl = jsonGetString(elem, "thumb");
435 image.width = jsonGetInt(elem, "width");
436 image.height = jsonGetInt(elem, "height");
437 image.style = jsonGetString(elem, "style");
438 image.mime = jsonGetString(elem, "mime");
439 image.score = jsonGetInt(elem, "score");
440 image.nsfw = jsonGetBool(elem, "nsfw");
441
442 if (image.id > 0 && !image.url.empty())
443 {
444 images.push_back(image);
445 }
446 }
447
448 // Sort by score (highest first)
449 std::sort(images.begin(), images.end(), [](const SteamGridDBImage& a, const SteamGridDBImage& b)
450 { return a.score > b.score; });
451
452 return images;
453}
454
455// ==============================================================================
456// File Utilities
457// ==============================================================================
458
459std::string SteamGridDBService::sanitizeFilename(const std::string& name)
460{
461 std::string safe;
462 for (char c : name)
463 {
464 if (std::isalnum(static_cast<unsigned char>(c)) || c == '-' || c == '_' || c == ' ')
465 {
466 safe += c;
467 }
468 else if (c == ':' || c == '/' || c == '\\')
469 {
470 safe += '_';
471 }
472 }
473
474 // Trim and collapse multiple spaces/underscores
475 while (!safe.empty() && (safe.front() == ' ' || safe.front() == '_'))
476 safe.erase(0, 1);
477 while (!safe.empty() && (safe.back() == ' ' || safe.back() == '_'))
478 safe.pop_back();
479
480 return safe;
481}
482
483std::string SteamGridDBService::getImageExtension(const std::string& mime)
484{
485 if (mime.find("png") != std::string::npos)
486 return ".png";
487 if (mime.find("jpeg") != std::string::npos || mime.find("jpg") != std::string::npos)
488 return ".jpg";
489 if (mime.find("webp") != std::string::npos)
490 return ".webp";
491 return ".jpg"; // Default
492}
493
494// ==============================================================================
495// Game Search
496// ==============================================================================
497
498std::vector<SteamGridDBGame> SteamGridDBService::searchGames(const std::string& query)
499{
500 if (query.empty())
501 return {};
502
503 Logger::info("SteamGridDB: Searching for '{}'", query);
504
505 std::string url = "https://www.steamgriddb.com/api/v2/search/autocomplete/" + urlEncode(query);
506
507 std::map<std::string, std::string> headers;
508 {
509 std::lock_guard<std::mutex> lock(apiKeyMutex_);
510 if (!apiKey_.empty())
511 {
512 headers["Authorization"] = "Bearer " + apiKey_;
513 }
514 }
515
516 std::string response = httpGet(url, headers);
517 if (response.empty())
518 {
519 Logger::warn("SteamGridDB: Empty response from search API");
520 return {};
521 }
522
523 auto games = parseGamesJson(response);
524 Logger::info("SteamGridDB: Found {} games matching '{}'", games.size(), query);
525 return games;
526}
527
529 const std::string& query,
530 const std::function<void(const std::vector<SteamGridDBGame>&)>& callback)
531{
532 auto future = std::make_shared<std::future<void>>(std::async(std::launch::async,
533 [query, callback]()
534 {
535 auto games =
536 searchGames(query);
537 if (callback)
538 callback(games);
539 }));
540 storeFuture(std::move(future));
541}
542
544{
545 if (steamAppId <= 0)
546 return {};
547
548 Logger::info("SteamGridDB: Looking up Steam App ID {}", steamAppId);
549
550 std::string url =
551 "https://www.steamgriddb.com/api/v2/games/steam/" + std::to_string(steamAppId);
552
553 std::map<std::string, std::string> headers;
554 {
555 std::lock_guard<std::mutex> lock(apiKeyMutex_);
556 if (!apiKey_.empty())
557 {
558 headers["Authorization"] = "Bearer " + apiKey_;
559 }
560 }
561
562 std::string response = httpGet(url, headers);
563 if (response.empty())
564 return {};
565
566 auto games = parseGamesJson(response);
567 if (!games.empty())
568 {
569 games[0].steamAppId = steamAppId;
570 return games[0];
571 }
572
573 return {};
574}
575
576// ==============================================================================
577// Image Fetching
578// ==============================================================================
579
580std::vector<SteamGridDBImage> SteamGridDBService::getGridImages(int gameId)
581{
582 if (gameId <= 0)
583 return {};
584
585 std::string url = "https://www.steamgriddb.com/api/v2/grids/game/" + std::to_string(gameId) +
586 "?dimensions=600x900";
587
588 std::map<std::string, std::string> headers;
589 {
590 std::lock_guard<std::mutex> lock(apiKeyMutex_);
591 if (!apiKey_.empty())
592 {
593 headers["Authorization"] = "Bearer " + apiKey_;
594 }
595 }
596
597 std::string response = httpGet(url, headers);
598 return parseImagesJson(response);
599}
600
601std::vector<SteamGridDBImage> SteamGridDBService::getHeroImages(int gameId)
602{
603 if (gameId <= 0)
604 return {};
605
606 std::string url = "https://www.steamgriddb.com/api/v2/heroes/game/" + std::to_string(gameId);
607
608 std::map<std::string, std::string> headers;
609 {
610 std::lock_guard<std::mutex> lock(apiKeyMutex_);
611 if (!apiKey_.empty())
612 {
613 headers["Authorization"] = "Bearer " + apiKey_;
614 }
615 }
616
617 std::string response = httpGet(url, headers);
618 return parseImagesJson(response);
619}
620
621std::vector<SteamGridDBImage> SteamGridDBService::getLogoImages(int gameId)
622{
623 if (gameId <= 0)
624 return {};
625
626 std::string url = "https://www.steamgriddb.com/api/v2/logos/game/" + std::to_string(gameId);
627
628 std::map<std::string, std::string> headers;
629 {
630 std::lock_guard<std::mutex> lock(apiKeyMutex_);
631 if (!apiKey_.empty())
632 {
633 headers["Authorization"] = "Bearer " + apiKey_;
634 }
635 }
636
637 std::string response = httpGet(url, headers);
638 return parseImagesJson(response);
639}
640
641std::vector<SteamGridDBImage> SteamGridDBService::getIconImages(int gameId)
642{
643 if (gameId <= 0)
644 return {};
645
646 std::string url = "https://www.steamgriddb.com/api/v2/icons/game/" + std::to_string(gameId);
647
648 std::map<std::string, std::string> headers;
649 {
650 std::lock_guard<std::mutex> lock(apiKeyMutex_);
651 if (!apiKey_.empty())
652 {
653 headers["Authorization"] = "Bearer " + apiKey_;
654 }
655 }
656
657 std::string response = httpGet(url, headers);
658 return parseImagesJson(response);
659}
660
662{
664
665 if (gameId <= 0)
666 return set;
667
668 Logger::info("SteamGridDB: Fetching all images for game ID {}", gameId);
669
670 set.grids = getGridImages(gameId);
671 set.heroes = getHeroImages(gameId);
672 set.logos = getLogoImages(gameId);
673 set.icons = getIconImages(gameId);
674
675 Logger::info("SteamGridDB: Found {} grids, {} heroes, {} logos, {} icons", set.grids.size(),
676 set.heroes.size(), set.logos.size(), set.icons.size());
677
678 return set;
679}
680
681// ==============================================================================
682// Image Download
683// ==============================================================================
684
686 const std::string& gameName)
687{
688 if (image.url.empty())
689 return "";
690
691 std::string cacheDir = getCacheDirectory();
692 if (cacheDir.empty())
693 return "";
694
695 std::string safeName = sanitizeFilename(gameName);
696 std::string extension = getImageExtension(image.mime);
697 std::string filename = safeName + "_" + std::to_string(image.id) + extension;
698 std::string localPath = cacheDir + "/" + filename;
699
700 // Check if already cached
701 if (fs::exists(localPath) && fs::file_size(localPath) > 0)
702 {
703 Logger::debug("SteamGridDB: Using cached image: {}", localPath);
704 return localPath;
705 }
706
707 Logger::info("SteamGridDB: Downloading image for '{}' from {}", gameName, image.url);
708
709 if (downloadFile(image.url, localPath))
710 {
711 Logger::info("SteamGridDB: Downloaded image to {}", localPath);
712 return localPath;
713 }
714
715 return "";
716}
717
718std::string SteamGridDBService::downloadBestCover(const std::string& gameName)
719{
720 if (gameName.empty())
721 return "";
722
723 // First check cache
724 std::string cached = getCachedCover(gameName);
725 if (!cached.empty())
726 {
727 Logger::debug("SteamGridDB: Using cached cover for '{}'", gameName);
728 return cached;
729 }
730
731 Logger::info("SteamGridDB: Searching for cover art for '{}'", gameName);
732
733 // Search for the game
734 auto games = searchGames(gameName);
735 if (games.empty())
736 {
737 Logger::warn("SteamGridDB: No games found matching '{}'", gameName);
738 return "";
739 }
740
741 // Find best match (prefer exact name match)
742 int bestGameId = games[0].id;
743 std::string nameToMatch = gameName;
744 std::transform(nameToMatch.begin(), nameToMatch.end(), nameToMatch.begin(),
745 [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
746
747 for (const auto& game : games)
748 {
749 std::string gameNameLower = game.name;
750 std::transform(gameNameLower.begin(), gameNameLower.end(), gameNameLower.begin(),
751 [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
752
753 if (gameNameLower == nameToMatch)
754 {
755 bestGameId = game.id;
756 break;
757 }
758 }
759
760 // Get cover images
761 auto covers = getGridImages(bestGameId);
762 if (covers.empty())
763 {
764 Logger::warn("SteamGridDB: No cover images found for '{}'", gameName);
765 return "";
766 }
767
768 // Download the best (highest scored, non-NSFW) cover
769 for (const auto& cover : covers)
770 {
771 if (!cover.nsfw)
772 {
773 return downloadImage(cover, gameName);
774 }
775 }
776
777 // Fall back to first cover if all are NSFW flagged
778 if (!covers.empty())
779 {
780 return downloadImage(covers[0], gameName);
781 }
782
783 return "";
784}
785
787 const std::string& gameName, const std::function<void(const std::string&)>& callback)
788{
789 auto future =
790 std::make_shared<std::future<void>>(std::async(std::launch::async,
791 [gameName, callback]()
792 {
793 std::string path =
794 downloadBestCover(gameName);
795 if (callback)
796 callback(path);
797 }));
798 storeFuture(std::move(future));
799}
800
801std::string SteamGridDBService::getCachedCover(const std::string& gameName)
802{
803 std::string cacheDir = getCacheDirectory();
804 if (cacheDir.empty())
805 return "";
806
807 std::string safeName = sanitizeFilename(gameName);
808 if (safeName.empty())
809 return "";
810
811 // Look for any cached cover with this game name prefix
812 try
813 {
814 for (const auto& entry : fs::directory_iterator(cacheDir))
815 {
816 if (!entry.is_regular_file())
817 continue;
818
819 std::string filename = entry.path().filename().string();
820 if (filename.find(safeName) == 0)
821 {
822 return entry.path().string();
823 }
824 }
825 }
826 catch (...)
827 {
828 // Ignore errors
829 }
830
831 return "";
832}
833
834// ==============================================================================
835// Cache Management
836// ==============================================================================
837
839{
840 std::string cacheDir = getCacheDirectory();
841 if (cacheDir.empty())
842 return;
843
844 try
845 {
846 for (const auto& entry : fs::directory_iterator(cacheDir))
847 {
848 if (entry.is_regular_file())
849 {
850 fs::remove(entry.path());
851 }
852 }
853 Logger::info("SteamGridDB: Cache cleared");
854 }
855 catch (const std::exception& e)
856 {
857 Logger::warn("SteamGridDB: Failed to clear cache: {}", e.what());
858 }
859}
860
862{
863 std::string cacheDir = getCacheDirectory();
864 if (cacheDir.empty())
865 return 0;
866
867 size_t totalSize = 0;
868
869 try
870 {
871 for (const auto& entry : fs::directory_iterator(cacheDir))
872 {
873 if (entry.is_regular_file())
874 {
875 totalSize += entry.file_size();
876 }
877 }
878 }
879 catch (...)
880 {
881 // Ignore errors
882 }
883
884 return totalSize;
885}
static void info(const std::string &message, Args &&... args)
Log info message (general information).
Definition logger.h:108
static void debug(const std::string &message, Args &&... args)
Log debug message (verbose development info).
Definition logger.h:100
static void error(const std::string &message, Args &&... args)
Log error message (recoverable failure).
Definition logger.h:124
static void warn(const std::string &message, Args &&... args)
Log warning message (non-critical issue).
Definition logger.h:116
static std::string escapeArg(const std::string &arg)
Escape a string for safe use as a shell argument.
Definition shell_utils.h:65
static std::vector< SteamGridDBGame > searchGames(const std::string &query)
Search for games by name.
static std::string downloadImage(const SteamGridDBImage &image, const std::string &gameName)
Download an image to local cache.
static std::string getCachedCover(const std::string &gameName)
Check if we have a cached cover for a game.
static std::vector< SteamGridDBImage > getGridImages(int gameId)
Get grid/cover images for a game.
static SteamGridDBGame getGameBySteamAppId(int steamAppId)
Get game info by Steam App ID.
static std::string downloadBestCover(const std::string &gameName)
Download best cover art for a game by name.
static void searchGamesAsync(const std::string &query, const std::function< void(const std::vector< SteamGridDBGame > &)> &callback)
Search for games by name asynchronously.
static void setApiKey(const std::string &key)
Set the API key for SteamGridDB.
static std::vector< SteamGridDBImage > getLogoImages(int gameId)
Get logo images for a game.
static bool hasApiKey()
Check if API key is configured.
static SteamGridDBImageSet getAllImages(int gameId)
Get all images for a game.
static void downloadBestCoverAsync(const std::string &gameName, const std::function< void(const std::string &)> &callback)
Download best cover art asynchronously.
static void clearCache()
Clear all cached images.
static size_t getCacheSize()
Get total size of cached images in bytes.
static std::string getCacheDirectory()
Get the cache directory for downloaded images.
static std::vector< SteamGridDBImage > getHeroImages(int gameId)
Get hero images for a game.
static std::vector< SteamGridDBImage > getIconImages(int gameId)
Get icon images for a game.
nlohmann::json json
std::string jsonGetString(const std::string &json, const std::string &key)
std::vector< std::string > jsonSplitArray(const std::string &json, const std::string &arrayKey)
int jsonGetInt(const std::string &json, const std::string &key)
int jsonGetInt(const std::string &json, const std::string &key)
std::vector< std::shared_ptr< std::future< void > > > activeFutures_
std::vector< std::string > jsonSplitArray(const std::string &json, const std::string &arrayKey="")
void storeFuture(std::shared_ptr< std::future< void > > f)
bool jsonGetBool(const std::string &json, const std::string &key)
std::string jsonGetString(const std::string &json, const std::string &key)
Search result from SteamGridDB.
int steamAppId
Steam App ID if linked (0 if not Steam).
int id
SteamGridDB game ID.
std::string releaseDate
Release date (YYYY-MM-DD).
std::string name
Game name.
bool verified
If game is verified on SteamGridDB.
Complete set of images for a game.
std::vector< SteamGridDBImage > icons
Icon images.
std::vector< SteamGridDBImage > heroes
Hero images (wide banners).
std::vector< SteamGridDBImage > logos
Logo images with transparency.
std::vector< SteamGridDBImage > grids
Cover art / grid images (600x900).
Image result from SteamGridDB.
int width
Image width in pixels.
std::string thumbUrl
URL for thumbnail.
std::string mime
MIME type (image/png, image/jpeg).
std::string url
URL to download image.
std::string style
Style: "alternate", "blurred", "white_logo", etc.
int score
Community score.
int height
Image height in pixels.
int id
Image ID on SteamGridDB.