54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""Resolución de rutas: dónde está games.toml y dónde guardar los datos.
|
|
|
|
Cuando se compila con Nuitka (``--standalone``) el atributo global ``__compiled__``
|
|
existe, así que usamos la carpeta del ejecutable. Ejecutando desde fuente usamos la
|
|
raíz del proyecto (la carpeta que contiene el paquete ``jlauncher``).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
CONFIG_NAME = "games.toml"
|
|
|
|
|
|
def is_compiled() -> bool:
|
|
"""True si corremos como binario Nuitka (define ``__compiled__`` en cada módulo)."""
|
|
return "__compiled__" in globals()
|
|
|
|
|
|
def base_dir() -> Path:
|
|
"""Carpeta base junto a la que viven games.toml y jlauncher_data."""
|
|
if is_compiled():
|
|
return Path(sys.executable).resolve().parent
|
|
# Desde fuente: raíz del proyecto = padre del paquete jlauncher/
|
|
return Path(__file__).resolve().parent.parent
|
|
|
|
|
|
def config_file() -> Path:
|
|
"""Ruta a games.toml (junto al ejecutable / raíz del proyecto)."""
|
|
return base_dir() / CONFIG_NAME
|
|
|
|
|
|
def data_root(data_dir: str = "jlauncher_data") -> Path:
|
|
"""Carpeta raíz de datos; se crea si no existe."""
|
|
root = base_dir() / data_dir
|
|
root.mkdir(parents=True, exist_ok=True)
|
|
return root
|
|
|
|
|
|
def game_dir(root: Path, game_id: str) -> Path:
|
|
"""Carpeta de un juego: <root>/<id>/."""
|
|
return root / game_id
|
|
|
|
|
|
def repo_dir(root: Path, game_id: str) -> Path:
|
|
"""Carpeta del clone git: <root>/<id>/repo/."""
|
|
return game_dir(root, game_id) / "repo"
|
|
|
|
|
|
def metadata_dir(root: Path, game_id: str) -> Path:
|
|
"""Carpeta de metadata cacheada: <root>/<id>/metadata/."""
|
|
return game_dir(root, game_id) / "metadata"
|