You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB
Python

import logging
import os.path
import yaml
class LCSettings:
FOLDER_NAME = "LCModManager"
FILE_NAME = "lc_mod_manager_settings.yaml"
DEFAULT_SETTINGS = {
"game_path": None,
}
def __init__(self):
self.__logger = logging.getLogger("ModManager")
self.file_path = "./"+LCSettings.FILE_NAME
if not os.path.isfile(self.file_path):
self.__logger.warning(f"Couldn't find settings file \"{self.file_path}\" during LCSettings.init() ...")
self.__create_default_settings_file()
self.settings = yaml.safe_load(open(self.file_path, 'r'))
def __create_default_settings_file(self):
self.__logger.warning(f"Writing new default settings file at {self.file_path}")
yaml.safe_dump(LCSettings.DEFAULT_SETTINGS, open(self.file_path, 'w'))
def get_settings(self) -> dict:
return self.settings
def get_game_folder(self) -> str:
return self.settings["game_path"]
def get_mod_folder(self) -> str:
return os.path.join(self.settings["game_path"], LCSettings.FOLDER_NAME)
def get_plugin_folder(self) -> str:
return os.path.join(self.settings["game_path"], "BepInEx", "plugins")
def apply_changes(self):
"""
Writes the current settings to file in case there were changes
:return:
"""
self.__logger.info("Writing settings down to file!")
yaml.safe_dump(self.settings, open(self.file_path, 'w'))