Update NSLGameScanner.py

This commit is contained in:
Roy 2024-06-21 04:18:00 -07:00 committed by GitHub
parent 9867dd5a22
commit ca5255f6fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -202,24 +202,21 @@ if os.path.exists(shortcuts_file):
try:
with open(shortcuts_file, 'rb') as file:
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:
print(f"Error reading shortcuts file: {e}")
print("Please check the file and try again.")
sys.exit() # Exit the script if an error occurs
# 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': {}}
# Check data integrity before writing to file
if shortcuts and isinstance(shortcuts, dict) and 'shortcuts' in shortcuts:
with open(shortcuts_file, 'wb') as file:
vdf.binary_dumps(shortcuts, file)
else:
print("The data to be written to the shortcuts file is not valid.")
else:
# 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)
# Open the config.vdf file