[gnome-games] sega-saturn: Replace SegaSaturnGame by GenericGame
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] sega-saturn: Replace SegaSaturnGame by GenericGame
- Date: Thu, 12 May 2016 16:53:40 +0000 (UTC)
commit 1c8544b14616663d790a15364e4402dc6616053e
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu May 12 08:16:49 2016 +0200
sega-saturn: Replace SegaSaturnGame by GenericGame
This is needed to remove custom game types and to simplify the code
base.
plugins/sega-saturn/src/Makefile.am | 1 -
plugins/sega-saturn/src/sega-saturn-game.vala | 84 -----------------------
plugins/sega-saturn/src/sega-saturn-plugin.vala | 52 ++++++++++++++-
3 files changed, 51 insertions(+), 86 deletions(-)
---
diff --git a/plugins/sega-saturn/src/Makefile.am b/plugins/sega-saturn/src/Makefile.am
index 94a2dab..a53cb7b 100644
--- a/plugins/sega-saturn/src/Makefile.am
+++ b/plugins/sega-saturn/src/Makefile.am
@@ -6,7 +6,6 @@ libgames_sega_saturn_plugin_la_DEPENDENCIES = \
$(NULL)
libgames_sega_saturn_plugin_la_SOURCES = \
- sega-saturn-game.vala \
sega-saturn-header.vala \
sega-saturn-plugin.vala \
sega-saturn-uid.vala \
diff --git a/plugins/sega-saturn/src/sega-saturn-plugin.vala b/plugins/sega-saturn/src/sega-saturn-plugin.vala
index d82a659..e0668ae 100644
--- a/plugins/sega-saturn/src/sega-saturn-plugin.vala
+++ b/plugins/sega-saturn/src/sega-saturn-plugin.vala
@@ -2,6 +2,8 @@
private class Games.SegaSaturnPlugin : Object, Plugin {
private const string MIME_TYPE = "application/x-saturn-rom";
+ private const string MODULE_BASENAME = "libretro-saturn.so";
+ private const bool SUPPORTS_SNAPSHOTTING = false;
public GameSource get_game_source () throws Error {
var query = new MimeTypeTrackerQuery (MIME_TYPE, game_for_uri);
@@ -13,7 +15,55 @@ private class Games.SegaSaturnPlugin : Object, Plugin {
}
private static Game game_for_uri (string uri) throws Error {
- return new SegaSaturnGame (uri);
+ var file = File.new_for_uri (uri);
+ var header = new SegaSaturnHeader (file);
+ header.check_validity ();
+
+ var cue = get_associated_cue_sheet (file);
+ var real_uri = cue ?? uri;
+
+ var uid = new SegaSaturnUid (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);
+ }
+
+ private static string? get_associated_cue_sheet (File file) throws Error {
+ var directory = file.get_parent ();
+ var enumerator = directory.enumerate_children (FileAttribute.STANDARD_NAME, 0);
+
+ FileInfo file_info;
+ while ((file_info = enumerator.next_file ()) != null) {
+ var name = file_info.get_name ();
+ var child = directory.resolve_relative_path (name);
+ var child_info = child.query_info ("*", FileQueryInfoFlags.NONE);
+ var type = child_info.get_content_type ();
+
+ if (type == "application/x-cue" && cue_contains_file (child, file))
+ return child.get_uri ();
+ }
+
+ return null;
+ }
+
+ private static bool cue_contains_file (File cue, File file) throws Error {
+ var file_input_stream = cue.read ();
+ var data_input_stream = new DataInputStream (file_input_stream);
+
+ var regex = /FILE\s+"(.*?)"\s+BINARY/;
+
+ string line;
+ MatchInfo match_info;
+ while ((line = data_input_stream.read_line (null)) != null) {
+ if (regex.match (line, RegexMatchFlags.ANCHORED, out match_info))
+ if (match_info.fetch (1) == file.get_basename ())
+ return true;
+ }
+
+ return false;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]