diff --git a/protonenv/config.py b/protonenv/config.py index 71a262d..f272344 100644 --- a/protonenv/config.py +++ b/protonenv/config.py @@ -1,19 +1,30 @@ import os +from dataclasses import dataclass + +from .utils import json_load # --- -class Configuration(object): - def __init__(self, dictionary=None): - if dictionary is not None: - self.__dict__.update(dictionary) +HOME_DIR = os.path.expanduser("~") +PROTONENV_DIR = os.path.join(HOME_DIR, '.protonenv') + +@dataclass +class Configuration: + common_dir: str = os.path.join(HOME_DIR, '.steam/debian-installation/steamapps/common') + protonenv_dir: str = PROTONENV_DIR + prefixes_dir: str = os.path.join(PROTONENV_DIR, 'prefixes') + temporary_dir: str = os.path.join(PROTONENV_DIR, 'temp') + config_path: str = os.path.join(PROTONENV_DIR, 'config.json') + + def read_json(self): + json_config = json_load(self.config_path) + for k in ["common_dir", "protonenv_dir", "prefixes_dir", "temporary_dir", "config_path"]: + if k in json_config: + self.__setattr__(k, json_config[k]) + + return self # --- -HOME_DIR = os.path.expanduser("~") -config = Configuration() -config.common_dir = os.path.join(HOME_DIR, '.steam/debian-installation/steamapps/common') -config.protonenv_dir = os.path.join(HOME_DIR, '.protonenv') -config.prefixes_dir = os.path.join(config.protonenv_dir, 'prefixes') -config.temporary_dir = os.path.join(config.protonenv_dir, 'temp') -config.config_path = os.path.join(config.protonenv_dir, 'config.json') \ No newline at end of file +config = Configuration().read_json() diff --git a/protonenv/core.py b/protonenv/core.py index abf4387..5ab1a55 100644 --- a/protonenv/core.py +++ b/protonenv/core.py @@ -38,7 +38,7 @@ def ask_common_dir(): ans = config.common_dir if os.path.exists(ans): break - print(f'{ans} does not exists, try again...') + print(f'{ans} does not exist, try again...') return ans @@ -118,9 +118,9 @@ def uninstall(args): @subcommand([Argument("version", help="Proton version"), Argument("prefix", help="Prefix name")]) def prefix(args): if prefix_exists(args.prefix): - die(f'Prefix "{args.prefix}" has already exists.') + die(f'Prefix "{args.prefix}" already exists.') if not proton_exists(args.version): - die(f'Proton {args.version} does not exists.') + die(f'Proton {args.version} does not exist.') os.makedirs(get_prefix_path(args.prefix)) prefix_config = {"version": args.version} prefix_config_save(args.prefix, prefix_config) @@ -129,7 +129,7 @@ def prefix(args): @subcommand([Argument("prefix", help="Prefix name"), Argument("--flags", help="Environment variable: KEY=VALUE", nargs='+'), Argument("--command", help="Default command")]) def default(args): if not prefix_exists(args.prefix): - die(f'Prefix {args.prefix} does not exists.') + die(f'Prefix {args.prefix} does not exist.') prefix_config = prefix_config_load(args.prefix) if args.command: prefix_config['command'] = args.command @@ -151,7 +151,7 @@ def default(args): @subcommand([Argument("prefix", help="Prefix name")]) def info(args): if not prefix_exists(args.prefix): - die(f'Prefix {args.prefix} does not exists.') + die(f'Prefix {args.prefix} does not exist.') prefix_config = prefix_config_load(args.prefix) die(f'\ {args.prefix}\n\ @@ -164,7 +164,7 @@ def info(args): @subcommand([Argument("prefix", help="Prefix name"), Argument("--open", action="store_true", help="Open the directory")]) def directory(args): if not prefix_exists(args.prefix): - die(f'Prefix {args.prefix} does not exists.') + die(f'Prefix {args.prefix} does not exist.') content_path = get_prefix_content_path(args.prefix) if args.open: cmd_exec(f'xdg-open {content_path}') @@ -174,7 +174,7 @@ def directory(args): def run(args): if not prefix_exists(args.name): if not proton_exists(args.name): - die(f'{args.name} does not exists.') + die(f'{args.name} does not exist.') if not args.command: die('Command is not specified.') proton_exec(args.name, None, args.command) @@ -193,4 +193,4 @@ def main(): if args.subcommand is None: cli.print_help() else: - args.func(args) \ No newline at end of file + args.func(args) diff --git a/protonenv/core_utils.py b/protonenv/core_utils.py index 5acfe32..a206b05 100644 --- a/protonenv/core_utils.py +++ b/protonenv/core_utils.py @@ -30,7 +30,7 @@ def proton_exists(version): return os.path.exists(get_proton_exec_path(version)) def config_load(): - return Configuration(json_load(config.config_path)) + return Configuration().read_json() def config_save(content): json_dump(config.config_path, vars(content)) diff --git a/protonenv/proton.json b/protonenv/proton.json index a0d0e28..98bd0ba 100644 --- a/protonenv/proton.json +++ b/protonenv/proton.json @@ -4,5 +4,6 @@ "4.2" : "1054830", "4.11" : "1113280", "5.0" : "1245040", - "5.13" : "1420170" + "5.13" : "1420170", + "6.3" : "1580130" } \ No newline at end of file