[gnome-games/wip/aplazas/type-registration: 13/19] Replace mega-drive plugin by sega-cd plugin



commit 79698db1e1cd3722b07581f7e3e7f37848f8159d
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu May 25 16:38:49 2017 +0200

    Replace mega-drive plugin by sega-cd plugin
    
    The mega-drive plugin stopped handling all Sega Genesis related types
    in the previous commit and was only handling the Sega CD types. This
    replacement makes the role of this plugin more clear.

 configure.ac                                       |    2 +-
 plugins/Makefile.am                                |    8 +-
 plugins/mega-drive/configure.ac                    |   14 ----
 plugins/mega-drive/data/mega-drive.plugin          |    6 --
 plugins/mega-drive/src/mega-drive-system.vala      |   10 ---
 plugins/{mega-drive => sega-cd}/Makefile.am        |    0
 plugins/sega-cd/configure.ac                       |   14 ++++
 plugins/{mega-drive => sega-cd}/data/Makefile.am   |    2 +-
 plugins/sega-cd/data/sega-cd.plugin                |    6 ++
 plugins/{mega-drive => sega-cd}/src/Makefile.am    |   28 ++++----
 .../src/sega-cd-header.vala}                       |   69 ++++++--------------
 .../src/sega-cd-plugin.vala}                       |   49 +++++++-------
 plugins/sega-cd/src/sega-cd-system.vala            |    7 ++
 13 files changed, 91 insertions(+), 124 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2f1bfad..0d84db6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,13 +29,13 @@ m4_include([plugins/game-cube/configure.ac])
 m4_include([plugins/libretro/configure.ac])
 m4_include([plugins/love/configure.ac])
 m4_include([plugins/mame/configure.ac])
-m4_include([plugins/mega-drive/configure.ac])
 m4_include([plugins/ms-dos/configure.ac])
 m4_include([plugins/neo-geo-pocket/configure.ac])
 m4_include([plugins/nintendo-64/configure.ac])
 m4_include([plugins/nintendo-ds/configure.ac])
 m4_include([plugins/pc-engine/configure.ac])
 m4_include([plugins/playstation/configure.ac])
+m4_include([plugins/sega-cd/configure.ac])
 m4_include([plugins/sega-saturn/configure.ac])
 m4_include([plugins/snes/configure.ac])
 m4_include([plugins/steam/configure.ac])
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 73ab3a6..f9ed64c 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -24,10 +24,6 @@ if ENABLE_MAME_PLUGIN
 SUBDIRS += mame
 endif
 
-if ENABLE_MEGA_DRIVE_PLUGIN
-SUBDIRS += mega-drive
-endif
-
 if ENABLE_MS_DOS_PLUGIN
 SUBDIRS += ms-dos
 endif
@@ -56,6 +52,10 @@ if ENABLE_PLAYSTATION_PLUGIN
 SUBDIRS += playstation
 endif
 
+if ENABLE_SEGA_CD_PLUGIN
+SUBDIRS += sega-cd
+endif
+
 if ENABLE_SEGA_SATURN_PLUGIN
 SUBDIRS += sega-saturn
 endif
diff --git a/plugins/mega-drive/Makefile.am b/plugins/sega-cd/Makefile.am
similarity index 100%
rename from plugins/mega-drive/Makefile.am
rename to plugins/sega-cd/Makefile.am
diff --git a/plugins/sega-cd/configure.ac b/plugins/sega-cd/configure.ac
new file mode 100644
index 0000000..78b9062
--- /dev/null
+++ b/plugins/sega-cd/configure.ac
@@ -0,0 +1,14 @@
+PKG_CHECK_MODULES(SEGA_CD_PLUGIN, [
+       gio-2.0
+       glib-2.0 >= $GLIB_MIN_VERSION
+       gtk+-3.0
+       retro-gtk-0.10
+], [enable_sega_cd_plugin=yes], [enable_sega_cd_plugin=no])
+
+AM_CONDITIONAL(ENABLE_SEGA_CD_PLUGIN, test x$enable_sega_cd_plugin != xno)
+
+AC_CONFIG_FILES([
+       plugins/sega-cd/Makefile
+       plugins/sega-cd/data/Makefile
+       plugins/sega-cd/src/Makefile
+])
diff --git a/plugins/mega-drive/data/Makefile.am b/plugins/sega-cd/data/Makefile.am
similarity index 73%
rename from plugins/mega-drive/data/Makefile.am
rename to plugins/sega-cd/data/Makefile.am
index 59bbfe2..e8c73b6 100644
--- a/plugins/mega-drive/data/Makefile.am
+++ b/plugins/sega-cd/data/Makefile.am
@@ -1,6 +1,6 @@
 EXTRA_DIST = $(plugin_DATA)
 
 plugindir = $(libdir)/gnome-games/plugins
