mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 18:18:47 +01:00
Optimize multi-ROM exclusion matching pass
Co-authored-by: gantoine <3247106+gantoine@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
5a1e238a5f
commit
98bc9a9eea
@@ -374,20 +374,36 @@ class FSRomsHandler(FSHandler):
|
||||
|
||||
def exclude_multi_roms(self, roms: list[str]) -> list[str]:
|
||||
excluded_names = cm.get_config().EXCLUDED_MULTI_FILES
|
||||
normalized_excluded = {
|
||||
excluded_name.strip().lower() for excluded_name in excluded_names
|
||||
}
|
||||
excluded_files: set[str] = set()
|
||||
normalized_patterns = [
|
||||
excluded_name.strip().lower()
|
||||
for excluded_name in excluded_names
|
||||
if excluded_name.strip()
|
||||
]
|
||||
|
||||
def has_wildcard(pattern: str) -> bool:
|
||||
return any(char in pattern for char in ("*", "?", "["))
|
||||
|
||||
exact_matches = {
|
||||
pattern for pattern in normalized_patterns if not has_wildcard(pattern)
|
||||
}
|
||||
wildcard_patterns = [
|
||||
pattern for pattern in normalized_patterns if has_wildcard(pattern)
|
||||
]
|
||||
|
||||
kept_roms: list[str] = []
|
||||
for rom in roms:
|
||||
normalized_rom_name = rom.strip().lower()
|
||||
if normalized_rom_name in normalized_excluded or any(
|
||||
fnmatch.fnmatch(normalized_rom_name, exc_name)
|
||||
for exc_name in normalized_excluded
|
||||
if normalized_rom_name in exact_matches:
|
||||
continue
|
||||
if any(
|
||||
fnmatch.fnmatch(normalized_rom_name, pattern)
|
||||
for pattern in wildcard_patterns
|
||||
):
|
||||
excluded_files.add(rom)
|
||||
continue
|
||||
|
||||
return [f for f in roms if f not in excluded_files]
|
||||
kept_roms.append(rom)
|
||||
|
||||
return kept_roms
|
||||
|
||||
def _build_rom_file(
|
||||
self, rom: Rom, rom_path: Path, file_name: str, file_hash: FileHash
|
||||
|
||||
Reference in New Issue
Block a user