diff --git a/commands/retrodeck.py b/commands/retrodeck.py new file mode 100644 index 0000000..e66a531 --- /dev/null +++ b/commands/retrodeck.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +from argparse import ArgumentParser +from csv import reader +from hashlib import md5 +from pathlib import Path +from urllib import request + +parser = ArgumentParser() +parser.add_argument( + "-d", + "--directory", + default=Path.cwd(), + type=Path, + help="Folder to scan for existing bioses", +) +args = parser.parse_args() + +with request.urlopen( + "https://raw.githubusercontent.com/RetroDECK/RetroDECK/main/emu-configs/defaults/retrodeck/reference_lists/bios_checklist.cfg" +) as response: + bioses = reader(response.read().decode().splitlines(), delimiter="^") + + for bios in bioses: + if "pico" in bios[0]: + continue + + bios_path = args.directory / bios[1] / bios[0] + local_path = list((args.directory / bios[1]).glob(bios[0], case_sensitive=False)) + + if not local_path: + print( + f"\033[91mMissing {bios_path.relative_to(args.directory)} on " + f"{bios[3]} with hash {bios[2]}\033[00m" + ) + elif bios[2] == "Unknown": + print(f"Unknown checksum for {bios_path.relative_to(args.directory)} on {bios[3]}") + else: + with open(local_path[0], "rb") as file: + checksum = md5(file.read()).hexdigest() + + if checksum != bios[2]: + print( + f"\033[93mChecksum mismatch for {bios_path.relative_to(args.directory)} on " + f"{bios[3]}: {checksum}\033[00m != \033[92m{bios[2]}\033[00m" + )