-dist_plugin_DATA = mega-drive.plugin
+dist_plugin_DATA = sega-cd.plugin
 
 -include $(top_srcdir)/git.mk
diff --git a/plugins/sega-cd/data/sega-cd.plugin b/plugins/sega-cd/data/sega-cd.plugin
new file mode 100644
index 0000000..237ab24
--- /dev/null
+++ b/plugins/sega-cd/data/sega-cd.plugin
@@ -0,0 +1,6 @@
+[Plugin]
+Module=libgames-sega-cd-plugin
+Name=Sega CD Plugin
+Description=Provides support for Sega CD and Sega CD 32X games.
+Authors=Adrien Plazas <kekun plazas laposte net>
+Copyright=Copyright © 2017 Adrien Plazas
diff --git a/plugins/mega-drive/src/Makefile.am b/plugins/sega-cd/src/Makefile.am
similarity index 50%
rename from plugins/mega-drive/src/Makefile.am
rename to plugins/sega-cd/src/Makefile.am
index 05b96d5..df5496c 100644
--- a/plugins/mega-drive/src/Makefile.am
+++ b/plugins/sega-cd/src/Makefile.am
@@ -1,40 +1,40 @@
 plugindir = $(libdir)/gnome-games/plugins
-plugin_LTLIBRARIES = libgames-mega-drive-plugin.la
+plugin_LTLIBRARIES = libgames-sega-cd-plugin.la
 
-libgames_mega_drive_plugin_la_DEPENDENCIES = \
+libgames_sega_cd_plugin_la_DEPENDENCIES = \
        $(top_builddir)/src/gnome-games.vapi \
        $(NULL)
 
-libgames_mega_drive_plugin_la_SOURCES = \
-       mega-drive-header.vala \
-       mega-drive-plugin.vala \
-       mega-drive-system.vala \
+libgames_sega_cd_plugin_la_SOURCES = \
+       sega-cd-header.vala \
+       sega-cd-plugin.vala \
+       sega-cd-system.vala \
        $(NULL)
 
-libgames_mega_drive_plugin_la_VALAFLAGS = \
+libgames_sega_cd_plugin_la_VALAFLAGS = \
        --target-glib=@GLIB_MIN_VERSION@ \
        --pkg gnome-games \
        --vapidir $(top_builddir)/src \
        $(NULL)
 
-libgames_mega_drive_plugin_la_CFLAGS = \
-       $(MEGA_DRIVE_PLUGIN_CFLAGS) \
+libgames_sega_cd_plugin_la_CFLAGS = \
+       $(SEGA_CD_PLUGIN_CFLAGS) \
        $(GNOME_GAMES_CFLAGS) \
-       -DG_LOG_DOMAIN=\"GamesDesktop\" \
+       -DG_LOG_DOMAIN=\"GamesSegaCD\" \
        -DLOCALEDIR=\"$(localedir)\" \
        $(NULL)
 
-libgames_mega_drive_plugin_la_CPPFLAGS = \
+libgames_sega_cd_plugin_la_CPPFLAGS = \
        -I$(top_srcdir) \
        -I$(top_srcdir)/src \
        $(NULL)
 
-libgames_mega_drive_plugin_la_LIBADD = \
-       $(MEGA_DRIVE_PLUGIN_LIBS) \
+libgames_sega_cd_plugin_la_LIBADD = \
+       $(SEGA_CD_PLUGIN_LIBS) \
        $(GNOME_GAMES_LIBS) \
        $(NULL)
 
-libgames_mega_drive_plugin_la_LDFLAGS = \
+libgames_sega_cd_plugin_la_LDFLAGS = \
        -no-undefined \
        -module \
        -avoid-version \
