From 83537b1e16bcdcadb9518744d4a06ca40a906808 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sat, 16 Dec 2023 23:09:20 +0000 Subject: [PATCH 01/18] CtInfo: Add button to make compat tool global default --- pupgui2/resources/ui/pupgui2_ctinfodialog.ui | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pupgui2/resources/ui/pupgui2_ctinfodialog.ui b/pupgui2/resources/ui/pupgui2_ctinfodialog.ui index 4f731e8d..9b104ce4 100644 --- a/pupgui2/resources/ui/pupgui2_ctinfodialog.ui +++ b/pupgui2/resources/ui/pupgui2_ctinfodialog.ui @@ -275,6 +275,13 @@ + + + + Set as Global + + + From 6e8cbdf2742027668583b666ba2c3866636c151d Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sat, 16 Dec 2023 23:11:52 +0000 Subject: [PATCH 02/18] CtInfo: Only show Mark Global button for Steam launcher --- pupgui2/pupgui2ctinfodialog.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pupgui2/pupgui2ctinfodialog.py b/pupgui2/pupgui2ctinfodialog.py index 301df3fc..1908810e 100644 --- a/pupgui2/pupgui2ctinfodialog.py +++ b/pupgui2/pupgui2ctinfodialog.py @@ -29,6 +29,7 @@ def __init__(self, parent=None, ctool: BasicCompatTool = None, install_loc=None) self.games: List[Union[SteamApp, LutrisGame, HeroicGame]] = [] self.install_loc = install_loc self.is_batch_update_available = False + self.is_mark_global_available = self.install_loc.get('launcher') == 'steam' and 'vdf_dir' in self.install_loc self.load_ui() self.setup_ui() @@ -46,6 +47,7 @@ def setup_ui(self): self.ui.txtInstallDirectory.setText(self.ctool.get_install_dir()) self.ui.btnBatchUpdate.setVisible(False) self.ui.searchBox.setVisible(False) + self.ui.btnMarkGlobal.setVisible(self.is_mark_global_available) self.update_game_list() @@ -64,6 +66,7 @@ def update_game_list(self, cached=True): self.is_batch_update_available = True self.ui.btnBatchUpdate.setVisible(not self.ui.searchBox.isVisible()) self.ui.btnBatchUpdate.clicked.connect(self.btn_batch_update_clicked) + self.ui.btnMarkGlobal.clicked.connect(self.btn_mark_global_clicked) elif self.install_loc.get('launcher') == 'lutris': self.update_game_list_lutris() elif is_heroic_launcher(self.install_loc.get('launcher')): @@ -161,3 +164,6 @@ def search_ctinfo_games(self, text): for row in range(self.ui.listGames.rowCount()): should_hide: bool = not text.lower() in self.ui.listGames.item(row, 1).text().lower() self.ui.listGames.setRowHidden(row, should_hide) + + def btn_mark_global_clicked(self): + print('Mark global clicked') From 5236d50d61da9b01254844495d73c14fa130b5e7 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sat, 16 Dec 2023 23:14:33 +0000 Subject: [PATCH 03/18] CtInfo: Only show Mark Global for CTType.CUSTOM --- pupgui2/pupgui2ctinfodialog.py | 4 ++-- pupgui2/steamutil.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pupgui2/pupgui2ctinfodialog.py b/pupgui2/pupgui2ctinfodialog.py index 1908810e..0e4c7cc0 100644 --- a/pupgui2/pupgui2ctinfodialog.py +++ b/pupgui2/pupgui2ctinfodialog.py @@ -5,7 +5,7 @@ from pupgui2.datastructures import BasicCompatTool, CTType, SteamApp, LutrisGame, HeroicGame from pupgui2.lutrisutil import get_lutris_game_list from pupgui2.pupgui2ctbatchupdatedialog import PupguiCtBatchUpdateDialog -from pupgui2.steamutil import get_steam_game_list +from pupgui2.steamutil import get_steam_game_list, set_global_compat_tool from pupgui2.util import open_webbrowser_thread, get_random_game_name from pupgui2.heroicutil import get_heroic_game_list, is_heroic_launcher @@ -29,7 +29,7 @@ def __init__(self, parent=None, ctool: BasicCompatTool = None, install_loc=None) self.games: List[Union[SteamApp, LutrisGame, HeroicGame]] = [] self.install_loc = install_loc self.is_batch_update_available = False - self.is_mark_global_available = self.install_loc.get('launcher') == 'steam' and 'vdf_dir' in self.install_loc + self.is_mark_global_available = self.ctool.ct_type == CTType.CUSTOM and self.install_loc.get('launcher') == 'steam' and 'vdf_dir' in self.install_loc self.load_ui() self.setup_ui() diff --git a/pupgui2/steamutil.py b/pupgui2/steamutil.py index 5c33cd43..b3acc2dd 100644 --- a/pupgui2/steamutil.py +++ b/pupgui2/steamutil.py @@ -791,4 +791,8 @@ 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 set_global_compat_tool(ctool: BasicCompatTool): + if ctool.ct_type == CTType.CUSTOM: + print('Mark Global supported') From 98dc0ec6fdd9cf56eb22968049f9c792f50f8637 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sat, 16 Dec 2023 23:28:19 +0000 Subject: [PATCH 04/18] CtInfo: Initial implementation of set_global_compat_tool --- pupgui2/pupgui2ctinfodialog.py | 2 ++ pupgui2/steamutil.py | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pupgui2/pupgui2ctinfodialog.py b/pupgui2/pupgui2ctinfodialog.py index 0e4c7cc0..0fa72b83 100644 --- a/pupgui2/pupgui2ctinfodialog.py +++ b/pupgui2/pupgui2ctinfodialog.py @@ -167,3 +167,5 @@ def search_ctinfo_games(self, text): def btn_mark_global_clicked(self): print('Mark global clicked') + set_global_compat_tool(self.ctool, self.install_loc.get('vdf_dir')) + self.btn_refresh_games_clicked() diff --git a/pupgui2/steamutil.py b/pupgui2/steamutil.py index b3acc2dd..54938d82 100644 --- a/pupgui2/steamutil.py +++ b/pupgui2/steamutil.py @@ -793,6 +793,28 @@ def determine_most_recent_steam_user(steam_users: List[SteamUser]) -> SteamUser: print('Warning: No Steam users found. Returning None') return None -def set_global_compat_tool(ctool: BasicCompatTool): +def set_global_compat_tool(ctool: BasicCompatTool, steam_config_folder): + """ Update the global compatibility tool to the ctool parameter defined in config.vdf CompatToolMapping (AppID '0') """ + if ctool.ct_type == CTType.CUSTOM: - print('Mark Global supported') + config_vdf_file = os.path.join(os.path.expanduser(steam_config_folder), 'config.vdf') + if not os.path.exists(config_vdf_file): + return False + + try: + d = vdf.load(open(config_vdf_file)) + c = get_steam_vdf_compat_tool_mapping(d) + + # Create or update the '0' CompatToolMapping entry + if not c.get('0', {}): + c['0'] = { 'name': ctool.get_internal_name(), 'config': '', 'priority': '75' } + else: + c['0']['name'] = ctool.get_internal_name() + + # Unsure if this will work + # vdf.dump(d, open(config_vdf_file, 'w'), pretty=True) + except Exception as e: + print(f'Error, could not update Global Steam compatibility tool to {ctool.displayname}: {e}, vdf: {config_vdf_file}') + return False + + return True From cbd2318d2cf8017354794563de4642e4dd3e4312 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sun, 17 Dec 2023 00:23:14 +0000 Subject: [PATCH 05/18] CtInfo: Don't show Mark Global button for Global Tool --- pupgui2/pupgui2ctinfodialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pupgui2/pupgui2ctinfodialog.py b/pupgui2/pupgui2ctinfodialog.py index 0fa72b83..4931bca1 100644 --- a/pupgui2/pupgui2ctinfodialog.py +++ b/pupgui2/pupgui2ctinfodialog.py @@ -29,7 +29,7 @@ def __init__(self, parent=None, ctool: BasicCompatTool = None, install_loc=None) self.games: List[Union[SteamApp, LutrisGame, HeroicGame]] = [] self.install_loc = install_loc self.is_batch_update_available = False - self.is_mark_global_available = self.ctool.ct_type == CTType.CUSTOM and self.install_loc.get('launcher') == 'steam' and 'vdf_dir' in self.install_loc + self.is_mark_global_available = (self.ctool.ct_type == CTType.CUSTOM and not self.ctool.is_global) and self.install_loc.get('launcher') == 'steam' and 'vdf_dir' in self.install_loc self.load_ui() self.setup_ui() From 03cd5c378dd28a8fe6c7b37e6a08b04400dbbb4c Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Tue, 30 Jan 2024 00:32:15 +0000 Subject: [PATCH 06/18] CtInfo: Remove print --- pupgui2/pupgui2ctinfodialog.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pupgui2/pupgui2ctinfodialog.py b/pupgui2/pupgui2ctinfodialog.py index 4931bca1..dde04ab8 100644 --- a/pupgui2/pupgui2ctinfodialog.py +++ b/pupgui2/pupgui2ctinfodialog.py @@ -166,6 +166,5 @@ def search_ctinfo_games(self, text): self.ui.listGames.setRowHidden(row, should_hide) def btn_mark_global_clicked(self): - print('Mark global clicked') set_global_compat_tool(self.ctool, self.install_loc.get('vdf_dir')) self.btn_refresh_games_clicked() From b2ded7386e29065f6c7ee616a68dbd2b8d855780 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Tue, 30 Jan 2024 00:38:12 +0000 Subject: [PATCH 07/18] steamutil: Enable writing to config.vdf --- pupgui2/steamutil.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pupgui2/steamutil.py b/pupgui2/steamutil.py index 54938d82..69fb0479 100644 --- a/pupgui2/steamutil.py +++ b/pupgui2/steamutil.py @@ -811,8 +811,7 @@ def set_global_compat_tool(ctool: BasicCompatTool, steam_config_folder): else: c['0']['name'] = ctool.get_internal_name() - # Unsure if this will work - # vdf.dump(d, open(config_vdf_file, 'w'), pretty=True) + vdf.dump(d, open(config_vdf_file, 'w'), pretty=True) except Exception as e: print(f'Error, could not update Global Steam compatibility tool to {ctool.displayname}: {e}, vdf: {config_vdf_file}') return False From 618083e4d43949ee836b38c7a18f5d8e4c6f598c Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sat, 20 Apr 2024 17:59:53 +0100 Subject: [PATCH 08/18] steamutil: `return 1` when adding shortcut fails --- pupgui2/steamutil.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pupgui2/steamutil.py b/pupgui2/steamutil.py index b29ec2ae..31a0fc94 100644 --- a/pupgui2/steamutil.py +++ b/pupgui2/steamutil.py @@ -636,6 +636,8 @@ def install_steam_library_shortcut(steam_config_folder: str, remove_shortcut=Fal except Exception as e: print(f'Error: Could not add {APP_NAME} as Steam shortcut:', e) + return 1 + return 0 From 5b0793a4ed95968c6c620c910db6527162f19389 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sat, 20 Apr 2024 18:15:01 +0100 Subject: [PATCH 09/18] CtInfo: Break out is_mark_global_available out into a util function This more easily allows us to perform this check with launcher-specific checks, instead of having a messy one-liner --- pupgui2/pupgui2ctinfodialog.py | 4 ++-- pupgui2/util.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pupgui2/pupgui2ctinfodialog.py b/pupgui2/pupgui2ctinfodialog.py index ba0f51f4..07491b8e 100644 --- a/pupgui2/pupgui2ctinfodialog.py +++ b/pupgui2/pupgui2ctinfodialog.py @@ -6,7 +6,7 @@ from pupgui2.lutrisutil import get_lutris_game_list, is_lutris_game_using_wine from pupgui2.pupgui2ctbatchupdatedialog import PupguiCtBatchUpdateDialog from pupgui2.steamutil import get_steam_game_list, set_global_compat_tool -from pupgui2.util import open_webbrowser_thread, get_random_game_name +from pupgui2.util import open_webbrowser_thread, get_random_game_name, is_mark_global_available from pupgui2.heroicutil import get_heroic_game_list, is_heroic_launcher from PySide6.QtCore import QObject, Signal, QDataStream, QByteArray @@ -29,7 +29,7 @@ def __init__(self, parent=None, ctool: BasicCompatTool = None, install_loc=None) self.games: List[Union[SteamApp, LutrisGame, HeroicGame]] = [] self.install_loc = install_loc self.is_batch_update_available = False - self.is_mark_global_available = (self.ctool.ct_type == CTType.CUSTOM and not self.ctool.is_global) and self.install_loc.get('launcher') == 'steam' and 'vdf_dir' in self.install_loc + self.is_mark_global_available = is_mark_global_available(self.install_loc, self.ctool) self.load_ui() self.setup_ui() diff --git a/pupgui2/util.py b/pupgui2/util.py index e91991fa..0c0cba77 100644 --- a/pupgui2/util.py +++ b/pupgui2/util.py @@ -892,3 +892,24 @@ def get_random_game_name(games: List[Union[SteamApp, LutrisGame, HeroicGame]]) - tooltip_game_name = random_game.title return tooltip_game_name + + +def is_mark_global_available(install_loc, ctool: BasicCompatTool): + allowed_launchers = [ 'steam', 'lutris' ] # Only allow marking global for these launchers + + # Only allow marking global for compatibility tools and not runtimes etc + if ctool.ct_type != CTType.CUSTOM: + return False + + # Exit early if launcher is not on our list of compatible/allowed launchers + if install_loc.get('launcher') not in allowed_launchers: + return False + + # Only allow marking global for Steam if we have the VDF directory path + if install_loc.get('launcher') == 'steam' and 'vdf_dir' not in install_loc: + return False + + # Could put other conditions for other launchers in an elif here, i.e. check for Lutris and ensure a specific path exists + # Nothing here yet... + + return True # All other checks passed so default to true From 6fd4d26e8d926ad777d113e5d06153079d7fbe9d Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Thu, 25 Apr 2024 18:38:01 +0100 Subject: [PATCH 10/18] CtInfo: Correctly bind btn_mark_global_clicked to btnMarkGlobal --- pupgui2/pupgui2ctinfodialog.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pupgui2/pupgui2ctinfodialog.py b/pupgui2/pupgui2ctinfodialog.py index 07491b8e..5941b050 100644 --- a/pupgui2/pupgui2ctinfodialog.py +++ b/pupgui2/pupgui2ctinfodialog.py @@ -66,6 +66,8 @@ def update_game_list(self, cached=True): self.is_batch_update_available = True self.ui.btnBatchUpdate.setVisible(not self.ui.searchBox.isVisible()) self.ui.btnBatchUpdate.clicked.connect(self.btn_batch_update_clicked) + + if self.is_mark_global_available: self.ui.btnMarkGlobal.clicked.connect(self.btn_mark_global_clicked) elif self.install_loc.get('launcher') == 'lutris': self.update_game_list_lutris() From 9f7c1c26e04ece22b542e4d3771d2901bb800748 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sun, 2 Jun 2024 16:20:50 +0100 Subject: [PATCH 11/18] Refactor to use generic set_launcher_global_tool util function This can be called anywhere and given the current launcher, and it will handle the details of calling the correct util function to set a global tool for that launcher, and giving it the required information --- pupgui2/pupgui2ctinfodialog.py | 6 +++--- pupgui2/steamutil.py | 2 +- pupgui2/util.py | 35 ++++++++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/pupgui2/pupgui2ctinfodialog.py b/pupgui2/pupgui2ctinfodialog.py index 5941b050..e61dd19e 100644 --- a/pupgui2/pupgui2ctinfodialog.py +++ b/pupgui2/pupgui2ctinfodialog.py @@ -5,8 +5,8 @@ from pupgui2.datastructures import BasicCompatTool, CTType, SteamApp, LutrisGame, HeroicGame from pupgui2.lutrisutil import get_lutris_game_list, is_lutris_game_using_wine from pupgui2.pupgui2ctbatchupdatedialog import PupguiCtBatchUpdateDialog -from pupgui2.steamutil import get_steam_game_list, set_global_compat_tool -from pupgui2.util import open_webbrowser_thread, get_random_game_name, is_mark_global_available +from pupgui2.steamutil import get_steam_game_list +from pupgui2.util import open_webbrowser_thread, get_random_game_name, is_mark_global_available, set_launcher_global_tool from pupgui2.heroicutil import get_heroic_game_list, is_heroic_launcher from PySide6.QtCore import QObject, Signal, QDataStream, QByteArray @@ -168,5 +168,5 @@ def search_ctinfo_games(self, text): self.ui.listGames.setRowHidden(row, should_hide) def btn_mark_global_clicked(self): - set_global_compat_tool(self.ctool, self.install_loc.get('vdf_dir')) + set_launcher_global_tool(self.install_loc, self.ctool) self.btn_refresh_games_clicked() diff --git a/pupgui2/steamutil.py b/pupgui2/steamutil.py index 31a0fc94..5e13cf6a 100644 --- a/pupgui2/steamutil.py +++ b/pupgui2/steamutil.py @@ -796,7 +796,7 @@ def determine_most_recent_steam_user(steam_users: List[SteamUser]) -> SteamUser: return None -def set_global_compat_tool(ctool: BasicCompatTool, steam_config_folder): +def set_steam_global_compat_tool(steam_config_folder: str, ctool: BasicCompatTool): """ Update the global compatibility tool to the ctool parameter defined in config.vdf CompatToolMapping (AppID '0') """ if ctool.ct_type == CTType.CUSTOM: diff --git a/pupgui2/util.py b/pupgui2/util.py index 0c0cba77..2912a281 100644 --- a/pupgui2/util.py +++ b/pupgui2/util.py @@ -23,7 +23,7 @@ from pupgui2.constants import AWACY_GAME_LIST_URL, LOCAL_AWACY_GAME_LIST 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, is_valid_steam_install +from pupgui2.steamutil import remove_steamtinkerlaunch, is_valid_steam_install, set_steam_global_compat_tool def create_msgbox( @@ -894,7 +894,17 @@ def get_random_game_name(games: List[Union[SteamApp, LutrisGame, HeroicGame]]) - return tooltip_game_name -def is_mark_global_available(install_loc, ctool: BasicCompatTool): +def is_mark_global_available(install_loc, ctool: BasicCompatTool) -> bool: + + """ + Check if marking a tool is "global" is supported by the current launcher, + and if the given ctool can be marked as global for this launcher. + + For example, runtimes are not valid to be marked as Global. + + Return Type: bool + """ + allowed_launchers = [ 'steam', 'lutris' ] # Only allow marking global for these launchers # Only allow marking global for compatibility tools and not runtimes etc @@ -913,3 +923,24 @@ def is_mark_global_available(install_loc, ctool: BasicCompatTool): # Nothing here yet... return True # All other checks passed so default to true + + +def set_launcher_global_tool(install_loc, compat_tool: BasicCompatTool): + + """ + Set a given compat_tool as global for a given launcher by calling the + relevant util function for that launcher. + """ + + launcher = install_loc.get('launcher', '').lower() + + # Skip empty launcher + if not launcher: + return + + if not is_mark_global_available(install_loc, compat_tool): + return + + if launcher == 'steam': + steam_config_folder = install_loc.get('vdf_dir', '') + set_steam_global_compat_tool(steam_config_folder, compat_tool) From 02fd807663edff72518368ff15477b21d9b38db7 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sun, 2 Jun 2024 16:32:04 +0100 Subject: [PATCH 12/18] Set correct tab focus order Fixes the Mark Global button having default focus. Now the Close button has the default focus. --- pupgui2/resources/ui/pupgui2_ctinfodialog.ui | 38 ++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/pupgui2/resources/ui/pupgui2_ctinfodialog.ui b/pupgui2/resources/ui/pupgui2_ctinfodialog.ui index 9b104ce4..96e166c4 100644 --- a/pupgui2/resources/ui/pupgui2_ctinfodialog.ui +++ b/pupgui2/resources/ui/pupgui2_ctinfodialog.ui @@ -14,8 +14,7 @@ About compatibility tool - - .. + @@ -33,7 +32,7 @@ - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextSelectableByMouse @@ -50,7 +49,7 @@ - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextSelectableByMouse @@ -67,7 +66,7 @@ - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + Qt::TextInteractionFlag::LinksAccessibleByMouse|Qt::TextInteractionFlag::TextSelectableByMouse @@ -76,7 +75,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -84,6 +83,9 @@ + + Qt::FocusPolicy::NoFocus + Games using compatibility tool: @@ -99,7 +101,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -118,8 +120,7 @@ - - .. + @@ -132,8 +133,7 @@ - - .. + @@ -170,13 +170,13 @@ - Qt::ClickFocus + Qt::FocusPolicy::ClickFocus - QAbstractItemView::NoEditTriggers + QAbstractItemView::EditTrigger::NoEditTriggers - QAbstractItemView::SelectRows + QAbstractItemView::SelectionBehavior::SelectRows true @@ -248,7 +248,7 @@ No games - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter @@ -285,7 +285,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -298,7 +298,7 @@ - Qt::StrongFocus + Qt::FocusPolicy::StrongFocus Close @@ -311,10 +311,12 @@ btnClose + btnMarkGlobal + searchBox btnBatchUpdate btnSearch - searchBox btnRefreshGames + lblGamesUsingTool From 24061ce788b0de2593fb8345c7909898db675ff5 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sun, 2 Jun 2024 16:35:21 +0100 Subject: [PATCH 13/18] remove unnecessary property from CtInfo designer file --- pupgui2/resources/ui/pupgui2_ctinfodialog.ui | 3 --- 1 file changed, 3 deletions(-) diff --git a/pupgui2/resources/ui/pupgui2_ctinfodialog.ui b/pupgui2/resources/ui/pupgui2_ctinfodialog.ui index 96e166c4..50b85839 100644 --- a/pupgui2/resources/ui/pupgui2_ctinfodialog.ui +++ b/pupgui2/resources/ui/pupgui2_ctinfodialog.ui @@ -83,9 +83,6 @@ - - Qt::FocusPolicy::NoFocus - Games using compatibility tool: From 05fb631fa40061a2458bc616f3780652d0d984e8 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sun, 16 Jun 2024 20:42:09 +0100 Subject: [PATCH 14/18] Toggle Mark Global button visibility after pressing If the current tool is successfully marked as global, hide the Mark Global button using the same logic used to show/hide the button when the CtInfo dialog is opened. Also move the show/hide logic for the Mark Global button to `update_game_list_ui` so that it is not launcher-specific; `is_mark_global_available` handles the launcher checks for us. --- pupgui2/pupgui2ctinfodialog.py | 9 +++++---- pupgui2/util.py | 10 +++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pupgui2/pupgui2ctinfodialog.py b/pupgui2/pupgui2ctinfodialog.py index e61dd19e..133f1214 100644 --- a/pupgui2/pupgui2ctinfodialog.py +++ b/pupgui2/pupgui2ctinfodialog.py @@ -66,9 +66,6 @@ def update_game_list(self, cached=True): self.is_batch_update_available = True self.ui.btnBatchUpdate.setVisible(not self.ui.searchBox.isVisible()) self.ui.btnBatchUpdate.clicked.connect(self.btn_batch_update_clicked) - - if self.is_mark_global_available: - self.ui.btnMarkGlobal.clicked.connect(self.btn_mark_global_clicked) elif self.install_loc.get('launcher') == 'lutris': self.update_game_list_lutris() elif is_heroic_launcher(self.install_loc.get('launcher')): @@ -131,6 +128,10 @@ def update_game_list_ui(self): if self.ctool.is_global: self.ui.lblGamesList.setText(self.tr('Tool is Global')) + self.ui.btnMarkGlobal.setVisible(self.is_mark_global_available) + if self.is_mark_global_available: + self.ui.btnMarkGlobal.clicked.connect(self.btn_mark_global_clicked) + if len(self.games) < 0 or self.ctool.is_global: self.ui.btnClose.setFocus() @@ -168,5 +169,5 @@ def search_ctinfo_games(self, text): self.ui.listGames.setRowHidden(row, should_hide) def btn_mark_global_clicked(self): - set_launcher_global_tool(self.install_loc, self.ctool) + self.is_mark_global_available = not set_launcher_global_tool(self.install_loc, self.ctool) self.btn_refresh_games_clicked() diff --git a/pupgui2/util.py b/pupgui2/util.py index 2912a281..5091932e 100644 --- a/pupgui2/util.py +++ b/pupgui2/util.py @@ -925,7 +925,7 @@ def is_mark_global_available(install_loc, ctool: BasicCompatTool) -> bool: return True # All other checks passed so default to true -def set_launcher_global_tool(install_loc, compat_tool: BasicCompatTool): +def set_launcher_global_tool(install_loc, compat_tool: BasicCompatTool) -> bool: """ Set a given compat_tool as global for a given launcher by calling the @@ -936,11 +936,15 @@ def set_launcher_global_tool(install_loc, compat_tool: BasicCompatTool): # Skip empty launcher if not launcher: - return + return False if not is_mark_global_available(install_loc, compat_tool): - return + return False if launcher == 'steam': steam_config_folder = install_loc.get('vdf_dir', '') set_steam_global_compat_tool(steam_config_folder, compat_tool) + + return True + + return False From 08849b77e6e71f6c1021be294baf718864a129b0 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sun, 16 Jun 2024 20:44:53 +0100 Subject: [PATCH 15/18] Use return value of `set_steam_global_compat_tool` in `set_launcher_global_tool` Also makes sure `set_steam_global_compat_tool` always returns a bool. --- pupgui2/steamutil.py | 2 ++ pupgui2/util.py | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pupgui2/steamutil.py b/pupgui2/steamutil.py index 5e13cf6a..1979c514 100644 --- a/pupgui2/steamutil.py +++ b/pupgui2/steamutil.py @@ -821,6 +821,8 @@ def set_steam_global_compat_tool(steam_config_folder: str, ctool: BasicCompatToo return True + return False + def is_valid_steam_install(steam_path) -> bool: diff --git a/pupgui2/util.py b/pupgui2/util.py index 5091932e..0a4f09aa 100644 --- a/pupgui2/util.py +++ b/pupgui2/util.py @@ -943,8 +943,7 @@ def set_launcher_global_tool(install_loc, compat_tool: BasicCompatTool) -> bool: if launcher == 'steam': steam_config_folder = install_loc.get('vdf_dir', '') - set_steam_global_compat_tool(steam_config_folder, compat_tool) - return True + return set_steam_global_compat_tool(steam_config_folder, compat_tool) return False From 922f9cfe4fb1f80b73b02591a8ac8b65bf044e67 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sat, 6 Jul 2024 23:10:32 +0100 Subject: [PATCH 16/18] Don't allow marking already global compat tools as global Also handle updating is_mark_global_available on refresh. Now if the global tool is updated external to ProtonUp-Qt, refreshing will show the 'Set as Global' button. --- pupgui2/pupgui2ctinfodialog.py | 10 ++++++---- pupgui2/util.py | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pupgui2/pupgui2ctinfodialog.py b/pupgui2/pupgui2ctinfodialog.py index 133f1214..6f618b62 100644 --- a/pupgui2/pupgui2ctinfodialog.py +++ b/pupgui2/pupgui2ctinfodialog.py @@ -29,7 +29,7 @@ def __init__(self, parent=None, ctool: BasicCompatTool = None, install_loc=None) self.games: List[Union[SteamApp, LutrisGame, HeroicGame]] = [] self.install_loc = install_loc self.is_batch_update_available = False - self.is_mark_global_available = is_mark_global_available(self.install_loc, self.ctool) + self.is_mark_global_available = False self.load_ui() self.setup_ui() @@ -42,14 +42,14 @@ def load_ui(self): self.ui = loader.load(ui_file.device()) def setup_ui(self): + self.update_game_list() + self.ui.txtToolName.setText(self.ctool.displayname) self.ui.txtLauncherName.setText(self.install_loc.get('display_name')) self.ui.txtInstallDirectory.setText(self.ctool.get_install_dir()) self.ui.btnBatchUpdate.setVisible(False) self.ui.searchBox.setVisible(False) - self.ui.btnMarkGlobal.setVisible(self.is_mark_global_available) - - self.update_game_list() + self.ui.btnMarkGlobal.setVisible(self.is_mark_global_available) # Gets updated in update_game_list self.ui.btnSearch.clicked.connect(self.btn_search_clicked) self.ui.btnRefreshGames.clicked.connect(self.btn_refresh_games_clicked) @@ -60,6 +60,8 @@ def setup_ui(self): QShortcut(QKeySequence.Find, self.ui).activated.connect(self.btn_search_clicked) def update_game_list(self, cached=True): + self.is_mark_global_available = is_mark_global_available(self.install_loc, self.ctool) + if self.install_loc.get('launcher') == 'steam' and 'vdf_dir' in self.install_loc: self.update_game_list_steam(cached=cached) if 'Proton' in self.ctool.displayname and self.ctool.ct_type == CTType.CUSTOM: # 'batch update' option for Proton-GE diff --git a/pupgui2/util.py b/pupgui2/util.py index 0a4f09aa..3f11b280 100644 --- a/pupgui2/util.py +++ b/pupgui2/util.py @@ -911,6 +911,10 @@ def is_mark_global_available(install_loc, ctool: BasicCompatTool) -> bool: if ctool.ct_type != CTType.CUSTOM: return False + # Don't allow marking global compat tools as global + if ctool.is_global: + return False + # Exit early if launcher is not on our list of compatible/allowed launchers if install_loc.get('launcher') not in allowed_launchers: return False From c1fa092baf999d83791d76f4f81946866e20ddda Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sat, 6 Jul 2024 23:12:57 +0100 Subject: [PATCH 17/18] steamutil: Simplify set_steam_global_compat_tool Return early if CTType doesn't match instead of nesting. --- pupgui2/steamutil.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/pupgui2/steamutil.py b/pupgui2/steamutil.py index 1979c514..8758c20d 100644 --- a/pupgui2/steamutil.py +++ b/pupgui2/steamutil.py @@ -799,29 +799,30 @@ def determine_most_recent_steam_user(steam_users: List[SteamUser]) -> SteamUser: def set_steam_global_compat_tool(steam_config_folder: str, ctool: BasicCompatTool): """ Update the global compatibility tool to the ctool parameter defined in config.vdf CompatToolMapping (AppID '0') """ - if ctool.ct_type == CTType.CUSTOM: - config_vdf_file = os.path.join(os.path.expanduser(steam_config_folder), 'config.vdf') - if not os.path.exists(config_vdf_file): - return False + if ctool.ct_type != CTType.CUSTOM: + return False - try: - d = vdf.load(open(config_vdf_file)) - c = get_steam_vdf_compat_tool_mapping(d) + config_vdf_file = os.path.join(os.path.expanduser(steam_config_folder), 'config.vdf') + if not os.path.exists(config_vdf_file): + return False - # Create or update the '0' CompatToolMapping entry - if not c.get('0', {}): - c['0'] = { 'name': ctool.get_internal_name(), 'config': '', 'priority': '75' } - else: - c['0']['name'] = ctool.get_internal_name() + try: + d = vdf.load(open(config_vdf_file)) + c = get_steam_vdf_compat_tool_mapping(d) - vdf.dump(d, open(config_vdf_file, 'w'), pretty=True) - except Exception as e: - print(f'Error, could not update Global Steam compatibility tool to {ctool.displayname}: {e}, vdf: {config_vdf_file}') - return False + # Create or update the '0' CompatToolMapping entry + if not c.get('0', {}): + c['0'] = { 'name': ctool.get_internal_name(), 'config': '', 'priority': '75' } + else: + c['0']['name'] = ctool.get_internal_name() - return True + vdf.dump(d, open(config_vdf_file, 'w'), pretty=True) + except Exception as e: + print(f'Error, could not update Global Steam compatibility tool to {ctool.displayname}: {e}, vdf: {config_vdf_file}') + return False + + return True - return False def is_valid_steam_install(steam_path) -> bool: From 6394f9be5a9918b9b7fe6eb460008d52655d5ec6 Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sat, 6 Jul 2024 23:36:00 +0100 Subject: [PATCH 18/18] Move self.is_mark_global_available assignment to update_game_list_ui --- pupgui2/pupgui2ctinfodialog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pupgui2/pupgui2ctinfodialog.py b/pupgui2/pupgui2ctinfodialog.py index 6f618b62..aa430e61 100644 --- a/pupgui2/pupgui2ctinfodialog.py +++ b/pupgui2/pupgui2ctinfodialog.py @@ -60,8 +60,6 @@ def setup_ui(self): QShortcut(QKeySequence.Find, self.ui).activated.connect(self.btn_search_clicked) def update_game_list(self, cached=True): - self.is_mark_global_available = is_mark_global_available(self.install_loc, self.ctool) - if self.install_loc.get('launcher') == 'steam' and 'vdf_dir' in self.install_loc: self.update_game_list_steam(cached=cached) if 'Proton' in self.ctool.displayname and self.ctool.ct_type == CTType.CUSTOM: # 'batch update' option for Proton-GE @@ -122,6 +120,8 @@ def setup_game_list(self, row_count: int, header_labels: List[str]): self.ui.txtNumGamesUsingTool.setText(str(row_count)) def update_game_list_ui(self): + self.is_mark_global_available = is_mark_global_available(self.install_loc, self.ctool) + # switch between showing the QTableWidget (listGames) or the QLabel (lblGamesList) self.ui.stackTableOrText.setCurrentIndex(0 if len(self.games) > 0 and not self.ctool.is_global else 1) self.ui.btnBatchUpdate.setEnabled(len(self.games) > 0 and not self.ctool.is_global)