mirror of
https://github.com/lutris/lutris
synced 2024-11-02 11:48:38 +00:00
Add missing games section in the side bar
This commit is contained in:
parent
7eceeaeb8c
commit
af63d72bf0
5 changed files with 40 additions and 9 deletions
|
@ -9,7 +9,7 @@ from lutris.database.games import add_game
|
|||
from lutris.game import Game
|
||||
from lutris.gui.dialogs import ModalDialog
|
||||
from lutris.scanners.default_installers import DEFAULT_INSTALLERS
|
||||
from lutris.scanners.lutris import add_to_path_cache, get_path_cache
|
||||
from lutris.scanners.lutris import get_path_cache
|
||||
from lutris.scanners.tosec import clean_rom_name, guess_platform, search_tosec_by_md5
|
||||
from lutris.services.lutris import download_lutris_media
|
||||
from lutris.util.jobs import AsyncCall
|
||||
|
@ -199,5 +199,4 @@ class ImportGameDialog(ModalDialog):
|
|||
configpath=configpath
|
||||
)
|
||||
download_lutris_media(slug)
|
||||
add_to_path_cache(Game(game_id))
|
||||
return game_id
|
||||
|
|
|
@ -5,7 +5,6 @@ from gi.repository import Gtk, Pango
|
|||
from lutris.database.games import get_games
|
||||
from lutris.game import Game
|
||||
from lutris.gui.dialogs import ModalDialog, QuestionDialog
|
||||
from lutris.scanners.lutris import remove_from_path_cache
|
||||
from lutris.util.jobs import AsyncCall
|
||||
from lutris.util.log import logger
|
||||
from lutris.util.strings import gtk_safe, human_size
|
||||
|
@ -100,7 +99,6 @@ class UninstallGameDialog(ModalDialog):
|
|||
self.folder_label.set_markup(_("Uninstalling game and deleting files..."))
|
||||
else:
|
||||
self.folder_label.set_markup(_("Uninstalling game..."))
|
||||
remove_from_path_cache(self.game)
|
||||
self.game.remove(self.delete_files)
|
||||
self.destroy()
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ from lutris.gui.widgets.game_bar import GameBar
|
|||
from lutris.gui.widgets.gi_composites import GtkTemplate
|
||||
from lutris.gui.widgets.sidebar import LutrisSidebar
|
||||
from lutris.gui.widgets.utils import load_icon_theme, open_uri
|
||||
from lutris.scanners.lutris import remove_from_path_cache
|
||||
from lutris.scanners.lutris import remove_from_path_cache, add_to_path_cache, get_missing_game_ids
|
||||
# pylint: disable=no-member
|
||||
from lutris.services.base import BaseService
|
||||
from lutris.services.lutris import LutrisService
|
||||
|
@ -126,7 +126,7 @@ class LutrisWindow(Gtk.ApplicationWindow,
|
|||
self.game_bar = None
|
||||
self.revealer_box = Gtk.HBox(visible=True)
|
||||
self.game_revealer.add(self.revealer_box)
|
||||
|
||||
self.get_missing_games()
|
||||
self.connect("view-updated", self.update_store)
|
||||
GObject.add_emission_hook(BaseService, "service-login", self.on_service_login)
|
||||
GObject.add_emission_hook(BaseService, "service-logout", self.on_service_logout)
|
||||
|
@ -284,6 +284,17 @@ class LutrisWindow(Gtk.ApplicationWindow,
|
|||
"""Return a list of currently running games"""
|
||||
return games_db.get_games_by_ids([game.id for game in self.application.running_games])
|
||||
|
||||
def get_missing_games(self):
|
||||
missing_ids = get_missing_game_ids()
|
||||
missing_games = games_db.get_games_by_ids(missing_ids)
|
||||
if missing_games:
|
||||
self.sidebar.missing_row.show()
|
||||
else:
|
||||
if missing_ids:
|
||||
logger.warning("Path cache out of date? (%s IDs missing)", len(missing_ids))
|
||||
self.sidebar.missing_row.hide()
|
||||
return missing_games
|
||||
|
||||
def get_recent_games(self):
|
||||
"""Return a list of currently running games"""
|
||||
searches, _filters, excludes = self.get_sql_filters()
|
||||
|
@ -367,6 +378,7 @@ class LutrisWindow(Gtk.ApplicationWindow,
|
|||
return self.get_service_games(service_name)
|
||||
dynamic_categories = {
|
||||
"recent": self.get_recent_games,
|
||||
"missing": self.get_missing_games,
|
||||
"running": self.get_running_games,
|
||||
}
|
||||
if self.filters.get("dynamic_category") in dynamic_categories:
|
||||
|
@ -844,6 +856,7 @@ class LutrisWindow(Gtk.ApplicationWindow,
|
|||
|
||||
def on_game_updated(self, game):
|
||||
"""Updates an individual entry in the view when a game is updated"""
|
||||
add_to_path_cache(game)
|
||||
if game.appid and self.service:
|
||||
db_game = ServiceGameCollection.get_game(self.service.id, game.appid)
|
||||
else:
|
||||
|
@ -878,8 +891,8 @@ class LutrisWindow(Gtk.ApplicationWindow,
|
|||
def on_game_removed(self, game):
|
||||
"""Simple method used to refresh the view"""
|
||||
remove_from_path_cache(game)
|
||||
self.get_missing_games()
|
||||
self.emit("view-updated")
|
||||
|
||||
return True
|
||||
|
||||
@watch_errors()
|
||||
|
|
|
@ -281,6 +281,7 @@ class LutrisSidebar(Gtk.ListBox):
|
|||
self.categories = None
|
||||
# A dummy objects that allows inspecting why/when we have a show() call on the object.
|
||||
self.running_row = DummyRow()
|
||||
self.missing_row = DummyRow()
|
||||
if selected:
|
||||
self.selected_row_type, self.selected_row_id = selected.split(":")
|
||||
else:
|
||||
|
@ -356,6 +357,13 @@ class LutrisSidebar(Gtk.ListBox):
|
|||
Gtk.Image.new_from_icon_name("favorite-symbolic", Gtk.IconSize.MENU)
|
||||
)
|
||||
)
|
||||
self.missing_row = SidebarRow(
|
||||
"missing",
|
||||
"dynamic_category",
|
||||
_("Missing"),
|
||||
Gtk.Image.new_from_icon_name("dialog-warning-symbolic", Gtk.IconSize.MENU)
|
||||
)
|
||||
self.add(self.missing_row)
|
||||
|
||||
self.running_row = SidebarRow(
|
||||
"running",
|
||||
|
|
|
@ -148,6 +148,8 @@ def build_path_cache(recreate=False):
|
|||
|
||||
|
||||
def add_to_path_cache(game):
|
||||
"""Add or update the path of a game in the cache"""
|
||||
logger.debug("Adding %s to path cache", game)
|
||||
path = get_path_from_config(game)
|
||||
if not path:
|
||||
logger.warning("No path for %s", game)
|
||||
|
@ -159,10 +161,12 @@ def add_to_path_cache(game):
|
|||
|
||||
|
||||
def remove_from_path_cache(game):
|
||||
logger.debug("Removing %s from path cache", game)
|
||||
current_cache = get_path_cache()
|
||||
if game.id not in current_cache:
|
||||
if str(game.id) not in current_cache:
|
||||
logger.warning("Game %s (id=%s) not in cache path", game, game.id)
|
||||
return
|
||||
del current_cache[game.id]
|
||||
del current_cache[str(game.id)]
|
||||
with open(GAME_PATH_CACHE_PATH, "w", encoding="utf-8") as cache_file:
|
||||
json.dump(current_cache, cache_file, indent=2)
|
||||
|
||||
|
@ -171,3 +175,12 @@ def get_path_cache():
|
|||
"""Return the contents of the path cache file"""
|
||||
with open(GAME_PATH_CACHE_PATH, encoding="utf-8") as cache_file:
|
||||
return json.load(cache_file)
|
||||
|
||||
|
||||
def get_missing_game_ids():
|
||||
"""Return a list of IDs for games that can't be found"""
|
||||
missing_ids = []
|
||||
for game_id, path in get_path_cache().items():
|
||||
if not os.path.exists(path):
|
||||
missing_ids.append(game_id)
|
||||
return missing_ids
|
||||
|
|
Loading…
Reference in a new issue