Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Name": "Steam Search",
"Description": "Search and launch your Steam Game library",
"Author": "Garulf",
"Version": "9.0.1",
"Version": "9.0.2",
"Language": "executable",
"Website": "https://github.com/Garulf/Steam-Search",
"IcoPath": "run.exe",
Expand Down
77 changes: 63 additions & 14 deletions plugin/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def games(self):
LibraryItem(
name=manifest['AppState']['name'],
path=Path(self.path).joinpath(
manifest['AppState']['installdir']),
'steamapps', 'common', manifest['AppState']['installdir']),
id=manifest['AppState']['appid'],
image_dir=image_dir,
)
Expand All @@ -64,22 +64,23 @@ def __init__(self, image_dir: Union[str, Path]):
image_dir = Path(image_dir)
self.grid = image_dir.name == 'grid'
self._files_cache = {}
self._iterdir = image_dir.iterdir()
try:
for file in image_dir.iterdir():
haystack_prefix = file.name.split(".", 1)[0]
self._files_cache[haystack_prefix] = file
except FileNotFoundError:
pass

def get_image(self, id: str, type: str, sep='_') -> Optional[Path]:
prefix = f'{id}{sep}{type}'
alt_prefix = f'app_{id}{sep}{type}'
try:
if prefix in self._files_cache:
return self._files_cache[prefix]
else:
for file in self._iterdir:
haystack_prefix = file.name.split(".", 1)[0]
self._files_cache[haystack_prefix] = file
if prefix == haystack_prefix:
return file
return None
for key, file in self._files_cache.items():
if key.startswith(prefix) or key.startswith(alt_prefix):
return file
except FileNotFoundError:
return None
return None


class LibraryItem:
Expand Down Expand Up @@ -128,21 +129,33 @@ def icon(self) -> Path:
"""
Return the icon for this library item.
"""
return self.get_image('icon') or Path(self.unquoted_path())
img = self.get_image('icon')
if img:
return img
exe = self._find_local_exe_icon()
if exe:
return exe
return Path(self.unquoted_path())

@cached_property
def hero(self) -> Path:
"""
Return the hero image for this library item.
"""
return self.get_image('hero')
img = self.get_image('hero')
if img:
return img
return None

@cached_property
def logo(self) -> Path:
"""
Return the logo for this library item.
"""
return self.get_image('logo')
img = self.get_image('logo')
if img:
return img
return None

@cached_property
def poster(self) -> Path:
Expand All @@ -158,6 +171,42 @@ def grid(self) -> str:
"""
return self.get_image('', sep='')

def _find_local_exe_icon(self) -> Optional[Path]:
base = self.path
try:
if base.is_file() and base.suffix.lower() == ".exe":
return base
candidates = []
name_no_space = self.name.replace(" ", "")
dir_name = base.name
candidates.extend([
base.joinpath(f"{dir_name}.exe"),
base.joinpath(f"{self.name}.exe"),
base.joinpath(f"{name_no_space}.exe"),
base.joinpath("Win64", f"{dir_name}-Win64-Shipping.exe"),
base.joinpath("Binaries", "Win64", f"{dir_name}-Win64-Shipping.exe"),
base.joinpath("Binaries", "Win64", f"{name_no_space}-Win64-Shipping.exe"),
])
for p in candidates:
if p.exists():
return p
ue_dirs = [
base.joinpath("Binaries", "Win64"),
base.joinpath("Win64"),
base.joinpath("bin"),
base.joinpath("Bin"),
base.joinpath("bin64"),
]
for d in ue_dirs:
if d.exists():
for child in d.glob("*.exe"):
return child
for child in base.glob("*.exe"):
return child
except Exception:
return None
return None

def generate_id(self) -> str:
"""
Generate Steam ID for this library item.
Expand Down