62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
"""Resolución de rutas: dónde está games.toml y dónde guardar los datos.
|
|
|
|
Compilado con Nuitka, ``__compiled__`` existe. En modo ``--onefile`` la carpeta del
|
|
binario real la expone ``NUITKA_ONEFILE_DIRECTORY`` (Nuitka 4.x); con versiones que usan
|
|
``NUITKA_ONEFILE_BINARY`` tomamos su carpeta; si no, ``sys.executable`` (standalone).
|
|
Ejecutando desde fuente usamos la raíz del proyecto (la carpeta que contiene ``jlauncher``).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
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():
|
|
directory = os.environ.get("NUITKA_ONEFILE_DIRECTORY")
|
|
if directory:
|
|
return Path(directory).resolve()
|
|
binary = os.environ.get("NUITKA_ONEFILE_BINARY")
|
|
if binary:
|
|
return Path(binary).resolve().parent
|
|
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"
|