From c8270b5361d88241c206b2f17732d1f28ed5766c Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:33:41 +0100 Subject: [PATCH] refactor: test an entry's build in read_by_build --- scripts/packs/extras.py | 12 +++--------- scripts/probes/regioncheck.py | 3 ++- scripts/resolve/directories.py | 5 ++--- scripts/resolve/validation.py | 20 +++++++------------- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/scripts/packs/extras.py b/scripts/packs/extras.py index a0d6f3684..9119c5540 100644 --- a/scripts/packs/extras.py +++ b/scripts/packs/extras.py @@ -28,7 +28,7 @@ from resolve.standalone import standalone_set as platform_standalone_set from model.declarations import OUTER_ROOTS, outer_layout from core.paths import declared_destination, sanitize_pack_path from resolve.content import declares_shape, shape_fits, size_fits -from resolve.validation import deliverable, read_from_save_dir, read_from_system_dir +from resolve.validation import deliverable, read_by_build, read_from_save_dir, read_from_system_dir from packs.paths import libretro_systems, save_destination, save_layout from resolve.regions import FILE_GROUP @@ -675,10 +675,7 @@ def _seeds_a_scan(f: dict, layout: dict, standalone: bool) -> bool: # A file of the build the platform does not run seeds nothing: # armsx2's proverb.zip is fetched by the Android app into its own # arcade/ folder, and the libretro packs carried it at system/. - mode = f.get("mode") - if (mode == "standalone" and not standalone) or ( - mode == "libretro" and standalone - ): + if not read_by_build(f, standalone): return False # The scan walks the BIOS tree: a file read below the save # directory is placed by the gap report's pass. @@ -1707,10 +1704,7 @@ def _copies_entry(f: dict, is_standalone: bool, scope: _CopyScope) -> bool: # (Dolphin's codehandler.bin ships in its Sys tree). if "path" in f and f["path"] is None: return False - file_mode = f.get("mode") - if file_mode == "standalone" and not is_standalone: - return False - if file_mode == "libretro" and is_standalone: + if not read_by_build(f, is_standalone): return False return read_from_system_dir(f, is_standalone) diff --git a/scripts/probes/regioncheck.py b/scripts/probes/regioncheck.py index 3030b03ce..f95b8a245 100644 --- a/scripts/probes/regioncheck.py +++ b/scripts/probes/regioncheck.py @@ -19,6 +19,7 @@ from probes.content import Content, load_content, load_file from probes.cores import cached_nightly from probes.entries import entry_dest, held_file, regions_of from probes.host import CONTENT_FILE +from resolve.validation import read_by_build CORES = REPO_ROOT / ".cache" / "region" / "cores" @@ -41,7 +42,7 @@ def region_entries(profile: dict, system: str) -> list[dict]: entry for entry in profile.get("files") or () if system in entry_system_ids(entry, profile) and regions_of(entry) and "world" not in regions_of(entry) - and entry.get("category", "bios") == "bios" and entry.get("mode") != "standalone" + and entry.get("category", "bios") == "bios" and read_by_build(entry, False) ] diff --git a/scripts/resolve/directories.py b/scripts/resolve/directories.py index 38a24b0f1..7654ddba8 100644 --- a/scripts/resolve/directories.py +++ b/scripts/resolve/directories.py @@ -2,7 +2,7 @@ from __future__ import annotations - +from resolve.validation import read_by_build _directory_members_cache: dict[int, tuple[dict, dict[str, dict[str, str]]]] = {} @@ -78,10 +78,9 @@ def expand_directory_entries( # A file the profile names itself is left to that entry, in the same # build and below the same root: MAME's libretro floppy samples share # their path with the standalone tree RetroPie reads below roms/. - other_build = "libretro" if standalone else "standalone" named = { (entry.get("root") or "", destination(entry)) for entry in files - if entry.get("type") != "directory" and entry.get("mode") != other_build + if entry.get("type") != "directory" and read_by_build(entry, standalone) } expanded: list[dict] = [] for entry in files: diff --git a/scripts/resolve/validation.py b/scripts/resolve/validation.py index f719b16c0..330d2db98 100644 --- a/scripts/resolve/validation.py +++ b/scripts/resolve/validation.py @@ -656,10 +656,7 @@ def outside_gap_scope(file_entry: dict, is_standalone: bool) -> bool: return True if "path" in file_entry and file_entry["path"] is None: return True - mode = file_entry.get("mode") - if (mode == "standalone" and not is_standalone) or ( - mode == "libretro" and is_standalone - ): + if not read_by_build(file_entry, is_standalone): return True return not ( read_from_system_dir(file_entry, is_standalone) @@ -779,17 +776,14 @@ def opens_by_name(file_entry: dict, profile: dict, standalone: bool = False) -> return True +def read_by_build(entry: dict, standalone: bool) -> bool: + """Whether the build that runs (standalone or libretro) reads the entry.""" + return entry.get("mode") != ("libretro" if standalone else "standalone") + + def filter_files_by_mode(files: list[dict], standalone: bool) -> list[dict]: """Filter file entries by libretro/standalone mode.""" - result = [] - for f in files: - fmode = f.get("mode", "") - if standalone and fmode == "libretro": - continue - if not standalone and fmode == "standalone": - continue - result.append(f) - return result + return [f for f in files if read_by_build(f, standalone)] def installed_with_emulator(entry: dict, platform: str = "") -> bool: