[gnome-games] playstation: Add the PlayStation plugin



commit f56b6451ebc0640a847eaabb8701f45ec8e28fd8
Author: Ricard Gascons <gascons1995 gmail com>
Date:   Mon Jun 13 16:18:19 2016 +0200

    playstation: Add the PlayStation plugin
    
    Provides support for PlayStation games.
    
    Fixes #94

 configure.ac                                    |    1 +
 plugins/Makefile.am                             |    4 ++
 plugins/playstation/Makefile.am                 |    3 +
 plugins/playstation/configure.ac                |   14 ++++++
 plugins/playstation/data/Makefile.am            |    6 +++
 plugins/playstation/data/playstation.plugin     |    6 +++
 plugins/playstation/src/Makefile.am             |   56 +++++++++++++++++++++++
 plugins/playstation/src/playstation-error.vala  |    5 ++
 plugins/playstation/src/playstation-header.vala |   48 +++++++++++++++++++
 plugins/playstation/src/playstation-plugin.vala |   38 +++++++++++++++
 plugins/playstation/src/playstation-uid.vala    |   20 ++++++++
 11 files changed, 201 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 70a7caa..015190e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,6 +40,7 @@ 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-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 43525ac..e52cdc6 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -72,6 +72,10 @@ if ENABLE_PC_ENGINE_PLUGIN
 SUBDIRS += pc-engine
 endif
 
+if ENABLE_PLAYSTATION_PLUGIN
+SUBDIRS += playstation
+endif
+
 if ENABLE_SEGA_SATURN_PLUGIN
 SUBDIRS += sega-saturn
 endif
