[gnome-games/wip/exalm/uid: 6/13] Stop using Uid



commit 4e1dfc7ac009a012311dea44fece5d5c776a58b0
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Feb 21 18:17:27 2020 +0500

    Stop using Uid
    
    Just use strings.

 plugins/libretro/src/libretro-plugin.vala       |  2 +-
 plugins/ms-dos/src/ms-dos-plugin.vala           |  2 +-
 plugins/nintendo-ds/src/nintendo-ds-plugin.vala |  2 +-
 plugins/playstation/src/playstation-plugin.vala |  2 +-
 src/core/cover-loader.vala                      |  2 +-
 src/core/game-collection.vala                   | 39 ++++---------------------
 src/core/game-model.vala                        | 10 +------
 src/core/game.vala                              | 37 ++++-------------------
 src/core/savestate.vala                         |  5 ++--
 src/database/database.vala                      |  6 ++--
 src/retro/retro-runner-builder.vala             |  2 +-
 src/retro/retro-runner-factory.vala             |  2 +-
 src/retro/retro-runner.vala                     |  3 +-
 13 files changed, 24 insertions(+), 90 deletions(-)
---
diff --git a/plugins/libretro/src/libretro-plugin.vala b/plugins/libretro/src/libretro-plugin.vala
index a24b1e51..49ce6659 100644
--- a/plugins/libretro/src/libretro-plugin.vala
+++ b/plugins/libretro/src/libretro-plugin.vala
@@ -78,7 +78,7 @@ private class Games.LibretroPlugin : Object, Plugin {
                var builder = new RetroRunnerBuilder ();
                builder.core_descriptor = core_descriptor;
                builder.platform = platform;
-               builder.uid = game.get_uid ();
+               builder.uid = game.uid;
                builder.title = game.name;
                builder.input_capabilities = input_capabilities;
                return builder.to_runner ();
diff --git a/plugins/ms-dos/src/ms-dos-plugin.vala b/plugins/ms-dos/src/ms-dos-plugin.vala
index 411dc6bd..208b7de7 100644
--- a/plugins/ms-dos/src/ms-dos-plugin.vala
+++ b/plugins/ms-dos/src/ms-dos-plugin.vala
@@ -52,7 +52,7 @@ private class Games.MsDosPlugin : Object, Plugin {
                var builder = new RetroRunnerBuilder ();
                builder.core_source = core_source;
                builder.uri = game.get_uri ();
-               builder.uid = game.get_uid ();
+               builder.uid = game.uid;
                builder.title = game.name;
                builder.input_capabilities = input_capabilities;
                var runner = builder.to_runner ();
diff --git a/plugins/nintendo-ds/src/nintendo-ds-plugin.vala b/plugins/nintendo-ds/src/nintendo-ds-plugin.vala
index aa259ba3..a5ffc1bd 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-plugin.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-plugin.vala
@@ -57,7 +57,7 @@ private class Games.NintendoDsPlugin : Object, Plugin {
                var builder = new RetroRunnerBuilder ();
                builder.core_source = core_source;
                builder.uri = game.get_uri ();
-               builder.uid = game.get_uid ();
+               builder.uid = game.uid;
                builder.title = game.name;
                return builder.to_runner (typeof (NintendoDsRunner));
        }
diff --git a/plugins/playstation/src/playstation-plugin.vala b/plugins/playstation/src/playstation-plugin.vala
index c6b9e84f..46f9a88e 100644
--- a/plugins/playstation/src/playstation-plugin.vala
+++ b/plugins/playstation/src/playstation-plugin.vala
@@ -41,7 +41,7 @@ private class Games.PlayStation : Object, Plugin {
                var builder = new RetroRunnerBuilder ();
                builder.core_source = core_source;
                builder.media_set = game.get_media_set ();
-               builder.uid = game.get_uid ();
+               builder.uid = game.uid;
                builder.title = game.name;
 
                return builder.to_runner ();
diff --git a/src/core/cover-loader.vala b/src/core/cover-loader.vala
index e8e0bb00..715a720d 100644
--- a/src/core/cover-loader.vala
+++ b/src/core/cover-loader.vala
@@ -80,7 +80,7 @@ public class Games.CoverLoader : Object {
        private string get_cover_cache_path (Game game, int size) throws Error {
                var dir = Application.get_covers_cache_dir (size);
 
-               var uid = game.get_uid ().get_uid ();
+               var uid = game.uid;
 
                return @"$dir/$uid.png";
        }
diff --git a/src/core/game-collection.vala b/src/core/game-collection.vala
index 2fdd8abb..a9e547af 100644
--- a/src/core/game-collection.vala
+++ b/src/core/game-collection.vala
@@ -103,16 +103,10 @@ private class Games.GameCollection : Object {
                                        database.list_cached_games ((game) => {
                                                cached_games[game.get_uri ().to_string ()] = game;
 
-                                               string? uid = null;
-                                               try {
-                                                       uid = game.get_uid ().get_uid ();
-                                               }
-                                               catch (Error e) {}
-
-                                               if (games.contains (uid))
+                                               if (games.contains (game.uid))
                                                        return;
 
-                                               games[uid] = game;
+                                               games[game.uid] = game;
 
                                                Idle.add (() => {
                                                        game_added (game);
@@ -150,13 +144,7 @@ private class Games.GameCollection : Object {
                                        warning ("Couldn't remove game: %s", e.message);
                                }
 
-                               string? uid = null;
-                               try {
-                                       uid = game.get_uid ().get_uid ();
-                               }
-                               catch (Error e) {}
-
-                               games.remove (uid);
+                               games.remove (game.uid);
                                if (removed)
                                        Idle.add (() => {
                                                game_removed (game);
@@ -275,16 +263,7 @@ private class Games.GameCollection : Object {
                        warning ("Couldn't cache game: %s", e.message);
                }
 
-               string? uid = null;
-               try {
-                       uid = game.get_uid ().get_uid ();
-               }
-               catch (Error e) {}
-
-               if (games.contains (uid) && prev_game == null)
-                       return;
-
-               games[uid] = game;
+               games[game.uid] = game;
 
                Idle.add (() => {
                        if (prev_game != null)
@@ -307,15 +286,7 @@ private class Games.GameCollection : Object {
                ulong loading_done_id = 0;
 
                game_added_id = game_added.connect ((game) => {
-                       string? game_uid = null;
-                       try {
-                               game_uid = game.get_uid ().get_uid ();
-                       }
-                       catch (Error e) {
-                               return;
-                       }
-
-                       if (game_uid != uid)
+                       if (game.uid != uid)
                                return;
 
                        result = game;
diff --git a/src/core/game-model.vala b/src/core/game-model.vala
index c19d9e12..d40044ba 100644
--- a/src/core/game-model.vala
+++ b/src/core/game-model.vala
@@ -67,14 +67,6 @@ private class Games.GameModel : Object, ListModel {
                if (ret != 0)
                        return ret;
 
-               try {
-                       var uid1 = a.get_uid ().get_uid ();
-                       var uid2 = b.get_uid ().get_uid ();
-
-                       return uid1.collate (uid2);
-               }
-               catch (Error e) {
-                       assert_not_reached ();
-               }
+               return a.uid.collate (b.uid);
        }
 }
diff --git a/src/core/game.vala b/src/core/game.vala
index 8cdd4901..dd1084b4 100644
--- a/src/core/game.vala
+++ b/src/core/game.vala
@@ -20,7 +20,8 @@ public class Games.Game : Object {
                }
        }
 
-       private Uid game_uid;
+       public string uid { get; private set; }
+
        private Uri game_uri;
        private Title game_title;
        private Icon game_icon;
@@ -29,16 +30,12 @@ public class Games.Game : Object {
        private MediaSet? media_set;
 
        public Game (string uid, Uri uri, Title title, Platform platform) {
-               game_uid = new GenericUid (uid);
+               this.uid = uid;
                game_uri = uri;
                game_title = title;
                game_platform = platform;
        }
 
-       public Uid get_uid () {
-               return game_uid;
-       }
-
        public Uri get_uri () {
                return game_uri;
        }
@@ -87,37 +84,13 @@ public class Games.Game : Object {
        }
 
        public static uint hash (Game key) {
-               var uid = "";
-               try {
-                       uid = key.get_uid ().get_uid ();
-               }
-               catch (Error e) {
-                       critical (e.message);
-               }
-
-               return str_hash (uid);
+               return str_hash (key.uid);
        }
 
        public static bool equal (Game a, Game b) {
                if (direct_equal (a, b))
                        return true;
 
-               var a_uid = "";
-               try {
-                       a_uid = a.get_uid ().get_uid ();
-               }
-               catch (Error e) {
-                       critical (e.message);
-               }
-
-               var b_uid = "";
-               try {
-                       b_uid = b.get_uid ().get_uid ();
-               }
-               catch (Error e) {
-                       critical (e.message);
-               }
-
-               return str_equal (a_uid, b_uid);
+               return str_equal (a.uid, b.uid);
        }
 }
diff --git a/src/core/savestate.vala b/src/core/savestate.vala
index 0148977d..ab5d050a 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -174,12 +174,11 @@ public class Games.Savestate : Object {
                }
        }
 
-       public static Savestate[] get_game_savestates (Uid game_uid, Platform platform, string core_id) 
throws Error {
+       public static Savestate[] get_game_savestates (string uid, Platform platform, string core_id) throws 
Error {
                var data_dir_path = Application.get_data_dir ();
                var savestates_dir_path = Path.build_filename (data_dir_path, "savestates");
-               var uid_str = game_uid.get_uid ();
                var core_id_prefix = core_id.replace (".libretro", "");
-               var game_savestates_dir_path = Path.build_filename (savestates_dir_path, uid_str + "-" + 
core_id_prefix);
+               var game_savestates_dir_path = Path.build_filename (savestates_dir_path, uid + "-" + 
core_id_prefix);
                var game_savestates_dir_file = File.new_for_path (game_savestates_dir_path);
 
                if (!game_savestates_dir_file.query_exists ()) {
diff --git a/src/database/database.vala b/src/database/database.vala
index 665c47bb..70efc3e6 100644
--- a/src/database/database.vala
+++ b/src/database/database.vala
@@ -194,7 +194,7 @@ private class Games.Database : Object {
        }
 
        public Game? store_game (Game game) throws Error {
-               var uid = game.get_uid ().get_uid ();
+               var uid = game.uid;
                var uri = game.get_uri ().to_string ();
                var title = game.name;
                var platform = game.get_platform ().get_id ();
@@ -228,7 +228,7 @@ private class Games.Database : Object {
        }
 
        public void update_game (Game game, Game? prev_game = null) throws Error {
-               var uid = game.get_uid ().get_uid ();
+               var uid = game.uid;
                var uri = game.get_uri ().to_string ();
                var title = game.name;
                var media_set = serialize_media_set (game);
@@ -254,7 +254,7 @@ private class Games.Database : Object {
        }
 
        public bool remove_game (string uri, Game game) throws Error {
-               var uid = game.get_uid ().get_uid ();
+               var uid = game.uid;
 
                delete_uri_query.reset ();
                bind_text (delete_uri_query, "$URI", uri);
diff --git a/src/retro/retro-runner-builder.vala b/src/retro/retro-runner-builder.vala
index 02254598..b09bd04f 100644
--- a/src/retro/retro-runner-builder.vala
+++ b/src/retro/retro-runner-builder.vala
@@ -1,7 +1,7 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 public class Games.RetroRunnerBuilder : Object {
-       public Uid uid { get; set; }
+       public string uid { get; set; }
        public string title { get; set; }
 
        private RetroCoreSource _core_source;
diff --git a/src/retro/retro-runner-factory.vala b/src/retro/retro-runner-factory.vala
index ef8300f3..f96fe997 100644
--- a/src/retro/retro-runner-factory.vala
+++ b/src/retro/retro-runner-factory.vala
@@ -17,7 +17,7 @@ public class Games.RetroRunnerFactory : Object, RunnerFactory {
                var builder = new RetroRunnerBuilder ();
                builder.core_source = core_source;
                builder.uri = game.get_uri ();
-               builder.uid = game.get_uid ();
+               builder.uid = game.uid;
                builder.title = game.name;
                var runner = builder.to_runner ();
 
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 15ab79be..f48fc88b 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -39,7 +39,7 @@ public class Games.RetroRunner : Object, Runner {
        private Retro.CoreDescriptor core_descriptor;
        private RetroCoreSource core_source;
        private Platform platform;
-       private Uid uid;
+       private string uid;
        private InputCapabilities input_capabilities;
        private Settings settings;
        private string game_title;
@@ -439,7 +439,6 @@ public class Games.RetroRunner : Object, Runner {
                // Get the savestates directory of the game
                var data_dir_path = Application.get_data_dir ();
                var savestates_dir_path = Path.build_filename (data_dir_path, "savestates");
-               var uid = uid.get_uid ();
                var core_id = get_core_id ();
                var core_id_prefix = core_id.replace (".libretro", "");
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]