HoYoCenter/app/config.py
2024-09-09 15:03:46 +08:00

34 lines
996 B
Python

import os
import json5
import app.env as env
class Config:
def __init__(self):
self._conf_Dict = json5.load(os.path.join(env.dirs.user_config_path, "config.json"), encoding="utf-8")
self.__name__ = "<Standard Dictionary>"
self.update()
def __getattr__(self, name):
if name in self._conf_Dict:
return self._conf_Dict[name]
else:
raise AttributeError(
f"'{self.__class__.__name__}' object has no attribute '{name}'"
)
def update(self):
for k, v in self._conf_Dict.items():
if isinstance(v, dict):
setattr(self, k, Config(v))
elif isinstance(v, list):
setattr(
self,
k,
[Config(item) if isinstance(item, dict) else item for item in v],
)
else:
setattr(self, k, v)
def __str__(self):
return str(self._conf_Dict)