Remove missing games - closes #85

This commit is contained in:
kramo
2023-08-15 20:11:06 +02:00
parent 8ca264ff95
commit 5abf3f300d
5 changed files with 60 additions and 1 deletions

View File

@@ -85,6 +85,19 @@ template $PreferencesWindow : Adw.PreferencesWindow {
title: _("Import"); title: _("Import");
icon-name: "document-save-symbolic"; icon-name: "document-save-symbolic";
Adw.PreferencesGroup import_behavior_group {
title: _("Behavior");
Adw.ActionRow {
title: _("Remove Missing Games");
activatable-widget: remove_missing_switch;
Switch remove_missing_switch {
valign: center;
}
}
}
Adw.PreferencesGroup sources_group { Adw.PreferencesGroup sources_group {
title: _("Sources"); title: _("Sources");

View File

@@ -10,6 +10,9 @@
<key name="high-quality-images" type="b"> <key name="high-quality-images" type="b">
<default>false</default> <default>false</default>
</key> </key>
<key name="remove-missing" type="b">
<default>true</default>
</key>
<key name="steam" type="b"> <key name="steam" type="b">
<default>true</default> <default>true</default>
</key> </key>

View File

@@ -49,8 +49,15 @@ class Importer(ErrorProducer):
n_pipelines_done: int = 0 n_pipelines_done: int = 0
game_pipelines: set[Pipeline] = None game_pipelines: set[Pipeline] = None
removed_games: set[Game] = set()
def __init__(self): def __init__(self):
super().__init__() super().__init__()
# TODO: make this stateful
shared.store.new_game_ids = set()
shared.store.duplicate_game_ids = set()
self.game_pipelines = set() self.game_pipelines = set()
self.sources = set() self.sources = set()
@@ -217,9 +224,36 @@ class Importer(ErrorProducer):
if self.finished: if self.finished:
self.import_callback() self.import_callback()
def remove_games(self):
"""Set removed to True for missing games"""
if not shared.schema.get_boolean("remove-missing"):
return
for game in shared.store:
if game.removed:
continue
if game.source == "imported":
continue
if not shared.schema.get_boolean(game.base_source):
continue
if game.game_id in shared.store.duplicate_game_ids:
continue
if game.game_id in shared.store.new_game_ids:
continue
logging.debug("Removing missing game %s (%s)", game.name, game.game_id)
game.removed = True
game.save()
game.update()
self.removed_games.add(game)
def import_callback(self): def import_callback(self):
"""Callback called when importing has finished""" """Callback called when importing has finished"""
logging.info("Import done") logging.info("Import done")
self.remove_games()
shared.store.new_game_ids = set()
shared.store.duplicate_game_ids = set()
self.import_dialog.close() self.import_dialog.close()
self.summary_toast = self.create_summary_toast() self.summary_toast = self.create_summary_toast()
self.create_error_dialog() self.create_error_dialog()

View File

@@ -52,6 +52,8 @@ class PreferencesWindow(Adw.PreferencesWindow):
cover_launches_game_switch = Gtk.Template.Child() cover_launches_game_switch = Gtk.Template.Child()
high_quality_images_switch = Gtk.Template.Child() high_quality_images_switch = Gtk.Template.Child()
remove_missing_switch = Gtk.Template.Child()
steam_expander_row = Gtk.Template.Child() steam_expander_row = Gtk.Template.Child()
steam_data_action_row = Gtk.Template.Child() steam_data_action_row = Gtk.Template.Child()
steam_data_file_chooser_button = Gtk.Template.Child() steam_data_file_chooser_button = Gtk.Template.Child()
@@ -184,6 +186,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
"exit-after-launch", "exit-after-launch",
"cover-launches-game", "cover-launches-game",
"high-quality-images", "high-quality-images",
"remove-missing",
"lutris-import-steam", "lutris-import-steam",
"lutris-import-flatpak", "lutris-import-flatpak",
"heroic-import-epic", "heroic-import-epic",

View File

@@ -18,7 +18,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import logging import logging
from typing import MutableMapping, Generator, Any from typing import Any, Generator, MutableMapping
from src import shared from src import shared
from src.game import Game from src.game import Game
@@ -33,12 +33,16 @@ class Store:
pipeline_managers: set[Manager] pipeline_managers: set[Manager]
pipelines: dict[str, Pipeline] pipelines: dict[str, Pipeline]
source_games: MutableMapping[str, MutableMapping[str, Game]] source_games: MutableMapping[str, MutableMapping[str, Game]]
new_game_ids: set[str]
duplicate_game_ids: set[str]
def __init__(self) -> None: def __init__(self) -> None:
self.managers = {} self.managers = {}
self.pipeline_managers = set() self.pipeline_managers = set()
self.pipelines = {} self.pipelines = {}
self.source_games = {} self.source_games = {}
self.new_game_ids = set()
self.duplicate_game_ids = set()
def __contains__(self, obj: object) -> bool: def __contains__(self, obj: object) -> bool:
"""Check if the game is present in the store with the `in` keyword""" """Check if the game is present in the store with the `in` keyword"""
@@ -114,6 +118,7 @@ class Store:
if not stored_game: if not stored_game:
# New game, do as normal # New game, do as normal
logging.debug("New store game %s (%s)", game.name, game.game_id) logging.debug("New store game %s (%s)", game.name, game.game_id)
self.new_game_ids.add(game.game_id)
elif stored_game.removed: elif stored_game.removed:
# Will replace a removed game, cleanup its remains # Will replace a removed game, cleanup its remains
logging.debug( logging.debug(
@@ -125,6 +130,7 @@ class Store:
else: else:
# Duplicate game, ignore it # Duplicate game, ignore it
logging.debug("Duplicate store game %s (%s)", game.name, game.game_id) logging.debug("Duplicate store game %s (%s)", game.name, game.game_id)
self.duplicate_game_ids.add(game.game_id)
return None return None
# Connect signals # Connect signals