Merge main

This commit is contained in:
kramo
2023-05-27 19:08:40 +02:00
57 changed files with 2176 additions and 1052 deletions

View File

@@ -33,7 +33,7 @@ from src.utils.save_cover import resize_cover, save_cover
from src.utils.steamgriddb import SGDBSave
@Gtk.Template(resource_path="/hu/kramo/Cartridges/gtk/details_window.ui")
@Gtk.Template(resource_path=shared.PREFIX + "/gtk/details_window.ui")
class DetailsWindow(Adw.Window):
__gtype_name__ = "DetailsWindow"

View File

@@ -24,13 +24,13 @@ import subprocess
from pathlib import Path
from time import time
from gi.repository import Adw, Gio, Gtk
from gi.repository import Adw, Gtk
from src import shared
from src.game_cover import GameCover
@Gtk.Template(resource_path="/hu/kramo/Cartridges/gtk/game.ui")
@Gtk.Template(resource_path=shared.PREFIX + "/gtk/game.ui")
class Game(Gtk.Box):
__gtype_name__ = "Game"
@@ -66,6 +66,7 @@ class Game(Gtk.Box):
self.win = shared.win
self.app = self.win.get_application()
self.version = shared.SPEC_VERSION
self.update_values(data)
@@ -180,7 +181,7 @@ class Game(Gtk.Box):
args = (
"flatpak-spawn --host /bin/sh -c " + shlex.quote(string) # Flatpak
if os.getenv("FLATPAK_ID") == "hu.kramo.Cartridges"
if os.getenv("FLATPAK_ID") == shared.APP_ID
else string # Others
)
@@ -192,7 +193,7 @@ class Game(Gtk.Box):
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0,
)
if Gio.Settings.new("hu.kramo.Cartridges").get_boolean("exit-after-launch"):
if shared.schema.get_boolean("exit-after-launch"):
self.app.quit()
# The variable is the title of the game

View File

@@ -20,6 +20,8 @@
from gi.repository import GdkPixbuf, Gio, GLib
from PIL import Image, ImageFilter, ImageStat
from src import shared
class GameCover:
pixbuf = None
@@ -30,7 +32,7 @@ class GameCover:
anim_iter = None
placeholder_pixbuf = GdkPixbuf.Pixbuf.new_from_resource_at_scale(
"/hu/kramo/Cartridges/library_placeholder.svg", 400, 600, False
shared.PREFIX + "/library_placeholder.svg", 400, 600, False
)
def __init__(self, pictures, path=None):
@@ -91,7 +93,7 @@ class GameCover:
)
else:
self.blurred = GdkPixbuf.Pixbuf.new_from_resource_at_scale(
"/hu/kramo/Cartridges/library_placeholder.svg", 2, 2, False
shared.PREFIX + "/library_placeholder.svg", 2, 2, False
)
self.luminance = (0.1, 0.8)

View File

