mirror of
https://github.com/moraroy/NonSteamLaunchers-On-Steam-Deck.git
synced 2024-11-20 16:19:19 +01:00
Merge pull request #176 from sysmoon14/main
Refactored EA App Scanner and Moved Existing Shortcut Check
This commit is contained in:
commit
4b99e4c27c
@ -9,6 +9,7 @@ import sys
|
|||||||
import subprocess
|
import subprocess
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
from urllib.request import urlretrieve
|
from urllib.request import urlretrieve
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
# Read variables from a file
|
# Read variables from a file
|
||||||
with open(f"{os.environ['HOME']}/.config/systemd/user/env_vars", 'r') as f:
|
with open(f"{os.environ['HOME']}/.config/systemd/user/env_vars", 'r') as f:
|
||||||
@ -198,7 +199,6 @@ def download_artwork(game_id, api_key, art_type, shortcut_id, dimensions=None):
|
|||||||
if art_type == 'icons':
|
if art_type == 'icons':
|
||||||
download_artwork(game_id, api_key, 'icons_ico', shortcut_id)
|
download_artwork(game_id, api_key, 'icons_ico', shortcut_id)
|
||||||
|
|
||||||
|
|
||||||
def get_game_id(game_name):
|
def get_game_id(game_name):
|
||||||
print(f"Searching for game ID for: {game_name}")
|
print(f"Searching for game ID for: {game_name}")
|
||||||
games = sgdb.search_game(game_name)
|
games = sgdb.search_game(game_name)
|
||||||
@ -213,9 +213,6 @@ def get_game_id(game_name):
|
|||||||
print("No game ID found")
|
print("No game ID found")
|
||||||
return "default_game_id" # Return a default value when no games are found
|
return "default_game_id" # Return a default value when no games are found
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_file_name(art_type, shortcut_id, dimensions=None):
|
def get_file_name(art_type, shortcut_id, dimensions=None):
|
||||||
singular_art_type = art_type.rstrip('s')
|
singular_art_type = art_type.rstrip('s')
|
||||||
if art_type == 'icons':
|
if art_type == 'icons':
|
||||||
@ -251,6 +248,15 @@ def add_compat_tool(shortcut_id):
|
|||||||
config_data['InstallConfigStore']['Software']['Valve']['Steam']['CompatToolMapping'][str(shortcut_id)] = {'name': f'{compat_tool_name}', 'config': '', 'priority': '250'}
|
config_data['InstallConfigStore']['Software']['Valve']['Steam']['CompatToolMapping'][str(shortcut_id)] = {'name': f'{compat_tool_name}', 'config': '', 'priority': '250'}
|
||||||
print(f"Creating new entry for {shortcut_id} in CompatToolMapping")
|
print(f"Creating new entry for {shortcut_id} in CompatToolMapping")
|
||||||
|
|
||||||
|
def check_if_shortcut_exists(shortcut_id, display_name, exe_path, start_dir, launch_options):
|
||||||
|
# Check if the game already exists in the shortcuts using the id
|
||||||
|
if any(s.get('appid') == str(shortcut_id) for s in shortcuts['shortcuts'].values()):
|
||||||
|
print(f"Existing shortcut found based on shortcut ID for game {display_name}. Skipping.")
|
||||||
|
return True
|
||||||
|
# Check if the game already exists in the shortcuts using the fields (probably unnecessary)
|
||||||
|
if any(s.get('appname') == display_name and s.get('exe') == exe_path and s.get('StartDir') == start_dir and s.get('LaunchOptions') == launch_options for s in shortcuts['shortcuts'].values()):
|
||||||
|
print(f"Existing shortcut found based on matching fields for game {display_name}. Skipping.")
|
||||||
|
return True
|
||||||
#End of Code
|
#End of Code
|
||||||
|
|
||||||
|
|
||||||
@ -353,14 +359,8 @@ if os.path.exists(dat_file_path):
|
|||||||
start_dir = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{epic_games_launcher}/pfx/drive_c/Program Files (x86)/Epic Games/Launcher/Portal/Binaries/Win32/\""
|
start_dir = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{epic_games_launcher}/pfx/drive_c/Program Files (x86)/Epic Games/Launcher/Portal/Binaries/Win32/\""
|
||||||
launch_options = f"STEAM_COMPAT_DATA_PATH=\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{epic_games_launcher}\" %command% -'com.epicgames.launcher://apps/{app_name}?action=launch&silent=true'"
|
launch_options = f"STEAM_COMPAT_DATA_PATH=\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{epic_games_launcher}\" %command% -'com.epicgames.launcher://apps/{app_name}?action=launch&silent=true'"
|
||||||
shortcut_id = get_steam_shortcut_id(exe_path, display_name)
|
shortcut_id = get_steam_shortcut_id(exe_path, display_name)
|
||||||
# Check if the game already exists in the shortcuts using the id
|
# Check if the game already exists in the shortcuts
|
||||||
if any(s.get('appid') == str(shortcut_id) for s in shortcuts['shortcuts'].values()):
|
if check_if_shortcut_exists(shortcut_id, display_name, exe_path, start_dir, launch_options):
|
||||||
print(f"Existing shortcut found based on shortcut ID for game {display_name}. Skipping.")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Check if the game already exists in the shortcuts using the fields (probably unnecessary)
|
|
||||||
if any(s.get('appname') == display_name and s.get('exe') == exe_path and s.get('StartDir') == start_dir and s.get('LaunchOptions') == launch_options for s in shortcuts['shortcuts'].values()):
|
|
||||||
print(f"Existing shortcut found based on matching fields for game {display_name}. Skipping.")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
@ -441,14 +441,8 @@ else:
|
|||||||
exe_path = f"\"{logged_in_home}/.local/share/Steam/Steam/steamapps/compatdata/{ubisoft_connect_launcher}/pfx/drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher/upc.exe\""
|
exe_path = f"\"{logged_in_home}/.local/share/Steam/Steam/steamapps/compatdata/{ubisoft_connect_launcher}/pfx/drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher/upc.exe\""
|
||||||
start_dir = f"\"{logged_in_home}/.local/share/Steam/Steam/steamapps/compatdata/{ubisoft_connect_launcher}/pfx/drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher/\""
|
start_dir = f"\"{logged_in_home}/.local/share/Steam/Steam/steamapps/compatdata/{ubisoft_connect_launcher}/pfx/drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher/\""
|
||||||
shortcut_id = get_steam_shortcut_id(exe_path, game)
|
shortcut_id = get_steam_shortcut_id(exe_path, game)
|
||||||
# Check if the game already exists in the shortcuts using the id
|
# Check if the game already exists in the shortcuts
|
||||||
if any(s.get('appid') == str(shortcut_id) for s in shortcuts['shortcuts'].values()):
|
if check_if_shortcut_exists(shortcut_id, game, exe_path, start_dir, launch_options):
|
||||||
print(f"Existing shortcut found based on shortcut ID for game {game}. Skipping.")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Check if the game already exists in the shortcuts using the fields (probably unnecessary)
|
|
||||||
if any(s.get('appname') == game and s.get('exe') == exe_path and s.get('StartDir') == start_dir and s.get('LaunchOptions') == launch_options for s in shortcuts['shortcuts'].values()):
|
|
||||||
print(f"Existing shortcut found based on matching fields for game {game}. Skipping.")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
game_id = get_game_id(game)
|
game_id = get_game_id(game)
|
||||||
@ -469,73 +463,67 @@ else:
|
|||||||
# End of Ubisoft Game Scanner
|
# End of Ubisoft Game Scanner
|
||||||
|
|
||||||
# EA App Game Scanner
|
# EA App Game Scanner
|
||||||
def getEAAppGameInfo(filePath):
|
|
||||||
|
def get_ea_app_game_info(installed_games, game_directory_path):
|
||||||
game_dict = {}
|
game_dict = {}
|
||||||
with open(filePath, 'r') as file:
|
for game in installed_games:
|
||||||
game_id = None
|
xml_file = ET.parse(f"{game_directory_path}{game}/__Installer/installerdata.xml")
|
||||||
|
xml_root = xml_file.getroot()
|
||||||
|
ea_ids = None
|
||||||
game_name = None
|
game_name = None
|
||||||
eaApp_install_found = False
|
for content_id in xml_root.iter('contentID'):
|
||||||
for line in file:
|
if ea_ids is None:
|
||||||
game_name = None # Reset game_name
|
ea_ids = content_id.text
|
||||||
if "Origin Games" in line:
|
else:
|
||||||
game_id = re.findall(r'Origin Games\\\\(\d+)', line)
|
ea_ids = ea_ids + ',' + content_id.text
|
||||||
if game_id:
|
for game_title in xml_root.iter('gameTitle'):
|
||||||
game_id = game_id[0]
|
if game_name is None:
|
||||||
eaApp_install_found = True
|
game_name = game_title.text
|
||||||
if "DisplayName" in line and eaApp_install_found:
|
continue
|
||||||
game_name = re.findall(r'\"(.+?)\"', line.split("=")[1])
|
for game_title in xml_root.iter('title'):
|
||||||
if game_name:
|
if game_name is None:
|
||||||
game_name = game_name[0].replace('\\x2122', '') # Remove the trademark symbol
|
game_name = game_title.text
|
||||||
eaApp_install_found = False
|
continue
|
||||||
if game_id and game_name: # Add the game's info to the dictionary if its ID was found in the folder
|
if game_name is None:
|
||||||
game_dict[game_name] = game_id
|
game_name = game
|
||||||
game_id = None
|
if ea_ids: # Add the game's info to the dictionary if its ID was found in the folder
|
||||||
|
game_dict[game_name] = ea_ids
|
||||||
return game_dict
|
return game_dict
|
||||||
|
|
||||||
registry_file_path = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ea_app_launcher}/pfx/system.reg"
|
|
||||||
game_directory_path = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ea_app_launcher}/pfx/drive_c/Program Files/EA Games/"
|
game_directory_path = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ea_app_launcher}/pfx/drive_c/Program Files/EA Games/"
|
||||||
|
|
||||||
if not os.path.exists(registry_file_path) or not os.path.isdir(game_directory_path):
|
if not os.path.isdir(game_directory_path):
|
||||||
print("EA App game data not found. Skipping EA App Scanner.")
|
print("EA App game data not found. Skipping EA App Scanner.")
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
game_dict = getEAAppGameInfo(registry_file_path)
|
installed_games = os.listdir(game_directory_path) # Get a list of game folders
|
||||||
installed_games = os.listdir(game_directory_path) # Get a list of all installed games
|
game_dict = get_ea_app_game_info(installed_games, game_directory_path)
|
||||||
|
|
||||||
for game, game_id in game_dict.items():
|
for game, ea_ids in game_dict.items():
|
||||||
if game in installed_games: # Check if the game is installed
|
launch_options = f"STEAM_COMPAT_DATA_PATH=\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ea_app_launcher}/\" %command% \"origin2://game/launch?offerIds={ea_ids}\""
|
||||||
launch_options = f"STEAM_COMPAT_DATA_PATH=\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{ea_app_launcher}/\" %command% \"origin2://game/launch?offerIds={game_id}\""
|
exe_path = f"\"{logged_in_home}/.local/share/Steam/Steam/steamapps/compatdata/{ea_app_launcher}/pfx/drive_c/Program Files/Electronic Arts/EA Desktop/EA Desktop/EALaunchHelper.exe\""
|
||||||
exe_path = f"\"{logged_in_home}/.local/share/Steam/Steam/steamapps/compatdata/{ea_app_launcher}/pfx/drive_c/Program Files/Electronic Arts/EA Desktop/EA Desktop/EALaunchHelper.exe\""
|
start_dir = f"\"{logged_in_home}/.local/share/Steam/Steam/steamapps/compatdata/{ea_app_launcher}/pfx/drive_c/Program Files/Electronic Arts/EA Desktop/EA Desktop/\""
|
||||||
start_dir = f"\"{logged_in_home}/.local/share/Steam/Steam/steamapps/compatdata/{ea_app_launcher}/pfx/drive_c/Program Files/Electronic Arts/EA Desktop/EA Desktop/\""
|
shortcut_id = get_steam_shortcut_id(exe_path, game)
|
||||||
shortcut_id = get_steam_shortcut_id(exe_path, game)
|
# Check if the game already exists in the shortcuts
|
||||||
# Check if the game already exists in the shortcuts using the id
|
if check_if_shortcut_exists(shortcut_id, game, exe_path, start_dir, launch_options):
|
||||||
if any(s.get('appid') == str(shortcut_id) for s in shortcuts['shortcuts'].values()):
|
continue
|
||||||
print(f"Existing shortcut found based on shortcut ID for game {game}. Skipping.")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Check if the game already exists in the shortcuts using the fields (probably unnecessary)
|
game_id = get_game_id(game)
|
||||||
if any(s.get('appname') == game and s.get('exe') == exe_path and s.get('StartDir') == start_dir and s.get('LaunchOptions') == launch_options for s in shortcuts['shortcuts'].values()):
|
if game_id is not None:
|
||||||
print(f"Existing shortcut found based on matching fields for game {game}. Skipping.")
|
get_sgdb_art(game_id, shortcut_id)
|
||||||
continue
|
# Check if the game already exists in the shortcuts
|
||||||
|
new_shortcuts_added = True
|
||||||
|
created_shortcuts.append(game)
|
||||||
|
shortcuts['shortcuts'][str(len(shortcuts['shortcuts']))] = {
|
||||||
|
'appid': str(shortcut_id),
|
||||||
|
'appname': game,
|
||||||
|
'exe': exe_path,
|
||||||
|
'StartDir': start_dir,
|
||||||
|
'LaunchOptions': launch_options,
|
||||||
|
'icon': f"{logged_in_home}/.steam/root/userdata/{steamid3}/config/grid/{get_file_name('icons', shortcut_id)}"
|
||||||
|
}
|
||||||
|
add_compat_tool(shortcut_id)
|
||||||
|
|
||||||
game_id = get_game_id(game)
|
#End of EA App Scanner
|
||||||
if game_id is not None:
|
|
||||||
get_sgdb_art(game_id, shortcut_id)
|
|
||||||
# Check if the game already exists in the shortcuts
|
|
||||||
new_shortcuts_added = True
|
|
||||||
created_shortcuts.append(game)
|
|
||||||
shortcuts['shortcuts'][str(len(shortcuts['shortcuts']))] = {
|
|
||||||
'appid': str(shortcut_id),
|
|
||||||
'appname': game,
|
|
||||||
'exe': exe_path,
|
|
||||||
'StartDir': start_dir,
|
|
||||||
'LaunchOptions': launch_options,
|
|
||||||
'icon': f"{logged_in_home}/.steam/root/userdata/{steamid3}/config/grid/{get_file_name('icons', shortcut_id)}"
|
|
||||||
}
|
|
||||||
add_compat_tool(shortcut_id)
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
#End if EA App Scanner
|
|
||||||
|
|
||||||
|
|
||||||
#Push down when more scanners are added
|
#Push down when more scanners are added
|
||||||
|
Loading…
Reference in New Issue
Block a user