Skip to content

Commit

Permalink
Fix parsing incomplete appmanifest files
Browse files Browse the repository at this point in the history
Incomplete appmanifest files can apparently be left over from old
installations. Ignore such files and print a warning.

Fixes #273
  • Loading branch information
Matoking committed Jan 16, 2024
1 parent de708dc commit e2a7871
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Fixed
- Fix Protontricks crash when custom Proton has an empty `compatibilitytool.vdf` manifest
- Fix Protontricks crash when an incomplete appmanifest file is parsed

## [1.11.0] - 2023-12-30
### Added
Expand Down
12 changes: 10 additions & 2 deletions src/protontricks/steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,16 @@ def from_appmanifest(cls, path, steam_lib_paths, steam_path=None):
try:
name = app_state["name"]
except KeyError:
# Older app installations also use `userconfig/name`
name = app_state["userconfig"]["name"]
try:
# Older app installations also use `userconfig/name`
name = app_state["userconfig"]["name"]
except KeyError:
logger.warning(
"Incomplete appmanifest found at %s. This might be a "
"leftover file from an old installation. Skipping...",
path
)
return None

# Proton prefix may exist on a different library
prefix_path = find_appid_proton_prefix(
Expand Down
34 changes: 34 additions & 0 deletions tests/test_steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,40 @@ def test_steam_app_from_appmanifest_empty(self, steam_app_factory):
"""
steam_app = steam_app_factory(name="Fake game", appid=10)

appmanifest_path = \
Path(steam_app.install_path).parent.parent / "appmanifest_10.acf"
appmanifest_path.write_text(
vdf.dumps({
"AppState": {
"appid": "10",
"Universe": "1",
"installdir": "Fake game",
# Use the same StateFlags mentioned in the #273 issue.
# Two flags set here are `StateUpdateRequired` and
# `StateUpdateStarted`, which might indicate the file
# is not properly tracked by Steam itself, since the
# installation directory was gone at this point.
"StateFlags": "1026"
}
})
)

# Incomplete appmanifest file is ignored
assert not SteamApp.from_appmanifest(
path=appmanifest_path,
steam_lib_paths=[]
)

def test_steam_app_from_appmanifest_incomplete(self, steam_app_factory):
"""
Try to deserialize from an incomplete appmanifest and check that no
SteamApp is returned.
Incomplete appmanifests can supposedly be created when moving app
installations
"""
steam_app = steam_app_factory(name="Fake game", appid=10)

appmanifest_path = \
Path(steam_app.install_path).parent.parent / "appmanifest_10.acf"
appmanifest_path.write_text("")
Expand Down

0 comments on commit e2a7871

Please sign in to comment.