[gnome-games] retro: Add RetroFirmware object
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] retro: Add RetroFirmware object
- Date: Tue, 23 Jun 2020 10:56:01 +0000 (UTC)
commit cfa8806403fda5e896dd974cbe1acd9f3ff7b444
Author: Adwait Rawat <adwait rawat gmail com>
Date: Mon Jun 22 21:00:55 2020 +0900
retro: Add RetroFirmware object
src/meson.build | 1 +
src/retro/retro-firmware.vala | 57 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
---
diff --git a/src/meson.build b/src/meson.build
index 4db4c265..8cd6e8c8 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -84,6 +84,7 @@ vala_sources = [
'retro/retro-core-manager.vala',
'retro/retro-core-source.vala',
'retro/retro-error.vala',
+ 'retro/retro-firmware.vala',
'retro/retro-gamepad.vala',
'retro/retro-input-manager.vala',
'retro/retro-options.vala',
diff --git a/src/retro/retro-firmware.vala b/src/retro/retro-firmware.vala
new file mode 100644
index 00000000..a4b00716
--- /dev/null
+++ b/src/retro/retro-firmware.vala
@@ -0,0 +1,57 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.RetroFirmware : Object, Firmware {
+ private string name;
+ private bool is_mandatory;
+ private string path;
+ private string? md5;
+ private string? sha512;
+
+ public RetroFirmware (string name, Retro.CoreDescriptor core_descriptor) throws Error {
+ this.name = name;
+
+ if (core_descriptor.has_firmware_md5 (name))
+ md5 = core_descriptor.get_firmware_md5 (name);
+ if (core_descriptor.has_firmware_sha512 (name))
+ sha512 = core_descriptor.get_firmware_sha512 (name);
+
+ is_mandatory = core_descriptor.get_is_firmware_mandatory (name);
+ path = core_descriptor.get_firmware_path (name);
+ }
+
+ public bool get_is_mandatory () {
+ return is_mandatory;
+ }
+
+ public void check_is_valid (Platform platform) throws FirmwareError {
+ var firmware_dir = File.new_for_path (platform.get_system_dir ());
+
+ var firmware = firmware_dir.get_child (path);
+ if (!firmware.query_exists ())
+ throw new FirmwareError.FIRMWARE_NOT_FOUND ("This game requires the %s firmware file
to run.", firmware.get_path ());
+
+ if (md5 == null && sha512 == null)
+ return;
+
+ try {
+ var stream = firmware.read ();
+
+ stream.seek (0, SeekType.END);
+ var size = (size_t) stream.tell ();
+ stream.seek (0, SeekType.SET);
+ var bytes = stream.read_bytes (size);
+
+ if (md5 != null) {
+ 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.get_path (), md5);
+ }
+
+ if (sha512 != null) {
+ 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.get_path (), sha512);
+ }
+ } catch (Error e) {
+ throw new FirmwareError.FIRMWARE_NOT_FOUND (e.message);
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]