From 00377a329343aa5416917a9579affc1574e39a6a Mon Sep 17 00:00:00 2001 From: Spencer Brown Date: Sun, 17 Nov 2024 15:44:23 +1000 Subject: [PATCH] Use has_children() instead of catching LeafKeyvalueError --- src/srctools/game.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/srctools/game.py b/src/srctools/game.py index 246c0658..9b3d0cf8 100644 --- a/src/srctools/game.py +++ b/src/srctools/game.py @@ -6,7 +6,7 @@ import sys from srctools.filesys import FileSystemChain, RawFileSystem, VPKFileSystem -from srctools.keyvalues import Keyvalues, LeafKeyvalueError +from srctools.keyvalues import Keyvalues from srctools.steam import find_app __all__ = ['GINFO', 'Game', 'find_gameinfo'] @@ -133,9 +133,7 @@ def vpk_patch(p: Path) -> Path: required = mount.bool("required", False) # Selects if we want to mount the "mod_folder" key as a folder or omit mountmoddir = mount.bool("mountmoddir", True) - enabled = mount.bool("enabled", True) - - if not enabled: # Undocumented keyval + if not mount.bool("enabled", True): # Undocumented keyval continue try: @@ -149,18 +147,16 @@ def vpk_patch(p: Path) -> Path: continue for child in mount: + # Ignore specified keys above if child.name in ("head", "required", "enabled", "mountmoddir"): - continue # Ignore + continue + # Ignore any other leaf KVs. + if not child.has_children(): + continue # Else we're working with a mod folder this_path = app_info.path / child.real_name - # If this is it cannot be iterated over, skip this keyvalue pair - try: - child.iter_tree() - except LeafKeyvalueError: - continue - for local_mount in child.iter_tree(): local_path = this_path / local_mount.value