Skip to content

Commit

Permalink
Update NSLGameScanner.py
Browse files Browse the repository at this point in the history
  • Loading branch information
moraroy authored Jun 21, 2024
1 parent 9867dd5 commit ca5255f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions NSLGameScanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,21 @@ def get_unsigned_shortcut_id(signed_shortcut_id):
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
Expand Down

0 comments on commit ca5255f

Please sign in to comment.