diff --git a/plugins/playstation/Makefile.am b/plugins/playstation/Makefile.am
new file mode 100644
index 0000000..1555c85
--- /dev/null
+++ b/plugins/playstation/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS = data src
+
+include $(top_srcdir)/git.mk
diff --git a/plugins/playstation/configure.ac b/plugins/playstation/configure.ac
new file mode 100644
index 0000000..123075d
--- /dev/null
+++ b/plugins/playstation/configure.ac
@@ -0,0 +1,14 @@
+PKG_CHECK_MODULES(PSX_PLUGIN, [
+       gio-2.0
+       glib-2.0 >= $GLIB_MIN_VERSION
+       gtk+-3.0
+       tracker-sparql-1.0
+], [enable_playstation_plugin=yes], [enable_playstation_plugin=no])
+
+AM_CONDITIONAL(ENABLE_PLAYSTATION_PLUGIN, test x$enable_playstation_plugin != xno)
+
+AC_CONFIG_FILES([
+       plugins/playstation/Makefile
+       plugins/playstation/data/Makefile
+       plugins/playstation/src/Makefile
+])
diff --git a/plugins/playstation/data/Makefile.am b/plugins/playstation/data/Makefile.am
new file mode 100644
index 0000000..a035090
--- /dev/null
+++ b/plugins/playstation/data/Makefile.am
@@ -0,0 +1,6 @@
+EXTRA_DIST = $(plugin_DATA)
+
+plugindir = $(libdir)/gnome-games/plugins
+dist_plugin_DATA = playstation.plugin
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/playstation/data/playstation.plugin b/plugins/playstation/data/playstation.plugin
new file mode 100644
index 0000000..feaf8e6
--- /dev/null
+++ b/plugins/playstation/data/playstation.plugin
@@ -0,0 +1,6 @@
+[Plugin]
+Module=libgames-playstation-plugin
+Name=PlayStation Plugin
+Description=Provides support for PlayStation games.
+Authors=Ricard Gascons <gascons1995 gmail com>
+Copyright=Copyright © 2016 Ricard Gascons
diff --git a/plugins/playstation/src/Makefile.am b/plugins/playstation/src/Makefile.am
new file mode 100644
index 0000000..311974a
--- /dev/null
+++ b/plugins/playstation/src/Makefile.am
@@ -0,0 +1,56 @@
+plugindir = $(libdir)/gnome-games/plugins
+plugin_LTLIBRARIES = libgames-playstation-plugin.la
+
+libgames_playstation_plugin_la_DEPENDENCIES = \
+       $(top_builddir)/src/gnome-games.vapi \
+       $(NULL)
+
+libgames_playstation_plugin_la_SOURCES = \
+       playstation-error.vala \
+       playstation-header.vala \
+       playstation-plugin.vala \
+       playstation-uid.vala \
+       $(NULL)
+
+libgames_playstation_plugin_la_VALAFLAGS = \
+       --target-glib=@GLIB_MIN_VERSION@ \
+       --pkg gnome-games \
+       --pkg gio-2.0 \
+       --pkg glib-2.0 \
+       --pkg gtk+-3.0 \
+       --pkg tracker-sparql-1.0 \
+       --vapidir $(top_builddir)/src \
+       $(NULL)
+
+libgames_playstation_plugin_la_CFLAGS = \
+       $(PLAYSTATION_PLUGIN_CFLAGS) \
+       $(GNOME_GAMES_CFLAGS) \
+       -DG_LOG_DOMAIN=\"GamesPlayStation\" \
+       -DLOCALEDIR=\"$(localedir)\" \
+       $(NULL)
+
+libgames_playstation_plugin_la_CPPFLAGS = \
+       -I$(top_srcdir) \
+       -I$(top_srcdir)/src \
+       $(NULL)
+
+libgames_playstation_plugin_la_LIBADD = \
+       $(PLAYSTATION_PLUGIN_LIBS) \
+       $(GNOME_GAMES_LIBS) \
+       $(NULL)
+
+libgames_playstation_plugin_la_LDFLAGS = \
+       -no-undefined \
+       -module \
+       -avoid-version \
+       $(NULL)
+
+EXTRA_DIST = \
+       $(plugin_DATA) \
+       $(NULL)
+
+MAINTAINERCLEANFILES = \
+       $(BUILT_SOURCES) \
+       $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/playstation/src/playstation-error.vala b/plugins/playstation/src/playstation-error.vala
new file mode 100644
index 0000000..1c7a460
--- /dev/null
+++ b/plugins/playstation/src/playstation-error.vala
@@ -0,0 +1,5 @@
+// This file is part of GNOME Games. License: GPLv3
+
+errordomain Games.PlayStationError {
+       INVALID_HEADER,
+}
diff --git a/plugins/playstation/src/playstation-header.vala b/plugins/playstation/src/playstation-header.vala
new file mode 100644
index 0000000..12111be
--- /dev/null
+++ b/plugins/playstation/src/playstation-header.vala
@@ -0,0 +1,48 @@
+// This file is part of GNOME Games. License: GPLv3
+
+private class Games.PlayStationHeader : Object {
+       private const size_t[] OFFSETS = { 0xD368, 0xD3A8 };
+       private const string[] IDS = { "SLUS", "SCUS", "SLES", "SCES", "SLPS", "SLPM", "SCPS" };
+       private const string MAGIC_VALUE = "BOOT";
+
+       private string _disc_id;
+       public string disc_id {
+               get { return _disc_id; }
+       }
+
+       private File file;
+
+       public PlayStationHeader (File file) {
+               this.file = file;
+       }
+
+       public void check_validity () throws Error {
+               var stream = new StringInputStream (file);
+               var offset = get_header_offset ();
+               var header = stream.read_string (offset);
+
+               foreach (var id in IDS) {
+                       if (!(id in header))
+                               continue;
+
+                       var raw_id = header.split (id)[1];
+                       raw_id = raw_id.split (";")[0];
+                       raw_id = raw_id.replace ("_", "-");
+                       raw_id = raw_id.replace (".", "");
+                       _disc_id = raw_id;
+               }
+
+               if (_disc_id == null)
+                       throw new PlayStationError.INVALID_HEADER (_("Invalid PlayStation header: disc ID not 
found in '%s'."), file.get_uri ());
+       }
+
+       private size_t get_header_offset () throws Error {
+               var stream = new StringInputStream (file);
+
+               foreach (var offset in OFFSETS)
+                       if (stream.has_string (offset, MAGIC_VALUE))
+                               return offset;
+
+               throw new PlayStationError.INVALID_HEADER (_("PlayStation header not found in '%s'."), 
file.get_uri ());
+       }
+}
diff --git a/plugins/playstation/src/playstation-plugin.vala b/plugins/playstation/src/playstation-plugin.vala
new file mode 100644
index 0000000..a3be700
--- /dev/null
+++ b/plugins/playstation/src/playstation-plugin.vala
@@ -0,0 +1,38 @@
+// This file is part of GNOME Games. License: GPLv3
+
+private class Games.PlayStation : Object, Plugin {
+       private const string MIME_TYPE = "application/x-cue";
+       private const string MODULE_BASENAME = "libretro-playstation.so";
+       private const bool SUPPORTS_SNAPSHOTTING = true;
+
+       public GameSource get_game_source () throws Error {
+               var query = new MimeTypeTrackerQuery (MIME_TYPE, game_for_uri);
+               var connection = Tracker.Sparql.Connection.@get ();
+               var source = new TrackerGameSource (connection);
+               source.add_query (query);
+
+               return source;
+       }
+
+       private static Game game_for_uri (string uri) throws Error {
+               var cue_file = File.new_for_uri (uri);
+               var cue_sheet = new CueSheet (cue_file);
+               var cue_track_node = cue_sheet.get_track (0);
+               var bin_file = cue_track_node.file.file;
+               var header = new PlayStationHeader (bin_file);
+               header.check_validity ();
+
+               var uid = new PlayStationUid (header);
+               var title = new FilenameTitle (uri);
+               var icon = new DummyIcon ();
+               var cover = new DummyCover ();
+               var runner = new RetroRunner (MODULE_BASENAME, uri, uid, SUPPORTS_SNAPSHOTTING);
+
+               return new GenericGame (title, icon, cover, runner);
+       }
+}
+
+[ModuleInit]
+public Type register_games_plugin (TypeModule module) {
+       return typeof(Games.PlayStation);
+}
diff --git a/plugins/playstation/src/playstation-uid.vala b/plugins/playstation/src/playstation-uid.vala
new file mode 100644
index 0000000..5952b5f
--- /dev/null
+++ b/plugins/playstation/src/playstation-uid.vala
@@ -0,0 +1,20 @@
+// This file is part of GNOME Games. License: GPLv3
+
+private class Games.PlayStationUid: Object, Uid {
+       private PlayStationHeader header;
+       private string uid;
+
+       public PlayStationUid (PlayStationHeader header) {
+               this.header = header;
+       }
+
+       public string get_uid () throws Error {
+               if (uid != null)
+                       return uid;
+
+               var disc_id = header.disc_id;
+               uid = @"playstation-$disc_id".down ();
+
+               return uid;
+       }
+}


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