From c54edc598ba741d86f53f905f61fdbf5622bf553 Mon Sep 17 00:00:00 2001 From: RealistikDash <36131887+RealistikDash@users.noreply.github.com> Date: Fri, 9 Jun 2023 13:48:29 +0100 Subject: [PATCH] [0.1.1] handle potential corrupt configs --- Makefile | 2 +- fps_bypass/config.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b8e6a84..10de891 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,2 @@ -build: fps_bypass/main.py +build: fps_bypass/*.py pyinstaller --onefile fps_bypass/main.py --name fps_bypass --clean --noconfirm --uac-admin -i "NONE" diff --git a/fps_bypass/config.py b/fps_bypass/config.py index f64123a..b0e6066 100644 --- a/fps_bypass/config.py +++ b/fps_bypass/config.py @@ -2,12 +2,15 @@ from __future__ import annotations import json +import logging import os from dataclasses import dataclass CONFIG_VERSION = 1 FPS_CONFIG_DIR = "gfps_bypass" +logger = logging.getLogger("rich") + # NOTE: All future values (after `target_fps`) must have a default value. @dataclass @@ -73,8 +76,13 @@ def read_config() -> Configuration | None: if not os.path.exists(f"{config_path}\\config.json"): return None - with open(f"{config_path}\\config.json") as f: - return config_from_json(f.read()) + try: + with open(f"{config_path}\\config.json") as f: + return config_from_json(f.read()) + except Exception: + logger.debug("Failed to read the config file. Deleting it.", exc_info=True) + delete_config() + return None def delete_config() -> None: