From 5ab3085083b484fb688f10ec862a3615b6213dc7 Mon Sep 17 00:00:00 2001 From: kramo Date: Sun, 17 Dec 2023 11:46:54 +0100 Subject: [PATCH] Use HOST_ prefixed env vars for host XDG base dirs --- cartridges/importer/bottles_source.py | 2 +- cartridges/importer/desktop_source.py | 2 +- cartridges/importer/heroic_source.py | 4 ++-- cartridges/importer/itch_source.py | 2 +- cartridges/importer/legendary_source.py | 2 +- cartridges/importer/lutris_source.py | 4 ++-- cartridges/importer/retroarch_source.py | 2 +- cartridges/shared.py.in | 15 +++++++++++---- 8 files changed, 20 insertions(+), 13 deletions(-) diff --git a/cartridges/importer/bottles_source.py b/cartridges/importer/bottles_source.py index fe6d09c..13ffdec 100644 --- a/cartridges/importer/bottles_source.py +++ b/cartridges/importer/bottles_source.py @@ -98,7 +98,7 @@ class BottlesSource(URLExecutableSource): candidates=( shared.flatpak_dir / "com.usebottles.bottles" / "data" / "bottles", shared.data_dir / "bottles/", - shared.home / ".local" / "share" / "bottles", + shared.host_data_dir / "bottles", ), paths={ "library.yml": LocationSubPath("library.yml"), diff --git a/cartridges/importer/desktop_source.py b/cartridges/importer/desktop_source.py index 1d1f32c..a755070 100644 --- a/cartridges/importer/desktop_source.py +++ b/cartridges/importer/desktop_source.py @@ -39,7 +39,7 @@ class DesktopSourceIterable(SourceIterable): icon_theme = Gtk.IconTheme.new() search_paths = [ - shared.home / ".local" / "share", + shared.host_data_dir, "/run/host/usr/local/share", "/run/host/usr/share", "/run/host/usr/share/pixmaps", diff --git a/cartridges/importer/heroic_source.py b/cartridges/importer/heroic_source.py index 1533de8..306c91e 100644 --- a/cartridges/importer/heroic_source.py +++ b/cartridges/importer/heroic_source.py @@ -233,7 +233,7 @@ class LegendaryIterable(StoreSubSourceIterable): else: # Heroic native logging.debug("Using Heroic native <= 2.8 legendary file") - path = shared.home / ".config" + path = shared.host_config_dir path = path / "legendary" / "installed.json" logging.debug("Using Heroic %s installed.json path %s", self.name, path) @@ -371,7 +371,7 @@ class HeroicSource(URLExecutableSource): schema_key="heroic-location", candidates=( shared.config_dir / "heroic", - shared.home / ".config" / "heroic", + shared.host_config_dir / "heroic", shared.flatpak_dir / "com.heroicgameslauncher.hgl" / "config" diff --git a/cartridges/importer/itch_source.py b/cartridges/importer/itch_source.py index c5bf786..2a73594 100644 --- a/cartridges/importer/itch_source.py +++ b/cartridges/importer/itch_source.py @@ -93,7 +93,7 @@ class ItchSource(URLExecutableSource): candidates=( shared.flatpak_dir / "io.itch.itch" / "config" / "itch", shared.config_dir / "itch", - shared.home / ".config" / "itch", + shared.host_config_dir / "itch", shared.appdata_dir / "itch", ), paths={ diff --git a/cartridges/importer/legendary_source.py b/cartridges/importer/legendary_source.py index 25221dd..c27cba9 100644 --- a/cartridges/importer/legendary_source.py +++ b/cartridges/importer/legendary_source.py @@ -108,7 +108,7 @@ class LegendarySource(ExecutableFormatSource): schema_key="legendary-location", candidates=( shared.config_dir / "legendary", - shared.home / ".config" / "legendary", + shared.host_config_dir / "legendary", ), paths={ "installed.json": LocationSubPath("installed.json"), diff --git a/cartridges/importer/lutris_source.py b/cartridges/importer/lutris_source.py index 892b7f6..8afb4e6 100644 --- a/cartridges/importer/lutris_source.py +++ b/cartridges/importer/lutris_source.py @@ -110,7 +110,7 @@ class LutrisSource(URLExecutableSource): candidates=( shared.flatpak_dir / "net.lutris.Lutris" / "data" / "lutris", shared.data_dir / "lutris", - shared.home / ".local" / "share" / "lutris", + shared.host_data_dir / "lutris", ), paths={ "pga.db": LocationSubPath("pga.db"), @@ -122,7 +122,7 @@ class LutrisSource(URLExecutableSource): candidates=( shared.flatpak_dir / "net.lutris.Lutris" / "cache" / "lutris", shared.cache_dir / "lutris", - shared.home / ".cache" / "lutris", + shared.host_cache_dir / "lutris", ), paths={ "coverart": LocationSubPath("coverart", True), diff --git a/cartridges/importer/retroarch_source.py b/cartridges/importer/retroarch_source.py index 4502ac3..ccc6b63 100644 --- a/cartridges/importer/retroarch_source.py +++ b/cartridges/importer/retroarch_source.py @@ -157,7 +157,7 @@ class RetroarchSource(Source): / "config" / "retroarch", shared.config_dir / "retroarch", - shared.home / ".config" / "retroarch", + shared.host_config_dir / "retroarch", # TODO: Windows support, waiting for executable path setting improvement # Path("C:\\RetroArch-Win64"), # Path("C:\\RetroArch-Win32"), diff --git a/cartridges/shared.py.in b/cartridges/shared.py.in index a7ce958..44852f8 100644 --- a/cartridges/shared.py.in +++ b/cartridges/shared.py.in @@ -17,8 +17,8 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -import os from enum import IntEnum, auto +from os import getenv from pathlib import Path from gi.repository import Gdk, Gio, GLib @@ -43,19 +43,26 @@ schema = Gio.Settings.new(APP_ID) state_schema = Gio.Settings.new(APP_ID + ".State") home = Path.home() + data_dir = Path(GLib.get_user_data_dir()) +host_data_dir = Path(getenv("HOST_XDG_DATA_HOME", Path.home() / ".local" / "share")) + config_dir = Path(GLib.get_user_config_dir()) +host_config_dir = Path(getenv("HOST_XDG_CONFIG_HOME", Path.home() / ".config")) + cache_dir = Path(GLib.get_user_cache_dir()) +host_cache_dir = Path(getenv("HOST_XDG_CACHE_HOME", Path.home() / ".cache")) + flatpak_dir = home / ".var" / "app" games_dir = data_dir / "cartridges" / "games" covers_dir = data_dir / "cartridges" / "covers" -appdata_dir = Path(os.getenv("appdata") or "C:\\Users\\Default\\AppData\\Roaming") +appdata_dir = Path(getenv("appdata") or r"C:\Users\Default\AppData\Roaming") local_appdata_dir = Path( - os.getenv("csidl_local_appdata") or "C:\\Users\\Default\\AppData\\Local" + getenv("csidl_local_appdata") or r"C:\Users\Default\AppData\Local" ) -programfiles32_dir = Path(os.getenv("programfiles(x86)") or "C:\\Program Files (x86)") +programfiles32_dir = Path(getenv("programfiles(x86)") or r"C:\Program Files (x86)") try: scale_factor = max(