diff --git a/backend/handler/filesystem/roms_handler.py b/backend/handler/filesystem/roms_handler.py index 7ffaf904e..30607b4bc 100644 --- a/backend/handler/filesystem/roms_handler.py +++ b/backend/handler/filesystem/roms_handler.py @@ -135,6 +135,9 @@ def read_zip_file(file: str | os.PathLike[str] | IO[bytes]) -> Iterator[bytes]: with z.open(file, "r") as f: while chunk := f.read(FILE_READ_CHUNK_SIZE): yield chunk + + # We only need to read the first file in the archive + return except zipfile.BadZipFile: if isinstance(file, Path): for chunk in read_basic_file(file): @@ -158,6 +161,9 @@ def read_tar_file( with f.extractfile(member) as ef: # type: ignore while chunk := ef.read(FILE_READ_CHUNK_SIZE): yield chunk + + # We only need to read the first file in the archive + return except tarfile.ReadError: for chunk in read_basic_file(file_path): yield chunk @@ -188,11 +194,13 @@ def process_7z_file( on_read=fn_hash_read, ) # Provide a file handler to `SevenZipFile` instead of a file path to deactivate the - # "parallel" mode in py7zr, which is needed to deterministically calculate the hashes, by - # reading each included file in order, one by one. + # "parallel" mode in py7zr, which is needed to deterministically calculate the hashes with open(file_path, "rb") as f: with py7zr.SevenZipFile(f, mode="r") as archive: - archive.extractall(factory=factory) # nosec B202 + file_list = archive.getnames() + for file in file_list: + archive.extract(file, factory=factory) + break # We only need to read the first file in the archive except ( Bad7zFile, DecompressionError, diff --git a/backend/handler/metadata/hasheous_handler.py b/backend/handler/metadata/hasheous_handler.py index 7988c2790..cd5882c8f 100644 --- a/backend/handler/metadata/hasheous_handler.py +++ b/backend/handler/metadata/hasheous_handler.py @@ -7,6 +7,7 @@ import pydash from config import DEV_MODE, HASHEOUS_API_ENABLED from fastapi import HTTPException, status from logger.logger import log +from models.rom import RomFile from utils import get_version from utils.context import ctx_httpx_client @@ -200,7 +201,7 @@ class HasheousHandler(MetadataHandler): ra_id=platform["ra_id"], ) - async def get_rom(self, rom_attrs: dict) -> HasheousRom: + async def lookup_rom(self, files: list[RomFile]) -> HasheousRom: fallback_rom = HasheousRom( hasheous_id=None, igdb_id=None, tgdb_id=None, ra_id=None ) @@ -208,9 +209,20 @@ class HasheousHandler(MetadataHandler): if not HASHEOUS_API_ENABLED: return fallback_rom - md5_hash = rom_attrs.get("md5_hash") - sha1_hash = rom_attrs.get("sha1_hash") - crc_hash = rom_attrs.get("crc_hash") + first_file = next( + ( + file + for file in files + if file.file_size_bytes is not None and file.file_size_bytes > 0 + ), + None, + ) + if first_file is None: + return fallback_rom + + md5_hash = first_file.md5_hash + sha1_hash = first_file.sha1_hash + crc_hash = first_file.crc_hash if not (md5_hash or sha1_hash or crc_hash): log.warning( diff --git a/backend/handler/scan_handler.py b/backend/handler/scan_handler.py index fa7856baa..d9317f41d 100644 --- a/backend/handler/scan_handler.py +++ b/backend/handler/scan_handler.py @@ -343,7 +343,7 @@ async def scan_rom( or (scan_type == ScanType.UNIDENTIFIED and not rom.hasheous_id) ) ): - return await meta_hasheous_handler.get_rom(rom_attrs) + return await meta_hasheous_handler.lookup_rom(fs_rom["files"]) return HasheousRom(hasheous_id=None, igdb_id=None, tgdb_id=None, ra_id=None) diff --git a/frontend/src/components/common/Game/Dialog/DeleteRom.vue b/frontend/src/components/common/Game/Dialog/DeleteRom.vue index d81f386b9..ca5236b9a 100644 --- a/frontend/src/components/common/Game/Dialog/DeleteRom.vue +++ b/frontend/src/components/common/Game/Dialog/DeleteRom.vue @@ -68,6 +68,16 @@ async function deleteRoms() { } romsStore.resetSelection(); romsStore.remove(roms.value); + romsStore.setRecentRoms( + romsStore.recentRoms.filter( + (r) => !roms.value.some((rom) => rom.id === r.id), + ), + ); + romsStore.setContinuePlayingRoms( + romsStore.continuePlayingRoms.filter( + (r) => !roms.value.some((rom) => rom.id === r.id), + ), + ); emitter?.emit("refreshDrawer", null); closeDialog(); if (route.name == "rom") { diff --git a/frontend/src/stores/roms.ts b/frontend/src/stores/roms.ts index 9b52fee53..2a39d467e 100644 --- a/frontend/src/stores/roms.ts +++ b/frontend/src/stores/roms.ts @@ -73,7 +73,7 @@ export default defineStore("roms", { setRecentRoms(roms: SimpleRom[]) { this.recentRoms = roms; }, - setContinuePlayedRoms(roms: SimpleRom[]) { + setContinuePlayingRoms(roms: SimpleRom[]) { this.continuePlayingRoms = roms; }, setCurrentCollection(collection: Collection | null) { diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue index 4d994f6a8..24604e08e 100644 --- a/frontend/src/views/Home.vue +++ b/frontend/src/views/Home.vue @@ -83,7 +83,7 @@ const fetchContinuePlayingRoms = async (): Promise => { data: { items }, } = await romApi.getRecentPlayedRoms(); const filteredItems = items.filter((rom) => rom.rom_user.last_played); - romsStore.setContinuePlayedRoms(filteredItems); + romsStore.setContinuePlayingRoms(filteredItems); } catch (error) { console.error("Failed to fetch continue playing ROMs:", error); } finally {