[gnome-games] playstation: Add PlayStationHeader.search_id_in_header()
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] playstation: Add PlayStationHeader.search_id_in_header()
- Date: Sun, 28 Aug 2016 07:39:09 +0000 (UTC)
commit 78eeb73564237e601babd556829a1ef6d717875f
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sun Aug 28 09:30:23 2016 +0200
playstation: Add PlayStationHeader.search_id_in_header()
Look for IDs in the 'PLAYSTATION' header.
This allows to support games having no 'BOOT' header but containing the
disc's ID in the 'PLAYSTATION' header.
https://bugzilla.gnome.org/show_bug.cgi?id=770470
plugins/playstation/src/playstation-header.vala | 43 +++++++++++++++++++++++
1 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/plugins/playstation/src/playstation-header.vala b/plugins/playstation/src/playstation-header.vala
index 762b824..289c863 100644
--- a/plugins/playstation/src/playstation-header.vala
+++ b/plugins/playstation/src/playstation-header.vala
@@ -1,6 +1,13 @@
// This file is part of GNOME Games. License: GPLv3
private class Games.PlayStationHeader : Object {
+ private const size_t[] HEADER_OFFSETS = {
+ 0x9320, // .bin
+ 0x9360, // .iso
+ };
+ private const size_t HEADER_TITLE_OFFSET = 0x20;
+ private const string HEADER_MAGIC_VALUE = "PLAYSTATION";
+
private const size_t[] BOOT_OFFSETS = {
0xD368, // .bin
0xD3A8, // .iso
@@ -31,9 +38,45 @@ private class Games.PlayStationHeader : Object {
if (_disc_id != null)
return;
+ _disc_id = search_id_in_header ();
+ if (_disc_id != null)
+ return;
+
throw new PlayStationError.INVALID_HEADER (_("Invalid PlayStation header: disc ID not found
in '%s'."), file.get_uri ());
}
+ private string? search_id_in_header () throws Error {
+ var offset = get_header_offset ();
+ if (offset == null)
+ return null;
+
+ var stream = new StringInputStream (file);
+ var header = stream.read_string_for_size (offset + HEADER_TITLE_OFFSET, DISC_ID_SIZE);
+
+ var raw_id = header.up ();
+ raw_id = raw_id.replace ("_", "-");
+
+ foreach (var id in IDS) {
+ if (!(id in header))
+ continue;
+
+ if (is_a_disc_id (raw_id))
+ return raw_id;
+ }
+
+ return null;
+ }
+
+ private size_t? get_header_offset () throws Error {
+ var stream = new StringInputStream (file);
+
+ foreach (var offset in HEADER_OFFSETS)
+ if (stream.has_string (offset, HEADER_MAGIC_VALUE))
+ return offset;
+
+ return null;
+ }
+
private string? get_id_from_boot () throws Error {
var offset = get_boot_offset ();
if (offset == null)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]