[gnome-games/wip/exalm/3ds: 3/8] List 3DS games in collection
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/3ds: 3/8] List 3DS games in collection
- Date: Sat, 5 Dec 2020 13:57:20 +0000 (UTC)
commit f6716d1c15489da1f06921ff84bce553f26046a7
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sun Nov 8 16:05:43 2020 +0500
List 3DS games in collection
Add a simple 3DS plugin for finding games. It doesn't provide a view
switcher like DS plugin yet, since we don't ship any core.
See https://gitlab.freedesktop.org/xdg/shared-mime-info/-/merge_requests/86
data/org.gnome.Games.desktop.in.in | 2 +-
meson_options.txt | 1 +
plugins/meson.build | 1 +
plugins/nintendo-3ds/data/meson.build | 1 +
plugins/nintendo-3ds/data/nintendo-3ds.plugin | 6 +++
plugins/nintendo-3ds/meson.build | 2 +
plugins/nintendo-3ds/src/meson.build | 17 ++++++
plugins/nintendo-3ds/src/nintendo-3ds-header.vala | 55 +++++++++++++++++++
plugins/nintendo-3ds/src/nintendo-3ds-plugin.vala | 66 +++++++++++++++++++++++
9 files changed, 150 insertions(+), 1 deletion(-)
---
diff --git a/data/org.gnome.Games.desktop.in.in b/data/org.gnome.Games.desktop.in.in
index 779e780a..bae7d866 100644
--- a/data/org.gnome.Games.desktop.in.in
+++ b/data/org.gnome.Games.desktop.in.in
@@ -13,4 +13,4 @@ Type=Application
StartupNotify=true
DBusActivatable=true
Categories=GNOME;GTK;Player;Game;
-MimeType=application/vnd.nintendo.snes.rom;application/x-amiga-disk-format;application/x-atari-2600-rom;application/x-atari-7800-rom;application/x-atari-lynx-rom;application/x-cue;application/x-discjuggler-cd-image;application/x-doom-wad;application/x-fds-disk;application/x-gameboy-color-rom;application/x-gameboy-rom;application/x-gamecube-rom;application/x-gamegear-rom;application/x-gba-rom;application/x-gd-rom-cue;application/x-genesis-32x-rom;application/x-genesis-rom;application/x-love-game;application/x-mame-rom;application/x-ms-dos-executable;application/x-n64-rom;application/x-neo-geo-pocket-color-rom;application/x-neo-geo-pocket-rom;application/x-nes-rom;application/x-nintendo-ds-rom;application/x-pc-engine-rom;application/x-playstation-rom;application/x-saturn-rom;application/x-sega-cd-rom;application/x-sega-pico-rom;application/x-sg1000-rom;application/x-sms-rom;application/x-virtual-boy-rom;application/x-wii-rom;application/x-wii-wad;application/x-wonderswan-color-rom;app
lication/x-wonderswan-rom;application/zip;
+MimeType=application/vnd.nintendo.snes.rom;application/x-amiga-disk-format;application/x-atari-2600-rom;application/x-atari-7800-rom;application/x-atari-lynx-rom;application/x-cue;application/x-discjuggler-cd-image;application/x-doom-wad;application/x-fds-disk;application/x-gameboy-color-rom;application/x-gameboy-rom;application/x-gamecube-rom;application/x-gamegear-rom;application/x-gba-rom;application/x-gd-rom-cue;application/x-genesis-32x-rom;application/x-genesis-rom;application/x-love-game;application/x-mame-rom;application/x-ms-dos-executable;application/x-n64-rom;application/x-neo-geo-pocket-color-rom;application/x-neo-geo-pocket-rom;application/x-nes-rom;application/x-nintendo-3ds-executable;application/x-nintendo-3ds-rom;application/x-nintendo-ds-rom;application/x-pc-engine-rom;application/x-playstation-rom;application/x-saturn-rom;application/x-sega-cd-rom;application/x-sega-pico-rom;application/x-sg1000-rom;application/x-sms-rom;application/x-virtual-boy-rom;application/x
-wii-rom;application/x-wii-wad;application/x-wonderswan-color-rom;application/x-wonderswan-rom;application/zip;
diff --git a/meson_options.txt b/meson_options.txt
index fa589741..1012b464 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -17,6 +17,7 @@ option ('libretro-plugin', description: 'Support for Libretro games',
option ('love-plugin', description: 'Support for LÖVE games', type: 'boolean')
option ('mame-plugin', description: 'Support for MAME games', type: 'boolean')
option ('ms-dos-plugin', description: 'Support for MS-DOS games', type: 'boolean')
+option ('nintendo-3ds-plugin', description: 'Support for Nintendo 3DS games', type: 'boolean')
option ('nintendo-64-plugin', description: 'Support for Nintendo 64 games', type: 'boolean')
option ('nintendo-ds-plugin', description: 'Support for Nintendo DS games', type: 'boolean')
option ('playstation-plugin', description: 'Support for PlayStation games', type: 'boolean')
diff --git a/plugins/meson.build b/plugins/meson.build
index f15025bb..015da414 100644
--- a/plugins/meson.build
+++ b/plugins/meson.build
@@ -6,6 +6,7 @@ plugins = [
'love',
'mame',
'ms-dos',
+ 'nintendo-3ds',
'nintendo-64',
'nintendo-ds',
'playstation',
diff --git a/plugins/nintendo-3ds/data/meson.build b/plugins/nintendo-3ds/data/meson.build
new file mode 100644
index 00000000..0d4b6c49
--- /dev/null
+++ b/plugins/nintendo-3ds/data/meson.build
@@ -0,0 +1 @@
+install_data (plugin_name + '.plugin', install_dir: plugins_dir)
diff --git a/plugins/nintendo-3ds/data/nintendo-3ds.plugin b/plugins/nintendo-3ds/data/nintendo-3ds.plugin
new file mode 100644
index 00000000..f3edf634
--- /dev/null
+++ b/plugins/nintendo-3ds/data/nintendo-3ds.plugin
@@ -0,0 +1,6 @@
+[Plugin]
+Module=libgames-nintendo-3ds-plugin
+Name=Nintendo 3DS Plugin
+Description=Provides support for Nintendo 3DS games.
+Authors=Alexander Mikhaylenko <alexm gnome org>
+Copyright=Copyright © 2020 Alexander Mikhaylenko
diff --git a/plugins/nintendo-3ds/meson.build b/plugins/nintendo-3ds/meson.build
new file mode 100644
index 00000000..d7e84900
--- /dev/null
+++ b/plugins/nintendo-3ds/meson.build
@@ -0,0 +1,2 @@
+subdir ('data')
+subdir ('src')
diff --git a/plugins/nintendo-3ds/src/meson.build b/plugins/nintendo-3ds/src/meson.build
new file mode 100644
index 00000000..b1aadedb
--- /dev/null
+++ b/plugins/nintendo-3ds/src/meson.build
@@ -0,0 +1,17 @@
+vala_sources = [
+ 'nintendo-3ds-header.vala',
+ 'nintendo-3ds-plugin.vala',
+]
+
+c_args = [
+ '-DG_LOG_DOMAIN="GamesNintendo3DS"'
+]
+
+shared_module (
+ 'games-' + plugin_name + '-plugin',
+ vala_sources,
+ dependencies: gnome_games_dep,
+ c_args: c_args,
+ install: true,
+ install_dir: plugins_dir
+)
diff --git a/plugins/nintendo-3ds/src/nintendo-3ds-header.vala
b/plugins/nintendo-3ds/src/nintendo-3ds-header.vala
new file mode 100644
index 00000000..eb0129c3
--- /dev/null
+++ b/plugins/nintendo-3ds/src/nintendo-3ds-header.vala
@@ -0,0 +1,55 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+// Documentation: https://www.planetvb.com/content/downloads/documents/stsvb.html
+private class Games.Nintendo3DsHeader : Object {
+ private const size_t MAGIC_OFFSET = 0x189;
+ private const uint8 MAGIC_VALUE = 0;
+
+ private File file;
+
+ public Nintendo3DsHeader (File file) {
+ this.file = file;
+ }
+
+ public void check_validity () throws Nintendo3DSError {
+ var stream = get_stream ();
+ ssize_t read = 0;
+
+ try {
+ stream.seek (MAGIC_OFFSET, SeekType.SET);
+ }
+ catch (Error e) {
+ throw new Nintendo3DSError.INVALID_SIZE ("Invalid Nintendo 3DS ROM header size: %s",
e.message);
+ }
+
+ var buffer = new uint8[1];
+ try {
+ read = stream.read (buffer);
+ }
+ catch (Error e) {
+ throw new Nintendo3DSError.INVALID_SIZE (e.message);
+ }
+
+ if (read < 1)
+ throw new Nintendo3DSError.INVALID_SIZE ("Invalid Nintendo 3DS ROM header size.");
+
+ if (buffer[0] != MAGIC_VALUE)
+ throw new Nintendo3DSError.ROM_ENCRYPTED ("The ROM is encrypted.");
+ }
+
+ private FileInputStream get_stream () throws Nintendo3DSError {
+ try {
+ return file.read ();
+ }
+ catch (Error e) {
+ throw new Nintendo3DSError.CANT_READ_FILE ("Couldn’t read file: %s", e.message);
+ }
+ }
+}
+
+errordomain Games.Nintendo3DSError {
+ CANT_READ_FILE,
+ INVALID_FILE,
+ INVALID_SIZE,
+ ROM_ENCRYPTED,
+}
diff --git a/plugins/nintendo-3ds/src/nintendo-3ds-plugin.vala
b/plugins/nintendo-3ds/src/nintendo-3ds-plugin.vala
new file mode 100644
index 00000000..976dc76b
--- /dev/null
+++ b/plugins/nintendo-3ds/src/nintendo-3ds-plugin.vala
@@ -0,0 +1,66 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.Nintendo3DsPlugin : Object, Plugin {
+ private const string 3DS_MIME_TYPE = "application/x-nintendo-3ds-rom";
+ private const string 3DSX_MIME_TYPE = "application/x-nintendo-3ds-executable";
+ private const string PLATFORM_ID = "Nintendo3DS";
+ private const string PLATFORM_NAME = _("Nintendo 3DS");
+ private const string PLATFORM_UID_PREFIX = "nintendo-3ds";
+ private const string[] MIME_TYPES = { 3DS_MIME_TYPE, 3DSX_MIME_TYPE };
+
+ private static RetroPlatform platform;
+
+ static construct {
+ platform = new RetroPlatform (PLATFORM_ID, PLATFORM_NAME, MIME_TYPES, PLATFORM_UID_PREFIX);
+ }
+
+ public Platform[] get_platforms () {
+ return { platform };
+ }
+
+ public string[] get_mime_types () {
+ return MIME_TYPES;
+ }
+
+ public UriGameFactory[] get_uri_game_factories () {
+ var game_uri_adapter = new GenericGameUriAdapter (game_for_uri);
+ var factory = new GenericUriGameFactory (game_uri_adapter);
+ foreach (var mime_type in MIME_TYPES)
+ factory.add_mime_type (mime_type);
+
+ return { factory };
+ }
+
+ public RunnerFactory[] get_runner_factories () {
+ var factory = new RetroRunnerFactory (platform);
+
+ return { factory };
+ }
+
+ private static Game game_for_uri (Uri uri) throws Error {
+ var file = uri.to_file ();
+
+ var file_info = file.query_info ("*", FileQueryInfoFlags.NONE);
+ if (file_info.get_content_type () == 3DS_MIME_TYPE) {
+ var header = new Nintendo3DsHeader (file);
+ header.check_validity ();
+ }
+
+ var uid = new Uid (Fingerprint.get_uid (uri, PLATFORM_UID_PREFIX));
+ var title = new FilenameTitle (uri);
+ var media = new GriloMedia (title, 3DS_MIME_TYPE);
+ var cover = new CompositeCover ({
+ new LocalCover (uri),
+ new GriloCover (media, uid)});
+
+ var game = new Game (uid, uri, title, platform);
+ game.set_cover (cover);
+
+ return game;
+ }
+}
+
+[ModuleInit]
+public Type register_games_plugin (TypeModule module) {
+ return typeof (Games.Nintendo3DsPlugin);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]