Skip to content

Commit

Permalink
Merge pull request #16 from Garulf/fix-missing-steam
Browse files Browse the repository at this point in the history
Fix missing steam
  • Loading branch information
Garulf authored Dec 17, 2021
2 parents 1e208b3 + 12bbe93 commit 520d4c1
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 16 deletions.
12 changes: 12 additions & 0 deletions SettingsTemplate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
body:
- type: textBlock
attributes:
name: description
description: >
Search and launch you Steam games library!
- type: input
attributes:
name: steam_path
label: 'Steam Executable Directory:'
description: Location of steam.exe
defaultValue: ""
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": "2.1.0",
"Version": "3.0.0",
"Language": "python",
"Website": "https://github.com/Garulf/Steam-Search",
"IcoPath": "plugin\\icon\\steam-icon.png",
Expand Down
43 changes: 35 additions & 8 deletions plugin/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
STEAM_SUB_KEY = r'SOFTWARE\WOW6432Node\Valve\Steam'

DEFAULT_STEAM_PATH = r"c:\Program Files (x86)\Steam"
STEAM_EXE = "steam.exe"
LIBRARY_CACHE_EXT = '.jpg'
ICON_SUFFIX = '_icon'
HEADER_SUFFIX = '_header'
Expand All @@ -15,20 +16,46 @@
STEAMAPPS_FOLDER = 'steamapps'


class SteamExecutableNotFound(Exception):
def __init__(self, path) -> None:
message = f'Could not locate steam.exe at: {path}'
super().__init__(message)
class SteamLibraryNotFound(Exception):

def __init__(self, path) -> None:
message = f'Could not find Steam libraries manifest ("libraryfolders.vdf") at: {path}'
super().__init__(message)

class Steam(object):

def __init__(self, steam_path=None):
self._steam_path = None
self._check_steam_exe(steam_path)
self._steam_path = steam_path


@property
def steam_path(self):
if self._steam_path is None:
if not self._steam_path:
path = self._steam_registry()
if path is not None:
self._steam_path = path
elif Path(DEFAULT_STEAM_PATH).exists():
self._steam_path = DEFAULT_STEAM_PATH
else:
self._steam_path = None
self._check_steam_exe(self._steam_path)
return Path(self._steam_path)

def _check_steam_exe(self, path):
if not Path(path, STEAM_EXE).exists():
raise SteamExecutableNotFound(Path(path, STEAM_EXE))

def _steam_registry(self):
try:
with reg.OpenKey(HKEY_LOCAL_MACHINE, STEAM_SUB_KEY) as hkey:
try:
self._steam_path = Path(reg.QueryValueEx(hkey, "InstallPath")[0])
except FileNotFoundError:
pass
return self._steam_path
return reg.QueryValueEx(hkey, "InstallPath")[0]
except FileNotFoundError:
return None

def all_games(self):
games = []
Expand All @@ -43,7 +70,7 @@ def libraries(self):
libraries = []
libraries_manifest_path = self.steam_path.joinpath('steamapps', 'libraryfolders.vdf')
if not libraries_manifest_path.exists():
return []
raise SteamLibraryNotFound(libraries_manifest_path)
try:
library_folders = vdf.load(open(libraries_manifest_path, 'r', encoding='utf-8', errors='ignore'))
except FileNotFoundError:
Expand Down
21 changes: 15 additions & 6 deletions plugin/steam_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@
import webbrowser
from pathlib import Path

from helper import Steam
from helper import Steam, SteamLibraryNotFound, SteamExecutableNotFound

from flox import Flox
from flox import Flox, Launcher, ICON_SETTINGS


class SteamSearch(Flox):
def __init__(self):
self._steam = Steam()
super().__init__()

def query(self, query):
games = self._steam.all_games()
try:
self._steam = Steam(self.settings.get('steam_path'))
if self.settings.get('steam_path') is None or self.settings.get('steam_path') == '':
self.settings['steam_path'] = str(self._steam.steam_path)
games = self._steam.all_games()
except (SteamLibraryNotFound, SteamExecutableNotFound):
self.add_item(
title="Steam library not found!",
subtitle="Please set your Steam library path in the settings",
method=self.open_setting_dialog,
icon=ICON_SETTINGS
)
return
q = query.lower()
pattern = ".*?".join(q)
regex = re.compile(pattern)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
git+git://github.com/garulf/flox@v0.6.0#egg=flox
git+git://github.com/garulf/flox@v0.7.1#egg=flox
vdf==3.4

0 comments on commit 520d4c1

Please sign in to comment.