Skip to content

Commit

Permalink
Turns out pefile leaves attributes off entirely if the data wasn't fo…
Browse files Browse the repository at this point in the history
…und in the PE file; I'll add a check for that.

Also, index() does not return None, it raises an exception. I'll add handling for that case too.

Resolves #5460
  • Loading branch information
danieljohnson2 committed May 1, 2024
1 parent 31dfcd2 commit 59ed033
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lutris/runners/wine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,9 @@ def extract_icon(self, game_slug):
extractor = ExtractIcon(self.game_exe)
groups = extractor.get_group_icons()

if not groups:
return False

icons = []
biggestsize = (0, 0)
biggesticon = -1
Expand Down
21 changes: 16 additions & 5 deletions lutris/util/wine/extract_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,25 @@ def __init__(self, filepath):
self.pe = pefile.PE(filepath)

def find_resource_base(self, res_type):
rt_base_idx = [entry.id for entry in self.pe.DIRECTORY_ENTRY_RESOURCE.entries].index(
pefile.RESOURCE_TYPE[res_type]
)
if hasattr(self.pe, "DIRECTORY_ENTRY_RESOURCE"):
try:
rt_base_idx = [entry.id for entry in self.pe.DIRECTORY_ENTRY_RESOURCE.entries].index(
pefile.RESOURCE_TYPE[res_type]
)

if rt_base_idx is not None:
return self.pe.DIRECTORY_ENTRY_RESOURCE.entries[rt_base_idx]
if rt_base_idx is not None:
return self.pe.DIRECTORY_ENTRY_RESOURCE.entries[rt_base_idx]
except (ValueError, IndexError):
pass # if the resource is not found or the index is bogus

return None

def find_resource(self, res_type, res_index):
rt_base_dir = self.find_resource_base(res_type)

if not rt_base_dir:
return None

if res_index < 0:
try:
idx = [entry.id for entry in rt_base_dir.directory.entries].index(-res_index)
Expand All @@ -65,6 +72,10 @@ def find_resource(self, res_type, res_index):

def get_group_icons(self):
rt_base_dir = self.find_resource_base("RT_GROUP_ICON")

if not rt_base_dir:
return []

groups = []
for res_index in range(0, len(rt_base_dir.directory.entries)):
grp_icon_dir_entry = self.find_resource("RT_GROUP_ICON", res_index)
Expand Down

0 comments on commit 59ed033

Please sign in to comment.