Added file explorer

This commit is contained in:
BarsTiger
2022-12-18 16:37:20 +02:00
parent 36933437f8
commit fb1f10608f
15 changed files with 1104 additions and 496 deletions

View File

@@ -1 +1,2 @@
from .settings import Config
from .paths import PathsConfig

View File

@@ -13,3 +13,10 @@ class ConfigModel:
out_micro: str
restream: bool
direct_stream: bool
@dataclass_json
@dataclass(frozen=True)
class PathsModel:
first_browser_path: str
second_browser_path: str

43
modules/config/paths.py Normal file
View File

@@ -0,0 +1,43 @@
from modules.config.model import PathsModel
import json
import os
class PathsConfig:
@staticmethod
def default():
return {
"first_browser_path": "",
"second_browser_path": ""
}
@staticmethod
def fix() -> None:
try:
with open("data/config.path", "w") as file:
json.dump(PathsConfig.default(), file)
except FileNotFoundError:
if not os.path.exists('data'):
os.mkdir('data')
PathsConfig.fix()
@staticmethod
def get() -> PathsModel:
try:
with open("data/config.path", "r") as file:
return PathsModel.from_dict(json.load(file))
except:
PathsConfig.fix()
return PathsConfig.get()
@staticmethod
def update(key: str, value: str | None) -> dict:
with open("data/config.path", "r") as file:
settings = json.load(file)
settings[key] = value
with open("data/config.path", "w") as file:
json.dump(settings, file)
return settings