31 lines
991 B
Python
31 lines
991 B
Python
"""settings.json — user preferences."""
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import asdict, dataclass, fields
|
|
from pathlib import Path
|
|
|
|
from .util import atomic_write_json, read_json
|
|
|
|
LINK_MODES = ("symlink", "hardlink", "copy")
|
|
|
|
|
|
@dataclass
|
|
class Settings:
|
|
game_dir: str = "" # manual override; empty = auto-discover
|
|
link_mode: str = "symlink"
|
|
auto_deploy: bool = True # deploy on every checkbox toggle (Fluffy behaviour)
|
|
steam_user_id: str = "" # empty = first userdata dir
|
|
reframework_version: str = ""
|
|
|
|
@classmethod
|
|
def load(cls, path: Path) -> "Settings":
|
|
raw = read_json(path, {})
|
|
known = {f.name for f in fields(cls)}
|
|
s = cls(**{k: v for k, v in raw.items() if k in known}) if isinstance(raw, dict) else cls()
|
|
if s.link_mode not in LINK_MODES:
|
|
s.link_mode = "symlink"
|
|
return s
|
|
|
|
def save(self, path: Path) -> None:
|
|
atomic_write_json(path, asdict(self))
|