Skip to content

Commit

Permalink
Add exception handling so that if we can't parse the icon from an EXE…
Browse files Browse the repository at this point in the history
…, we log and continue. It's okay not to have an icon; all the cool kids use banners.

Resolves #5475
  • Loading branch information
danieljohnson2 committed May 14, 2024
1 parent 52fb949 commit 87b18f2
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions lutris/runners/wine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,31 +1241,36 @@ def extract_icon(self, game_slug):
"""Extracts the 128*128 icon from EXE and saves it, if not resizes the biggest icon found.
returns true if an icon is saved, false if not"""

wantedsize = (128, 128)
pathtoicon = settings.ICON_PATH + "/lutris_" + game_slug + ".png"
if not self.game_exe or os.path.exists(pathtoicon) or not PEFILE_AVAILABLE:
try:
wantedsize = (128, 128)
pathtoicon = settings.ICON_PATH + "/lutris_" + game_slug + ".png"
exe = self.game_exe
if not exe or os.path.exists(pathtoicon) or not PEFILE_AVAILABLE:
return False

extractor = ExtractIcon(self.game_exe)
groups = extractor.get_group_icons()

if not groups:
return False

icons = []
biggestsize = (0, 0)
biggesticon = -1
for i in range(len(groups[0])):
icons.append(extractor.export(groups[0], i))
if icons[i].size > biggestsize:
biggesticon = i
biggestsize = icons[i].size
elif icons[i].size == wantedsize:
icons[i].save(pathtoicon)
return True

if biggesticon >= 0:
resized = icons[biggesticon].resize(wantedsize)
resized.save(pathtoicon)
return True
return False

extractor = ExtractIcon(self.game_exe)
groups = extractor.get_group_icons()

if not groups:
except Exception as ex:
logger.exception("Unable to extract icon from %s: %s", exe, ex)
return False

icons = []
biggestsize = (0, 0)
biggesticon = -1
for i in range(len(groups[0])):
icons.append(extractor.export(groups[0], i))
if icons[i].size > biggestsize:
biggesticon = i
biggestsize = icons[i].size
elif icons[i].size == wantedsize:
icons[i].save(pathtoicon)
return True

if biggesticon >= 0:
resized = icons[biggesticon].resize(wantedsize)
resized.save(pathtoicon)
return True
return False

0 comments on commit 87b18f2

Please sign in to comment.