LouisAsanaka / Valorant-Zone-Stats

View your VALORANT performance in different areas of every map in the game!
MIT License
99 stars 17 forks source link

Create logs directory at startup for first time use #2

Closed Ashesh3 closed 3 years ago

Ashesh3 commented 3 years ago

When running the program for the first time, the program tries to use logging.FileHandler to create the debug.log file in the Valorant-Zone-Stats folder in AppData. The issue is that this folder does not exist when a new user starts the app for the first time. and logging.FileHandler will not create this directory on its own.

Hence the program crashes with the following error

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\<username>\\AppData\\Roaming\\Valorant-Zone-Stats\\debug.log'

I notice that migrate_files tries to create that directory if it does not exist, however it is after the logger is attempted to initialize, hence the required directories are never created.

Instead of creating the app folder in migrate_files function which is run on module's main method. We can create that folder one time (if does not already exist), right before the logger is loaded, this will ensure that the folder is always present in all cases.

This PR should fix the above issue and has been tested on my machine.

LouisAsanaka commented 3 years ago

Thank you for the find and the fix! I didn't fully test the code after I changed the logger stuff.