diff --git a/src/importer/sources/bottles_source.py b/src/importer/sources/bottles_source.py index c98d431..5ce598d 100644 --- a/src/importer/sources/bottles_source.py +++ b/src/importer/sources/bottles_source.py @@ -11,7 +11,6 @@ from src.importer.sources.source import ( URLExecutableSource, ) from src.utils.decorators import ( - replaced_by_env_path, replaced_by_path, replaced_by_schema_key, ) @@ -72,7 +71,6 @@ class BottlesSource(URLExecutableSource): @property @replaced_by_schema_key @replaced_by_path("~/.var/app/com.usebottles.bottles/data/bottles/") - @replaced_by_env_path("XDG_DATA_HOME", "bottles/") - @replaced_by_path("~/.local/share/bottles/") + @replaced_by_path(shared.data_dir / "bottles") def location(self) -> Path: raise FileNotFoundError() diff --git a/src/importer/sources/heroic_source.py b/src/importer/sources/heroic_source.py index 76c34d6..adcf34d 100644 --- a/src/importer/sources/heroic_source.py +++ b/src/importer/sources/heroic_source.py @@ -14,7 +14,6 @@ from src.importer.sources.source import ( SourceIterator, ) from src.utils.decorators import ( - replaced_by_env_path, replaced_by_path, replaced_by_schema_key, ) @@ -130,8 +129,7 @@ class HeroicSource(URLExecutableSource): @property @replaced_by_schema_key @replaced_by_path("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/") - @replaced_by_env_path("XDG_CONFIG_HOME", "heroic/") - @replaced_by_path("~/.config/heroic/") - @replaced_by_env_path("appdata", "heroic/") + @replaced_by_path(shared.config_dir / "heroic") + @replaced_by_path(shared.appdata_dir / "heroic") def location(self) -> Path: raise FileNotFoundError() diff --git a/src/importer/sources/itch_source.py b/src/importer/sources/itch_source.py index 7d282dc..6d8a157 100644 --- a/src/importer/sources/itch_source.py +++ b/src/importer/sources/itch_source.py @@ -10,7 +10,6 @@ from src.importer.sources.source import ( URLExecutableSource, ) from src.utils.decorators import ( - replaced_by_env_path, replaced_by_path, replaced_by_schema_key, ) @@ -65,8 +64,7 @@ class ItchSource(URLExecutableSource): @property @replaced_by_schema_key @replaced_by_path("~/.var/app/io.itch.itch/config/itch/") - @replaced_by_env_path("XDG_DATA_HOME", "itch/") - @replaced_by_path("~/.config/itch") - @replaced_by_env_path("appdata", "itch/") + @replaced_by_path(shared.config_dir / "itch") + @replaced_by_path(shared.appdata_dir / "itch") def location(self) -> Path: raise FileNotFoundError() diff --git a/src/importer/sources/legendary_source.py b/src/importer/sources/legendary_source.py index 150f518..87f1f05 100644 --- a/src/importer/sources/legendary_source.py +++ b/src/importer/sources/legendary_source.py @@ -8,11 +8,7 @@ from typing import Generator from src import shared # pylint: disable=no-name-in-module from src.game import Game from src.importer.sources.source import Source, SourceIterationResult, SourceIterator -from src.utils.decorators import ( - replaced_by_env_path, - replaced_by_path, - replaced_by_schema_key, -) +from src.utils.decorators import replaced_by_path, replaced_by_schema_key class LegendarySourceIterator(SourceIterator): @@ -79,8 +75,6 @@ class LegendarySource(Source): @property @replaced_by_schema_key - @replaced_by_env_path("XDG_CONFIG_HOME", "legendary/") - @replaced_by_path("~/.config/legendary/") - @replaced_by_path("~\\.config\\legendary\\") + @replaced_by_path(shared.config_dir / "legendary") def location(self) -> Path: raise FileNotFoundError() diff --git a/src/importer/sources/steam_source.py b/src/importer/sources/steam_source.py index 68aa861..c275dc7 100644 --- a/src/importer/sources/steam_source.py +++ b/src/importer/sources/steam_source.py @@ -11,7 +11,6 @@ from src.importer.sources.source import ( URLExecutableSource, ) from src.utils.decorators import ( - replaced_by_env_path, replaced_by_path, replaced_by_schema_key, ) @@ -102,9 +101,8 @@ class SteamSource(URLExecutableSource): @property @replaced_by_schema_key @replaced_by_path("~/.var/app/com.valvesoftware.Steam/data/Steam/") - @replaced_by_env_path("XDG_DATA_HOME", "Steam/") + @replaced_by_path(shared.data_dir / "Steam") @replaced_by_path("~/.steam/") - @replaced_by_path("~/.local/share/Steam/") - @replaced_by_env_path("programfiles(x86)", "Steam") + @replaced_by_path(shared.programfiles32_dir / "Steam") def location(self): raise FileNotFoundError() diff --git a/src/shared.py.in b/src/shared.py.in index 6f08a29..d7d60a7 100644 --- a/src/shared.py.in +++ b/src/shared.py.in @@ -50,6 +50,9 @@ cache_dir = ( games_dir = data_dir / "cartridges" / "games" covers_dir = data_dir / "cartridges" / "covers" +appdata_dir = Path(os.getenv("appdata") or "C:\\Users\\Default\\AppData\\Roaming") +programfiles32_dir = Path(os.getenv("programfiles(x86)") or "C:\\Program Files (x86)") + scale_factor = max( monitor.get_scale_factor() for monitor in Gdk.Display.get_default().get_monitors() ) diff --git a/src/utils/decorators.py b/src/utils/decorators.py index 4664808..be572ec 100644 --- a/src/utils/decorators.py +++ b/src/utils/decorators.py @@ -22,24 +22,6 @@ def replaced_by_path(override: PathLike): # Decorator builder return decorator -def replaced_by_env_path(env_var_name: str, suffix: PathLike | None = None): - """Replace the method's returned path with a path whose root is the env variable""" - - def decorator(original_function): # Built decorator (closure) - @wraps(original_function) - def wrapper(*args, **kwargs): # func's override - try: - env_var = environ[env_var_name] - except KeyError: - return original_function(*args, **kwargs) - override = Path(env_var) / suffix - return replaced_by_path(override)(original_function)(*args, **kwargs) - - return wrapper - - return decorator - - def replaced_by_schema_key(original_method): # Built decorator (closure) """ Replace the original method's value by the path pointed at in the schema