Save deflated pixbuf data instead of .png
This commit is contained in:
@@ -90,7 +90,7 @@ def bottles_parser(parent_widget, action):
|
|||||||
values["last_played"] = 0
|
values["last_played"] = 0
|
||||||
|
|
||||||
if game["thumbnail"]:
|
if game["thumbnail"]:
|
||||||
save_cover(values, parent_widget, os.path.join(bottles_dir, "bottles", game["bottle"]["path"], "grids", game["thumbnail"].split(":")[1]))
|
values["pixbuf_options"] = save_cover(values, parent_widget, os.path.join(bottles_dir, "bottles", game["bottle"]["path"], "grids", game["thumbnail"].split(":")[1]))
|
||||||
|
|
||||||
bottles_games[values["game_id"]] = values
|
bottles_games[values["game_id"]] = values
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ def create_details_window(parent_widget, game_id = None):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if pixbuf != None:
|
if pixbuf != None:
|
||||||
save_cover(None, parent_widget, None, pixbuf, game_id)
|
values["pixbuf_options"] = save_cover(None, parent_widget, None, pixbuf, game_id)
|
||||||
|
|
||||||
values["name"] = final_name
|
values["name"] = final_name
|
||||||
values["executable"] = final_executable
|
values["executable"] = final_executable
|
||||||
|
|||||||
@@ -19,14 +19,17 @@
|
|||||||
|
|
||||||
def get_cover(game, parent_widget):
|
def get_cover(game, parent_widget):
|
||||||
from gi.repository import GdkPixbuf
|
from gi.repository import GdkPixbuf
|
||||||
import os
|
import os, zlib
|
||||||
|
|
||||||
cover_path = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers", game["game_id"] + ".png")
|
cover_path = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers", game["game_id"] + ".dat")
|
||||||
|
|
||||||
if os.path.isfile(cover_path) == False:
|
if os.path.isfile(cover_path) == False:
|
||||||
return parent_widget.placeholder_pixbuf
|
return parent_widget.placeholder_pixbuf
|
||||||
|
|
||||||
|
open_file = open(cover_path, "rb")
|
||||||
|
data = zlib.decompress(open_file.read())
|
||||||
|
open_file.close()
|
||||||
try:
|
try:
|
||||||
return GdkPixbuf.Pixbuf.new_from_file(cover_path)
|
return GdkPixbuf.Pixbuf.new_from_data(data, *parent_widget.games[game["game_id"]]["pixbuf_options"])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return parent_widget.placeholder_pixbuf
|
return parent_widget.placeholder_pixbuf
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ def heroic_parser(parent_widget, action):
|
|||||||
|
|
||||||
image_path = os.path.join(heroic_dir, "images-cache", hashlib.sha256((game["art_square"] + "?h=400&resize=1&w=300").encode()).hexdigest())
|
image_path = os.path.join(heroic_dir, "images-cache", hashlib.sha256((game["art_square"] + "?h=400&resize=1&w=300").encode()).hexdigest())
|
||||||
if os.path.exists(image_path):
|
if os.path.exists(image_path):
|
||||||
save_cover(values, parent_widget, image_path)
|
values["pixbuf_options"] = save_cover(values, parent_widget, image_path)
|
||||||
|
|
||||||
heroic_games[values["game_id"]] = values
|
heroic_games[values["game_id"]] = values
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ def heroic_parser(parent_widget, action):
|
|||||||
image_path = os.path.join(heroic_dir, "images-cache",
|
image_path = os.path.join(heroic_dir, "images-cache",
|
||||||
hashlib.sha256(game["art_square"].encode()).hexdigest())
|
hashlib.sha256(game["art_square"].encode()).hexdigest())
|
||||||
if os.path.exists(image_path):
|
if os.path.exists(image_path):
|
||||||
save_cover(values, parent_widget, image_path)
|
values["pixbuf_options"] = save_cover(values, parent_widget, image_path)
|
||||||
break
|
break
|
||||||
|
|
||||||
values["executable"] = "xdg-open heroic://launch/" + app_name
|
values["executable"] = "xdg-open heroic://launch/" + app_name
|
||||||
@@ -166,7 +166,7 @@ def heroic_parser(parent_widget, action):
|
|||||||
image_path = os.path.join(heroic_dir, "images-cache",
|
image_path = os.path.join(heroic_dir, "images-cache",
|
||||||
hashlib.sha256(item["art_square"].encode()).hexdigest())
|
hashlib.sha256(item["art_square"].encode()).hexdigest())
|
||||||
if os.path.exists(image_path):
|
if os.path.exists(image_path):
|
||||||
save_cover(values, parent_widget, image_path)
|
values["pixbuf_options"] = save_cover(values, parent_widget, image_path)
|
||||||
|
|
||||||
heroic_games[values["game_id"]] = values
|
heroic_games[values["game_id"]] = values
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
def save_cover(game, parent_widget, file_path, pixbuf = None, game_id = None):
|
def save_cover(game, parent_widget, file_path, pixbuf = None, game_id = None):
|
||||||
from gi.repository import GdkPixbuf, Gio
|
from gi.repository import GdkPixbuf
|
||||||
import os
|
import os, zlib
|
||||||
|
|
||||||
covers_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers")
|
covers_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers")
|
||||||
if os.path.exists(covers_dir) == False:
|
if os.path.exists(covers_dir) == False:
|
||||||
@@ -28,13 +28,12 @@ def save_cover(game, parent_widget, file_path, pixbuf = None, game_id = None):
|
|||||||
if game_id == None:
|
if game_id == None:
|
||||||
game_id = game["game_id"]
|
game_id = game["game_id"]
|
||||||
|
|
||||||
|
cover_path = os.path.join(covers_dir, game_id + ".dat")
|
||||||
|
|
||||||
if pixbuf == None:
|
if pixbuf == None:
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(file_path, 400, 600, False)
|
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(file_path, 600, 900, False)
|
||||||
|
|
||||||
def cover_callback(*args):
|
open_file = open(cover_path, "wb")
|
||||||
parent_widget.busy_games.remove(game_id)
|
open_file.write(zlib.compress(bytes(pixbuf.get_pixels()), 1))
|
||||||
parent_widget.update_games([game_id])
|
open_file.close()
|
||||||
|
return [pixbuf.get_colorspace(), pixbuf.get_has_alpha(), pixbuf.get_bits_per_sample(), pixbuf.get_width(), pixbuf.get_height(), pixbuf.get_rowstride()]
|
||||||
file = Gio.File.new_for_path(os.path.join(covers_dir, game_id + ".png"))
|
|
||||||
parent_widget.busy_games.append(game_id)
|
|
||||||
pixbuf.save_to_streamv_async(file.replace(None, False, Gio.FileCreateFlags.NONE), "png", None, None, None, cover_callback)
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ def steam_parser(parent_widget, action):
|
|||||||
values["last_played"] = 0
|
values["last_played"] = 0
|
||||||
|
|
||||||
if os.path.isfile(os.path.join(steam_dir, "appcache", "librarycache", values["appid"] + "_library_600x900.jpg")):
|
if os.path.isfile(os.path.join(steam_dir, "appcache", "librarycache", values["appid"] + "_library_600x900.jpg")):
|
||||||
save_cover(values, parent_widget, os.path.join(steam_dir, "appcache", "librarycache", values["appid"] + "_library_600x900.jpg"))
|
values["pixbuf_options"] = save_cover(values, parent_widget, os.path.join(steam_dir, "appcache", "librarycache", values["appid"] + "_library_600x900.jpg"))
|
||||||
|
|
||||||
steam_games[values["game_id"]] = values
|
steam_games[values["game_id"]] = values
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user