Skip to content

Commit

Permalink
Merge pull request #411 from loathingKernel/develop
Browse files Browse the repository at this point in the history
Fix a few issues with Steam shortcuts
  • Loading branch information
loathingKernel authored Jun 4, 2024
2 parents 8fc92a3 + 89b765b commit 3ccd3e7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pywebview = [
]
legendary-gl = "^0.20.34"
orjson = "^3.8.0"
typing-extensions = "^4.3.0"
vdf = "^4.3"

[tool.poetry.scripts]
start = "rare.main:main"
Expand Down
4 changes: 2 additions & 2 deletions rare/components/tabs/games/game_widgets/game_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ def update_actions(self):

if steam_shortcuts_supported() and self.rgame.is_installed:
if steam_shortcut_exists(self.rgame.app_name):
self.steam_shortcut_action.setText(self.tr("Remove from Steam"))
self.steam_shortcut_action.setText(self.tr("Remove Steam shortcut"))
else:
self.steam_shortcut_action.setText(self.tr("Add to Steam"))
self.steam_shortcut_action.setText(self.tr("Create Steam shortcut"))
self.addAction(self.steam_shortcut_action)

self.addAction(self.reload_action)
Expand Down
19 changes: 14 additions & 5 deletions rare/utils/steam_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def find_steam_users(steam_path: str) -> List[SteamUser]:
def _load_shortcuts(steam_path: str, user: SteamUser) -> Dict[str, SteamShortcut]:
_shortcuts = {}
vdf_path = os.path.join(steam_path, "userdata", str(user.short_id), "config", "shortcuts.vdf")
if not os.path.exists(vdf_path):
return _shortcuts
with open(vdf_path, 'rb') as f:
shortcuts = vdf.binary_load(f).get("shortcuts", {})
for idx, shortcut in shortcuts.items():
Expand Down Expand Up @@ -100,11 +102,13 @@ def load_steam_shortcuts():


def save_steam_shortcuts():
if __steam_shortcuts:
_save_shortcuts(__steam_dir, __steam_user, __steam_shortcuts)
logger.info("Saved Steam shortcuts for user %s(%s)", __steam_user.account_name, __steam_user.persona_name)
else:
logger.error("Failed to save Steam shortcuts")
logger.info(
"%s Steam shortcuts for user %s(%s)",
"Saving" if __steam_shortcuts else "Removing",
__steam_user.account_name,
__steam_user.persona_name
)
_save_shortcuts(__steam_dir, __steam_user, __steam_shortcuts)


def steam_shortcut_exists(app_name: str) -> bool:
Expand Down Expand Up @@ -152,6 +156,8 @@ def add_steam_shortcut(app_name: str, app_title: str) -> SteamShortcut:

def add_steam_coverart(app_name: str, shortcut: SteamShortcut):
steam_grid_dir = os.path.join(__steam_dir, "userdata", str(__steam_user.short_id), "config", "grid")
if not os.path.exists(steam_grid_dir):
os.mkdir(steam_grid_dir)
shutil.copy(image_wide_path(app_name), os.path.join(steam_grid_dir, shortcut.game_hero))
shutil.copy(image_icon_path(app_name), os.path.join(steam_grid_dir, shortcut.game_logo))
shutil.copy(image_wide_path(app_name), os.path.join(steam_grid_dir, shortcut.grid_wide))
Expand All @@ -160,6 +166,9 @@ def add_steam_coverart(app_name: str, shortcut: SteamShortcut):

def remove_steam_coverart(shortcut: SteamShortcut):
steam_grid_dir = os.path.join(__steam_dir, "userdata", str(__steam_user.short_id), "config", "grid")
if not os.path.exists(steam_grid_dir):
logger.warning("Path does not exist %s", steam_grid_dir)
return
Path(steam_grid_dir).joinpath(shortcut.game_hero).unlink(missing_ok=True)
Path(steam_grid_dir).joinpath(shortcut.game_logo).unlink(missing_ok=True)
Path(steam_grid_dir).joinpath(shortcut.grid_wide).unlink(missing_ok=True)
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
build
wheel
pylint
mypy
black[d]
toml
cx-freeze
Expand Down

0 comments on commit 3ccd3e7

Please sign in to comment.