1
0
Fork 0
mirror of synced 2024-06-29 11:40:37 +12:00
Rare/rare/utils/config_helper.py
2022-03-14 17:23:52 +01:00

39 lines
950 B
Python

from typing import Callable
from legendary.core import LegendaryCore
from legendary.utils.config import LGDConf
config: LGDConf = None
save_config: Callable[[], None] = None
def init_config_handler(core: LegendaryCore):
global config, save_config
config = core.lgd.config
save_config = core.lgd.save_config
def add_option(app_name: str, option: str, value: str):
value = value.replace("%%", "%").replace("%", "%%")
if not config.has_section(app_name):
config[app_name] = {}
config.set(app_name, option, value)
save_config()
def remove_option(app_name, option):
if config.has_option(app_name, option):
config.remove_option(app_name, option)
if config.has_section(app_name) and not config[app_name]:
config.remove_section(app_name)
save_config()
def remove_section(app_name):
if config.has_section(app_name):
config.remove_section(app_name)
save_config()