added check for shortcuts

This commit is contained in:
Roy 2024-06-11 03:34:18 -07:00 committed by GitHub
parent a9a76f94be
commit 79947e5e12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -192,12 +192,16 @@ else:
try: try:
with open(shortcuts_file, 'rb') as file: with open(shortcuts_file, 'rb') as file:
shortcuts = vdf.binary_loads(file.read()) shortcuts = vdf.binary_loads(file.read())
# If the file is empty or does not contain the 'shortcuts' key, initialize an empty 'shortcuts' dictionary
if not shortcuts or 'shortcuts' not in shortcuts:
shortcuts = {'shortcuts': {}}
except Exception as e: except Exception as e:
print(f"Error reading shortcuts file: {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 # If an error occurs when reading the file, create a new file with an empty "shortcuts" section
with open(shortcuts_file, 'wb') as file: with open(shortcuts_file, 'wb') as file:
vdf.binary_dumps({'shortcuts': {}}, 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)