From a15d4df820eb9a22e26e7fbd66d5c4fdc098b28b Mon Sep 17 00:00:00 2001 From: Percentnineteen Date: Fri, 6 Jun 2025 13:40:19 -0500 Subject: [PATCH 1/2] enable custom mapping in the .env --- RomM/api.py | 13 +++++++++++-- RomM/env.template | 5 +++++ RomM/filesystem.py | 5 +++++ RomM/main.py | 3 +++ RomM/platform_maps.py | 28 ++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/RomM/api.py b/RomM/api.py index 8ecd2fb..5784c79 100644 --- a/RomM/api.py +++ b/RomM/api.py @@ -252,7 +252,14 @@ def fetch_platforms(self) -> None: for platform in platforms: if platform["rom_count"] > 0: platform_slug = platform["slug"].lower() - if self.file_system.is_muos: + if ( + platform_maps._env_maps + and platform_slug in platform_maps._env_platforms + and platform_slug not in self._exclude_platforms + ): + # A custom map from the .env was found, no need to check defaults + pass + elif self.file_system.is_muos: if ( platform_slug not in platform_maps.MUOS_SUPPORTED_PLATFORMS or platform_slug in self._exclude_platforms @@ -452,7 +459,9 @@ def fetch_roms(self) -> None: _roms = [] for rom in roms: platform_slug = rom["platform_slug"].lower() - if self.file_system.is_muos: + if platform_maps._env_maps and platform_slug in platform_maps._env_platforms: + pass + elif self.file_system.is_muos: if platform_slug not in platform_maps.MUOS_SUPPORTED_PLATFORMS: continue elif self.file_system.is_spruceos: diff --git a/RomM/env.template b/RomM/env.template index f6f6541..96d0b7b 100644 --- a/RomM/env.template +++ b/RomM/env.template @@ -15,3 +15,8 @@ COLLECTION_TYPE=collection # Do not display collections with these names (comma separated) # EXCLUDE_COLLECTIONS="" + +# Map RomM slugs to filesystem directories +# For example, if your PlayStation directory is called "psx": +# CUSTOM_MAPS='{"ps": "psx"}' +# CUSTOM_MAPS='' diff --git a/RomM/filesystem.py b/RomM/filesystem.py index 46699d2..8b3a574 100644 --- a/RomM/filesystem.py +++ b/RomM/filesystem.py @@ -96,6 +96,11 @@ def _get_platform_storage_dir_from_mapping(self, platform: str) -> str: platform, platform_dir ) + if platform_maps._env_maps and platform in platform_maps._env_platforms: + platform_dir = platform_maps._env_maps.get( + platform, platform_dir + ) + return platform_dir def _get_sd1_platforms_storage_path(self, platform: str) -> str: diff --git a/RomM/main.py b/RomM/main.py index be8318e..b9de30c 100644 --- a/RomM/main.py +++ b/RomM/main.py @@ -1,6 +1,7 @@ import os import sys import zipfile +import platform_maps # Add dependencies to path base_path = os.path.dirname(os.path.abspath(__file__)) @@ -48,6 +49,8 @@ def apply_pending_update(): os.makedirs(os.path.dirname(log_file), exist_ok=True) sys.stdout = open(log_file, "w", buffering=1) + # Read any custom maps + platform_maps.init_env_maps() def cleanup(romm: RomM, exit_code: int): romm.ui.cleanup() diff --git a/RomM/platform_maps.py b/RomM/platform_maps.py index 99bf4e8..7588614 100644 --- a/RomM/platform_maps.py +++ b/RomM/platform_maps.py @@ -1,3 +1,6 @@ +import os +import json + # Manual mapping of RomM slugs to device folder names and platform icons for es systems # This is sometimes needed to match custom system folders with defaults, for example ES-DE uses roms/gc and some Batocera forks use roms/gamecube # https://gitlab.com/es-de/emulationstation-de/-/blob/master/resources/systems/unix/es_systems.xml @@ -192,3 +195,28 @@ SPRUCEOS_SUPPORTED_PLATFORMS_FS = frozenset( SPRUCEOS_SUPPORTED_PLATFORMS_FS_MAP.values() ) + +_env_maps = None +_env_platforms = None + +def _load_env_maps() -> dict[str, str]: + raw = os.getenv("CUSTOM_MAPS") + if not raw: + return {} + try: + loaded = json.loads(raw) + return loaded + except json.JSONDecodeError as e: + print(f"Error: CUSTOM_MAPS is an invalid JSON format: {e}") + return {} + except Exception as e: + print(f"Error: Unexpected error: {e}") + return {} + +def init_env_maps(): + global _env_maps + global _env_platforms + if _env_maps is None: + _env_maps = _load_env_maps() + if _env_platforms is None: + _env_platforms = frozenset(_env_maps.keys()) From 9e8b99afdd27d018ceddbaa88fa64eb8e6177571 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 7 Jun 2025 09:33:38 -0400 Subject: [PATCH 2/2] fix linting --- RomM/api.py | 7 +++++-- RomM/filesystem.py | 4 +--- RomM/main.py | 2 ++ RomM/platform_maps.py | 4 +++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/RomM/api.py b/RomM/api.py index 5784c79..b56baef 100644 --- a/RomM/api.py +++ b/RomM/api.py @@ -257,7 +257,7 @@ def fetch_platforms(self) -> None: and platform_slug in platform_maps._env_platforms and platform_slug not in self._exclude_platforms ): - # A custom map from the .env was found, no need to check defaults + # A custom map from the .env was found, no need to check defaults pass elif self.file_system.is_muos: if ( @@ -459,7 +459,10 @@ def fetch_roms(self) -> None: _roms = [] for rom in roms: platform_slug = rom["platform_slug"].lower() - if platform_maps._env_maps and platform_slug in platform_maps._env_platforms: + if ( + platform_maps._env_maps + and platform_slug in platform_maps._env_platforms + ): pass elif self.file_system.is_muos: if platform_slug not in platform_maps.MUOS_SUPPORTED_PLATFORMS: diff --git a/RomM/filesystem.py b/RomM/filesystem.py index 8b3a574..bc8828b 100644 --- a/RomM/filesystem.py +++ b/RomM/filesystem.py @@ -97,9 +97,7 @@ def _get_platform_storage_dir_from_mapping(self, platform: str) -> str: ) if platform_maps._env_maps and platform in platform_maps._env_platforms: - platform_dir = platform_maps._env_maps.get( - platform, platform_dir - ) + platform_dir = platform_maps._env_maps.get(platform, platform_dir) return platform_dir diff --git a/RomM/main.py b/RomM/main.py index b9de30c..0122814 100644 --- a/RomM/main.py +++ b/RomM/main.py @@ -1,6 +1,7 @@ import os import sys import zipfile + import platform_maps # Add dependencies to path @@ -52,6 +53,7 @@ def apply_pending_update(): # Read any custom maps platform_maps.init_env_maps() + def cleanup(romm: RomM, exit_code: int): romm.ui.cleanup() romm.input.cleanup() diff --git a/RomM/platform_maps.py b/RomM/platform_maps.py index 7588614..ac770d2 100644 --- a/RomM/platform_maps.py +++ b/RomM/platform_maps.py @@ -1,5 +1,5 @@ -import os import json +import os # Manual mapping of RomM slugs to device folder names and platform icons for es systems # This is sometimes needed to match custom system folders with defaults, for example ES-DE uses roms/gc and some Batocera forks use roms/gamecube @@ -199,6 +199,7 @@ _env_maps = None _env_platforms = None + def _load_env_maps() -> dict[str, str]: raw = os.getenv("CUSTOM_MAPS") if not raw: @@ -213,6 +214,7 @@ def _load_env_maps() -> dict[str, str]: print(f"Error: Unexpected error: {e}") return {} + def init_env_maps(): global _env_maps global _env_platforms