mirror of
https://github.com/moraroy/NonSteamLaunchers-On-Steam-Deck.git
synced 2024-11-20 08:09:18 +01:00
added error handling
This commit is contained in:
parent
226beebf24
commit
5450cdc523
@ -181,9 +181,25 @@ grid64 = ""
|
|||||||
logo64 = ""
|
logo64 = ""
|
||||||
hero64 = ""
|
hero64 = ""
|
||||||
|
|
||||||
# Load the existing shortcuts
|
# Define the path to the shortcuts file
|
||||||
with open(f"{logged_in_home}/.steam/root/userdata/{steamid3}/config/shortcuts.vdf", 'rb') as file:
|
shortcuts_file = f"{logged_in_home}/.steam/root/userdata/{steamid3}/config/shortcuts.vdf"
|
||||||
shortcuts = vdf.binary_loads(file.read())
|
|
||||||
|
# Check if the shortcuts file exists
|
||||||
|
if not os.path.exists(shortcuts_file):
|
||||||
|
# If the file does not exist, create a new file with an empty "shortcuts" section
|
||||||
|
with open(shortcuts_file, 'wb') as file:
|
||||||
|
vdf.binary_dumps({'shortcuts': {}}, file)
|
||||||
|
else:
|
||||||
|
# If the file exists, try to load it
|
||||||
|
try:
|
||||||
|
with open(shortcuts_file, 'rb') as file:
|
||||||
|
shortcuts = vdf.binary_loads(file.read())
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error reading shortcuts file: {e}")
|
||||||
|
# If an error occurs when reading the file, create a new file with an empty "shortcuts" section
|
||||||
|
with open(shortcuts_file, 'wb') as file:
|
||||||
|
vdf.binary_dumps({'shortcuts': {}}, file)
|
||||||
|
|
||||||
# Open the config.vdf file
|
# Open the config.vdf file
|
||||||
with open(f"{logged_in_home}/.steam/root/config/config.vdf", 'r') as file:
|
with open(f"{logged_in_home}/.steam/root/config/config.vdf", 'r') as file:
|
||||||
config_data = vdf.load(file)
|
config_data = vdf.load(file)
|
||||||
@ -1039,10 +1055,16 @@ for game in games:
|
|||||||
if new_shortcuts_added or shortcuts_updated:
|
if new_shortcuts_added or shortcuts_updated:
|
||||||
print(f"Saving new config and shortcuts files")
|
print(f"Saving new config and shortcuts files")
|
||||||
conf = vdf.dumps(config_data, pretty=True)
|
conf = vdf.dumps(config_data, pretty=True)
|
||||||
with open(f"{logged_in_home}/.steam/root/config/config.vdf", 'w') as file:
|
try:
|
||||||
file.write(conf)
|
with open(f"{logged_in_home}/.steam/root/config/config.vdf", 'w') as file:
|
||||||
with open(f"{logged_in_home}/.steam/root/userdata/{steamid3}/config/shortcuts.vdf", 'wb') as file:
|
file.write(conf)
|
||||||
file.write(vdf.binary_dumps(shortcuts))
|
except IOError as e:
|
||||||
|
print(f"Error writing to config.vdf: {e}")
|
||||||
|
try:
|
||||||
|
with open(f"{logged_in_home}/.steam/root/userdata/{steamid3}/config/shortcuts.vdf", 'wb') as file:
|
||||||
|
file.write(vdf.binary_dumps(shortcuts))
|
||||||
|
except IOError as e:
|
||||||
|
print(f"Error writing to shortcuts.vdf: {e}")
|
||||||
|
|
||||||
# Print the created shortcuts
|
# Print the created shortcuts
|
||||||
if created_shortcuts:
|
if created_shortcuts:
|
||||||
@ -1053,31 +1075,35 @@ if new_shortcuts_added or shortcuts_updated:
|
|||||||
# Create the path to the output file
|
# Create the path to the output file
|
||||||
output_file_path = f"{logged_in_home}/.config/systemd/user/NSLGameScanner_output.log"
|
output_file_path = f"{logged_in_home}/.config/systemd/user/NSLGameScanner_output.log"
|
||||||
# Open the output file in write mode
|
# Open the output file in write mode
|
||||||
with open(output_file_path, 'w') as output_file:
|
try:
|
||||||
for game in decky_shortcuts.values():
|
with open(output_file_path, 'w') as output_file:
|
||||||
# Skip if 'appname' or 'exe' is None
|
for game in decky_shortcuts.values():
|
||||||
if game.get('appname') is None or game.get('exe') is None:
|
# Skip if 'appname' or 'exe' is None
|
||||||
continue
|
if game.get('appname') is None or game.get('exe') is None:
|
||||||
|
continue
|
||||||
|
|
||||||
# Create a dictionary to hold the shortcut information
|
# Create a dictionary to hold the shortcut information
|
||||||
shortcut_info = {
|
shortcut_info = {
|
||||||
'appname': game.get('appname'),
|
'appname': game.get('appname'),
|
||||||
'exe': game.get('exe'),
|
'exe': game.get('exe'),
|
||||||
'StartDir': game.get('StartDir'),
|
'StartDir': game.get('StartDir'),
|
||||||
'icon': game.get('icon'),
|
'icon': game.get('icon'),
|
||||||
'LaunchOptions': game.get('LaunchOptions'),
|
'LaunchOptions': game.get('LaunchOptions'),
|
||||||
'CompatTool': game.get('CompatTool'),
|
'CompatTool': game.get('CompatTool'),
|
||||||
'WideGrid': game.get('WideGrid'),
|
'WideGrid': game.get('WideGrid'),
|
||||||
'Grid': game.get('Grid'),
|
'Grid': game.get('Grid'),
|
||||||
'Hero': game.get('Hero'),
|
'Hero': game.get('Hero'),
|
||||||
'Logo': game.get('Logo'),
|
'Logo': game.get('Logo'),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Print the shortcut information in JSON format
|
# Print the shortcut information in JSON format
|
||||||
message = json.dumps(shortcut_info)
|
message = json.dumps(shortcut_info)
|
||||||
print(message, flush=True) # Print to stdout
|
print(message, flush=True) # Print to stdout
|
||||||
|
|
||||||
# Print the shortcut information to the output file
|
# Print the shortcut information to the output file
|
||||||
print(message, file=output_file, flush=True)
|
print(message, file=output_file, flush=True)
|
||||||
|
except IOError as e:
|
||||||
|
print(f"Error writing to output file: {e}")
|
||||||
|
|
||||||
print("All finished!")
|
print("All finished!")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user