From ca5255f6fb920ddefbb7c1c197dc0d887d039dd5 Mon Sep 17 00:00:00 2001 From: Roy <88516395+moraroy@users.noreply.github.com> Date: Fri, 21 Jun 2024 04:18:00 -0700 Subject: [PATCH] Update NSLGameScanner.py --- NSLGameScanner.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/NSLGameScanner.py b/NSLGameScanner.py index 3674dfe..b5b00ec 100644 --- a/NSLGameScanner.py +++ b/NSLGameScanner.py @@ -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