[gnome-games] pc-engine: Support CD-ROM² games
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] pc-engine: Support CD-ROM² games
- Date: Wed, 17 Aug 2016 20:21:26 +0000 (UTC)
commit c3c621cf855cc73fcc24a236c83c871701f54130
Author: Adrien Plazas <kekun plazas laposte net>
Date: Fri Jul 29 12:56:08 2016 +0200
pc-engine: Support CD-ROM² games
https://bugzilla.gnome.org/show_bug.cgi?id=769496
plugins/pc-engine/data/pc-engine.plugin | 2 +-
plugins/pc-engine/src/Makefile.am | 1 +
plugins/pc-engine/src/pc-engine-error.vala | 5 +++
plugins/pc-engine/src/pc-engine-plugin.vala | 39 +++++++++++++++++++++++++++
4 files changed, 46 insertions(+), 1 deletions(-)
---
diff --git a/plugins/pc-engine/data/pc-engine.plugin b/plugins/pc-engine/data/pc-engine.plugin
index 3496f58..dc41af0 100644
--- a/plugins/pc-engine/data/pc-engine.plugin
+++ b/plugins/pc-engine/data/pc-engine.plugin
@@ -1,6 +1,6 @@
[Plugin]
Module=libgames-pc-engine-plugin
Name=PC-Engine Plugin
-Description=Provides support for PC-Engine/TurboGrafx-16 games.
+Description=Provides support for PC-Engine/TurboGrafx-16 and CD-ROM² games.
Authors=Adrien Plazas <kekun plazas laposte net>
Copyright=Copyright © 2016 Adrien Plazas
diff --git a/plugins/pc-engine/src/Makefile.am b/plugins/pc-engine/src/Makefile.am
index 9c2dca2..60f0e93 100644
--- a/plugins/pc-engine/src/Makefile.am
+++ b/plugins/pc-engine/src/Makefile.am
@@ -6,6 +6,7 @@ libgames_pc_engine_plugin_la_DEPENDENCIES = \
$(NULL)
libgames_pc_engine_plugin_la_SOURCES = \
+ pc-engine-error.vala \
pc-engine-plugin.vala \
$(NULL)
diff --git a/plugins/pc-engine/src/pc-engine-error.vala b/plugins/pc-engine/src/pc-engine-error.vala
new file mode 100644
index 0000000..737da83
--- /dev/null
+++ b/plugins/pc-engine/src/pc-engine-error.vala
@@ -0,0 +1,5 @@
+// This file is part of GNOME Games. License: GPLv3
+
+private errordomain Games.PcEngineError {
+ INVALID_DISC,
+}
diff --git a/plugins/pc-engine/src/pc-engine-plugin.vala b/plugins/pc-engine/src/pc-engine-plugin.vala
index ae70362..d5838b3 100644
--- a/plugins/pc-engine/src/pc-engine-plugin.vala
+++ b/plugins/pc-engine/src/pc-engine-plugin.vala
@@ -2,16 +2,24 @@
private class Games.PcEnginePlugin : Object, Plugin {
private const string FINGERPRINT_PREFIX = "pc-engine";
+
private const string MIME_TYPE = "application/x-pc-engine-rom";
+
+ private const string CUE_MIME_TYPE = "application/x-cue";
+ private const string CD_MAGIC_VALUE = "PC Engine CD-ROM SYSTEM";
+
private const string MODULE_BASENAME = "libretro-pc-engine.so";
private const bool SUPPORTS_SNAPSHOTTING = true;
public GameSource get_game_source () throws Error {
var game_uri_adapter = new GenericSyncGameUriAdapter (game_for_uri);
+ var cd_game_uri_adapter = new GenericSyncGameUriAdapter (cd_game_for_uri);
var query = new MimeTypeTrackerQuery (MIME_TYPE, game_uri_adapter);
+ var cd_query = new MimeTypeTrackerQuery (CUE_MIME_TYPE, cd_game_uri_adapter);
var connection = Tracker.Sparql.Connection.@get ();
var source = new TrackerGameSource (connection);
source.add_query (query);
+ source.add_query (cd_query);
return source;
}
@@ -28,6 +36,37 @@ private class Games.PcEnginePlugin : Object, Plugin {
return new GenericGame (title, icon, cover, runner);
}
+
+ private static Game cd_game_for_uri (string uri) throws Error {
+ if (!is_valid_disc (uri))
+ throw new PcEngineError.INVALID_DISC ("'%s' isn't a valid PC-Engine CD-ROM² disc.",
uri);
+
+ var uid = new FingerprintUid (uri, FINGERPRINT_PREFIX);
+ var title = new FilenameTitle (uri);
+ var icon = new DummyIcon ();
+ var media = new GriloMedia (title, MIME_TYPE);
+ var cover = new GriloCover (media, uid);
+ var runner = new RetroRunner.with_mime_types (uri, uid, { CUE_MIME_TYPE, MIME_TYPE },
MODULE_BASENAME, SUPPORTS_SNAPSHOTTING);
+
+ return new GenericGame (title, icon, cover, runner);
+ }
+
+ private static bool is_valid_disc (string uri) throws Error {
+ var cue_file = File.new_for_uri (uri);
+ var cue_sheet = new CueSheet (cue_file);
+ if (cue_sheet.tracks_number < 2)
+ return false;
+
+ var track = cue_sheet.get_track (1);
+ if (!track.track_mode.is_mode1 ())
+ return false;
+
+ var bin_file = track.file.file;
+ 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]