🐛 Fix game import not refreshing remove covers
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
from src import shared # pylint: disable=no-name-in-module
|
from src import shared # pylint: disable=no-name-in-module
|
||||||
from src.game import Game
|
from src.game import Game
|
||||||
from src.store.managers.manager import Manager
|
from src.store.managers.manager import Manager
|
||||||
@@ -23,35 +25,43 @@ class Store:
|
|||||||
def manager_to_pipeline(self, manager_type: type[Manager]):
|
def manager_to_pipeline(self, manager_type: type[Manager]):
|
||||||
self.managers[manager_type][1] = True
|
self.managers[manager_type][1] = True
|
||||||
|
|
||||||
def add_game(
|
def cleanup_game(self, game: Game) -> None:
|
||||||
self, game: Game, additional_data: dict, replace=False
|
"""Remove a game's files"""
|
||||||
) -> Pipeline | None:
|
for path in (
|
||||||
"""Add a game to the app if not already there
|
shared.games_dir / f"{game.game_id}.json",
|
||||||
|
shared.covers_dir / f"{game.game_id}.tiff",
|
||||||
|
shared.covers_dir / f"{game.game_id}.gif",
|
||||||
|
):
|
||||||
|
path.unlink(missing_ok=True)
|
||||||
|
|
||||||
:param replace bool: Replace the game if it already exists
|
def add_game(self, game: Game, additional_data: dict) -> Pipeline | None:
|
||||||
"""
|
"""Add a game to the app"""
|
||||||
|
|
||||||
# Ignore games from a newer spec version
|
# Ignore games from a newer spec version
|
||||||
if game.version > shared.SPEC_VERSION:
|
if game.version > shared.SPEC_VERSION:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Ignore games that are already there
|
# Scanned game is already removed, just clean it up
|
||||||
if (
|
if game.removed:
|
||||||
game.game_id in self.games
|
self.cleanup_game(game)
|
||||||
and not self.games[game.game_id].removed
|
|
||||||
and not replace
|
|
||||||
):
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Cleanup removed games
|
# Handle game duplicates
|
||||||
if game.removed:
|
stored_game = self.games.get(game.game_id)
|
||||||
# TODO: come back to this later
|
if not stored_game:
|
||||||
for path in (
|
# New game, do as normal
|
||||||
shared.games_dir / f"{game.game_id}.json",
|
logging.debug("New store game %s (%s)", game.name, game.game_id)
|
||||||
shared.covers_dir / f"{game.game_id}.tiff",
|
elif stored_game.removed:
|
||||||
shared.covers_dir / f"{game.game_id}.gif",
|
# Will replace a removed game, cleanup its remains
|
||||||
):
|
logging.debug(
|
||||||
path.unlink(missing_ok=True)
|
"New store game %s (%s) (replacing a removed one)",
|
||||||
|
game.name,
|
||||||
|
game.game_id,
|
||||||
|
)
|
||||||
|
self.cleanup_game(stored_game)
|
||||||
|
else:
|
||||||
|
# Duplicate game, ignore it
|
||||||
|
logging.debug("Duplicate store game %s (%s)", game.name, game.game_id)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Connect signals
|
# Connect signals
|
||||||
|
|||||||
Reference in New Issue
Block a user