[gnome-games] mame: Add MameGameUriAdapter



commit a27ce8f8fe58b44a150d43bc190362e3680420e6
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue Aug 16 12:51:03 2016 +0200

    mame: Add MameGameUriAdapter
    
    This will be used in the next commit to asynchronously create MAME
    games.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769832

 plugins/mame/src/Makefile.am                |    1 +
 plugins/mame/src/mame-game-uri-adapter.vala |   34 +++++++++++++++++++++++++++
 plugins/mame/src/mame-plugin.vala           |   31 +-----------------------
 3 files changed, 36 insertions(+), 30 deletions(-)
---
diff --git a/plugins/mame/src/Makefile.am b/plugins/mame/src/Makefile.am
index ba27eaa..be60b81 100644
--- a/plugins/mame/src/Makefile.am
+++ b/plugins/mame/src/Makefile.am
@@ -31,6 +31,7 @@ libgames_mame_plugin_la_DEPENDENCIES = \
 libgames_mame_plugin_la_SOURCES = \
        mame-error.vala \
        mame-game-info.vala \
+       mame-game-uri-adapter.vala \
        mame-plugin.vala \
        $(BUILT_SOURCES) \
        $(NULL)
diff --git a/plugins/mame/src/mame-game-uri-adapter.vala b/plugins/mame/src/mame-game-uri-adapter.vala
new file mode 100644
index 0000000..fe23847
--- /dev/null
+++ b/plugins/mame/src/mame-game-uri-adapter.vala
@@ -0,0 +1,34 @@
+// This file is part of GNOME Games. License: GPLv3
+
+private class Games.MameGameUriAdapter : GameUriAdapter, Object {
+       private const string SEARCHED_MIME_TYPE = "application/zip";
+       private const string SPECIFIC_MIME_TYPE = "application/x-mame-rom";
+       private const string MODULE_BASENAME = "libretro-mame.so";
+       private const bool SUPPORTS_SNAPSHOTTING = false;
+
+       public async Game game_for_uri (string uri) throws Error {
+               var supported_games = MameGameInfo.get_supported_games ();
+
+               var file = File.new_for_uri (uri);
+               var game_id = file.get_basename ();
+               game_id = /\.zip$/.replace (game_id, game_id.length, 0, "");
+
+               if (!supported_games.contains (game_id))
+                       throw new MameError.INVALID_GAME_ID (_("Invalid MAME game id '%s' for '%s'."), 
game_id, uri);
+
+               var uid_string = @"mame-$game_id".down ();
+               var uid = new GenericUid (uid_string);
+
+               var info = supported_games[game_id];
+               var title_string = info.name;
+               title_string = title_string.split ("(")[0];
+               title_string = title_string.strip ();
+               var title = new GenericTitle (title_string);
+
+               var icon = new DummyIcon ();
+               var cover = new LocalCover (uri);
+               var runner = new RetroRunner.with_mime_types (uri, uid, { SEARCHED_MIME_TYPE, 
SPECIFIC_MIME_TYPE }, MODULE_BASENAME, SUPPORTS_SNAPSHOTTING);
+
+               return new GenericGame (title, icon, cover, runner);
+       }
+}
diff --git a/plugins/mame/src/mame-plugin.vala b/plugins/mame/src/mame-plugin.vala
index 136b756..f798fe9 100644
--- a/plugins/mame/src/mame-plugin.vala
+++ b/plugins/mame/src/mame-plugin.vala
@@ -2,12 +2,9 @@
 
 private class Games.MamePlugin : Object, Plugin {
        private const string SEARCHED_MIME_TYPE = "application/zip";
-       private const string SPECIFIC_MIME_TYPE = "application/x-mame-rom";
-       private const string MODULE_BASENAME = "libretro-mame.so";
-       private const bool SUPPORTS_SNAPSHOTTING = false;
 
        public GameSource get_game_source () throws Error {
-               var game_uri_adapter = new GenericSyncGameUriAdapter (game_for_uri);
+               var game_uri_adapter = new MameGameUriAdapter ();
                var query = new MimeTypeTrackerQuery (SEARCHED_MIME_TYPE, game_uri_adapter);
                var connection = Tracker.Sparql.Connection.@get ();
                var source = new TrackerGameSource (connection);
@@ -15,32 +12,6 @@ private class Games.MamePlugin : Object, Plugin {
 
                return source;
        }
-
-       private static Game game_for_uri (string uri) throws Error {
-               var supported_games = MameGameInfo.get_supported_games ();
-
-               var file = File.new_for_uri (uri);
-               var game_id = file.get_basename ();
-               game_id = /\.zip$/.replace (game_id, game_id.length, 0, "");
-
-               if (!supported_games.contains (game_id))
-                       throw new MameError.INVALID_GAME_ID (_("Invalid MAME game id '%s' for '%s'."), 
game_id, uri);
-
-               var uid_string = @"mame-$game_id".down ();
-               var uid = new GenericUid (uid_string);
-
-               var info = supported_games[game_id];
-               var title_string = info.name;
-               title_string = title_string.split ("(")[0];
-               title_string = title_string.strip ();
-               var title = new GenericTitle (title_string);
-
-               var icon = new DummyIcon ();
-               var cover = new LocalCover (uri);
-               var runner = new RetroRunner.with_mime_types (uri, uid, { SEARCHED_MIME_TYPE, 
SPECIFIC_MIME_TYPE }, MODULE_BASENAME, SUPPORTS_SNAPSHOTTING);
-
-               return new GenericGame (title, icon, cover, runner);
-       }
 }
 
 [ModuleInit]


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