Save all covers in a shared directory
This commit is contained in:
18
src/game.py
18
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
|
||||
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user