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,5 +1,5 @@
import configparser
import os
from pathlib import Path
#declare default vars
@@ -15,11 +15,21 @@ class Config():
config = configparser.ConfigParser()
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():
config['DEFAULT'] = {'Version': version}
config['ACCOUNT'] = {'KEY': "NK"}
config['ACCOUNT'] = {'ID': "NK"}
config['DEFAULT'] = {'Version': Config.version}
config['ACCOUNT'] = {}
config['ACCOUNT']['KEY'] = "NK"
config['ACCOUNT']["ID"] = "NA"
with open('Config.ini', 'w') as configfile:
config.write(configfile)
@@ -32,7 +42,7 @@ def loadConfig():
Config.AccountID = config["ACCOUNT"]["ID"]
Config.AccountID = config["ACCOUNT"]["KEY"]
except Exception as e:
print(f"An Error Occured , Check : {e}")
WarnMissingConfig(e)
def checkConfig():
if configPath.exists():