This commit is contained in:
kramo
2023-04-19 22:26:54 +02:00
parent 3cfb3c5028
commit 2b2b7e0c75
6 changed files with 24 additions and 52 deletions

View File

@@ -17,9 +17,9 @@
# #
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import hashlib
import json import json
import os import os
from hashlib import sha256
from pathlib import Path from pathlib import Path
from time import time from time import time
@@ -102,7 +102,7 @@ def heroic_importer(win):
image_path = ( image_path = (
heroic_dir heroic_dir
/ "images-cache" / "images-cache"
/ hashlib.sha256( / sha256(
(f'{game["art_square"]}?h=400&resize=1&w=300').encode() (f'{game["art_square"]}?h=400&resize=1&w=300').encode()
).hexdigest() ).hexdigest()
) )
@@ -143,7 +143,7 @@ def heroic_importer(win):
image_path = ( image_path = (
heroic_dir heroic_dir
/ "images-cache" / "images-cache"
/ hashlib.sha256(game["art_square"].encode()).hexdigest() / sha256(game["art_square"].encode()).hexdigest()
) )
values["executable"] = ( values["executable"] = (
@@ -193,7 +193,7 @@ def heroic_importer(win):
image_path = ( image_path = (
heroic_dir heroic_dir
/ "images-cache" / "images-cache"
/ hashlib.sha256(item["art_square"].encode()).hexdigest() / sha256(item["art_square"].encode()).hexdigest()
) )
importer.save_game(values, image_path if image_path.exists() else None) importer.save_game(values, image_path if image_path.exists() else None)

View File

@@ -171,7 +171,7 @@ def itch_importer(win):
ON ON
caves.game_id = games.id caves.game_id = games.id
; ;
""" """
connection = connect(database_tmp_path) connection = connect(database_tmp_path)
cursor = connection.execute(db_request) cursor = connection.execute(db_request)

View File

@@ -96,7 +96,7 @@ def lutris_importer(win):
AND configPath IS NOT NULL AND configPath IS NOT NULL
AND installed IS TRUE AND installed IS TRUE
; ;
""" """
connection = connect(database_tmp_path) connection = connect(database_tmp_path)
cursor = connection.execute(db_request) cursor = connection.execute(db_request)

View File

@@ -30,7 +30,6 @@ cartridges_sources = [
'importers/itch_importer.py', 'importers/itch_importer.py',
'utils/importer.py', 'utils/importer.py',
'utils/steamgriddb.py', 'utils/steamgriddb.py',
'utils/get_games.py',
'utils/save_cover.py', 'utils/save_cover.py',
'utils/create_dialog.py', 'utils/create_dialog.py',
'utils/create_details_window.py', 'utils/create_details_window.py',

View File

@@ -1,33 +0,0 @@
# get_games.py
#
# Copyright 2022-2023 kramo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
import json
def get_games(win):
games = {}
if not win.games_dir.exists():
return games
for open_file in win.games_dir.iterdir():
data = json.load(open_file.open())
games[data["game_id"]] = data
return games

View File

@@ -17,15 +17,15 @@
# #
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import datetime import json
import os import os
from datetime import datetime
from pathlib import Path from pathlib import Path
from struct import unpack_from from struct import unpack_from
from gi.repository import Adw, Gdk, GdkPixbuf, Gio, GLib, Gtk from gi.repository import Adw, Gdk, GdkPixbuf, Gio, GLib, Gtk
from .game import Game from .game import Game
from .get_games import get_games
@Gtk.Template(resource_path="/hu/kramo/Cartridges/gtk/window.ui") @Gtk.Template(resource_path="/hu/kramo/Cartridges/gtk/window.ui")
@@ -107,12 +107,6 @@ class CartridgesWindow(Adw.ApplicationWindow):
) )
self.image_size = (200 * scale_factor, 300 * scale_factor) self.image_size = (200 * scale_factor, 300 * scale_factor)
for game_id, game in get_games(self).items():
if game.get("removed"):
(self.games_dir / f"{game_id}.json").unlink(missing_ok=True)
(self.covers_dir / f"{game_id}.tiff").unlink(missing_ok=True)
(self.covers_dir / f"{game_id}.gif").unlink(missing_ok=True)
self.details_view.set_measure_overlay(self.details_view_box, True) self.details_view.set_measure_overlay(self.details_view_box, True)
self.details_view.set_clip_overlay(self.details_view_box, False) self.details_view.set_clip_overlay(self.details_view_box, False)
@@ -122,8 +116,20 @@ class CartridgesWindow(Adw.ApplicationWindow):
self.library.set_sort_func(self.sort_func) self.library.set_sort_func(self.sort_func)
self.hidden_library.set_sort_func(self.sort_func) self.hidden_library.set_sort_func(self.sort_func)
for game in get_games(self).values(): games = {}
Game(self, game).update()
if self.games_dir.exists():
for open_file in self.games_dir.iterdir():
data = json.load(open_file.open())
games[data["game_id"]] = data
for game_id, game in games.items():
if game.get("removed"):
(self.games_dir / f"{game_id}.json").unlink(missing_ok=True)
(self.covers_dir / f"{game_id}.tiff").unlink(missing_ok=True)
(self.covers_dir / f"{game_id}.gif").unlink(missing_ok=True)
else:
Game(self, game).update()
self.set_library_child() self.set_library_child()
@@ -193,8 +199,8 @@ class CartridgesWindow(Adw.ApplicationWindow):
self.active_game = game self.active_game = game
def get_time(self, timestamp): def get_time(self, timestamp):
date = datetime.datetime.fromtimestamp(timestamp) date = datetime.fromtimestamp(timestamp)
days_no = (datetime.datetime.today() - date).days days_no = (datetime.today() - date).days
if days_no == 0: if days_no == 0:
return _("Today") return _("Today")