Update NSLGameScanner.py

This commit is contained in:
Roy 2025-04-18 01:53:32 -07:00 committed by GitHub
parent e8eb30bdc8
commit 026106274b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1836,65 +1836,56 @@ else:
# Parse each JSON object
for json_object in json_objects:
json_object = json_object.strip()
# Skip empty JSON objects
if json_object == "{}":
continue
if json_object:
try:
# Attempt to load the JSON object
data = json.loads(json_object)
# Extract gameBiz from the root and from the 'gameInstallStatus' object
game_biz = data.get("gameBiz", "").strip()
# If gameBiz is empty, check inside the 'gameInstallStatus' object
if not game_biz:
game_biz = data.get("gameInstallStatus", {}).get("gameBiz", "").strip()
# Skip JSON objects where gameBiz is empty or already processed
if not game_biz or game_biz in seen_game_biz:
continue # Skip this object and move to the next one
continue
# Add this gameBiz to the seen set
seen_game_biz.add(game_biz)
# Extract other relevant fields
persistent_install_path = data.get("persistentInstallPath", None)
install_path = data.get("installPath", None) # This is the fallback option
game_install_status = data.get("gameInstallStatus", {})
game_exe_name = game_install_status.get("gameExeName", None)
game_shortcut_name = data.get("gameShortcutName", None) # Get the game shortcut name
install_path = game_install_status.get("gameInstallPath", None)
game_shortcut_name = data.get("gameShortcutName", None)
# Debugging prints to check the values of persistentInstallPath and installPath
print(f"GameBiz: {game_biz}")
print(f"Persistent Install Path: {persistent_install_path}")
print(f"Install Path: {install_path}")
# If persistentInstallPath is empty, use installPath as fallback
if not persistent_install_path:
print(f"Persistent Install Path is empty, using Install Path as fallback.")
print(f"Persistent Install Path is empty for gameBiz: {game_biz}, using Install Path as fallback.")
persistent_install_path = install_path
# Check if all important fields are missing or empty
if not game_exe_name and not persistent_install_path:
print(f"Skipping empty game entry for gameBiz: {game_biz}")
continue # Skip if all important fields are empty
if not game_exe_name or not persistent_install_path:
print(f"Skipping gameBiz: {game_biz} - Missing exe name or install path.")
continue
if not persistent_install_path:
print(f"Skipping gameBiz: {game_biz} - No persistent install path found.")
continue # Skip if no persistent install path
# Convert Windows-style path to Steam Proton path
proton_path_base = f"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{hoyoplay_launcher}/pfx/drive_c"
relative_game_path = persistent_install_path.replace("C:\\", "").replace("\\", "/")
full_game_dir = os.path.join(proton_path_base, relative_game_path)
full_game_exe = os.path.join(full_game_dir, game_exe_name)
if game_shortcut_name:
print(f" Game Shortcut Name: {game_shortcut_name}")
# Log information for debugging
print(f" Game Business: {game_biz}")
print(f" Game Shortcut Name: {game_shortcut_name}")
print(f" Game Executable: {game_exe_name}")
print(f" Persistent Install Path: {persistent_install_path}")
# Set the display name to the game shortcut name from the JSON
display_name = game_shortcut_name if game_shortcut_name else game_biz
launch_options = f"STEAM_COMPAT_DATA_PATH=\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{hoyoplay_launcher}/\" %command% \"--game={game_biz}\""
exe_path = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{hoyoplay_launcher}/pfx/drive_c/Program Files/HoYoPlay/launcher.exe\""
start_dir = f"\"{logged_in_home}/.local/share/Steam/steamapps/compatdata/{hoyoplay_launcher}/pfx/drive_c/Program Files/HoYoPlay\""
exe_path = f"\"{full_game_exe}\""
start_dir = f"\"{full_game_dir}\""
if any(v is None for v in [exe_path, display_name, launch_options, start_dir]):
print(f"Missing fields for gameBiz: {game_biz}, skipping entry creation.")
continue
# Create the new entry (this is where you can use your custom function for Steam shortcuts)
create_new_entry(exe_path, display_name, launch_options, start_dir)
@ -1906,11 +1897,6 @@ else:
# End of HoYoPlay Scanner
# End of HoYoPlay Scanner
# End of HoYoPlay Scanner
# Game Jolt Scanner
# File paths for both the game list and package details