diff --git a/install.ps1 b/install.ps1 index 856b63076..0ff74b13b 100644 --- a/install.ps1 +++ b/install.ps1 @@ -16,7 +16,7 @@ # and Invoke-WebRequest throws on a cut transfer before the hash is read: # the site's build rewrites this line there (scripts/sitebootstrap.py). $mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." - $defaultInstallSha256 = "5f4faa860489f00b33b167c9644ce15f7b24a38a9f04b3d6e10a813426cfe41a" + $defaultInstallSha256 = "f0ecb3333aecd54fd0195ff5735f68e17da2979abc142dfdeafecde6cfe89201" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. $maximumInstallerBytes = 8MB diff --git a/install.py b/install.py index 37402c339..cedc32fce 100644 --- a/install.py +++ b/install.py @@ -10722,6 +10722,23 @@ def resolve_systems(values: list[str], manifest: dict | None, files: list[dict], system_aliases(manifest), key_file_holders(files, omitted)) +def system_ids(names: Iterable[str], manifest: dict | None, files: list[dict], + omitted: list[dict]) -> dict[str, str]: + """Each of names that --system takes, with the system id it stands for: + a record keeps the psx typed at the install.""" + known = available_choices(files, omitted)["systems"] + aliases, holders = system_aliases(manifest), key_file_holders(files, omitted) + ids: dict[str, str] = {} + for name in names: + try: + picked = resolve_choices([name], known, "system", aliases, holders) + except ValueError: + continue + if len(picked) == 1: + ids[name] = picked[0] + return ids + + def parse_selection(text: str, count: int, ordered: bool = False) -> list[int]: """Numbers typed at a prompt: `3`, `1,4`, `2-5`, or `all`, 1-based. @@ -19735,14 +19752,15 @@ def _choice_names(options: list[tuple[str, str | None]], flag: str) -> list[str] def _choice_without(choice: list[str], flag: str, names: Collection[str], - left: list[str]) -> list[str]: + left: list[str], ids: Mapping[str, str] | None = None) -> list[str]: """A recorded choice once names of flag are taken out: those it named go, and a choice that named none gets the names left. A flag left with - no name is dropped.""" + no name is dropped. ids gives a recorded name the id it stands for.""" options = [option for option in record_options(choice) if option[0] != "--all-files"] gone = {name.casefold() for name in names} + same = ids or {} remaining = [name for name in (_choice_names(options, flag) or left) - if name.casefold() not in gone] + if same.get(name, name).casefold() not in gone] kept = [option for option in options if option[0] != flag] if remaining: kept.append((flag, ",".join(remaining))) @@ -19762,6 +19780,7 @@ class _RemovalScope(NamedTuple): named_cores: list[str] others: dict[tuple[str, str], str] wanted: set[str] + system_ids: dict[str, str] def norm(self, dest: str) -> str: """dest as the drive compares it, folded where it folds case.""" @@ -19788,7 +19807,10 @@ def _removal_scope( wanted = {_drive_key(dest, fold) for dest in files} # What stays chosen once the removal is done, as an install names it: # the systems or cores the record named, else every one of the list. - named_systems = {name.casefold() for name in _choice_names(options, "--system")} + recorded_systems = _choice_names(options, "--system") + ids = system_ids(recorded_systems, manifest, list(manifest.get("files") or []), + list(manifest.get("omitted_files") or [])) + named_systems = {ids.get(name, name).casefold() for name in recorded_systems} staying_systems = {name for name in known["systems"] if not named_systems or name.casefold() in named_systems} - chosen_systems named_cores = _choice_names(options, "--core") @@ -19796,7 +19818,7 @@ def _removal_scope( else set(known["cores"]) | set(manifest.get("core_names") or {}) ) - chosen_cores return _RemovalScope(fold, known, options, chosen_systems, chosen_cores, - staying_systems, staying_cores, named_cores, others, wanted) + staying_systems, staying_cores, named_cores, others, wanted, ids) def _removal_takes(scope: _RemovalScope, found: tuple, dest: str) -> bool: @@ -19857,7 +19879,8 @@ def _removal_choice(scope: _RemovalScope, recorded: list[str], *, files: Collect return recorded if scope.chosen_systems: choice = _choice_without(recorded, "--system", scope.chosen_systems, - sorted(scope.staying_systems | scope.chosen_systems)) + sorted(scope.staying_systems | scope.chosen_systems), + scope.system_ids) if not _choice_names(record_options(choice), "--system"): return None return choice diff --git a/install.sh b/install.sh index 20a68d2d7..dac195988 100755 --- a/install.sh +++ b/install.sh @@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins # curl or wget stop on a cut transfer before the hash is read: the site's # build rewrites this line there (scripts/sitebootstrap.py). MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." -DEFAULT_INSTALL_SHA256="5f4faa860489f00b33b167c9644ce15f7b24a38a9f04b3d6e10a813426cfe41a" +DEFAULT_INSTALL_SHA256="f0ecb3333aecd54fd0195ff5735f68e17da2979abc142dfdeafecde6cfe89201" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. MAX_INSTALLER_BYTES=8388608 diff --git a/install/launchers/index.json b/install/launchers/index.json index e522dfad2..786df74cc 100644 --- a/install/launchers/index.json +++ b/install/launchers/index.json @@ -27,8 +27,8 @@ { "dest": "roms/ports/retrobios/install.py", "repo_path": "install.py", - "size": 1461487, - "sha256": "5f4faa860489f00b33b167c9644ce15f7b24a38a9f04b3d6e10a813426cfe41a", + "size": 1462574, + "sha256": "f0ecb3333aecd54fd0195ff5735f68e17da2979abc142dfdeafecde6cfe89201", "executable": false }, { @@ -71,8 +71,8 @@ "muos": { "archive": { "dest": "ARCHIVE/RetroBIOS.muxapp", - "size": 1515112, - "sha256": "c4892f7c93182806e795d7bcc6c0c8568670c018fde4461fdad99f1976255426" + "size": 1516199, + "sha256": "69accbadbd356f458ef29ae77bbea45697a361e62c6b9ede5e157271058919f4" }, "members": [ { @@ -92,8 +92,8 @@ { "name": "RetroBIOS/install.py", "repo_path": "install.py", - "size": 1461487, - "sha256": "5f4faa860489f00b33b167c9644ce15f7b24a38a9f04b3d6e10a813426cfe41a", + "size": 1462574, + "sha256": "f0ecb3333aecd54fd0195ff5735f68e17da2979abc142dfdeafecde6cfe89201", "executable": false }, { @@ -166,8 +166,8 @@ { "dest": ".config/modules/retrobios/install.py", "repo_path": "install.py", - "size": 1461487, - "sha256": "5f4faa860489f00b33b167c9644ce15f7b24a38a9f04b3d6e10a813426cfe41a", + "size": 1462574, + "sha256": "f0ecb3333aecd54fd0195ff5735f68e17da2979abc142dfdeafecde6cfe89201", "executable": false }, { diff --git a/installer/choices.py b/installer/choices.py index f8853e2f6..9cc865785 100644 --- a/installer/choices.py +++ b/installer/choices.py @@ -182,6 +182,23 @@ def resolve_systems(values: list[str], manifest: dict | None, files: list[dict], system_aliases(manifest), key_file_holders(files, omitted)) +def system_ids(names: Iterable[str], manifest: dict | None, files: list[dict], + omitted: list[dict]) -> dict[str, str]: + """Each of names that --system takes, with the system id it stands for: + a record keeps the psx typed at the install.""" + known = available_choices(files, omitted)["systems"] + aliases, holders = system_aliases(manifest), key_file_holders(files, omitted) + ids: dict[str, str] = {} + for name in names: + try: + picked = resolve_choices([name], known, "system", aliases, holders) + except ValueError: + continue + if len(picked) == 1: + ids[name] = picked[0] + return ids + + def parse_selection(text: str, count: int, ordered: bool = False) -> list[int]: """Numbers typed at a prompt: `3`, `1,4`, `2-5`, or `all`, 1-based. diff --git a/installer/removal.py b/installer/removal.py index 295ed9d20..a48581bd7 100644 --- a/installer/removal.py +++ b/installer/removal.py @@ -10,11 +10,11 @@ import re import stat import sys import urllib.error -from collections.abc import Collection, Iterable +from collections.abc import Collection, Iterable, Mapping from pathlib import Path, PurePosixPath from typing import NamedTuple -from installer.choices import available_choices, emulator_names, resolve_choices, resolve_systems +from installer.choices import available_choices, emulator_names, resolve_choices, resolve_systems, system_ids from installer.console import QUIT_CODE, _answer_yes from installer.destination import card_dest from installer.detect_frontends import detect_platforms @@ -136,14 +136,15 @@ def _choice_names(options: list[tuple[str, str | None]], flag: str) -> list[str] def _choice_without(choice: list[str], flag: str, names: Collection[str], - left: list[str]) -> list[str]: + left: list[str], ids: Mapping[str, str] | None = None) -> list[str]: """A recorded choice once names of flag are taken out: those it named go, and a choice that named none gets the names left. A flag left with - no name is dropped.""" + no name is dropped. ids gives a recorded name the id it stands for.""" options = [option for option in record_options(choice) if option[0] != "--all-files"] gone = {name.casefold() for name in names} + same = ids or {} remaining = [name for name in (_choice_names(options, flag) or left) - if name.casefold() not in gone] + if same.get(name, name).casefold() not in gone] kept = [option for option in options if option[0] != flag] if remaining: kept.append((flag, ",".join(remaining))) @@ -163,6 +164,7 @@ class _RemovalScope(NamedTuple): named_cores: list[str] others: dict[tuple[str, str], str] wanted: set[str] + system_ids: dict[str, str] def norm(self, dest: str) -> str: """dest as the drive compares it, folded where it folds case.""" @@ -189,7 +191,10 @@ def _removal_scope( wanted = {_drive_key(dest, fold) for dest in files} # What stays chosen once the removal is done, as an install names it: # the systems or cores the record named, else every one of the list. - named_systems = {name.casefold() for name in _choice_names(options, "--system")} + recorded_systems = _choice_names(options, "--system") + ids = system_ids(recorded_systems, manifest, list(manifest.get("files") or []), + list(manifest.get("omitted_files") or [])) + named_systems = {ids.get(name, name).casefold() for name in recorded_systems} staying_systems = {name for name in known["systems"] if not named_systems or name.casefold() in named_systems} - chosen_systems named_cores = _choice_names(options, "--core") @@ -197,7 +202,7 @@ def _removal_scope( else set(known["cores"]) | set(manifest.get("core_names") or {}) ) - chosen_cores return _RemovalScope(fold, known, options, chosen_systems, chosen_cores, - staying_systems, staying_cores, named_cores, others, wanted) + staying_systems, staying_cores, named_cores, others, wanted, ids) def _removal_takes(scope: _RemovalScope, found: tuple, dest: str) -> bool: @@ -258,7 +263,8 @@ def _removal_choice(scope: _RemovalScope, recorded: list[str], *, files: Collect return recorded if scope.chosen_systems: choice = _choice_without(recorded, "--system", scope.chosen_systems, - sorted(scope.staying_systems | scope.chosen_systems)) + sorted(scope.staying_systems | scope.chosen_systems), + scope.system_ids) if not _choice_names(record_options(choice), "--system"): return None return choice diff --git a/tests/test_install_removal.py b/tests/test_install_removal.py index ca6964daf..bf74ec498 100644 --- a/tests/test_install_removal.py +++ b/tests/test_install_removal.py @@ -194,6 +194,8 @@ class TheNamesAnInstallTakes(unittest.TestCase): proc = repo.run("--remove", "--system", "psx", "--yes") self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr) self.assertEqual(sorted(repo.snapshot()), sorted(GBA_ONLY + ["shared.bin"])) + # The record no longer names psx, or the next update put it back. + self.assertEqual(repo.setup()["choice"], ["--system", "nintendo-gba"]) class NeverTouched(unittest.TestCase):