[gnome-games/wip/aplazas/781334-refactor-game-source: 1/12] mega-drive: Provide MIME types and URI game factories
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/aplazas/781334-refactor-game-source: 1/12] mega-drive: Provide MIME types and URI game factories
- Date: Thu, 4 May 2017 17:41:26 +0000 (UTC)
commit 76f354196ef5b3355e17ab2a065d8dc7346d4571
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu May 4 15:37:59 2017 +0200
mega-drive: Provide MIME types and URI game factories
Also stop providing a GameSource.
This helps splitting the conerns of looking for game resources and
building games from them.
plugins/mega-drive/src/mega-drive-plugin.vala | 54 +++++++++++++++++--------
1 files changed, 37 insertions(+), 17 deletions(-)
---
diff --git a/plugins/mega-drive/src/mega-drive-plugin.vala b/plugins/mega-drive/src/mega-drive-plugin.vala
index 3663b4e..470088d 100644
--- a/plugins/mega-drive/src/mega-drive-plugin.vala
+++ b/plugins/mega-drive/src/mega-drive-plugin.vala
@@ -19,24 +19,29 @@ private class Games.MegaDrivePlugin : Object, Plugin {
private const string MEGA_CD_PLATFORM = "SegaCD";
private const string MEGA_CD_32X_PLATFORM = "SegaCD32X";
- public GameSource? get_game_source () throws Error {
+ public string[] get_mime_types () {
+ return {
+ MEGA_DRIVE_MIME_TYPE,
+ 32X_MIME_TYPE,
+ PICO_MIME_TYPE,
+ CUE_MIME_TYPE,
+ MEGA_CD_MIME_TYPE,
+ };
+ }
+
+ public UriGameFactory[] get_uri_game_factories () {
var game_uri_adapter = new GenericSyncGameUriAdapter (game_for_uri);
+ var factory = new GenericUriGameFactory (game_uri_adapter);
+ factory.add_mime_type (MEGA_DRIVE_MIME_TYPE);
+ factory.add_mime_type (32X_MIME_TYPE);
+ factory.add_mime_type (PICO_MIME_TYPE);
+
var cd_game_uri_adapter = new GenericSyncGameUriAdapter (cd_game_for_uri);
- // FIXME We should be able to use one factory for Mega Drive and
- // 32X.
- var mega_drive_factory = new GenericUriGameFactory (game_uri_adapter);
- var 32x_factory = new GenericUriGameFactory (game_uri_adapter);
var mega_cd_factory = new GenericUriGameFactory (cd_game_uri_adapter);
- var mega_drive_query = new MimeTypeTrackerQuery (MEGA_DRIVE_MIME_TYPE, mega_drive_factory);
- var 32x_query = new MimeTypeTrackerQuery (32X_MIME_TYPE, 32x_factory);
- var mega_cd_query = new MimeTypeTrackerQuery (CUE_MIME_TYPE, mega_cd_factory);
- var connection = Tracker.Sparql.Connection.@get ();
- var source = new TrackerGameSource (connection);
- source.add_query (mega_drive_query);
- source.add_query (32x_query);
- source.add_query (mega_cd_query);
-
- return source;
+ mega_cd_factory.add_mime_type (CUE_MIME_TYPE);
+ mega_cd_factory.add_mime_type (MEGA_CD_MIME_TYPE);
+
+ return { factory, mega_cd_factory };
}
private static Game game_for_uri (string uri) throws Error {
@@ -80,8 +85,23 @@ private class Games.MegaDrivePlugin : Object, Plugin {
private static Game cd_game_for_uri (string uri) throws Error {
var file = File.new_for_uri (uri);
- var cue = new CueSheet (file);
- var bin_file = get_binary_file (cue);
+ 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);
+ bin_file = get_binary_file (cue);
+
+ break;
+ case MEGA_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);
+ }
var header = new MegaDriveHeader (bin_file);
header.check_validity ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]