[gnome-games/wip/exalm/rebrand: 18/102] database: Stop using DummyPlatform
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/rebrand: 18/102] database: Stop using DummyPlatform
- Date: Thu, 8 Apr 2021 21:29:43 +0000 (UTC)
commit 7e7c4fbad1b1159a2dba0bfbb98b3d2a68229b91
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Mon Mar 29 20:14:35 2021 +0500
database: Stop using DummyPlatform
Just remove the games we couldn't load immediately.
src/database/database-error.vala | 1 +
src/database/database.vala | 33 ++++++++++++++++++++++++++-------
2 files changed, 27 insertions(+), 7 deletions(-)
---
diff --git a/src/database/database-error.vala b/src/database/database-error.vala
index 279107ee..26f9ab38 100644
--- a/src/database/database-error.vala
+++ b/src/database/database-error.vala
@@ -5,4 +5,5 @@ private errordomain Games.DatabaseError {
EXECUTION_FAILED,
PREPARATION_FAILED,
BINDING_FAILED,
+ INVALID_GAME,
}
diff --git a/src/database/database.vala b/src/database/database.vala
index 1bac2ee2..330fcca9 100644
--- a/src/database/database.vala
+++ b/src/database/database.vala
@@ -400,9 +400,7 @@ private class Games.Database : Object {
store_game_uri (uid, uri);
}
- public bool remove_game (string uri, Game game) throws Error {
- var uid = game.uid.to_string ();
-
+ private bool remove_game_by_uid (string uri, string uid) throws Error {
delete_uri_query.reset ();
bind_text (delete_uri_query, "$URI", uri);
@@ -428,6 +426,10 @@ private class Games.Database : Object {
return true;
}
+ public bool remove_game (string uri, Game game) throws Error {
+ return remove_game_by_uid (uri, game.uid.to_string ());
+ }
+
private Game get_cached_game (string uid) throws Error {
get_cached_game_query.reset ();
bind_text (get_cached_game_query, "$UID", uid);
@@ -446,9 +448,16 @@ private class Games.Database : Object {
throw new DatabaseError.EXECUTION_FAILED ("Couldn't get game for uid (%s)", uid);
}
+ private struct InvalidGame {
+ string uid;
+ string uri;
+ }
+
public void list_cached_games (GameCallback game_callback) throws Error {
list_cached_games_query.reset ();
+ InvalidGame[] invalid_games = {};
+
while (list_cached_games_query.step () == Sqlite.ROW) {
var uid = list_cached_games_query.column_text (0);
var uri = list_cached_games_query.column_text (1);
@@ -458,21 +467,31 @@ private class Games.Database : Object {
var is_favorite = list_cached_games_query.column_int (5);
var last_played = list_cached_games_query.column_text (6);
- var game = create_game (uid, uri, title, platform, media_set, is_favorite,
last_played);
- game_callback (game);
+ try {
+ var game = create_game (uid, uri, title, platform, media_set, is_favorite,
last_played);
+ game_callback (game);
+ } catch (DatabaseError.INVALID_GAME error) {
+ critical ("Couldn't load game %s: %s", title, error.message);
+
+ InvalidGame game = { uid, uri };
+ invalid_games += game;
+ }
}
+
+ foreach (var game in invalid_games)
+ remove_game_by_uid (game.uri, game.uid);
}
private Game create_game (string uid, string uri, string title,
string platform, string? media_set,
- int is_favorite, string? last_played) {
+ int is_favorite, string? last_played) throws DatabaseError {
var game_uid = new Uid (uid);
var game_uri = new Uri (uri);
var game_title = new GenericTitle (title);
var game_platform = PlatformRegister.get_register ().get_platform (platform);
if (game_platform == null)
- game_platform = new DummyPlatform ();
+ throw new DatabaseError.INVALID_GAME ("Unknown platform: %s", platform);
var game = new Game (game_uid, game_uri, game_title, game_platform);
game.is_favorite = is_favorite == 1;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]