[gnome-games/wip/aplazas/781334-refactor-game-source: 24/37] mega-drive: Provide MIME types and URI game factories



commit 8db12605e3194edf09ec08571d1fc034f8e8fb84
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu May 4 15:37:59 2017 +0200

    mega-drive: Provide MIME types and URI game factories
    
    Also stop providing a GameSource.
    
    This helps splitting the conerns of looking for game resources and
    building games from them.

 plugins/mega-drive/configure.ac               |    1 -
 plugins/mega-drive/src/mega-drive-plugin.vala |   54 +++++++++++++++++--------
 2 files changed, 37 insertions(+), 18 deletions(-)
---
diff --git a/plugins/mega-drive/configure.ac b/plugins/mega-drive/configure.ac
index 9d985ce..1368c57 100644
--- a/plugins/mega-drive/configure.ac
+++ b/plugins/mega-drive/configure.ac
@@ -3,7 +3,6 @@ PKG_CHECK_MODULES(MEGA_DRIVE_PLUGIN, [
        glib-2.0 >= $GLIB_MIN_VERSION
        gtk+-3.0
        retro-gtk-0.10
-       tracker-sparql-1.0
 ], [enable_mega_drive_plugin=yes], [enable_mega_drive_plugin=no])
 
 AM_CONDITIONAL(ENABLE_MEGA_DRIVE_PLUGIN, test x$enable_mega_drive_plugin != xno)
diff --git a/plugins/mega-drive/src/mega-drive-plugin.vala b/plugins/mega-drive/src/mega-drive-plugin.vala
index 3663b4e..470088d 100644
--- a/plugins/mega-drive/src/mega-drive-plugin.vala
+++ b/plugins/mega-drive/src/mega-drive-plugin.vala
@@ -19,24 +19,29 @@ private class Games.MegaDrivePlugin : Object, Plugin {
        private const string MEGA_CD_PLATFORM = "SegaCD";
        private const string MEGA_CD_32X_PLATFORM = "SegaCD32X";
 
-       public GameSource? get_game_source () throws Error {
+       public string[] get_mime_types () {
+               return {
+                       MEGA_DRIVE_MIME_TYPE,
+                       32X_MIME_TYPE,
+                       PICO_MIME_TYPE,
+                       CUE_MIME_TYPE,
+                       MEGA_CD_MIME_TYPE,
+               };
+       }
+
+       public UriGameFactory[] get_uri_game_factories () {
                var game_uri_adapter = new GenericSyncGameUriAdapter (game_for_uri);
+               var factory = new GenericUriGameFactory (game_uri_adapter);
+               factory.add_mime_type (MEGA_DRIVE_MIME_TYPE);
+               factory.add_mime_type (32X_MIME_TYPE);
+               factory.add_mime_type (PICO_MIME_TYPE);
+
                var cd_game_uri_adapter = new GenericSyncGameUriAdapter (cd_game_for_uri);
-               // FIXME We should be able to use one factory for Mega Drive and
-               // 32X.
-               var mega_drive_factory = new GenericUriGameFactory (game_uri_adapter);
-               var 32x_factory = new GenericUriGameFactory (game_uri_adapter);
                var mega_cd_factory = new GenericUriGameFactory (cd_game_uri_adapter);
-               var mega_drive_query = new MimeTypeTrackerQuery (MEGA_DRIVE_MIME_TYPE, mega_drive_factory);
-               var 32x_query = new MimeTypeTrackerQuery (32X_MIME_TYPE, 32x_factory);
-               var mega_cd_query = new MimeTypeTrackerQuery (CUE_MIME_TYPE, mega_cd_factory);
-               var connection = Tracker.Sparql.Connection.@get ();
-               var source = new TrackerGameSource (connection);
-               source.add_query (mega_drive_query);
-               source.add_query (32x_query);
-               source.add_query (mega_cd_query);
-
-               return source;
+               mega_cd_factory.add_mime_type (CUE_MIME_TYPE);
+               mega_cd_factory.add_mime_type (MEGA_CD_MIME_TYPE);
+
+               return { factory, mega_cd_factory };
        }
 
        private static Game game_for_uri (string uri) throws Error {
@@ -80,8 +85,23 @@ private class Games.MegaDrivePlugin : Object, Plugin {
 
        private static Game cd_game_for_uri (string uri) throws Error {
                var file = File.new_for_uri (uri);
-               var cue = new CueSheet (file);
-               var bin_file = get_binary_file (cue);
+               var file_info = file.query_info (FileAttribute.STANDARD_CONTENT_TYPE, 
FileQueryInfoFlags.NONE);
+               var mime_type = file_info.get_content_type ();
+
+               File bin_file;
+               switch (mime_type) {
+               case CUE_MIME_TYPE:
+                       var cue = new CueSheet (file);
+                       bin_file = get_binary_file (cue);
+
+                       break;
+               case MEGA_CD_MIME_TYPE:
+                       bin_file = file;
+
+                       break;
+               default:
+                       throw new MegaDriveError.INVALID_FILE_TYPE ("Invalid file type: expected %s or %s but 
got %s for file %s.", CUE_MIME_TYPE, MEGA_CD_MIME_TYPE, mime_type, uri);
+               }
 
                var header = new MegaDriveHeader (bin_file);
                header.check_validity ();


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