@@ -68,7 +68,7 @@ class LutrisSourceIterator(SourceIterator):
# Create game
values = {
"version": shared.spec_version,
"version": shared.SPEC_VERSION,
"added": int(time()),
"hidden": row[4],
"name": row[1],

View File

@@ -72,7 +72,7 @@ class SteamSourceIterator(SourceIterator):
# Build game from local data
appid = local_data["appid"]
values = {
"version": shared.spec_version,
"version": shared.SPEC_VERSION,
"added": int(time()),
"name": local_data["name"],
"source": self.source.id,

View File

@@ -28,22 +28,19 @@ from src.utils.check_install import check_install
def bottles_installed(path=None):
location_key = "bottles-location"
bottles_dir = (
path if path else Path(shared.schema.get_string(location_key)).expanduser()
)
check = "library.yml"
if not (bottles_dir / check).is_file():
locations = (
(Path(),)
if path
else (
Path.home() / ".var/app/com.usebottles.bottles/data/bottles",
shared.data_dir / "bottles",
)
locations = (
(path,)
if path
else (
Path(shared.schema.get_string(location_key)).expanduser(),
Path.home() / ".var/app/com.usebottles.bottles/data/bottles",
shared.data_dir / "bottles",
)
)
bottles_dir = check_install(check, locations, (shared.schema, location_key))
bottles_dir = check_install(check, locations, (shared.schema, location_key))
return bottles_dir
@@ -57,7 +54,7 @@ def bottles_importer():
data = (bottles_dir / "library.yml").read_text("utf-8")
library = yaml.load(data, Loader=yaml.Loader)
library = yaml.safe_load(data)
importer = shared.importer
importer.total_queue += len(library)

View File

@@ -29,25 +29,22 @@ from src.utils.check_install import check_install
def heroic_installed(path=None):
location_key = "heroic-location"
heroic_dir = (
path if path else Path(shared.schema.get_string(location_key)).expanduser()
)
check = "config.json"
if not (heroic_dir / check).is_file():
locations = (
(Path(),)
if path
else (
Path.home() / ".var/app/com.heroicgameslauncher.hgl/config/heroic",
shared.config_dir / "heroic",
)
locations = (
(path,)
if path
else (
Path(shared.schema.get_string(location_key)).expanduser(),
Path.home() / ".var/app/com.heroicgameslauncher.hgl/config/heroic",
shared.config_dir / "heroic",
)
)
if os.name == "nt" and not path:
locations += (Path(os.getenv("appdata")) / "heroic",)
if os.name == "nt" and not path:
locations += (Path(os.getenv("appdata")) / "heroic",)
heroic_dir = check_install(check, locations, (shared.schema, location_key))
heroic_dir = check_install(check, locations, (shared.schema, location_key))
return heroic_dir
@@ -63,7 +60,7 @@ def heroic_importer():
# Import Epic games
if not shared.schema.get_boolean("heroic-import-epic"):
pass
elif (heroic_dir / "store_cache" / "legendary_library.json").exists():
elif (heroic_dir / "store_cache" / "legendary_library.json").is_file():
library = json.load(
(heroic_dir / "store_cache" / "legendary_library.json").open()
)
@@ -107,7 +104,7 @@ def heroic_importer():
).hexdigest()
)
importer.save_game(values, image_path if image_path.exists() else None)
importer.save_game(values, image_path if image_path.is_file() else None)
except KeyError:
pass
@@ -115,9 +112,9 @@ def heroic_importer():
# Import GOG games
if not shared.schema.get_boolean("heroic-import-gog"):
pass
elif (heroic_dir / "gog_store" / "installed.json").exists() and (
elif (heroic_dir / "gog_store" / "installed.json").is_file() and (
heroic_dir / "store_cache" / "gog_library.json"
).exists():
).is_file():
installed = json.load((heroic_dir / "gog_store" / "installed.json").open())
importer.total_queue += len(installed["installed"])
@@ -159,12 +156,12 @@ def heroic_importer():
values["source"] = "heroic_gog"
values["added"] = current_time
importer.save_game(values, image_path if image_path.exists() else None)
importer.save_game(values, image_path if image_path.is_file() else None)
# Import sideloaded games
if not shared.schema.get_boolean("heroic-import-sideload"):
pass
elif (heroic_dir / "sideload_apps" / "library.json").exists():
elif (heroic_dir / "sideload_apps" / "library.json").is_file():
library = json.load((heroic_dir / "sideload_apps" / "library.json").open())
importer.total_queue += len(library["games"])
@@ -198,4 +195,4 @@ def heroic_importer():
/ sha256(item["art_square"].encode()).hexdigest()
)
importer.save_game(values, image_path if image_path.exists() else None)
importer.save_game(values, image_path if image_path.is_file() else None)

View File

@@ -122,25 +122,22 @@ def get_games_async(rows, importer):
def itch_installed(path=None):
location_key = "itch-location"
itch_dir = (
path if path else Path(shared.schema.get_string(location_key)).expanduser()
)
check = Path("db") / "butler.db"
if not (itch_dir / check).is_file():
locations = (
(Path(),)
if path
else (
Path.home() / ".var/app/io.itch.itch/config/itch",
shared.config_dir / "itch",
)
locations = (
(path,)
if path
else (
Path(shared.schema.get_string(location_key)).expanduser(),
Path.home() / ".var/app/io.itch.itch/config/itch",
shared.config_dir / "itch",
)
)
if os.name == "nt" and not path:
locations += (Path(os.getenv("appdata")) / "itch",)
if os.name == "nt" and not path:
locations += (Path(os.getenv("appdata")) / "itch",)
itch_dir = check_install(check, locations, (shared.schema, location_key))
itch_dir = check_install(check, locations, (shared.schema, location_key))
return itch_dir

View File

@@ -28,44 +28,38 @@ from src.utils.check_install import check_install
def lutris_installed(path=None):
location_key = "lutris-location"
lutris_dir = (
path if path else Path(shared.schema.get_string(location_key)).expanduser()
)
check = "pga.db"
if not (lutris_dir / check).is_file():
locations = (
(Path(),)
if path
else (
Path.home() / ".var/app/net.lutris.Lutris/data/lutris",
shared.data_dir / "lutris",
)
locations = (
(path,)
if path
else (
Path(shared.schema.get_string(location_key)).expanduser(),
Path.home() / ".var/app/net.lutris.Lutris/data/lutris",
shared.data_dir / "lutris",
)
)
lutris_dir = check_install(check, locations, (shared.schema, location_key))
lutris_dir = check_install(check, locations, (shared.schema, location_key))
return lutris_dir
def lutris_cache_exists(path=None):
cache_key = "lutris-cache-location"
cache_dir = path if path else Path(shared.schema.get_string(cache_key)).expanduser()
cache_check = "coverart"
if not (cache_dir / cache_check).exists():
cache_locations = (
(Path(),)
if path
else (
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "cache" / "lutris",
shared.cache_dir / "lutris",
)
cache_locations = (
(path,)
if path
else (
Path(shared.schema.get_string(cache_key)).expanduser(),
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "cache" / "lutris",
shared.cache_dir / "lutris",
)
)
cache_dir = check_install(
cache_check, cache_locations, (shared.schema, cache_key)
)
cache_dir = check_install(cache_check, cache_locations, (shared.schema, cache_key))
return cache_dir
@@ -136,4 +130,4 @@ def lutris_importer():
values["source"] = f"lutris_{row[3]}"
image_path = cache_dir / "coverart" / f"{row[2]}.jpg"
importer.save_game(values, image_path if image_path.exists() else None)
importer.save_game(values, image_path if image_path.is_file() else None)

View File

@@ -35,9 +35,10 @@ def update_values_from_data(content, values):
values["blacklisted"] = True
else:
data = basic_data["data"]
values["developer"] = ", ".join(data["developers"])
if data.get("developers"):
values["developer"] = ", ".join(data["developers"])
if data["type"] != "game":
if data.get("type") != "game":
values["blacklisted"] = True
return values
@@ -88,11 +89,11 @@ def get_game(task, datatypes, current_time, appmanifest, steam_dir):
open_file.raise_for_status()
content = open_file.json()
except requests.exceptions.RequestException:
task.return_value((values, image_path if image_path.exists() else None))
task.return_value((values, image_path if image_path.is_file() else None))
return
values = update_values_from_data(content, values)
task.return_value((values, image_path if image_path.exists() else None))
task.return_value((values, image_path if image_path.is_file() else None))
def get_games_async(appmanifests, steam_dir, importer):
@@ -124,28 +125,24 @@ def get_games_async(appmanifests, steam_dir, importer):
def steam_installed(path=None):
location_key = "steam-location"
steam_dir = Path(shared.schema.get_string(location_key)).expanduser()
check = "steamapps"
if not (steam_dir / check).is_file():
subdirs = ("steam", "Steam")
locations = (
(path,)
if path
else (
steam_dir,
Path.home() / ".steam",
shared.data_dir / "Steam",
Path.home() / ".var/app/com.valvesoftware.Steam/data/Steam",
)
subdirs = ("steam", "Steam")
locations = (
(path,)
if path
else (
Path(shared.schema.get_string(location_key)).expanduser(),
Path.home() / ".steam",
shared.data_dir / "Steam",
Path.home() / ".var/app/com.valvesoftware.Steam/data/Steam",
)
)
if os.name == "nt":
locations += (Path(os.getenv("programfiles(x86)")) / "Steam",)
if os.name == "nt":
locations += (Path(os.getenv("programfiles(x86)")) / "Steam",)
steam_dir = check_install(
check, locations, (shared.schema, location_key), subdirs
)
steam_dir = check_install(check, locations, (shared.schema, location_key), subdirs)
return steam_dir
@@ -166,13 +163,12 @@ def steam_importer():
steam_dirs = [steam_dir]
for directory in steam_dirs:
if not (directory / "steamapps").exists():
steam_dirs.remove(directory)
for directory in steam_dirs:
for open_file in (directory / "steamapps").iterdir():
if open_file.is_file() and "appmanifest" in open_file.name:
appmanifests.append(open_file)
try:
for open_file in (directory / "steamapps").iterdir():
if open_file.is_file() and "appmanifest" in open_file.name:
appmanifests.append(open_file)
except FileNotFoundError:
continue
importer = shared.importer
importer.total_queue += len(appmanifests)

View File

@@ -54,12 +54,15 @@ class CartridgesApplication(Adw.Application):
def __init__(self):
super().__init__(
application_id="hu.kramo.Cartridges", flags=Gio.ApplicationFlags.FLAGS_NONE
application_id=shared.APP_ID, flags=Gio.ApplicationFlags.FLAGS_NONE
)
def do_activate(self): # pylint: disable=arguments-differ
"""Called on app creation"""
# Set fallback icon-name
Gtk.Window.set_default_icon_name(shared.APP_ID)
# Create the main window
self.win = self.props.active_window # pylint: disable=no-member
if not self.win:
@@ -136,9 +139,9 @@ class CartridgesApplication(Adw.Application):
about = Adw.AboutWindow(
transient_for=self.win,
application_name=_("Cartridges"),
application_icon="hu.kramo.Cartridges",
application_icon=shared.APP_ID,
developer_name="kramo",
version="1.5",
version=shared.VERSION,
developers=[
"kramo https://kramo.hu",
"Arcitec https://github.com/Arcitec",

View File

@@ -1,13 +1,5 @@
moduledir = join_paths(pkgdatadir, 'src')
python = import('python')
conf = configuration_data()
conf.set('PYTHON', python.find_installation('python3').path())
conf.set('VERSION', meson.project_version())
conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir')))
conf.set('pkgdatadir', pkgdatadir)
configure_file(
input: 'cartridges.in',
output: 'cartridges',
@@ -28,7 +20,11 @@ install_data(
'details_window.py',
'game.py',
'game_cover.py',
'shared.py',
configure_file(
input: 'shared.py.in',
output: 'shared.py',
configuration: conf
)
],
install_dir: moduledir
)

View File

@@ -35,7 +35,7 @@ from src.importers.steam_importer import steam_installed
from src.utils.create_dialog import create_dialog
@Gtk.Template(resource_path="/hu/kramo/Cartridges/gtk/preferences.ui")
@Gtk.Template(resource_path=shared.PREFIX + "/gtk/preferences.ui")
class PreferencesWindow(Adw.PreferencesWindow):
__gtype_name__ = "PreferencesWindow"
@@ -259,7 +259,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
getattr(win, f'{source_id.replace("-", "_")}_action_row').set_subtitle(
# Remove the path if the dir is picked via the Flatpak portal
re.sub(
"/run/user/\\d*/doc/......../",
"/run/user/\\d*/doc/.*/",
"",
str(
Path(shared.schema.get_string(f"{source_id}-location")).expanduser()

View File

@@ -1,4 +1,4 @@
# shared.py
# shared.py.in
#
# Copyright 2022-2023 kramo
#
@@ -22,8 +22,13 @@ from pathlib import Path
from gi.repository import Gdk, Gio
schema = Gio.Settings.new("hu.kramo.Cartridges")
state_schema = Gio.Settings.new("hu.kramo.Cartridges.State")
APP_ID = "@APP_ID@"
VERSION = "@VERSION@"
PREFIX = "@PREFIX@"
SPEC_VERSION = 1.5 # The version of the game_id.json spec
schema = Gio.Settings.new(APP_ID)
state_schema = Gio.Settings.new(APP_ID + ".State")
data_dir = (
Path(os.getenv("XDG_DATA_HOME"))
@@ -51,5 +56,5 @@ image_size = (200 * scale_factor, 300 * scale_factor)
# pylint: disable=invalid-name
win = None
store = None
spec_version = 2.0 # The version of the game_id.json spec
importer = None
store = None

View File

@@ -27,7 +27,7 @@ class Store:
"""
# Ignore games from a newer spec version
if game.version > shared.spec_version:
if game.version > shared.SPEC_VERSION:
return None
# Ignore games that are already there

View File

@@ -24,10 +24,9 @@ from pathlib import Path
def check_install(check, locations, setting=None, subdirs=(Path(),)):
for location in locations:
for subdir in (Path(),) + subdirs:
if (location / subdir / check).is_file() or (
location / subdir / check
).exists():
if (location / subdir / check).exists():
if setting:
setting[0].set_string(setting[1], str(location / subdir))
return location / subdir
return False

View File

@@ -19,10 +19,12 @@
from datetime import datetime
from gi.repository import Adw, Gio, GLib, Gtk
from gi.repository import Adw, GLib, Gtk
from src import shared
@Gtk.Template(resource_path="/hu/kramo/Cartridges/gtk/window.ui")
@Gtk.Template(resource_path=shared.PREFIX + "/gtk/window.ui")
class CartridgesWindow(Adw.ApplicationWindow):
__gtype_name__ = "CartridgesWindow"
@@ -86,6 +88,11 @@ class CartridgesWindow(Adw.ApplicationWindow):
self.set_library_child()
self.notice_empty.set_icon_name(shared.APP_ID + "-symbolic")
if "Devel" in shared.APP_ID:
self.add_css_class("devel")
# Connect search entries
self.search_bar.connect_entry(self.search_entry)
self.hidden_search_bar.connect_entry(self.hidden_search_entry)
@@ -139,9 +146,8 @@ class CartridgesWindow(Adw.ApplicationWindow):
)
filtered = text != "" and not (
text in game.name.lower() or text in game.developer.lower()
if game.developer
else None
text in game.name.lower()
or (text in game.developer.lower() if game.developer else False)
)
game.filtered = filtered
@@ -291,9 +297,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
self.sort_state = str(state).strip("'")
self.library.invalidate_sort()
Gio.Settings(schema_id="hu.kramo.Cartridges.State").set_string(
"sort-mode", self.sort_state
)
shared.state_schema.set_string("sort-mode", self.sort_state)
def on_toggle_search_action(self, *_args):
if self.stack.get_visible_child() == self.library_view: