19#include <nlohmann/json.hpp>
24namespace fs = std::filesystem;
35 [](
const std::shared_ptr<std::future<void>>& fu)
37 return fu->wait_for(std::chrono::seconds(0)) ==
38 std::future_status::ready;
56 if (installPath.empty() || executable.empty())
59 std::error_code ec1, ec2;
60 const fs::path candidate = fs::path(installPath) / executable;
61 const fs::path canonCand = fs::weakly_canonical(candidate, ec1);
62 const fs::path canonBase = fs::weakly_canonical(fs::path(installPath), ec2);
66 std::error_code relEc;
67 const fs::path rel = fs::relative(canonCand, canonBase, relEc);
68 if (relEc || rel.empty() || *rel.begin() ==
"..")
76std::vector<std::string> GameScannerService::customScanDirs_;
77std::mutex GameScannerService::customScanDirsMutex_;
81 std::lock_guard<std::mutex> lock(customScanDirsMutex_);
82 customScanDirs_ = dirs;
92 std::hash<std::string> hasher;
94 std::ostringstream oss;
95 oss << std::hex << hash;
136 std::string overrides;
139 if (!overrides.empty())
141 overrides += dll +
"=" + mode;
184std::string GameScannerService::getHomeDir()
186 const char* home = std::getenv(
"HOME");
187 return home ? home :
"";
190std::string GameScannerService::expandPath(
const std::string& path)
195 std::string result = path;
198 if (result[0] ==
'~')
200 std::string home = getHomeDir();
203 result = home + result.substr(1);
208 size_t pos = result.find(
"$HOME");
209 if (pos != std::string::npos)
211 std::string home = getHomeDir();
212 result.replace(pos, 5, home);
218uint64_t GameScannerService::getDirectorySize(
const std::string& path)
220 uint64_t totalSize = 0;
223 for (
const auto& entry :
224 fs::recursive_directory_iterator(path, fs::directory_options::skip_permission_denied))
226 if (entry.is_regular_file())
228 totalSize += entry.file_size();
239time_t GameScannerService::getLastModified(
const std::string& path)
243 auto ftime = fs::last_write_time(path);
244 auto sctp = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
245 ftime - fs::file_time_type::clock::now() + std::chrono::system_clock::now());
246 return std::chrono::system_clock::to_time_t(sctp);
258std::string GameScannerService::extractJsonString(
const std::string&
json,
const std::string& key)
260 std::string searchKey =
"\"" + key +
"\"";
261 size_t keyPos =
json.find(searchKey);
262 if (keyPos == std::string::npos)
265 size_t colonPos =
json.find(
':', keyPos + searchKey.length());
266 if (colonPos == std::string::npos)
269 size_t valueStart =
json.find_first_not_of(
" \t\n\r", colonPos + 1);
270 if (valueStart == std::string::npos)
273 if (
json[valueStart] ==
'"')
275 size_t valueEnd =
json.find(
'"', valueStart + 1);
276 if (valueEnd == std::string::npos)
278 return json.substr(valueStart + 1, valueEnd - valueStart - 1);
284int GameScannerService::extractJsonInt(
const std::string&
json,
const std::string& key)
286 std::string searchKey =
"\"" + key +
"\"";
287 size_t keyPos =
json.find(searchKey);
288 if (keyPos == std::string::npos)
291 size_t colonPos =
json.find(
':', keyPos + searchKey.length());
292 if (colonPos == std::string::npos)
295 size_t valueStart =
json.find_first_not_of(
" \t\n\r", colonPos + 1);
296 if (valueStart == std::string::npos)
299 size_t valueEnd =
json.find_first_of(
",}\n\r", valueStart);
300 std::string valueStr =
json.substr(valueStart, valueEnd - valueStart);
304 return std::stoi(valueStr);
312bool GameScannerService::extractJsonBool(
const std::string&
json,
const std::string& key)
314 std::string searchKey =
"\"" + key +
"\"";
315 size_t keyPos =
json.find(searchKey);
316 if (keyPos == std::string::npos)
319 size_t colonPos =
json.find(
':', keyPos + searchKey.length());
320 if (colonPos == std::string::npos)
323 size_t valueStart =
json.find_first_not_of(
" \t\n\r", colonPos + 1);
324 if (valueStart == std::string::npos)
327 return json.substr(valueStart, 4) ==
"true";
337 return !gamesDir.empty() && fs::exists(gamesDir);
342 return fs::exists(expandPath(
"~/.local/share/bottles/bottles")) ||
343 fs::exists(expandPath(
"~/.var/app/com.usebottles.bottles/data/bottles/bottles"));
348 return fs::exists(expandPath(
"~/.config/heroic")) ||
349 fs::exists(expandPath(
"~/.var/app/com.heroicgameslauncher.hgl/config/heroic"));
354 std::string legendaryDir = expandPath(
"~/.config/legendary");
355 return fs::exists(legendaryDir);
414 std::vector<ScannedGame> games;
417 if (gamesDir.empty() || !fs::exists(gamesDir))
419 Logger::info(
"[GameScanner] Lutris games directory not found");
423 Logger::info(
"[GameScanner] Scanning Lutris games at {}", gamesDir);
427 for (
const auto& entry : fs::directory_iterator(gamesDir))
429 if (!entry.is_regular_file())
432 std::string filename = entry.path().filename().string();
433 if (filename.size() < 4 || filename.substr(filename.size() - 4) !=
".yml")
436 auto parsed = parseLutrisConfig(entry.path().string());
437 for (
auto& game : parsed)
439 games.push_back(std::move(game));
443 catch (
const std::exception& e)
445 Logger::warn(
"[GameScanner] Error scanning Lutris: {}", e.what());
448 Logger::info(
"[GameScanner] Found {} games in Lutris", games.size());
452std::vector<ScannedGame> GameScannerService::parseLutrisConfig(
const std::string& configPath)
454 std::vector<ScannedGame> games;
476 if (config.
arch ==
"win32" || config.
arch ==
"win64" || !config.
prefix.empty())
480 std::transform(lowerWineVersion.begin(), lowerWineVersion.end(), lowerWineVersion.begin(),
481 [](
unsigned char c) { return static_cast<char>(::tolower(c)); });
483 if (lowerWineVersion.find(
"proton") != std::string::npos ||
484 lowerWineVersion.find(
"umu") != std::string::npos ||
485 lowerWineVersion.find(
"ge-proton") != std::string::npos)
489 Logger::info(
"[GameScanner] Detected Proton runner for {}: {}", config.
name,
510 std::string nameLower = config.
name;
511 std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(),
512 [](
unsigned char c) { return static_cast<char>(::tolower(c)); });
514 if (nameLower.find(
"battle.net") != std::string::npos ||
515 nameLower.find(
"battlenet") != std::string::npos ||
516 nameLower.find(
"blizzard") != std::string::npos)
519 std::vector<std::string> battlenetExcludes = {
520 "Agent.exe",
"Battle.net Helper.exe",
521 "Battle.net.exe",
"Battle.net Launcher.exe",
522 "CrashReporter.exe",
"BlizzardBrowser.exe",
523 "BlizzardError.exe",
"Blizzard Update Agent.exe",
524 "WowVoiceProxy.exe"};
525 for (
const auto& proc : battlenetExcludes)
530 if (existing == proc)
539 Logger::info(
"[GameScanner] Added Battle.net launcher exclusions for: {}", config.
name);
541 else if (nameLower.find(
"ea app") != std::string::npos ||
542 nameLower.find(
"origin") != std::string::npos)
545 std::vector<std::string> eaExcludes = {
"EADesktop.exe",
546 "EABackgroundService.exe",
547 "EALocalHostSvc.exe",
549 "OriginWebHelperService.exe",
550 "OriginClientService.exe",
554 for (
const auto& proc : eaExcludes)
559 if (existing == proc)
568 Logger::info(
"[GameScanner] Added EA App launcher exclusions for: {}", config.
name);
570 else if (nameLower.find(
"epic") != std::string::npos)
573 std::vector<std::string> epicExcludes = {
"EpicGamesLauncher.exe",
"EpicWebHelper.exe",
574 "UnrealCEFSubProcess.exe",
575 "CrashReportClient.exe"};
576 for (
const auto& proc : epicExcludes)
581 if (existing == proc)
590 Logger::info(
"[GameScanner] Added Epic Games launcher exclusions for: {}", config.
name);
592 else if (nameLower.find(
"ubisoft") != std::string::npos ||
593 nameLower.find(
"uplay") != std::string::npos)
596 std::vector<std::string> ubiExcludes = {
597 "UbisoftConnect.exe",
"UbisoftGameLauncher.exe",
"upc.exe",
"UplayWebCore.exe",
598 "Uplay.exe",
"UplayCrashReporter.exe"};
599 for (
const auto& proc : ubiExcludes)
604 if (existing == proc)
613 Logger::info(
"[GameScanner] Added Ubisoft launcher exclusions for: {}", config.
name);
615 else if (nameLower.find(
"gog") != std::string::npos ||
616 nameLower.find(
"galaxy") != std::string::npos)
619 std::vector<std::string> gogExcludes = {
"GalaxyClient.exe",
"GalaxyClientService.exe",
620 "GalaxyCommunication.exe",
"GOG Galaxy.exe",
622 for (
const auto& proc : gogExcludes)
627 if (existing == proc)
636 Logger::info(
"[GameScanner] Added GOG Galaxy launcher exclusions for: {}", config.
name);
647 if (prefixPath.filename() !=
"." && prefixPath.filename() !=
"..")
657 std::string coverPath = expandPath(
"~/.local/share/lutris/coverart/" + artworkSlug +
".jpg");
658 if (fs::exists(coverPath))
661 Logger::debug(
"[GameScanner] Found Lutris cover art: {}", coverPath);
666 coverPath = expandPath(
"~/.local/share/lutris/coverart/" + artworkSlug +
".png");
667 if (fs::exists(coverPath))
674 std::string bannerPath = expandPath(
"~/.local/share/lutris/banners/" + artworkSlug +
".jpg");
675 if (fs::exists(bannerPath))
678 Logger::debug(
"[GameScanner] Found Lutris banner: {}", bannerPath);
682 bannerPath = expandPath(
"~/.local/share/lutris/banners/" + artworkSlug +
".png");
683 if (fs::exists(bannerPath))
690 std::string iconPath =
691 expandPath(
"~/.local/share/icons/hicolor/128x128/apps/lutris_" + config.
slug +
".png");
692 if (fs::exists(iconPath))
699 iconPath = expandPath(
"~/.local/share/lutris/icons/" + artworkSlug +
".png");
700 if (fs::exists(iconPath))
707 games.push_back(game);
718 std::vector<ScannedGame> games;
720 std::string bottlesDir = expandPath(
"~/.local/share/bottles/bottles");
721 if (!fs::exists(bottlesDir))
723 bottlesDir = expandPath(
"~/.var/app/com.usebottles.bottles/data/bottles/bottles");
725 if (!fs::exists(bottlesDir))
727 Logger::info(
"[GameScanner] Bottles directory not found");
731 Logger::info(
"[GameScanner] Scanning Bottles at {}", bottlesDir);
735 for (
const auto& entry : fs::directory_iterator(bottlesDir))
737 if (!entry.is_directory())
740 std::string bottlePath = entry.path().string();
743 if (!fs::exists(bottlePath +
"/drive_c"))
746 auto parsed = parseBottleConfig(bottlePath);
747 for (
auto& game : parsed)
749 games.push_back(std::move(game));
753 catch (
const std::exception& e)
755 Logger::warn(
"[GameScanner] Error scanning Bottles: {}", e.what());
758 Logger::info(
"[GameScanner] Found {} games in Bottles", games.size());
762std::vector<ScannedGame> GameScannerService::parseBottleConfig(
const std::string& bottlePath)
764 std::vector<ScannedGame> games;
769 std::string configPath = bottlePath +
"/bottle.yml";
770 if (!fs::exists(configPath))
778 std::string programsPath = bottlePath +
"/.local/share/applications";
779 if (fs::exists(programsPath))
781 for (
const auto& entry : fs::directory_iterator(programsPath))
783 if (!entry.is_regular_file())
786 std::string filename = entry.path().filename().string();
787 if (filename.find(
".desktop") == std::string::npos)
790 auto desktopGames = parseDesktopFile(entry.path().string());
791 for (
auto& game : desktopGames)
796 games.push_back(std::move(game));
802 std::vector<std::string> gameDirs = {
803 bottlePath +
"/drive_c/Program Files/",
804 bottlePath +
"/drive_c/Program Files (x86)/",
805 bottlePath +
"/drive_c/Games/",
808 for (
const auto& gameDir : gameDirs)
810 if (!fs::exists(gameDir))
815 for (
const auto& entry : fs::directory_iterator(gameDir))
817 if (!entry.is_directory())
820 std::string gamePath = entry.path().string();
821 std::string gameName = entry.path().filename().string();
824 if (gameName ==
"Common Files" || gameName ==
"Internet Explorer" ||
825 gameName ==
"Windows NT" || gameName ==
"WindowsPowerShell" ||
826 gameName.find(
"Microsoft") != std::string::npos)
832 for (
const auto& gameEntry : fs::directory_iterator(gamePath))
834 if (!gameEntry.is_regular_file())
837 std::string exeName = gameEntry.path().filename().string();
838 if (exeName.size() > 4 && exeName.substr(exeName.size() - 4) ==
".exe")
841 std::string lowerExe = exeName;
842 std::transform(lowerExe.begin(), lowerExe.end(), lowerExe.begin(),
844 { return static_cast<char>(::tolower(c)); });
845 if (lowerExe.find(
"unins") != std::string::npos ||
846 lowerExe.find(
"setup") != std::string::npos ||
847 lowerExe.find(
"install") != std::string::npos ||
848 lowerExe.find(
"update") != std::string::npos ||
849 lowerExe.find(
"crash") != std::string::npos ||
850 lowerExe.find(
"report") != std::string::npos)
856 game.
name = gameName;
863 game.
lastModified = getLastModified(gameEntry.path().string());
866 games.push_back(game);
887 std::vector<ScannedGame> games;
889 std::string heroicDir = expandPath(
"~/.config/heroic");
890 if (!fs::exists(heroicDir))
892 heroicDir = expandPath(
"~/.var/app/com.heroicgameslauncher.hgl/config/heroic");
894 if (!fs::exists(heroicDir))
896 Logger::info(
"[GameScanner] Heroic directory not found");
900 Logger::info(
"[GameScanner] Scanning Heroic at {}", heroicDir);
903 std::string gogInstalledPath = heroicDir +
"/gog_store/installed.json";
904 if (fs::exists(gogInstalledPath))
906 auto gogGames = parseHeroicInstalledJson(gogInstalledPath,
GameSource::GOG);
907 for (
auto& game : gogGames)
909 games.push_back(std::move(game));
914 std::string epicInstalledPath = heroicDir +
"/legendaryConfig/legendary/installed.json";
915 if (fs::exists(epicInstalledPath))
917 auto epicGames = parseHeroicInstalledJson(epicInstalledPath,
GameSource::Epic);
918 for (
auto& game : epicGames)
920 games.push_back(std::move(game));
925 epicInstalledPath = heroicDir +
"/store/installed.json";
926 if (fs::exists(epicInstalledPath))
928 auto epicGames = parseHeroicInstalledJson(epicInstalledPath,
GameSource::Epic);
929 for (
auto& game : epicGames)
931 games.push_back(std::move(game));
935 Logger::info(
"[GameScanner] Found {} games in Heroic", games.size());
939std::vector<ScannedGame> GameScannerService::parseHeroicInstalledJson(
const std::string& jsonPath,
942 std::vector<ScannedGame> games;
944 std::ifstream file(jsonPath);
956 for (
auto& [key, value] : j.items())
958 if (!value.is_object())
961 std::string installPath = value.value(
"install_path",
"");
962 std::string title = value.value(
"title", key);
963 std::string appName = value.value(
"app_name", key);
964 std::string executable = value.value(
"executable",
"");
966 if (installPath.empty())
970 game.
name = title.empty() ? appName : title;
981 if (!executable.empty())
983 const fs::path resolved = resolveContainedExecutable(installPath, executable);
984 if (!resolved.empty() && fs::exists(resolved))
988 else if (resolved.empty())
990 Logger::warn(
"[Scanner] Rejected Heroic executable that "
991 "escapes installPath: {}",
1008 std::string ext = fs::path(game.
executablePath).extension().string();
1009 std::transform(ext.begin(), ext.end(), ext.begin(),
1010 [](
unsigned char c) { return static_cast<char>(::tolower(c)); });
1014 game.
sizeOnDisk = getDirectorySize(installPath);
1017 games.push_back(game);
1020 else if (j.is_array())
1022 for (
const auto& value : j)
1024 if (!value.is_object())
1027 std::string installPath = value.value(
"install_path",
"");
1028 std::string title = value.value(
"title",
"");
1029 std::string appName = value.value(
"app_name",
"");
1031 if (installPath.empty())
1035 game.
name = title.empty() ? appName : title;
1041 std::string executable = value.value(
"executable",
"");
1042 if (!executable.empty())
1044 bool hasTraversal =
false;
1045 for (
const auto& component : fs::path(executable))
1047 if (component ==
"..")
1049 hasTraversal =
true;
1055 std::string fullExe = installPath +
"/" + executable;
1056 if (fs::exists(fullExe))
1061 Logger::warn(
"[Scanner] Rejected executable with path traversal: {}",
1066 std::string ext = fs::path(game.
executablePath).extension().string();
1067 std::transform(ext.begin(), ext.end(), ext.begin(),
1068 [](
unsigned char c) { return static_cast<char>(::tolower(c)); });
1072 game.
sizeOnDisk = getDirectorySize(installPath);
1075 games.push_back(game);
1079 catch (
const std::exception& e)
1081 Logger::error(
"[GameScanner] Failed to parse Heroic JSON {}: {}", jsonPath, e.what());
1093 std::vector<ScannedGame> games;
1095 std::string legendaryDir = expandPath(
"~/.config/legendary");
1096 std::string installedPath = legendaryDir +
"/installed.json";
1098 if (!fs::exists(installedPath))
1100 Logger::info(
"[GameScanner] Legendary installed.json not found");
1104 Logger::info(
"[GameScanner] Scanning Legendary at {}", legendaryDir);
1106 auto parsedGames = parseLegendaryInstalledJson(installedPath);
1107 for (
auto& game : parsedGames)
1109 games.push_back(std::move(game));
1112 Logger::info(
"[GameScanner] Found {} games in Legendary", games.size());
1116std::vector<ScannedGame>
1117GameScannerService::parseLegendaryInstalledJson(
const std::string& jsonPath)
1119 std::vector<ScannedGame> games;
1121 std::ifstream file(jsonPath);
1122 if (!file.is_open())
1130 for (
auto& [appName, value] : j.items())
1132 if (!value.is_object())
1135 std::string installPath = value.value(
"install_path",
"");
1136 if (installPath.empty())
1139 std::string title = value.value(
"title", appName);
1140 std::string executable = value.value(
"executable",
"");
1148 if (!executable.empty())
1153 const fs::path resolved = resolveContainedExecutable(installPath, executable);
1154 if (!resolved.empty() && fs::exists(resolved))
1158 else if (resolved.empty())
1160 Logger::warn(
"[Scanner] Rejected Legendary executable that "
1161 "escapes installPath: {}",
1175 std::string ext = fs::path(game.
executablePath).extension().string();
1176 std::transform(ext.begin(), ext.end(), ext.begin(),
1177 [](
unsigned char c) { return static_cast<char>(::tolower(c)); });
1181 game.
sizeOnDisk = getDirectorySize(installPath);
1184 games.push_back(game);
1187 catch (
const std::exception& e)
1189 Logger::error(
"[GameScanner] Failed to parse Legendary JSON {}: {}", jsonPath, e.what());
1201 std::vector<ScannedGame> games;
1203 Logger::info(
"[GameScanner] Scanning for native Linux games");
1206 std::vector<std::string> gameDirs = {
1207 expandPath(
"~/Games"),
1208 expandPath(
"~/games"),
1209 expandPath(
"~/GOG Games"),
1210 expandPath(
"~/.local/share/games"),
1217 std::lock_guard<std::mutex> lock(customScanDirsMutex_);
1218 for (
const auto& customDir : customScanDirs_)
1220 if (!customDir.empty())
1222 gameDirs.push_back(customDir);
1227 for (
const auto& gameDir : gameDirs)
1229 if (!fs::exists(gameDir))
1234 for (
const auto& entry : fs::directory_iterator(gameDir))
1236 if (!entry.is_directory())
1239 std::string gamePath = entry.path().string();
1240 std::string gameName = entry.path().filename().string();
1243 std::string lowerName = gameName;
1244 std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(),
1245 [](
unsigned char c) { return static_cast<char>(::tolower(c)); });
1246 if (lowerName ==
"steamapps" || lowerName ==
"steam" ||
1247 lowerName.find(
"steamapps") != std::string::npos)
1249 Logger::debug(
"[GameScanner] Skipping Steam directory: {}", gameName);
1254 if (fs::exists(gamePath +
"/pfx.lock") || fs::exists(gamePath +
"/drive_c") ||
1255 fs::exists(gamePath +
"/dosdevices"))
1257 Logger::debug(
"[GameScanner] Skipping Wine prefix: {}", gameName);
1262 for (
const auto& gameEntry : fs::directory_iterator(gamePath))
1264 if (!gameEntry.is_regular_file())
1269 auto perms = fs::status(gameEntry.path()).permissions();
1270 if ((perms & fs::perms::owner_exec) != fs::perms::none)
1272 std::string filename = gameEntry.path().filename().string();
1273 std::string ext = gameEntry.path().extension().string();
1276 std::string lower = filename;
1277 std::transform(lower.begin(), lower.end(), lower.begin(),
1279 { return static_cast<char>(::tolower(c)); });
1280 if (lower.find(
"unins") != std::string::npos ||
1281 lower.find(
"crash") != std::string::npos ||
1282 lower.find(
"report") != std::string::npos || lower ==
"start.sh" ||
1290 if (ext ==
".sh" && (lower.find(
"install") != std::string::npos ||
1291 lower.find(
"setup") != std::string::npos ||
1292 lower.find(
"config") != std::string::npos))
1296 if (lower ==
"pfx.lock" || lower.find(
".lock") != std::string::npos ||
1297 ext ==
".acf" || ext ==
".vdf" ||
1298 lower.find(
"wine") != std::string::npos ||
1299 lower.find(
"proton") != std::string::npos)
1305 game.
name = gameName;
1310 game.
sizeOnDisk = getDirectorySize(gamePath);
1311 game.
lastModified = getLastModified(gameEntry.path().string());
1314 games.push_back(game);
1330 std::string applicationsDir = expandPath(
"~/.local/share/applications");
1331 if (fs::exists(applicationsDir))
1333 for (
const auto& entry : fs::directory_iterator(applicationsDir))
1335 if (!entry.is_regular_file())
1338 std::string filename = entry.path().filename().string();
1339 if (filename.find(
".desktop") == std::string::npos)
1344 if (filename.find(
"steam_app_") == 0)
1346 Logger::debug(
"[GameScanner] Skipping Steam desktop file: {}", filename);
1353 std::ifstream quickCheck(entry.path().string());
1354 std::string checkLine;
1355 bool isSteamShortcut =
false;
1356 while (std::getline(quickCheck, checkLine))
1358 if (checkLine.find(
"Exec=") == 0 &&
1359 (checkLine.find(
"steam://") != std::string::npos ||
1360 checkLine.find(
"Exec=steam ") == 0))
1362 isSteamShortcut =
true;
1365 if (checkLine.find(
"Icon=steam_icon_") == 0)
1367 isSteamShortcut =
true;
1371 if (isSteamShortcut)
1373 Logger::debug(
"[GameScanner] Skipping Steam shortcut: {}", filename);
1378 auto desktopGames = parseDesktopFile(entry.path().string());
1379 for (
auto& game : desktopGames)
1382 bool duplicate =
false;
1383 for (
const auto& existing : games)
1393 games.push_back(std::move(game));
1399 Logger::info(
"[GameScanner] Found {} native games", games.size());
1403std::vector<ScannedGame> GameScannerService::parseDesktopFile(
const std::string& desktopPath)
1405 std::vector<ScannedGame> games;
1407 std::ifstream file(desktopPath);
1408 if (!file.is_open())
1411 std::string name, exec, icon, categories;
1413 bool inDesktopEntry =
false;
1415 while (std::getline(file, line))
1418 size_t start = line.find_first_not_of(
" \t");
1419 if (start == std::string::npos)
1421 line = line.substr(start);
1425 inDesktopEntry = (line ==
"[Desktop Entry]");
1429 if (!inDesktopEntry)
1432 size_t eq = line.find(
'=');
1433 if (eq == std::string::npos)
1436 std::string key = line.substr(0, eq);
1437 std::string value = line.substr(eq + 1);
1441 else if (key ==
"Exec")
1443 else if (key ==
"Icon")
1445 else if (key ==
"Categories")
1450 if (!exec.empty() && !name.empty())
1452 bool isGame = categories.find(
"Game") != std::string::npos;
1457 std::string lowerName = name;
1458 std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(),
1459 [](
unsigned char c) { return static_cast<char>(::tolower(c)); });
1462 if (lowerName.find(
"settings") != std::string::npos ||
1463 lowerName.find(
"configure") != std::string::npos ||
1464 lowerName.find(
"editor") != std::string::npos ||
1465 lowerName.find(
"utility") != std::string::npos)
1479 std::string lowerExec = exec;
1480 std::transform(lowerExec.begin(), lowerExec.end(), lowerExec.begin(),
1481 [](
unsigned char c) { return static_cast<char>(::tolower(c)); });
1482 if (lowerExec.find(
"gamelauncher") != std::string::npos)
1488 std::string exePath = exec;
1491 std::regex fieldCode(
"%[fFuUdDnNickvm]");
1492 exePath = std::regex_replace(exePath, fieldCode,
"");
1495 size_t first = exePath.find_first_not_of(
" \t");
1496 size_t last = exePath.find_last_not_of(
" \t");
1497 if (first != std::string::npos)
1498 exePath = exePath.substr(first, last - first + 1);
1501 if (exePath.find(
"env ") == 0)
1504 std::regex envRegex(
"env\\s+[^/]+(/[^ ]+)");
1506 if (std::regex_search(exePath, match, envRegex))
1508 exePath = match[1].str();
1513 size_t space = exePath.find(
' ');
1514 if (space != std::string::npos)
1516 std::string firstToken = exePath.substr(0, space);
1517 if (firstToken[0] ==
'/' || firstToken[0] ==
'~')
1519 exePath = firstToken;
1523 exePath = expandPath(exePath);
1525 if (!exePath.empty() && (fs::exists(exePath) || exePath[0] !=
'/'))
1540 if (fs::exists(exePath))
1542 game.
installDir = fs::path(exePath).parent_path().string();
1547 games.push_back(game);
1561 std::vector<ScannedGame> games;
1566 std::vector<std::string> prefixDirs = {
1567 expandPath(
"~/.wine"),
1568 expandPath(
"~/.wineprefixes"),
1571 for (
const auto& prefixPath : prefixDirs)
1573 if (!fs::exists(prefixPath))
1577 if (fs::exists(prefixPath +
"/drive_c"))
1580 auto bottleGames = parseBottleConfig(prefixPath);
1581 for (
auto& game : bottleGames)
1584 games.push_back(std::move(game));
1592 for (
const auto& entry : fs::directory_iterator(prefixPath))
1594 if (!entry.is_directory())
1597 if (fs::exists(entry.path().string() +
"/drive_c"))
1599 auto prefixGames = parseBottleConfig(entry.path().string());
1600 for (
auto& game : prefixGames)
1603 games.push_back(std::move(game));
1614 Logger::info(
"[GameScanner] Found {} games in Wine prefixes", games.size());
1624 std::vector<ScannedGame> allGames;
1628 auto reportProgress = [&](
const std::string& source)
1635 progress.
gamesFound =
static_cast<int>(allGames.size());
1636 if (progressCallback)
1638 progressCallback(progress);
1643 auto safeScan = [&](
const std::string& source,
1644 const std::function<std::vector<ScannedGame>()>& scanFunc,
1645 const std::function<bool()>& isInstalled =
nullptr)
1649 if (progressCallback)
1650 progressCallback(progress);
1654 if (isInstalled && !isInstalled())
1657 reportProgress(source);
1661 auto games = scanFunc();
1662 for (
auto& game : games)
1664 allGames.push_back(std::move(game));
1669 Logger::debug(
"[GameScanner] No games found in {}", source);
1672 catch (
const fs::filesystem_error& e)
1674 std::string errorMsg =
"Filesystem error: " + std::string(e.what());
1675 Logger::warn(
"[GameScanner] {} scan failed: {}", source, errorMsg);
1676 progress.
addError(source, errorMsg);
1678 catch (
const std::exception& e)
1680 std::string errorMsg = e.what();
1681 Logger::warn(
"[GameScanner] {} scan failed: {}", source, errorMsg);
1682 progress.
addError(source, errorMsg);
1686 Logger::warn(
"[GameScanner] {} scan failed: Unknown error", source);
1687 progress.
addError(source,
"Unknown error during scan");
1690 reportProgress(source);
1705 if (progressCallback)
1708 progress.
gamesFound =
static_cast<int>(allGames.size());
1709 progressCallback(progress);
1716 for (
const auto& error : progress.
errors)
1722 Logger::info(
"[GameScanner] Total games found: {}", allGames.size());
1729 auto future = std::make_shared<std::future<void>>(std::async(std::launch::async,
1730 [onComplete, onProgress]()
1737 storeFuture(std::move(future));
1746 std::vector<ScannedGame> unique;
1747 std::map<std::string, size_t> seenPaths;
1748 std::map<int, size_t> seenSteamAppIds;
1750 auto tryMerge = [&](
size_t existingIdx,
ScannedGame& game)
1756 existing = std::move(game);
1760 existing = std::move(game);
1765 existing = std::move(game);
1769 for (
auto& game : games)
1774 auto steamIt = seenSteamAppIds.find(game.
steamAppId);
1775 if (steamIt != seenSteamAppIds.end())
1777 tryMerge(steamIt->second, game);
1788 key = fs::canonical(key).string();
1795 auto it = seenPaths.find(key);
1796 if (it == seenPaths.end())
1798 size_t idx = unique.size();
1800 seenPaths[key] = idx;
1803 unique.push_back(std::move(game));
1807 tryMerge(it->second, game);
1815 const std::vector<Game>& library)
1818 std::map<std::string, std::string> libraryPaths;
1819 std::map<int, std::string> librarySteamAppIds;
1820 std::map<std::string, std::string> libraryInstallDirs;
1822 for (
const auto& game : library)
1830 path = fs::canonical(path).string();
1835 libraryPaths[path] = game.
id;
1841 librarySteamAppIds[game.metadata.
steamAppId] = game.
id;
1845 if (!game.installPath.empty())
1847 std::string dir = game.installPath;
1850 dir = fs::canonical(dir).string();
1855 libraryInstallDirs[dir] = game.
id;
1860 for (
auto& game : games)
1869 path = fs::canonical(path).string();
1875 auto it = libraryPaths.find(path);
1876 if (it != libraryPaths.end())
1886 auto steamIt = librarySteamAppIds.find(game.
steamAppId);
1887 if (steamIt != librarySteamAppIds.end())
1891 Logger::debug(
"Marked '{}' as already imported (Steam App ID {} matches {})",
1903 dir = fs::canonical(dir).string();
1909 auto dirIt = libraryInstallDirs.find(dir);
1910 if (dirIt != libraryInstallDirs.end())
1914 Logger::debug(
"Marked '{}' as already imported (install dir matches {})", game.
name,
static bool isHeroicInstalled()
Check if Heroic Launcher is installed.
static std::vector< ScannedGame > scanLegendary()
Scan Legendary (Epic Games CLI) for installed games.
std::function< void(const std::vector< ScannedGame > &)> CompletionCallback
static bool isLegendaryInstalled()
Check if Legendary is installed.
static std::string getSourceIcon(GameSource source)
Get icon name for a game source.
static std::vector< ScannedGame > scanWinePrefixes()
Scan generic Wine prefixes for games.
static std::string getSourceDisplayName(GameSource source)
Get display name for a game source.
static std::vector< ScannedGame > scanBottles()
Scan Bottles for installed games.
static bool isLutrisInstalled()
Check if Lutris is installed.
static bool isBottlesInstalled()
Check if Bottles is installed.
static std::vector< ScannedGame > removeDuplicates(std::vector< ScannedGame > games)
Remove duplicate games from the list.
static void setCustomScanDirectories(const std::vector< std::string > &dirs)
Set custom scan directories for native game scanning.
static std::vector< ScannedGame > scanNativeGames()
Scan for native Linux games.
static std::vector< ScannedGame > scanAll(ProgressCallback progressCallback=nullptr)
Scan all available sources for games.
static void scanAllAsync(const CompletionCallback &onComplete, const ProgressCallback &onProgress=nullptr)
Scan all sources asynchronously.
static std::vector< ScannedGame > scanLutris()
Scan Lutris for installed games.
static std::vector< ScannedGame > scanHeroic()
Scan Heroic Launcher for Epic and GOG games.
static void markAlreadyImported(std::vector< ScannedGame > &games, const std::vector< Game > &library)
Mark games that are already in the library.
std::function< void(const ScanProgress &)> ProgressCallback
Complete representation of a game in the library.
GameMetadata metadata
Descriptive information and media.
std::string installPath
Installation directory path.
std::string name
Display name shown in UI.
void syncPlatformFromRunner()
Sync the deprecated platform field from the current runner and source.
GameRunner runner
Runner/compatibility layer to use (Native, Proton, Wine, etc.).
GameRunnerConfig runnerConfig
How to launch and run the game.
GameStatus status
Current installation and execution status.
uint64_t installSizeBytes
Installation size in bytes.
GameSource source
Where the game was acquired from (Steam, GOG, Local, etc.).
static void info(const std::string &message, Args &&... args)
Log info message (general information).
static void debug(const std::string &message, Args &&... args)
Log debug message (verbose development info).
static void error(const std::string &message, Args &&... args)
Log error message (recoverable failure).
static void warn(const std::string &message, Args &&... args)
Log warning message (non-critical issue).
static std::string getGamesDirectory()
Get the Lutris games directory.
static LutrisGameConfig parseConfigFile(const std::string &configPath)
Parse a Lutris game config file.
GameSource
Where the game was acquired from (store/service/local).
@ Steam
Steam store/platform.
@ Local
Manually added game (not from a store).
@ Itch
itch.io indie games
@ Lutris
Lutris community scripts.
@ GOG
GOG.com (DRM-free games).
@ Flatpak
Flatpak package.
@ Installed
Game is installed and ready to play.
@ Proton
Proton (Steam's Wine fork).
@ Native
Native Linux executable (no compatibility layer).
@ Wine
Wine compatibility layer.
fs::path resolveContainedExecutable(const std::string &installPath, const std::string &executable)
void storeFuture(std::shared_ptr< std::future< void > > f)
std::vector< std::shared_ptr< std::future< void > > > activeFutures_
std::string icon
Small square icon (icon.jpg).
std::string verticalCover
Vertical cover art (library_600x900.jpg).
std::string heroImage
Wide banner/hero image (library_hero.jpg).
std::string executablePath
Full path to game executable.
std::string wineDLL
DLL overrides (e.g., "d3d11=native,builtin").
std::string workingDirectory
Working directory for game execution.
std::string arguments
Command line arguments to pass to game.
std::vector< std::string > excludeProcesses
Processes to exclude when tracking launcher child processes These are helper processes that should no...
std::string winePrefix
WINEPREFIX path (Wine install location).
std::string runnerVersion
Runner version: "wine-8.0", "proton-8.0-5", etc.
std::string runnerType
Runner type: "wine", "proton", "native", etc.
std::string protonVersion
Proton version (e.g., "proton-cachyos-slr").
std::map< std::string, std::string > environmentVariables
Environment variables to set before launching (KEY=VALUE pairs).
Parsed configuration for a Lutris-managed game.
std::string workingDir
Working directory (optional).
std::string gameSlug
Game slug from lutris.net.
std::string name
Game display name.
std::string getFullExecutablePath() const
Get the full path to the executable.
std::map< std::string, std::string > dllOverrides
std::string prefix
Wine prefix path.
std::map< std::string, std::string > environmentVariables
std::vector< std::string > excludeProcesses
std::string wineVersion
Wine version name (e.g., "Proton - Experimental").
std::string slug
Game slug (unique identifier).
std::string arguments
Command line arguments (optional).
bool isValid() const
Check if config is valid and usable.
std::string arch
Wine architecture: "win32" or "win64".
void addError(const std::string &source, const std::string &message)
std::vector< std::string > errors
std::string currentOperation
std::string currentSource
std::string runnerVersion
std::map< std::string, std::string > environmentVars
std::vector< std::string > excludeProcesses
std::string existingGameId
std::string executablePath
std::map< std::string, std::string > dllOverrides