From 08729a1dbae809166abde493f8660ab31c6e447f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lidwin?= Date: Mon, 30 Jan 2023 18:18:38 +0100 Subject: [PATCH 1/2] Improve images import from Heroic --- src/utils/heroic_parser.py | 58 ++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/src/utils/heroic_parser.py b/src/utils/heroic_parser.py index 505be4b..8a87441 100644 --- a/src/utils/heroic_parser.py +++ b/src/utils/heroic_parser.py @@ -18,7 +18,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later def heroic_parser(parent_widget, action): - import os, json, time + import os, json, time, hashlib from gi.repository import Gtk, GLib @@ -46,7 +46,8 @@ def heroic_parser(parent_widget, action): if response == "choose_folder": choose_folder(widget) - create_dialog(parent_widget, _("Couldn't Import Games"), _("Heroic directory cannot be found."), "choose_folder", _("Set Heroic Location")).connect("response", response) + create_dialog(parent_widget, _("Couldn't Import Games"), _("Heroic directory cannot be found."), + "choose_folder", _("Set Heroic Location")).connect("response", response) if os.path.exists(os.path.join(heroic_dir, "config.json")) == True: pass @@ -58,21 +59,28 @@ def heroic_parser(parent_widget, action): current_time = int(time.time()) # Import Epic games - if schema.get_boolean("heroic-import-epic") == False: + if not schema.get_boolean("heroic-import-epic"): pass - elif os.path.exists(os.path.join(heroic_dir, "lib-cache", "installInfo.json")) == True: + elif os.path.exists(os.path.join(heroic_dir, "lib-cache", "installInfo.json")) and os.path.exists( + os.path.join(heroic_dir, "lib-cache", "library.json")): open_file = open(os.path.join(heroic_dir, "lib-cache", "installInfo.json"), "r") data = open_file.read() open_file.close() installInfo = json.loads(data) + + open_file = open(os.path.join(heroic_dir, "lib-cache", "library.json"), "r") + data = open_file.read() + library = json.loads(data) + open_file.close() for item in installInfo: - if installInfo[item]["install"] != None: + if installInfo[item].get("install") is not None: values = {} app_name = installInfo[item]["game"]["app_name"] values["game_id"] = "heroic_epic_" + app_name - if values["game_id"] in parent_widget.games and "removed" not in parent_widget.games[values["game_id"]].keys(): + if values["game_id"] in parent_widget.games and "removed" not in parent_widget.games[ + values["game_id"]].keys(): continue values["name"] = installInfo[item]["game"]["title"] @@ -81,15 +89,22 @@ def heroic_parser(parent_widget, action): values["source"] = "heroic_epic" values["added"] = current_time values["last_played"] = 0 - if os.path.isfile(os.path.join(heroic_dir, "icons", app_name + ".jpg")) == True: - values["pixbuf_options"] = save_cover(values, parent_widget, os.path.join(os.path.join(heroic_dir, "icons", app_name + ".jpg"))) + for game in library["library"]: + if game["app_name"] == app_name: + 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): + values["pixbuf_options"] = save_cover(values, parent_widget, image_path) + + break heroic_games[values["game_id"]] = values # Import GOG games - if schema.get_boolean("heroic-import-gog") == False: + if not schema.get_boolean("heroic-import-gog"): pass - elif os.path.exists(os.path.join(heroic_dir, "gog_store", "installed.json")) == True: + elif os.path.exists(os.path.join(heroic_dir, "gog_store", "installed.json")): open_file = open(os.path.join(heroic_dir, "gog_store", "installed.json"), "r") data = open_file.read() open_file.close() @@ -100,8 +115,9 @@ def heroic_parser(parent_widget, action): values["game_id"] = "heroic_gog_" + app_name - if values["game_id"] in parent_widget.games and "removed" not in parent_widget.games[values["game_id"]].keys(): - continue + if values["game_id"] in parent_widget.games and "removed" not in parent_widget.games[ + values["game_id"]].keys(): + continue # Get game title from library.json as it's not present in installed.json open_file = open(os.path.join(heroic_dir, "gog_store", "library.json"), "r") @@ -111,6 +127,10 @@ def heroic_parser(parent_widget, action): for game in library["games"]: if game["app_name"] == app_name: values["name"] = game["title"] + image_path = os.path.join(heroic_dir, "images-cache", + hashlib.sha256(game["art_square"].encode()).hexdigest()) + if os.path.exists(image_path): + values["pixbuf_options"] = save_cover(values, parent_widget, image_path) break values["executable"] = "xdg-open heroic://launch/" + app_name @@ -118,8 +138,6 @@ def heroic_parser(parent_widget, action): values["source"] = "heroic_gog" values["added"] = current_time values["last_played"] = 0 - if os.path.isfile(os.path.join(heroic_dir, "icons", app_name + ".jpg")) == True: - values["pixbuf_options"] = save_cover(values, parent_widget, os.path.join(os.path.join(heroic_dir, "icons", app_name + ".jpg"))) heroic_games[values["game_id"]] = values # Import sideloaded games @@ -136,7 +154,8 @@ def heroic_parser(parent_widget, action): values["game_id"] = "heroic_sideload_" + app_name - if values["game_id"] in parent_widget.games and "removed" not in parent_widget.games[values["game_id"]].keys(): + if values["game_id"] in parent_widget.games and "removed" not in parent_widget.games[ + values["game_id"]].keys(): continue values["name"] = item["title"] @@ -145,8 +164,10 @@ def heroic_parser(parent_widget, action): values["source"] = "heroic_sideload" values["added"] = current_time values["last_played"] = 0 - if os.path.isfile(os.path.join(heroic_dir, "icons", app_name + ".jpg")) == True: - values["pixbuf_options"] = save_cover(values, parent_widget, os.path.join(os.path.join(heroic_dir, "icons", app_name + ".jpg"))) + image_path = os.path.join(heroic_dir, "images-cache", + hashlib.sha256(item["art_square"].encode()).hexdigest()) + if os.path.exists(image_path): + values["pixbuf_options"] = save_cover(values, parent_widget, image_path) heroic_games[values["game_id"]] = values if len(heroic_games) == 0: @@ -154,5 +175,6 @@ def heroic_parser(parent_widget, action): elif len(heroic_games) == 1: create_dialog(parent_widget, _("Heroic Games Imported"), _("Successfully imported 1 game.")) elif len(heroic_games) > 1: - create_dialog(parent_widget, _("Heroic Games Imported"), _("Successfully imported") + " " + str(len(heroic_games)) + " " + _("games.")) + create_dialog(parent_widget, _("Heroic Games Imported"), + _("Successfully imported") + " " + str(len(heroic_games)) + " " + _("games.")) return heroic_games From 7351d2646941d46270d976cf56fdb5ac4b7ceb70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lidwin?= Date: Mon, 30 Jan 2023 18:19:29 +0100 Subject: [PATCH 2/2] Fix flatpak manifest --- hu.kramo.GameShelf.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hu.kramo.GameShelf.json b/hu.kramo.GameShelf.json index 94c44d0..2eae3e9 100644 --- a/hu.kramo.GameShelf.json +++ b/hu.kramo.GameShelf.json @@ -32,8 +32,8 @@ "buildsystem" : "meson", "sources" : [ { - "type" : "git", - "url" : "file:///home/kramo/Projects" + "type" : "dir", + "path" : "." } ] }