diff --git a/install.ps1 b/install.ps1 index 421aa0ac..f466cfb7 100644 --- a/install.ps1 +++ b/install.ps1 @@ -11,7 +11,7 @@ $ErrorActionPreference = "Stop" $defaultInstallUrl = "https://raw.githubusercontent.com/Abdess/retrobios/main/install.py" - $defaultInstallSha256 = "1238dfb08b3168992cf4e390358540c6c1bbadf23ae5b74fb34e9101a2a083ef" + $defaultInstallSha256 = "853300c169f08b2554a421aac33da1b5004d3eedd70ae9dec1d732766d06b1ca" $maximumInstallerBytes = 2MB $installerExit = 0 $installer = if ($PSScriptRoot) { Join-Path $PSScriptRoot "install.py" } else { $null } diff --git a/install.py b/install.py index ed648a04..56e4d075 100644 --- a/install.py +++ b/install.py @@ -40,7 +40,7 @@ import urllib.request import xml.etree.ElementTree as ET import zipfile import zlib -from collections.abc import Callable, Iterator +from collections.abc import Callable, Collection, Iterator from pathlib import Path, PurePosixPath from typing import BinaryIO, NamedTuple, TextIO @@ -6607,11 +6607,15 @@ def _bytes(files: list[dict]) -> int: def bulk_hint( to_download: list[dict], manifest: dict, systems_chosen: bool, cores_chosen: bool, + accepted: Collection[str] = (), ) -> list[str]: """Name what pulls most of a download, when narrowing saves over half of it. `--system 3do` fetched 349 MB for RetroArch, and `--core opera` 12.5 MB: the arcade cores that also read 3DO pulled the rest, and nothing said so. + accepted holds the names --core takes. Drawn from every core of the + system, the advice named ares, which loads no file of its own, and + `--core ares` was then refused. """ total = _bytes(to_download) if total < BULK_HINT_FROM: @@ -6619,7 +6623,8 @@ def bulk_hint( systems = {s for entry in to_download for s in entry_systems(entry)} if not cores_chosen and len(systems) == 1: system = next(iter(systems)) - candidates = (manifest.get("system_cores") or {}).get(system) or [] + candidates = [core for core in (manifest.get("system_cores") or {}).get(system) or [] + if core in accepted] by_core: dict[str, int] = {} for entry in to_download: for core in entry.get("cores") or []: @@ -7465,6 +7470,8 @@ def _install(args: argparse.Namespace, real_stdout: TextIO) -> None: args.emulator, manifest, plat_name, files, omitted_files ) + # What --core resolves against, for advice that names one. + core_choices = set(available_choices(files, omitted_files)["cores"]) selection = _requested_narrowing(args, plat_name, files, omitted_files, manifest) if ( selection is None @@ -7577,6 +7584,7 @@ def _install(args: argparse.Namespace, real_stdout: TextIO) -> None: systems_chosen=bool(selection and selection[0]), cores_chosen=bool((selection and selection[1]) or args.emulator or args.installed_cores or target), + accepted=core_choices, ) narrowed = bool( diff --git a/install.sh b/install.sh index e411f687..63aa076e 100755 --- a/install.sh +++ b/install.sh @@ -18,7 +18,7 @@ esac TEMP_INSTALLER="" TEMP_DIRECTORY="" DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/install.py" -DEFAULT_INSTALL_SHA256="1238dfb08b3168992cf4e390358540c6c1bbadf23ae5b74fb34e9101a2a083ef" +DEFAULT_INSTALL_SHA256="853300c169f08b2554a421aac33da1b5004d3eedd70ae9dec1d732766d06b1ca" MAX_INSTALLER_BYTES=2097152 cleanup() { diff --git a/tests/test_install_offline.py b/tests/test_install_offline.py index 834e320a..7a614694 100644 --- a/tests/test_install_offline.py +++ b/tests/test_install_offline.py @@ -477,12 +477,33 @@ class TheSummaryNamesTheBulk(unittest.TestCase): _sized("mame/3do_m2.zip", 37 * MB, ["3do"], ["mame"]), ] lines = install.bulk_hint(files, {"system_cores": {"3do": ["mame", "opera"]}}, - systems_chosen=True, cores_chosen=False) + systems_chosen=True, cores_chosen=False, + accepted={"mame", "opera"}) self.assertEqual(lines, [ " mame pulls 337.0 MB of this 349.0 MB download for 3do. --core opera " "keeps 12.0 MB of it and saves 337.0 MB (96%)." ]) + def test_only_a_core_the_option_accepts_is_advised(self): + """`--core ares keeps 11.0 MB` was printed, and `--core ares` then + answered "unknown core": ares emulates the PlayStation and loads no + file of its own, and --core takes only the cores that do.""" + files = [ + _sized("scph5501.bin", 1 * MB, ["sony-playstation"]), + _sized("ps2_bios.bin", 300 * MB, ["sony-playstation"], ["duckstation"]), + _sized("pcsx/extra.bin", 2 * MB, ["sony-playstation"], ["pcsx_rearmed"]), + ] + manifest = {"system_cores": {"sony-playstation": ["ares", "duckstation", + "pcsx_rearmed"]}} + lines = install.bulk_hint(files, manifest, True, False, + accepted={"duckstation", "pcsx_rearmed"}) + self.assertEqual(len(lines), 1) + self.assertIn("--core pcsx_rearmed keeps 3.0 MB", lines[0]) + self.assertNotIn("ares", lines[0]) + self.assertEqual(install.bulk_hint(files, manifest, True, False, + accepted={"duckstation"}), []) + self.assertEqual(install.bulk_hint(files, manifest, True, False), []) + def test_a_system_pulling_most_of_the_download_is_named(self): files = [_sized("a.zip", 400 * MB, ["arcade"]), _sized("b.bin", 50 * MB, ["nes"]), _sized("c.bin", 10 * MB, ["gba"])]