Skip to content

Commit

Permalink
Skip unidentifiable icon files
Browse files Browse the repository at this point in the history
Pillow cannot parse all image files (usually JPEG). This might be due to
the files not being valid image files in the first place, or Pillow not
being able to parse them. In any case, skip the file and log the error
if the image file cannot be parsed.

Fixes #264
Fixes #268
  • Loading branch information
Matoking committed Dec 29, 2023
1 parent 96f253d commit 68af854
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed
- Fix Protontricks not recognizing supported Steam Runtime installation due to changed name
- Fix Protontricks not recognizing default Proton installation for games with different Proton preselected by Valve testing
- Fix Protontricks crash when app has an unidentifiable app icon

## [1.10.5] - 2023-09-05
### Fixed
Expand Down
22 changes: 12 additions & 10 deletions src/protontricks/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,21 @@ def _get_appid2icon(steam_apps):
"App icon %s has unusual size, resizing",
app.icon_path
)
try:
resized_img = img.resize(APP_ICON_SIZE).convert("RGB")
resized_img.save(icon_cache_path)
final_icon_path = icon_cache_path
except Exception:
logger.warning(
"Could not resize %s, ignoring",
app.icon_path,
exc_info=True
)
resized_img = img.resize(APP_ICON_SIZE).convert("RGB")
resized_img.save(icon_cache_path)
final_icon_path = icon_cache_path
except FileNotFoundError:
# Icon does not exist, the placeholder will be used
pass
except Exception:
# Multitude of reasons can cause image parsing or resizing
# to fail. Instead of trying to catch everything, log the error
# and move on.
logger.warning(
"Could not resize %s, ignoring",
app.icon_path,
exc_info=True
)

appid2icon[app.appid] = final_icon_path

Expand Down
24 changes: 24 additions & 0 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ def test_select_game_icons_ensure_resize(
with Image.open(resized_icon_path) as img:
assert img.size == (32, 32)

def test_select_game_unidentifiable_icon_skipped(
self, gui_provider, steam_app_factory, steam_dir, home_dir, caplog):
"""
Select a game using the GUI. Ensure a custom icon that's not
identifiable by Pillow is skipped.
"""
steam_apps = [
steam_app_factory(name="Fake game 1", appid=10)
]

icon_path = steam_dir / "appcache" / "librarycache" / "10_icon.jpg"
icon_path.write_bytes(b"")

gui_provider.mock_stdout = "Fake game 1: 10"
selected_app = select_steam_app_with_gui(
steam_apps=steam_apps, steam_path=steam_dir
)

# Warning about icon was logged, but the app was selected successfully
record = caplog.records[-1]
assert record.message.startswith(f"Could not resize {icon_path}")

assert selected_app.appid == 10

def test_select_game_no_choice(
self, gui_provider, steam_app_factory, steam_dir):
"""
Expand Down

0 comments on commit 68af854

Please sign in to comment.