[gnome-games/wip/exalm/rebrand: 60/102] turbografx-cd: Migrate to a game parser




commit ac3875a55f797e5b079e93eb82d95e165bdd88b8
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Mar 30 03:58:22 2021 +0500

    turbografx-cd: Migrate to a game parser

 plugins/turbografx-cd/src/meson.build              |  1 +
 .../turbografx-cd/src/turbografx-cd-parser.vala    | 45 +++++++++++++++++++
 .../turbografx-cd/src/turbografx-cd-plugin.vala    | 51 +---------------------
 3 files changed, 48 insertions(+), 49 deletions(-)
---
diff --git a/plugins/turbografx-cd/src/meson.build b/plugins/turbografx-cd/src/meson.build
index 7cb6ca17..3157c5b7 100644
--- a/plugins/turbografx-cd/src/meson.build
+++ b/plugins/turbografx-cd/src/meson.build
@@ -1,5 +1,6 @@
 vala_sources = [
   'turbografx-cd-error.vala',
+  'turbografx-cd-parser.vala',
   'turbografx-cd-plugin.vala',
 ]
 
diff --git a/plugins/turbografx-cd/src/turbografx-cd-parser.vala 
b/plugins/turbografx-cd/src/turbografx-cd-parser.vala
new file mode 100644
index 00000000..3c0516f6
--- /dev/null
+++ b/plugins/turbografx-cd/src/turbografx-cd-parser.vala
@@ -0,0 +1,45 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.TurboGrafxCDParser : GameParser {
+       private const string CUE_MIME_TYPE = "application/x-cue";
+       private const string CD_MAGIC_VALUE = "PC Engine CD-ROM SYSTEM";
+
+       public TurboGrafxCDParser (Platform platform, Uri uri) {
+               base (platform, uri);
+       }
+
+       public override void parse () throws Error {
+               if (!is_valid_disc ())
+                       throw new TurboGrafxCDError.INVALID_DISC ("“%s” isn’t a valid TurboGrafx-CD disc.", 
uri.to_string ());
+       }
+
+       private bool is_valid_disc () throws Error {
+               var file = uri.to_file ();
+               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);
+                       if (cue.tracks_number < 2)
+                               return false;
+
+                       var track = cue.get_track (1);
+                       if (!track.track_mode.is_mode1 ())
+                               return false;
+
+                       bin_file = track.file.file;
+
+                       break;
+               // TODO Add support for binary files.
+               default:
+                       return false;
+               }
+
+               var path = bin_file.get_path ();
+               var offsets = Grep.get_offsets (path, CD_MAGIC_VALUE);
+
+               return offsets.length > 0;
+       }
+}
diff --git a/plugins/turbografx-cd/src/turbografx-cd-plugin.vala 
b/plugins/turbografx-cd/src/turbografx-cd-plugin.vala
index 41ecf67a..5a434ee8 100644
--- a/plugins/turbografx-cd/src/turbografx-cd-plugin.vala
+++ b/plugins/turbografx-cd/src/turbografx-cd-plugin.vala
@@ -3,7 +3,6 @@
 private class Games.TurboGrafxCDPlugin : Object, Plugin {
        private const string PHONY_MIME_TYPE = "application/x-pc-engine-cd-rom";
        private const string CUE_MIME_TYPE = "application/x-cue";
-       private const string CD_MAGIC_VALUE = "PC Engine CD-ROM SYSTEM";
        private const string PLATFORM_ID = "TurboGrafxCD";
        /* translators: known as "CD-ROM²" in eastern Asia and France */
        private const string PLATFORM_NAME = _("TurboGrafx-CD");
@@ -14,6 +13,7 @@ private class Games.TurboGrafxCDPlugin : Object, Plugin {
        static construct {
                string[] mime_types = { CUE_MIME_TYPE };
                platform = new Platform.with_mime_types (PLATFORM_ID, PLATFORM_NAME, mime_types, 
PHONY_MIME_TYPE, PLATFORM_UID_PREFIX);
+               platform.parser_type = typeof (TurboGrafxCDParser);
        }
 
        public Platform[] get_platforms () {
@@ -21,59 +21,12 @@ private class Games.TurboGrafxCDPlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new GenericGameUriAdapter (game_for_uri);
+               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
                var factory = new GenericUriGameFactory (game_uri_adapter);
                factory.add_mime_type (CUE_MIME_TYPE);
 
                return { factory };
        }
-
-       private static Game game_for_uri (Uri uri) throws Error {
-               if (!is_valid_disc (uri))
-                       throw new TurboGrafxCDError.INVALID_DISC ("“%s” isn’t a valid TurboGrafx-CD disc.", 
uri.to_string ());
-
-               var uid = new Uid (Fingerprint.get_uid (uri, PLATFORM_UID_PREFIX));
-               var title = new FilenameTitle (uri);
-               var media = new GriloMedia (title, PHONY_MIME_TYPE);
-               var cover = new CompositeCover ({
-                       new LocalCover (uri),
-                       new GriloCover (media, uid)});
-
-               var game = new Game (uid, uri, title, platform);
-               game.set_cover (cover);
-
-               return game;
-       }
-
-       private static bool is_valid_disc (Uri uri) throws Error {
-               var file = uri.to_file ();
-               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);
-                       if (cue.tracks_number < 2)
-                               return false;
-
-                       var track = cue.get_track (1);
-                       if (!track.track_mode.is_mode1 ())
-                               return false;
-
-                       bin_file = track.file.file;
-
-                       break;
-               // TODO Add support for binary files.
-               default:
-                       return false;
-               }
-
-               var path = bin_file.get_path ();
-               var offsets = Grep.get_offsets (path, CD_MAGIC_VALUE);
-
-               return offsets.length > 0;
-       }
 }
 
 [ModuleInit]


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