[gnome-games] core: Add FirmwareManager
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] core: Add FirmwareManager
- Date: Sun, 14 Jun 2020 13:18:59 +0000 (UTC)
commit e7bc01c279187292f41c1adc400cb99adce971a8
Author: Adwait Rawat <adwait rawat gmail com>
Date: Thu Jun 11 02:41:43 2020 +0900
core: Add FirmwareManager
Added FirmwareManager class to handle firmware related actions in a
different class as they were being handled by RetroCoreSource previously.
src/core/firmware-manager.vala | 51 ++++++++++++++++++++++++++++++++++++++++++
src/meson.build | 1 +
2 files changed, 52 insertions(+)
---
diff --git a/src/core/firmware-manager.vala b/src/core/firmware-manager.vala
new file mode 100644
index 00000000..1e43c170
--- /dev/null
+++ b/src/core/firmware-manager.vala
@@ -0,0 +1,51 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+errordomain Games.FirmwareError {
+ FIRMWARE_NOT_FOUND,
+}
+
+public class Games.FirmwareManager : Object {
+ public void is_all_firmware_valid (Core core, Platform platform) throws Error {
+ 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");
+
+ foreach (var firmware in core.get_all_firmware (platform)) {
+ if (!core.get_is_firmware_mandatory (firmware))
+ continue;
+
+ var firmware_path = core.get_firmware_path (firmware);
+ var firmware_file = firmware_dir.get_child (firmware_path);
+ if (!firmware_file.query_exists ())
+ throw new FirmwareError.FIRMWARE_NOT_FOUND ("This game requires the %s
firmware file to run.", firmware_file.get_path ());
+
+ check_firmware_is_valid (core, firmware, firmware_file);
+ }
+ }
+
+ private void check_firmware_is_valid (Core core, string firmware, File firmware_file) throws Error {
+ var has_md5 = core.has_firmware_md5 (firmware);
+ var has_sha512 = core.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.get_firmware_md5 (firmware);
+ if (Checksum.compute_for_bytes (ChecksumType.MD5, bytes) != md5)
+ throw new FirmwareError.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.get_firmware_sha512 (firmware);
+ if (Checksum.compute_for_bytes (ChecksumType.SHA512, bytes) != sha512)
+ throw new FirmwareError.FIRMWARE_NOT_FOUND ("This game requires the %s
firmware file with a SHA-512 fingerprint of %s to run.", firmware_file.get_path (), sha512);
+ }
+ }
+}
diff --git a/src/meson.build b/src/meson.build
index 5d56f024..ef621bc6 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -17,6 +17,7 @@ vala_sources = [
'core/core.vala',
'core/cover.vala',
'core/cover-loader.vala',
+ 'core/firmware-manager.vala',
'core/game.vala',
'core/game-callback.vala',
'core/game-collection.vala',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]