From 437bbf735adeffd831b9b9be9f3e0b1a668236df Mon Sep 17 00:00:00 2001 From: DavidoTek <54072917+DavidoTek@users.noreply.github.com> Date: Thu, 11 Jan 2024 15:08:05 +0100 Subject: [PATCH] Enable Luxtorpeda for all supported games-Button: Backend Logic See https://github.com/DavidoTek/ProtonUp-Qt/issues/342 for details --- pupgui2/constants.py | 2 ++ pupgui2/steamutil.py | 30 +++++++++++++++++++++++++++++- pupgui2/util.py | 25 ++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/pupgui2/constants.py b/pupgui2/constants.py index 97d77cdc..c8b74682 100644 --- a/pupgui2/constants.py +++ b/pupgui2/constants.py @@ -76,6 +76,8 @@ def PALETTE_DARK(): LOCAL_AWACY_GAME_LIST = os.path.join(TEMP_DIR, 'awacy_games.json') PROTONDB_API_URL = 'https://www.protondb.com/api/v1/reports/summaries/{game_id}.json' PROTONDB_APP_PAGE_URL = 'https://protondb.com/app/' +LUXTORPEDA_PACKAGESSNIPER_URL = 'https://luxtorpeda-dev.github.io/packagessniper_v2.json' +LUXTORPEDA_CTOOL_NAME = 'luxtorpeda' STEAM_BOXTRON_FLATPAK_APPSTREAM = 'appstream://com.valvesoftware.Steam.CompatibilityTool.Boxtron' STEAM_STL_FLATPAK_APPSTREAM = 'appstream://com.valvesoftware.Steam.Utility.steamtinkerlaunch' diff --git a/pupgui2/steamutil.py b/pupgui2/steamutil.py index 5c33cd43..893f4397 100644 --- a/pupgui2/steamutil.py +++ b/pupgui2/steamutil.py @@ -15,6 +15,7 @@ from pupgui2.constants import APP_NAME, APP_ID, APP_ICON_FILE from pupgui2.constants import PROTON_EAC_RUNTIME_APPID, PROTON_BATTLEYE_RUNTIME_APPID, PROTON_NEXT_APPID, STEAMLINUXRUNTIME_APPID, STEAMLINUXRUNTIME_SOLDIER_APPID, STEAMLINUXRUNTIME_SNIPER_APPID +from pupgui2.constants import LUXTORPEDA_CTOOL_NAME from pupgui2.constants import LOCAL_AWACY_GAME_LIST, PROTONDB_API_URL from pupgui2.constants import STEAM_STL_INSTALL_PATH, STEAM_STL_CONFIG_PATH, STEAM_STL_SHELL_FILES, STEAM_STL_FISH_VARIABLES, HOME_DIR from pupgui2.datastructures import SteamApp, AWACYStatus, BasicCompatTool, CTType, SteamUser, RuntimeType @@ -791,4 +792,31 @@ def determine_most_recent_steam_user(steam_users: List[SteamUser]) -> SteamUser: return steam_users[0] print('Warning: No Steam users found. Returning None') - return None \ No newline at end of file + return None + + +def luxtorpeda_set_all_games(steam_app_list: List[SteamApp], luxtorpeda_supported_app_ids: List[int], steam_config_folder: str) -> bool: + """ + Enables Luxtorpeda for all games in the steam_app_list that are in the luxtorpeda_supported_app_ids list. + + Parameters: + steam_app_list: List[SteamApp] + List of Steam apps + luxtorpeda_supported_app_ids: List[int] + List of app ids that are supported by Luxtorpeda + + Return Type: bool + """ + + if not os.path.exists(os.path.join(os.path.expanduser(steam_config_folder), 'config.vdf')): + return False + + if len(luxtorpeda_supported_app_ids) == 0: + return False + + for app in steam_app_list: + if app.app_id in luxtorpeda_supported_app_ids: + # For now ignore when steam_update_ctool fails for individual apps (return value is ignored) + steam_update_ctool(app, LUXTORPEDA_CTOOL_NAME, steam_config_folder) + + return True diff --git a/pupgui2/util.py b/pupgui2/util.py index 1b39bb75..92cdc3d3 100644 --- a/pupgui2/util.py +++ b/pupgui2/util.py @@ -9,6 +9,7 @@ import zipfile import tarfile import random +import json import zstandard @@ -20,7 +21,7 @@ from PySide6.QtWidgets import QApplication, QStyleFactory, QMessageBox, QCheckBox from pupgui2.constants import POSSIBLE_INSTALL_LOCATIONS, CONFIG_FILE, PALETTE_DARK, TEMP_DIR -from pupgui2.constants import AWACY_GAME_LIST_URL, LOCAL_AWACY_GAME_LIST +from pupgui2.constants import AWACY_GAME_LIST_URL, LOCAL_AWACY_GAME_LIST, LUXTORPEDA_PACKAGESSNIPER_URL from pupgui2.constants import GITHUB_API, GITLAB_API, GITLAB_API_RATELIMIT_TEXT from pupgui2.datastructures import BasicCompatTool, CTType, Launcher, SteamApp, LutrisGame, HeroicGame from pupgui2.steamutil import remove_steamtinkerlaunch @@ -872,3 +873,25 @@ def get_random_game_name(games: List[Union[SteamApp, LutrisGame, HeroicGame]]) - tooltip_game_name = random_game.title return tooltip_game_name + + +def get_luxtorpeda_supported_app_ids() -> List[int]: + """ + Downloads the latest package list from LUXTORPEDA_PACKAGESSNIPER_URL and returns a list of supported app IDs + Blocking until json is downloaded and parsed + + Return Type: List[int] + """ + try: + r = requests.get(LUXTORPEDA_PACKAGESSNIPER_URL) + j = json.loads(r.content) + + games = j.get('games', []) + + app_ids = [int(g.get('app_id')) for g in games if g.get('app_id', 'z').isdigit()] + + return app_ids + + except Exception as e: + print('Error fetching Luxtorpeda packages list: ' + str(e)) + return []