🎨 Simplified sources
This commit is contained in:
@@ -8,7 +8,12 @@ from typing import Generator, Optional, TypedDict
|
||||
|
||||
from src import shared
|
||||
from src.game import Game
|
||||
from src.importer.sources.source import NTSource, PosixSource, Source, SourceIterator
|
||||
from src.importer.sources.source import (
|
||||
LinuxSource,
|
||||
Source,
|
||||
SourceIterator,
|
||||
WindowsSource,
|
||||
)
|
||||
from src.utils.decorators import (
|
||||
replaced_by_env_path,
|
||||
replaced_by_path,
|
||||
@@ -121,7 +126,6 @@ class HeroicSource(Source):
|
||||
"""Generic heroic games launcher source"""
|
||||
|
||||
name = "Heroic"
|
||||
executable_format = "xdg-open heroic://launch/{app_name}"
|
||||
|
||||
@property
|
||||
def game_id_format(self) -> str:
|
||||
@@ -132,28 +136,20 @@ class HeroicSource(Source):
|
||||
return HeroicSourceIterator(source=self)
|
||||
|
||||
|
||||
class HeroicNativeSource(HeroicSource, PosixSource):
|
||||
variant = "native"
|
||||
class HeroicNativeSource(HeroicSource, LinuxSource):
|
||||
variant = "linux"
|
||||
executable_format = "xdg-open heroic://launch/{app_name}"
|
||||
|
||||
@property
|
||||
@replaced_by_schema_key("heroic-location")
|
||||
@replaced_by_path("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/")
|
||||
@replaced_by_env_path("XDG_CONFIG_HOME", "heroic/")
|
||||
@replaced_by_path("~/.config/heroic/")
|
||||
def location(self) -> Path:
|
||||
raise FileNotFoundError()
|
||||
|
||||
|
||||
class HeroicFlatpakSource(HeroicSource, PosixSource):
|
||||
variant = "flatpak"
|
||||
|
||||
@property
|
||||
@replaced_by_schema_key("heroic-flatpak-location")
|
||||
@replaced_by_path("~/.var/app/com.heroicgameslauncher.hgl/config/heroic/")
|
||||
def location(self) -> Path:
|
||||
raise FileNotFoundError()
|
||||
|
||||
|
||||
class HeroicWindowsSource(HeroicSource, NTSource):
|
||||
class HeroicWindowsSource(HeroicSource, WindowsSource):
|
||||
variant = "windows"
|
||||
executable_format = "start heroic://launch/{app_name}"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from time import time
|
||||
|
||||
from src import shared
|
||||
from src.game import Game
|
||||
from src.importer.sources.source import PosixSource, Source, SourceIterator
|
||||
from src.importer.sources.source import LinuxSource, Source, SourceIterator
|
||||
from src.utils.decorators import replaced_by_path, replaced_by_schema_key
|
||||
from src.utils.save_cover import resize_cover, save_cover
|
||||
|
||||
@@ -74,7 +74,6 @@ class LutrisSource(Source):
|
||||
"""Generic lutris source"""
|
||||
|
||||
name = "Lutris"
|
||||
executable_format = "xdg-open lutris:rungameid/{game_id}"
|
||||
|
||||
@property
|
||||
def game_id_format(self):
|
||||
@@ -84,21 +83,13 @@ class LutrisSource(Source):
|
||||
return LutrisSourceIterator(source=self)
|
||||
|
||||
|
||||
class LutrisNativeSource(LutrisSource, PosixSource):
|
||||
variant = "native"
|
||||
class LutrisNativeSource(LutrisSource, LinuxSource):
|
||||
variant = "linux"
|
||||
executable_format = "xdg-open lutris:rungameid/{game_id}"
|
||||
|
||||
@property
|
||||
@replaced_by_schema_key("lutris-location")
|
||||
@replaced_by_path("~/.var/app/net.lutris.Lutris/data/lutris/")
|
||||
@replaced_by_path("~/.local/share/lutris/")
|
||||
def location(self):
|
||||
raise FileNotFoundError()
|
||||
|
||||
|
||||
class LutrisFlatpakSource(LutrisSource, PosixSource):
|
||||
variant = "flatpak"
|
||||
|
||||
@property
|
||||
@replaced_by_schema_key("lutris-flatpak-location")
|
||||
@replaced_by_path("~/.var/app/net.lutris.Lutris/data/lutris/")
|
||||
def location(self):
|
||||
raise FileNotFoundError()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import os
|
||||
import sys
|
||||
from abc import abstractmethod
|
||||
from collections.abc import Iterable, Iterator
|
||||
from pathlib import Path
|
||||
@@ -66,7 +66,7 @@ class Source(Iterable):
|
||||
self.location
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
return os.name in self.available_on
|
||||
return sys.platform in self.available_on
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
@@ -83,17 +83,17 @@ class Source(Iterable):
|
||||
"""Get the source's iterator, to use in for loops"""
|
||||
|
||||
|
||||
class NTSource(Source):
|
||||
class WindowsSource(Source):
|
||||
"""Mixin for sources available on Windows"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.available_on.add("nt")
|
||||
self.available_on.add("win32")
|
||||
|
||||
|
||||
class PosixSource(Source):
|
||||
"""Mixin for sources available on POXIX-compliant systems"""
|
||||
class LinuxSource(Source):
|
||||
"""Mixin for sources available on Linux"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.available_on.add("posix")
|
||||
self.available_on.add("linux")
|
||||
|
||||
@@ -5,7 +5,12 @@ from typing import Iterator
|
||||
|
||||
from src import shared
|
||||
from src.game import Game
|
||||
from src.importer.sources.source import NTSource, PosixSource, Source, SourceIterator
|
||||
from src.importer.sources.source import (
|
||||
LinuxSource,
|
||||
Source,
|
||||
SourceIterator,
|
||||
WindowsSource,
|
||||
)
|
||||
from src.utils.decorators import (
|
||||
replaced_by_env_path,
|
||||
replaced_by_path,
|
||||
@@ -20,10 +25,12 @@ class SteamSourceIterator(SourceIterator):
|
||||
manifests: set = None
|
||||
manifests_iterator: Iterator[Path] = None
|
||||
installed_state_mask: int = 4
|
||||
appid_cache: set = None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.appid_cache = set()
|
||||
self.manifests = set()
|
||||
|
||||
# Get dirs that contain steam app manifests
|
||||
@@ -64,8 +71,13 @@ class SteamSourceIterator(SourceIterator):
|
||||
if not int(local_data["stateflags"]) & self.installed_state_mask:
|
||||
return None
|
||||
|
||||
# Build game from local data
|
||||
# Skip duplicate appids
|
||||
appid = local_data["appid"]
|
||||
if appid in self.appid_cache:
|
||||
return None
|
||||
self.appid_cache.add(appid)
|
||||
|
||||
# Build game from local data
|
||||
values = {
|
||||
"version": shared.SPEC_VERSION,
|
||||
"added": int(time()),
|
||||
@@ -91,17 +103,18 @@ class SteamSourceIterator(SourceIterator):
|
||||
|
||||
class SteamSource(Source):
|
||||
name = "Steam"
|
||||
executable_format = "xdg-open steam://rungameid/{game_id}"
|
||||
|
||||
def __iter__(self):
|
||||
return SteamSourceIterator(source=self)
|
||||
|
||||
|
||||
class SteamNativeSource(SteamSource, PosixSource):
|
||||
variant = "native"
|
||||
class SteamNativeSource(SteamSource, LinuxSource):
|
||||
variant = "linux"
|
||||
executable_format = "xdg-open steam://rungameid/{game_id}"
|
||||
|
||||
@property
|
||||
@replaced_by_schema_key("steam-location")
|
||||
@replaced_by_path("~/.var/app/com.valvesoftware.Steam/data/Steam/")
|
||||
@replaced_by_env_path("XDG_DATA_HOME", "Steam/")
|
||||
@replaced_by_path("~/.steam/")
|
||||
@replaced_by_path("~/.local/share/Steam/")
|
||||
@@ -109,23 +122,12 @@ class SteamNativeSource(SteamSource, PosixSource):
|
||||
raise FileNotFoundError()
|
||||
|
||||
|
||||
class SteamFlatpakSource(SteamSource, PosixSource):
|
||||
variant = "flatpak"
|
||||
|
||||
@property
|
||||
@replaced_by_schema_key("steam-flatpak-location")
|
||||
@replaced_by_path("~/.var/app/com.valvesoftware.Steam/data/Steam/")
|
||||
def location(self):
|
||||
raise FileNotFoundError()
|
||||
|
||||
|
||||
class SteamWindowsSource(SteamSource, NTSource):
|
||||
class SteamWindowsSource(SteamSource, WindowsSource):
|
||||
variant = "windows"
|
||||
executable_format = "start steam://rungameid/{game_id}"
|
||||
|
||||
@property
|
||||
@replaced_by_schema_key("steam-windows-location")
|
||||
@replaced_by_schema_key("steam-location")
|
||||
@replaced_by_env_path("programfiles(x86)", "Steam")
|
||||
@replaced_by_path("C:\\Program Files (x86)\\Steam")
|
||||
def location(self):
|
||||
raise FileNotFoundError()
|
||||
|
||||
Reference in New Issue
Block a user