diff --git a/plugins/mega-drive/src/mega-drive-header.vala b/plugins/sega-cd/src/sega-cd-header.vala
similarity index 52%
rename from plugins/mega-drive/src/mega-drive-header.vala
rename to plugins/sega-cd/src/sega-cd-header.vala
index 8fc3c6f..aeefe94 100644
--- a/plugins/mega-drive/src/mega-drive-header.vala
+++ b/plugins/sega-cd/src/sega-cd-header.vala
@@ -1,7 +1,7 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 // Documentation: https://en.wikibooks.org/wiki/Genesis_Programming
-private class Games.MegaDriveHeader : Object {
+private class Games.SegaCDHeader : Object {
        public const size_t HEADER_LENGTH = 0x200;
 
        private const size_t[] POSSIBLE_HEADER_OFFSETS = { 0x0, 0x10 };
@@ -13,29 +13,8 @@ private class Games.MegaDriveHeader : Object {
        // let's just use the 15 first chars.
        private const size_t SYSTEM_SIZE = 0xf;
 
-       private const size_t DOMESTIC_NAME_OFFSET = 0x120;
-       private const size_t NAME_SIZE = 0x30;
-
-       private string _domestic_name;
-       public string domestic_name {
-               get {
-                       if (_domestic_name != null)
-                               return _domestic_name;
-
-                       var stream = new StringInputStream (file);
-                       try {
-                               _domestic_name = stream.read_string_for_size (DOMESTIC_NAME_OFFSET, 
NAME_SIZE);
-                       }
-                       catch (Error e) {
-                               _domestic_name = "";
-                       }
-
-                       return _domestic_name;
-               }
-       }
-
-       private MegaDriveSystem? _system;
-       public MegaDriveSystem system {
+       private SegaCDSystem? _system;
+       public SegaCDSystem system {
                get {
                        if (_system != null)
                                return _system;
@@ -46,7 +25,7 @@ private class Games.MegaDriveHeader : Object {
                        catch (Error e) {
                                debug (e.message);
 
-                               _system = MegaDriveSystem.INVALID;
+                               _system = SegaCDSystem.INVALID;
                        }
 
                        return _system;
@@ -56,13 +35,13 @@ private class Games.MegaDriveHeader : Object {
        private File file;
        private size_t? offset;
 
-       public MegaDriveHeader (File file) {
+       public SegaCDHeader (File file) {
                this.file = file;
        }
 
        public void check_validity () throws Error {
-               if (system == MegaDriveSystem.INVALID)
-                       throw new MegaDriveError.INVALID_HEADER (_("The file doesn’t have a Genesis/Sega 
32X/Sega CD/Sega Pico header."));
+               if (system == SegaCDSystem.INVALID)
+                       throw new SegaCDError.INVALID_HEADER (_("The file doesn’t have a Genesis/Sega 
32X/Sega CD/Sega Pico header."));
        }
 
        public size_t get_offset () throws Error {
@@ -81,14 +60,16 @@ private class Games.MegaDriveHeader : Object {
                        }
                }
 
-                       throw new MegaDriveError.INVALID_HEADER (_("The file doesn’t have a Genesis/Sega 
32X/Sega CD/Sega Pico header."));
+                       throw new SegaCDError.INVALID_HEADER (_("The file doesn’t have a Genesis/Sega 
32X/Sega CD/Sega Pico header."));
        }
 
-       private MegaDriveSystem parse_system () throws Error {
+       private SegaCDSystem parse_system () throws Error {
                var stream = new StringInputStream (file);
 
                var offset = get_offset ();
-               var is_cd = stream.has_string (offset + CD_OFFSET, "SEGADISCSYSTEM");
+               if (!stream.has_string (offset + CD_OFFSET, "SEGADISCSYSTEM"))
+                       return SegaCDSystem.INVALID;
+
                var system_string = stream.read_string_for_size (offset + SYSTEM_OFFSET, SYSTEM_SIZE);
                system_string = system_string.chomp ();
 
@@ -96,44 +77,36 @@ private class Games.MegaDriveHeader : Object {
                case "SEGA MEGA DRIVE":
                case "SEGA GENESIS":
                case " SEGA MEGA DRIV":
-               case "SEGA_MEGA_DRIVE":
+               case "SEGA_SEGA_CD":
                case "SEGA are Regist":
-                       return is_cd ? MegaDriveSystem.MEGA_CD : MegaDriveSystem.MEGA_DRIVE;
+                       return SegaCDSystem.SEGA_CD;
                case "SEGA 32X":
-                       return is_cd ? MegaDriveSystem.MEGA_CD_32X : MegaDriveSystem.32X;
-               case "SEGA PICO":
-                       return is_cd ? MegaDriveSystem.INVALID : MegaDriveSystem.PICO;
+                       return SegaCDSystem.SEGA_CD_32X;
                default:
-                       return MegaDriveSystem.INVALID;
+                       return SegaCDSystem.INVALID;
                }
        }
 
-       public bool is_mega_drive () {
+       public bool is_sega_cd () {
                switch (system) {
-               case MegaDriveSystem.MEGA_DRIVE:
-               case MegaDriveSystem.MEGA_CD:
+               case SegaCDSystem.SEGA_CD:
                        return true;
                default:
                        return false;
                }
        }
 
-       public bool is_32x () {
+       public bool is_sega_cd_32x () {
                switch (system) {
-               case MegaDriveSystem.32X:
-               case MegaDriveSystem.MEGA_CD_32X:
+               case SegaCDSystem.SEGA_CD_32X:
                        return true;
                default:
                        return false;
                }
        }
-
-       public bool is_pico () {
-               return system == MegaDriveSystem.PICO;
-       }
 }
 
-errordomain Games.MegaDriveError {
+errordomain Games.SegaCDError {
        INVALID_HEADER,
        INVALID_CUE_SHEET,
        INVALID_FILE_TYPE,
diff --git a/plugins/mega-drive/src/mega-drive-plugin.vala b/plugins/sega-cd/src/sega-cd-plugin.vala
similarity index 55%
rename from plugins/mega-drive/src/mega-drive-plugin.vala
rename to plugins/sega-cd/src/sega-cd-plugin.vala
index b15ca4d..d7dcc6e 100644
--- a/plugins/mega-drive/src/mega-drive-plugin.vala
+++ b/plugins/sega-cd/src/sega-cd-plugin.vala
@@ -1,26 +1,23 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
-private class Games.MegaDrivePlugin : Object, Plugin {
+private class Games.SegaCDPlugin : Object, Plugin {
        private const string 32X_MIME_TYPE = "application/x-genesis-32x-rom";
 
-       private const string MEGA_CD_PREFIX = "mega-cd";
+       private const string SEGA_CD_PREFIX = "mega-cd";
        private const string CUE_MIME_TYPE = "application/x-cue";
-       private const string MEGA_CD_MIME_TYPE = "application/x-sega-cd-rom";
-       private const string MEGA_CD_PLATFORM = "SegaCD";
-       private const string MEGA_CD_32X_PLATFORM = "SegaCD32X";
+       private const string SEGA_CD_MIME_TYPE = "application/x-sega-cd-rom";
+       private const string SEGA_CD_PLATFORM = "SegaCD";
+       private const string SEGA_CD_32X_PLATFORM = "SegaCD32X";
 
        public string[] get_mime_types () {
-               return {
-                       CUE_MIME_TYPE,
-                       MEGA_CD_MIME_TYPE,
-               };
+               return { CUE_MIME_TYPE, SEGA_CD_MIME_TYPE };
        }
 
        public UriGameFactory[] get_uri_game_factories () {
                var game_uri_adapter = new GenericGameUriAdapter (game_for_uri);
                var factory = new GenericUriGameFactory (game_uri_adapter);
                factory.add_mime_type (CUE_MIME_TYPE);
-               factory.add_mime_type (MEGA_CD_MIME_TYPE);
+               factory.add_mime_type (SEGA_CD_MIME_TYPE);
 
                return { factory };
        }
@@ -37,36 +34,36 @@ private class Games.MegaDrivePlugin : Object, Plugin {
                        bin_file = get_binary_file (cue);
 
                        break;
-               case MEGA_CD_MIME_TYPE:
+               case SEGA_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.to_string ());
+                       throw new SegaCDError.INVALID_FILE_TYPE ("Invalid file type: expected %s or %s but 
got %s for file %s.", CUE_MIME_TYPE, SEGA_CD_MIME_TYPE, mime_type, uri.to_string ());
                }
 
-               var header = new MegaDriveHeader (bin_file);
+               var header = new SegaCDHeader (bin_file);
                header.check_validity ();
 
                string[] mime_types;
                string platform;
-               if (header.is_mega_drive ()) {
-                       mime_types = { CUE_MIME_TYPE, MEGA_CD_MIME_TYPE };
-                       platform = MEGA_CD_PLATFORM;
+               if (header.is_sega_cd ()) {
+                       mime_types = { CUE_MIME_TYPE, SEGA_CD_MIME_TYPE };
+                       platform = SEGA_CD_PLATFORM;
                }
-               else if (header.is_32x ()) {
-                       mime_types = { CUE_MIME_TYPE, MEGA_CD_MIME_TYPE, 32X_MIME_TYPE };
-                       platform = MEGA_CD_32X_PLATFORM;
+               else if (header.is_sega_cd_32x ()) {
+                       mime_types = { CUE_MIME_TYPE, SEGA_CD_MIME_TYPE, 32X_MIME_TYPE };
+                       platform = SEGA_CD_32X_PLATFORM;
                }
                else
                        assert_not_reached ();
 
                var bin_uri = new Uri (bin_file.get_uri ());
                var header_offset = header.get_offset ();
-               var uid = new FingerprintUid.for_chunk (bin_uri, MEGA_CD_PREFIX, header_offset, 
MegaDriveHeader.HEADER_LENGTH);
+               var uid = new FingerprintUid.for_chunk (bin_uri, SEGA_CD_PREFIX, header_offset, 
SegaCDHeader.HEADER_LENGTH);
                var title = new FilenameTitle (uri);
                var icon = new DummyIcon ();
-               var media = new GriloMedia (title, MEGA_CD_MIME_TYPE);
+               var media = new GriloMedia (title, SEGA_CD_MIME_TYPE);
                var cover = new CompositeCover ({
                        new LocalCover (uri),
                        new GriloCover (media, uid)});
@@ -78,18 +75,18 @@ private class Games.MegaDrivePlugin : Object, Plugin {
 
        private static File get_binary_file (CueSheet cue) throws Error {
                if (cue.tracks_number == 0)
-                       throw new MegaDriveError.INVALID_CUE_SHEET (_("The file “%s” doesn’t have a track."), 
cue.file.get_uri ());
+                       throw new SegaCDError.INVALID_CUE_SHEET (_("The file “%s” doesn’t have a track."), 
cue.file.get_uri ());
 
                var track = cue.get_track (0);
                var file = track.file;
 
                if (file.file_format != CueSheetFileFormat.BINARY && file.file_format != 
CueSheetFileFormat.UNKNOWN)
-                       throw new MegaDriveError.INVALID_CUE_SHEET (_("The file “%s” doesn’t have a valid 
binary file format."), cue.file.get_uri ());
+                       throw new SegaCDError.INVALID_CUE_SHEET (_("The file “%s” doesn’t have a valid binary 
file format."), cue.file.get_uri ());
 
                if (!track.track_mode.is_mode1 ())
-                       throw new MegaDriveError.INVALID_CUE_SHEET (_("The file “%s” doesn’t have a valid 
track mode for track %d."), cue.file.get_uri (), track.track_number);
+                       throw new SegaCDError.INVALID_CUE_SHEET (_("The file “%s” doesn’t have a valid track 
mode for track %d."), cue.file.get_uri (), track.track_number);
 
-               var header = new MegaDriveHeader (file.file);
+               var header = new SegaCDHeader (file.file);
                header.check_validity ();
 
                return file.file;
@@ -98,5 +95,5 @@ private class Games.MegaDrivePlugin : Object, Plugin {
 
 [ModuleInit]
 public Type register_games_plugin (TypeModule module) {
-       return typeof(Games.MegaDrivePlugin);
+       return typeof(Games.SegaCDPlugin);
 }
diff --git a/plugins/sega-cd/src/sega-cd-system.vala b/plugins/sega-cd/src/sega-cd-system.vala
new file mode 100644
index 0000000..2a770b8
--- /dev/null
+++ b/plugins/sega-cd/src/sega-cd-system.vala
@@ -0,0 +1,7 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private enum Games.SegaCDSystem {
+       INVALID,
+       SEGA_CD,
+       SEGA_CD_32X,
+}


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