From cc2b4053ea35087a3f12533130181ef9c8229193 Mon Sep 17 00:00:00 2001 From: Roy <88516395+moraroy@users.noreply.github.com> Date: Wed, 19 Jun 2024 12:32:05 -0700 Subject: [PATCH] error handling for vdf --- NSLGameScanner.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/NSLGameScanner.py b/NSLGameScanner.py index c308a54..bc632df 100644 --- a/NSLGameScanner.py +++ b/NSLGameScanner.py @@ -197,9 +197,15 @@ else: shortcuts = {'shortcuts': {}} 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) + print("Please check the file and try again.") + return + +# 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.") # Open the config.vdf file