Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
reword errors on getting invalid paths from retroarch.cfg
Browse files Browse the repository at this point in the history
add a default value for directories from retroarch.cfg based on the cfg parent directory if the value is 'default' and there is a default value given
  • Loading branch information
i30817 committed Jan 7, 2023
1 parent 4d44e0e commit ed55637
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions libretro_scummvm_playlist/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,21 @@
r'\u0009\u000a\u000b\u000c\u000d\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015' + \
r'\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f\u003a\u002a\u003f\u005c\u002f\u0026]'

def getPath(cfg: Path, setting):
def getPath(cfg: Path, setting: str, default_value: str):
with open(cfg) as f:
file_content = '[DUMMY]\n' + f.read()
import configparser
configParser = configparser.RawConfigParser()
configParser.read_string(file_content)
fdir = os.path.expanduser(configParser['DUMMY'][setting].strip('"'))
if fdir == 'default':
try:
fdir = os.path.expanduser(configParser['DUMMY'][setting].strip('"'))
except:
return None
if fdir == 'default':
if default_value:
return Path(cfg.parent,default_value)
else:
return None
return Path(fdir)

def writeExtraPaths(ini: Path, extra: Path, theme: Path, saves: Path, soundfont: Path):
Expand Down Expand Up @@ -135,10 +141,10 @@ def mainaux(cfg: Path = typer.Argument(CONFIG, help='Path to the retroarch cfg f
error(f'Invalid Retroarch cfg file: {cfg}')
raise typer.Exit(code=1)

playlist_dir = getPath(cfg, 'playlist_directory')
playlist_dir = getPath(cfg, 'playlist_directory', 'playlists')

if not playlist_dir.is_dir() or not os.access(playlist_dir, os.W_OK):
error(f'Invalid Retroarch playlist directory: {playlist_dir}')
if not playlist_dir or not playlist_dir.is_dir() or not os.access(playlist_dir, os.W_OK):
error(f'Invalid retroarch.cfg line: playlist_directory="{playlist_dir}"')
raise typer.Exit(code=1)

if playlist and not playlist.endswith('.lpl'):
Expand All @@ -151,9 +157,9 @@ def mainaux(cfg: Path = typer.Argument(CONFIG, help='Path to the retroarch cfg f
error(f'Invalid playlist file: {playlist}')
raise typer.Exit(code=1)

system_dir = getPath(cfg, 'system_directory')
if not system_dir.is_dir():
error(f'Invalid Retroarch system directory: {system_dir}')
system_dir = getPath(cfg, 'system_directory', 'system')
if not system_dir or not system_dir.is_dir():
error(f'Invalid retroarch.cfg line: system_directory="{system_dir}"')
raise typer.Exit(code=1)

system = Path(system_dir, 'scummvm.ini')
Expand All @@ -171,19 +177,19 @@ def mainaux(cfg: Path = typer.Argument(CONFIG, help='Path to the retroarch cfg f
error(f'Extra scummvm theme dir does not exist.\nPlease see the documentation to download it.')
raise typer.Exit(code=1)

saves_dir = getPath(cfg, 'savefile_directory')
saves_dir = getPath(cfg, 'savefile_directory', 'saves')
if not saves_dir or not saves_dir.is_dir():
error(f'Invalid Retroarch saves directory: {saves_dir}')
error(f'Invalid retroarch.cfg line: savefile_directory="{saves_dir}"')
raise typer.Exit(code=1)

cores_dir = getPath(cfg, 'libretro_directory')
if not cores_dir.is_dir():
error(f'Invalid Retroarch cores directory: {cores_dir}')
cores_dir = getPath(cfg, 'libretro_directory', 'cores')
if not cores_dir or not cores_dir.is_dir():
error(f'Invalid retroarch.cfg line: libretro_directory="{cores_dir}"')
raise typer.Exit(code=1)
core = os.path.abspath( Path(cores_dir, 'scummvm_libretro' + ( '.dll' if os.name == 'nt' else '.so' ) ) )

content_dir = getPath(cfg, 'rgui_browser_directory')
if not content_dir:
content_dir = getPath(cfg, 'rgui_browser_directory', None)
if not content_dir or not content_dir.is_dir():
content_dir = ''

with open(system) as f:
Expand Down

0 comments on commit ed55637

Please sign in to comment.