Batocera.PLUS-bios/missings/retrodeck.py
2024-09-07 00:54:14 +02:00

51 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python
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()
knowns = []
with open(Path(__file__).parent / "knowns.txt", "r") as f:
knowns = f.read().splitlines()
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]
if not bios_path.is_file():
print(
f"\033[91mMissing {bios_path.relative_to(args.directory)} on {bios[3]} with hash {bios[2]}\033[00m"
)
elif bios[2] == "Unknown":
if str(bios_path.relative_to(args.directory)) not in knowns:
print(
f"Unknown checksum for {bios_path.relative_to(args.directory)} on {bios[3]}"
)
else:
with open(bios_path, "rb") as file:
checksum = md5(file.read()).hexdigest()
if checksum != bios[2] and bios[1] != "dc/":
print(
f"\033[93mChecksum mismatch for {bios_path.relative_to(args.directory)} on {bios[3]}: {checksum}\033[00m != \033[92m{bios[2]}\033[00m"
)