Save covers directly into covers dir
Instead of saving the pixbuf of the new cover into a temporary file and then copy into covers dir, save it directly to there. Without this, a lot of temporary files are created on import, which remain on the system even after the application is closed.
This commit is contained in:
@@ -240,6 +240,7 @@ class DetailsDialog(Adw.Dialog):
|
|||||||
save_cover(
|
save_cover(
|
||||||
self.game.game_id,
|
self.game.game_id,
|
||||||
self.game_cover.path,
|
self.game_cover.path,
|
||||||
|
self.game_cover.pixbuf,
|
||||||
)
|
)
|
||||||
|
|
||||||
shared.store.add_game(self.game, {}, run_pipeline=False)
|
shared.store.add_game(self.game, {}, run_pipeline=False)
|
||||||
@@ -304,17 +305,17 @@ class DetailsDialog(Adw.Dialog):
|
|||||||
except UnidentifiedImageError:
|
except UnidentifiedImageError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not new_path:
|
if new_path:
|
||||||
new_path = convert_cover(
|
self.game_cover.new_cover(new_path)
|
||||||
|
else:
|
||||||
|
self.game_cover.new_cover(
|
||||||
pixbuf=shared.store.managers[CoverManager].composite_cover(
|
pixbuf=shared.store.managers[CoverManager].composite_cover(
|
||||||
Path(path)
|
Path(path)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if new_path:
|
self.cover_button_delete_revealer.set_reveal_child(True)
|
||||||
self.game_cover.new_cover(new_path)
|
self.cover_changed = True
|
||||||
self.cover_button_delete_revealer.set_reveal_child(True)
|
|
||||||
self.cover_changed = True
|
|
||||||
|
|
||||||
self.toggle_loading()
|
self.toggle_loading()
|
||||||
|
|
||||||
|
|||||||
@@ -45,12 +45,22 @@ class GameCover:
|
|||||||
self.pictures = pictures
|
self.pictures = pictures
|
||||||
self.new_cover(path)
|
self.new_cover(path)
|
||||||
|
|
||||||
def new_cover(self, path: Optional[Path] = None) -> None:
|
def new_cover(
|
||||||
|
self,
|
||||||
|
path: Optional[Path] = None,
|
||||||
|
pixbuf: Optional[GdkPixbuf.Pixbuf] = None
|
||||||
|
) -> None:
|
||||||
self.animation = None
|
self.animation = None
|
||||||
self.texture = None
|
self.texture = None
|
||||||
self.blurred = None
|
self.blurred = None
|
||||||
self.luminance = None
|
self.luminance = None
|
||||||
self.path = path
|
self.path = path
|
||||||
|
self.pixbuf = pixbuf
|
||||||
|
|
||||||
|
if pixbuf:
|
||||||
|
self.texture = Gdk.Texture.new_for_pixbuf(pixbuf)
|
||||||
|
self.set_texture(self.texture)
|
||||||
|
return
|
||||||
|
|
||||||
if path:
|
if path:
|
||||||
if path.suffix == ".gif":
|
if path.suffix == ".gif":
|
||||||
|
|||||||
@@ -192,7 +192,5 @@ class CoverManager(Manager):
|
|||||||
|
|
||||||
save_cover(
|
save_cover(
|
||||||
game.game_id,
|
game.game_id,
|
||||||
convert_cover(
|
pixbuf=self.composite_cover(image_path, **composite_kwargs),
|
||||||
pixbuf=self.composite_cover(image_path, **composite_kwargs)
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ from cartridges import shared
|
|||||||
|
|
||||||
def convert_cover(
|
def convert_cover(
|
||||||
cover_path: Optional[Path] = None,
|
cover_path: Optional[Path] = None,
|
||||||
pixbuf: Optional[GdkPixbuf.Pixbuf] = None,
|
|
||||||
resize: bool = True,
|
resize: bool = True,
|
||||||
) -> Optional[Path]:
|
) -> Optional[Path]:
|
||||||
if not cover_path and not pixbuf:
|
if not cover_path and not pixbuf:
|
||||||
@@ -44,10 +43,6 @@ def convert_cover(
|
|||||||
if not resize and cover_path and cover_path.suffix.lower()[1:] in pixbuf_extensions:
|
if not resize and cover_path and cover_path.suffix.lower()[1:] in pixbuf_extensions:
|
||||||
return cover_path
|
return cover_path
|
||||||
|
|
||||||
if pixbuf:
|
|
||||||
cover_path = Path(Gio.File.new_tmp("XXXXXX.tiff")[0].get_path())
|
|
||||||
pixbuf.savev(str(cover_path), "tiff", ["compression"], ["1"])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with Image.open(cover_path) as image:
|
with Image.open(cover_path) as image:
|
||||||
if getattr(image, "is_animated", False):
|
if getattr(image, "is_animated", False):
|
||||||
@@ -88,7 +83,11 @@ def convert_cover(
|
|||||||
return tmp_path
|
return tmp_path
|
||||||
|
|
||||||
|
|
||||||
def save_cover(game_id: str, cover_path: Path) -> None:
|
def save_cover(
|
||||||
|
game_id: str,
|
||||||
|
cover_path: Optional[Path] = None,
|
||||||
|
pixbuf: Optional[GdkPixbuf.Pixbuf] = None,
|
||||||
|
) -> None:
|
||||||
shared.covers_dir.mkdir(parents=True, exist_ok=True)
|
shared.covers_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
animated_path = shared.covers_dir / f"{game_id}.gif"
|
animated_path = shared.covers_dir / f"{game_id}.gif"
|
||||||
@@ -98,7 +97,15 @@ def save_cover(game_id: str, cover_path: Path) -> None:
|
|||||||
animated_path.unlink(missing_ok=True)
|
animated_path.unlink(missing_ok=True)
|
||||||
static_path.unlink(missing_ok=True)
|
static_path.unlink(missing_ok=True)
|
||||||
|
|
||||||
if not cover_path:
|
if not cover_path and not pixbuf:
|
||||||
|
return
|
||||||
|
|
||||||
|
if pixbuf:
|
||||||
|
pixbuf.savev(str(static_path), "tiff", ["compression"], ["1"])
|
||||||
|
|
||||||
|
if game_id in shared.win.game_covers:
|
||||||
|
shared.win.game_covers[game_id].new_cover(static_path)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
copyfile(
|
copyfile(
|
||||||
|
|||||||
Reference in New Issue
Block a user