diff --git a/backend/endpoints/sockets/scan.py b/backend/endpoints/sockets/scan.py index bc3374981..57afdb11f 100644 --- a/backend/endpoints/sockets/scan.py +++ b/backend/endpoints/sockets/scan.py @@ -455,6 +455,13 @@ async def _identify_platform( scanned_platform = await scan_platform(platform_slug, fs_platforms) if platform: scanned_platform.id = platform.id + # When the slug changes (e.g. the folder was re-mapped as a variant of a + # different base platform via PLATFORMS_VERSIONS), the old custom_name no + # longer applies to the new platform identity. Explicitly reset it so + # that session.merge() clears the stale value in the database and the + # platform displays its canonical metadata name instead. + if platform.slug != scanned_platform.slug: + scanned_platform.custom_name = "" await scan_stats.increment( socket_manager=socket_manager, diff --git a/backend/utils/platforms.py b/backend/utils/platforms.py index 705ecded4..a79d2eea9 100644 --- a/backend/utils/platforms.py +++ b/backend/utils/platforms.py @@ -26,7 +26,19 @@ def get_supported_platforms() -> list[PlatformSchema]: Flashpoint, and HowLongToBeat. """ db_platforms = db_platform_handler.get_platforms() - db_platforms_map = {p.slug: p for p in db_platforms} + + # Build a slug → platform map, preferring the "canonical" platform when + # multiple DB entries share the same slug (e.g. when several folder variants + # all point to the same base platform after a scan). A platform is + # considered canonical when its folder name matches the slug + # (case-insensitively), i.e. the folder was not remapped via + # PLATFORMS_VERSIONS / PLATFORMS_BINDING. When no canonical entry exists + # the first entry encountered (ordered by name ASC in the DB query) wins. + db_platforms_map: dict[str, Platform] = {} + for p in db_platforms: + slug = p.slug + if slug not in db_platforms_map or p.fs_slug.lower() == slug.lower(): + db_platforms_map[slug] = p now = datetime.now(timezone.utc) supported_platforms = []