[gnome-games] retro-core-source: Use FirmwareManager and Core
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] retro-core-source: Use FirmwareManager and Core
- Date: Sun, 14 Jun 2020 13:19:04 +0000 (UTC)
commit a188ed79ba66b746dc17f7b1bc0794ba3b6b346a
Author: Adwait Rawat <adwait rawat gmail com>
Date: Thu Jun 11 02:42:37 2020 +0900
retro-core-source: Use FirmwareManager and Core
Use FirmwareManager class and Core interface for firmware checks.
src/retro/retro-core-source.vala | 48 +++-------------------------------------
src/retro/retro-error.vala | 1 -
src/retro/retro-runner.vala | 2 +-
3 files changed, 4 insertions(+), 47 deletions(-)
---
diff --git a/src/retro/retro-core-source.vala b/src/retro/retro-core-source.vala
index fbd0c279..b6b6c0b8 100644
--- a/src/retro/retro-core-source.vala
+++ b/src/retro/retro-core-source.vala
@@ -36,6 +36,8 @@ public class Games.RetroCoreSource : Object {
search_module ();
var platform_id = platform.get_id ();
+ var firmware_manager = new FirmwareManager ();
+ var core = new RetroCore (core_descriptor);
if (core_descriptor == null) {
var mime_types = platform.get_mime_types ();
@@ -43,9 +45,7 @@ public class Games.RetroCoreSource : Object {
throw new RetroError.MODULE_NOT_FOUND ("No module found for platform “%s” and MIME
types [ “%s” ].", platform_id, string.joinv ("”, “", mime_types));
}
- if (core_descriptor.has_firmwares (platform_id))
- foreach (var firmware in core_descriptor_get_firmwares (core_descriptor, platform_id))
- check_firmware_is_valid (firmware);
+ firmware_manager.is_all_firmware_valid (core, platform);
}
private void search_module () throws Error {
@@ -56,46 +56,4 @@ public class Games.RetroCoreSource : Object {
if (core_descriptors.length > 0)
core_descriptor = core_descriptors[0];
}
-
- private void check_firmware_is_valid (string firmware) throws Error {
- if (!core_descriptor.get_is_firmware_mandatory (firmware))
- return;
-
- var platforms_dir = Application.get_platforms_dir ();
- var platform_id = platform.get_id ();
- var firmware_dir = File.new_for_path (@"$platforms_dir/$platform_id/system");
- var firmware_path = core_descriptor.get_firmware_path (firmware);
- var firmware_file = firmware_dir.get_child (firmware_path);
- if (!firmware_file.query_exists ())
- throw new RetroError.FIRMWARE_NOT_FOUND ("This game requires the %s firmware file to
run.", firmware_file.get_path ());
-
- var has_md5 = core_descriptor.has_firmware_md5 (firmware);
- var has_sha512 = core_descriptor.has_firmware_sha512 (firmware);
- if (!has_md5 || !has_sha512)
- return;
-
- var stream = firmware_file.read ();
-
- stream.seek (0, SeekType.END);
- var size = (size_t) stream.tell ();
- stream.seek (0, SeekType.SET);
- var bytes = stream.read_bytes (size);
-
- if (has_md5) {
- var md5 = core_descriptor.get_firmware_md5 (firmware);
- if (Checksum.compute_for_bytes (ChecksumType.MD5, bytes) != md5)
- throw new RetroError.FIRMWARE_NOT_FOUND ("This game requires the %s firmware
file with a MD5 fingerprint of %s to run.", firmware_file.get_path (), md5);
- }
-
- if (has_sha512) {
- var sha512 = core_descriptor.get_firmware_sha512 (firmware);
- if (Checksum.compute_for_bytes (ChecksumType.SHA512, bytes) != sha512)
- throw new RetroError.FIRMWARE_NOT_FOUND ("This game requires the %s firmware
file with a SHA-512 fingerprint of %s to run.", firmware_file.get_path (), sha512);
- }
- }
-
- // FIXME Workaround a bug in valac or vapigen preventing from using the
- // version from the retro-gtk VAPI.
- [CCode (cname="retro_core_descriptor_get_firmwares", array_length=true, array_length_cname="length",
array_length_type="gsize")]
- private static extern string[] core_descriptor_get_firmwares (Retro.CoreDescriptor core_descriptor,
string platform) throws Error;
}
diff --git a/src/retro/retro-error.vala b/src/retro/retro-error.vala
index 6c928313..341c8efa 100644
--- a/src/retro/retro-error.vala
+++ b/src/retro/retro-error.vala
@@ -5,5 +5,4 @@ private errordomain Games.RetroError {
INVALID_GAME_FILE,
COULDNT_WRITE_SNAPSHOT,
COULDNT_LOAD_SNAPSHOT,
- FIRMWARE_NOT_FOUND,
}
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 7a7cad29..92eb53e9 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -231,7 +231,7 @@ public class Games.RetroRunner : Object, Runner {
debug ("%s\n", e.message);
throw new RunnerError.UNSUPPORTED_SYSTEM (get_unsupported_system_message ());
}
- catch (RetroError.FIRMWARE_NOT_FOUND e) {
+ catch (FirmwareError.FIRMWARE_NOT_FOUND e) {
debug ("%s\n", e.message);
throw new RunnerError.UNSUPPORTED_SYSTEM (get_unsupported_system_message ());
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]