From 1d630722de3ec0edbd877094cd918c92f0ff3421 Mon Sep 17 00:00:00 2001 From: kramo <93832451+kra-mo@users.noreply.github.com> Date: Tue, 11 Apr 2023 18:31:46 +0200 Subject: [PATCH] Save all covers in a shared directory --- src/game.py | 18 ++++-------------- src/utils/create_details_window.py | 5 +---- src/utils/save_cover.py | 22 ++++++++++------------ src/utils/steamgriddb.py | 20 ++++++++++++++------ src/window.py | 6 +++--- 5 files changed, 32 insertions(+), 39 deletions(-) diff --git a/src/game.py b/src/game.py index 66f9c68..a741c6d 100644 --- a/src/game.py +++ b/src/game.py @@ -23,7 +23,7 @@ import shlex # pylint: disable=unused-import import subprocess import sys -from gi.repository import GdkPixbuf, Gio, Gtk +from gi.repository import Gio, Gtk from .game_cover import GameCover from .save_game import save_game @@ -119,23 +119,13 @@ class game(Gtk.Box): # pylint: disable=invalid-name save_game(self.parent_widget, data) def get_cover(self): - animated_cover_path = ( - self.parent_widget.data_dir - / "cartridges" - / "animated_covers" - / f"{self.game_id}.gif" - ) + covers_dir = self.parent_widget.data_dir / "cartridges" / "covers" + animated_cover_path = covers_dir / f"{self.game_id}.gif" if animated_cover_path.is_file(): return animated_cover_path - cover_path = ( - self.parent_widget.data_dir - / "cartridges" - / "covers" - / f"{self.game_id}.tiff" - ) - + cover_path = covers_dir / f"{self.game_id}.tiff" if cover_path.is_file(): return cover_path diff --git a/src/utils/create_details_window.py b/src/utils/create_details_window.py index 9729f1e..030d5d3 100644 --- a/src/utils/create_details_window.py +++ b/src/utils/create_details_window.py @@ -318,10 +318,7 @@ def create_details_window(parent_widget, game_id=None): parent_widget.data_dir / "cartridges" / "covers" / f"{game_id}.tiff" ).unlink(missing_ok=True) ( - parent_widget.data_dir - / "cartridges" - / "animated_covers" - / f"{game_id}.gif" + parent_widget.data_dir / "cartridges" / "covers" / f"{game_id}.gif" ).unlink(missing_ok=True) elif not ( diff --git a/src/utils/save_cover.py b/src/utils/save_cover.py index afc604b..c0cbedf 100644 --- a/src/utils/save_cover.py +++ b/src/utils/save_cover.py @@ -43,17 +43,21 @@ def resize_animation(cover_path): def save_cover( - parent_widget, game_id, cover_path=None, pixbuf=None, animation_path=None + parent_widget, + game_id, + cover_path=None, + pixbuf=None, + animation_path=None, ): covers_dir = parent_widget.data_dir / "cartridges" / "covers" - covers_dir.mkdir(parents=True, exist_ok=True) if animation_path: - pixbuf = GdkPixbuf.PixbufAnimation.new_from_file( - str(animation_path) - ).get_static_image() - elif not pixbuf: + (covers_dir / f"{game_id}.tiff").unlink(missing_ok=True) + copyfile(animation_path, covers_dir / f"{game_id}.gif") + return + + if not pixbuf: try: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( str(cover_path), *parent_widget.image_size, False @@ -68,9 +72,3 @@ def save_cover( ["compression"], ["8"] if parent_widget.schema.get_boolean("high-quality-images") else ["7"], ) - - if animation_path: - animation_dir = parent_widget.data_dir / "cartridges" / "animated_covers" - animation_dir.mkdir(parents=True, exist_ok=True) - - copyfile(animation_path, animation_dir / f"{game_id}.gif") diff --git a/src/utils/steamgriddb.py b/src/utils/steamgriddb.py index 8c90897..99f52a7 100644 --- a/src/utils/steamgriddb.py +++ b/src/utils/steamgriddb.py @@ -29,12 +29,20 @@ class SGDBSave: def update_cover(self, task, game): if self.parent_widget.schema.get_boolean("sgdb") and ( self.parent_widget.schema.get_boolean("sgdb-prefer") - or not ( - self.parent_widget.data_dir - / "cartridges" - / "covers" - / f"{game[0]}.tiff" - ).is_file() + or not any( + ( + self.parent_widget.data_dir + / "cartridges" + / "covers" + / f"{game[0]}.tiff" + ).is_file(), + ( + self.parent_widget.data_dir + / "cartridges" + / "covers" + / f"{game[0]}.gif" + ).is_file(), + ) ): if not self.importer: self.parent_widget.loading = game[0] diff --git a/src/window.py b/src/window.py index 4586b92..df1cb36 100644 --- a/src/window.py +++ b/src/window.py @@ -119,9 +119,9 @@ class CartridgesWindow(Adw.ApplicationWindow): (self.data_dir / "cartridges" / "covers" / f"{game_id}.tiff").unlink( missing_ok=True ) - ( - self.data_dir / "cartridges" / "animated_covers" / f"{game_id}.gif" - ).unlink(missing_ok=True) + (self.data_dir / "cartridges" / "covers" / f"{game_id}.gif").unlink( + missing_ok=True + ) rmtree(self.cache_dir / "cartridges" / "deleted_covers", True)