Config failsafe

This commit is contained in:
2025-09-05 23:47:51 +03:00
parent 14728105d0
commit 12c230cd03
2 changed files with 20 additions and 6 deletions

View File

@@ -1,3 +1,7 @@
[DEFAULT] [DEFAULT]
version = 1.12 version = 1.02
[ACCOUNT]
key = NK
id = NA

View File

@@ -1,5 +1,5 @@
import configparser import configparser
import os
from pathlib import Path from pathlib import Path
#declare default vars #declare default vars
@@ -15,11 +15,21 @@ class Config():
config = configparser.ConfigParser() config = configparser.ConfigParser()
configPath = Path("Config.ini") configPath = Path("Config.ini")
def WarnMissingConfig(ConfigError):
print(f"[⚠️ WARNING ⚠️] - Your config file is corrupt , something that has to do with {ConfigError}")
print("Program will exit before it crashes :)")
reset = input("It is recommended that you reset the app data (you will be logged out) y (reset) / n (exit)")
if reset == "y":
os.remove(configPath)
print("[⚠️ WARNING ⚠️] - Reset Done, Re-Open TiropitCLI")
exit(0)
def makeConfig(): def makeConfig():
config['DEFAULT'] = {'Version': version} config['DEFAULT'] = {'Version': Config.version}
config['ACCOUNT'] = {'KEY': "NK"} config['ACCOUNT'] = {}
config['ACCOUNT'] = {'ID': "NK"} config['ACCOUNT']['KEY'] = "NK"
config['ACCOUNT']["ID"] = "NA"
with open('Config.ini', 'w') as configfile: with open('Config.ini', 'w') as configfile:
config.write(configfile) config.write(configfile)
@@ -32,7 +42,7 @@ def loadConfig():
Config.AccountID = config["ACCOUNT"]["ID"] Config.AccountID = config["ACCOUNT"]["ID"]
Config.AccountID = config["ACCOUNT"]["KEY"] Config.AccountID = config["ACCOUNT"]["KEY"]
except Exception as e: except Exception as e:
print(f"An Error Occured , Check : {e}") WarnMissingConfig(e)
def checkConfig(): def checkConfig():
if configPath.exists(): if configPath.exists():