Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions protonenv/config.py
Original file line number Diff line number Diff line change
@@ -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')
config = Configuration().read_json()
16 changes: 8 additions & 8 deletions protonenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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\
Expand All @@ -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}')
Expand All @@ -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)
Expand All @@ -193,4 +193,4 @@ def main():
if args.subcommand is None:
cli.print_help()
else:
args.func(args)
args.func(args)
2 changes: 1 addition & 1 deletion protonenv/core_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion protonenv/proton.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"4.2" : "1054830",
"4.11" : "1113280",
"5.0" : "1245040",
"5.13" : "1420170"
"5.13" : "1420170",
"6.3" : "1580130"
}