mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 02:24:09 +01:00
Merge pull request #2073 from rommapp/4-metadata-fixes-5
Only use first file in compressed game when calculating hashes
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -83,7 +83,7 @@ const fetchContinuePlayingRoms = async (): Promise<void> => {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user