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 subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from gi.repository import GdkPixbuf, Gio, Gtk
|
from gi.repository import Gio, Gtk
|
||||||
|
|
||||||
from .game_cover import GameCover
|
from .game_cover import GameCover
|
||||||
from .save_game import save_game
|
from .save_game import save_game
|
||||||
@@ -119,23 +119,13 @@ class game(Gtk.Box): # pylint: disable=invalid-name
|
|||||||
save_game(self.parent_widget, data)
|
save_game(self.parent_widget, data)
|
||||||
|
|
||||||
def get_cover(self):
|
def get_cover(self):
|
||||||
animated_cover_path = (
|
covers_dir = self.parent_widget.data_dir / "cartridges" / "covers"
|
||||||
self.parent_widget.data_dir
|
|
||||||
/ "cartridges"
|
|
||||||
/ "animated_covers"
|
|
||||||
/ f"{self.game_id}.gif"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
animated_cover_path = covers_dir / f"{self.game_id}.gif"
|
||||||
if animated_cover_path.is_file():
|
if animated_cover_path.is_file():
|
||||||
return animated_cover_path
|
return animated_cover_path
|
||||||
|
|
||||||
cover_path = (
|
cover_path = covers_dir / f"{self.game_id}.tiff"
|
||||||
self.parent_widget.data_dir
|
|
||||||
/ "cartridges"
|
|
||||||
/ "covers"
|
|
||||||
/ f"{self.game_id}.tiff"
|
|
||||||
)
|
|
||||||
|
|
||||||
if cover_path.is_file():
|
if cover_path.is_file():
|
||||||
return cover_path
|
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"
|
parent_widget.data_dir / "cartridges" / "covers" / f"{game_id}.tiff"
|
||||||
).unlink(missing_ok=True)
|
).unlink(missing_ok=True)
|
||||||
(
|
(
|
||||||
parent_widget.data_dir
|
parent_widget.data_dir / "cartridges" / "covers" / f"{game_id}.gif"
|
||||||
/ "cartridges"
|
|
||||||
/ "animated_covers"
|
|
||||||
/ f"{game_id}.gif"
|
|
||||||
).unlink(missing_ok=True)
|
).unlink(missing_ok=True)
|
||||||
|
|
||||||
elif not (
|
elif not (
|
||||||
|
|||||||
@@ -43,17 +43,21 @@ def resize_animation(cover_path):
|
|||||||
|
|
||||||
|
|
||||||
def save_cover(
|
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 = parent_widget.data_dir / "cartridges" / "covers"
|
||||||
|
|
||||||
covers_dir.mkdir(parents=True, exist_ok=True)
|
covers_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
if animation_path:
|
if animation_path:
|
||||||
pixbuf = GdkPixbuf.PixbufAnimation.new_from_file(
|
(covers_dir / f"{game_id}.tiff").unlink(missing_ok=True)
|
||||||
str(animation_path)
|
copyfile(animation_path, covers_dir / f"{game_id}.gif")
|
||||||
).get_static_image()
|
return
|
||||||
elif not pixbuf:
|
|
||||||
|
if not pixbuf:
|
||||||
try:
|
try:
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||||
str(cover_path), *parent_widget.image_size, False
|
str(cover_path), *parent_widget.image_size, False
|
||||||
@@ -68,9 +72,3 @@ def save_cover(
|
|||||||
["compression"],
|
["compression"],
|
||||||
["8"] if parent_widget.schema.get_boolean("high-quality-images") else ["7"],
|
["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):
|
def update_cover(self, task, game):
|
||||||
if self.parent_widget.schema.get_boolean("sgdb") and (
|
if self.parent_widget.schema.get_boolean("sgdb") and (
|
||||||
self.parent_widget.schema.get_boolean("sgdb-prefer")
|
self.parent_widget.schema.get_boolean("sgdb-prefer")
|
||||||
or not (
|
or not any(
|
||||||
|
(
|
||||||
self.parent_widget.data_dir
|
self.parent_widget.data_dir
|
||||||
/ "cartridges"
|
/ "cartridges"
|
||||||
/ "covers"
|
/ "covers"
|
||||||
/ f"{game[0]}.tiff"
|
/ f"{game[0]}.tiff"
|
||||||
).is_file()
|
).is_file(),
|
||||||
|
(
|
||||||
|
self.parent_widget.data_dir
|
||||||
|
/ "cartridges"
|
||||||
|
/ "covers"
|
||||||
|
/ f"{game[0]}.gif"
|
||||||
|
).is_file(),
|
||||||
|
)
|
||||||
):
|
):
|
||||||
if not self.importer:
|
if not self.importer:
|
||||||
self.parent_widget.loading = game[0]
|
self.parent_widget.loading = game[0]
|
||||||
|
|||||||
@@ -119,9 +119,9 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
(self.data_dir / "cartridges" / "covers" / f"{game_id}.tiff").unlink(
|
(self.data_dir / "cartridges" / "covers" / f"{game_id}.tiff").unlink(
|
||||||
missing_ok=True
|
missing_ok=True
|
||||||
)
|
)
|
||||||
(
|
(self.data_dir / "cartridges" / "covers" / f"{game_id}.gif").unlink(
|
||||||
self.data_dir / "cartridges" / "animated_covers" / f"{game_id}.gif"
|
missing_ok=True
|
||||||
).unlink(missing_ok=True)
|
)
|
||||||
|
|
||||||
rmtree(self.cache_dir / "cartridges" / "deleted_covers", True)
|
rmtree(self.cache_dir / "cartridges" / "deleted_covers", True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user