[gnome-games] playstation: Add PlayStationHeader.get_id_from_boot()



commit c2e8fc2f713a9ff4d0efcf1c77f79cf6d903aad7
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sun Aug 28 09:23:41 2016 +0200

    playstation: Add PlayStationHeader.get_id_from_boot()
    
    Add the get_id_from_boot() method to look for IDs in the BOOT header
    section.
    
    This will allow to look for IDs in more places in the next commits.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=770470

 plugins/playstation/src/playstation-header.vala |   27 +++++++++++++++++-----
 1 files changed, 21 insertions(+), 6 deletions(-)
---
diff --git a/plugins/playstation/src/playstation-header.vala b/plugins/playstation/src/playstation-header.vala
index e3ccaaf..ae02b3b 100644
--- a/plugins/playstation/src/playstation-header.vala
+++ b/plugins/playstation/src/playstation-header.vala
@@ -21,8 +21,22 @@ private class Games.PlayStationHeader : Object {
        }
 
        public void check_validity () throws Error {
-               var stream = new StringInputStream (file);
+               if (_disc_id != null)
+                       return;
+
+               _disc_id = get_id_from_boot ();
+               if (_disc_id != null)
+                       return;
+
+               throw new PlayStationError.INVALID_HEADER (_("Invalid PlayStation header: disc ID not found 
in '%s'."), file.get_uri ());
+       }
+
+       private string? get_id_from_boot () throws Error {
                var offset = get_boot_offset ();
+               if (offset == null)
+                       return null;
+
+               var stream = new StringInputStream (file);
                var header = stream.read_string (offset);
 
                foreach (var id in IDS) {
@@ -33,20 +47,21 @@ private class Games.PlayStationHeader : Object {
                        raw_id = raw_id.split (";")[0];
                        raw_id = raw_id.replace ("_", "-");
                        raw_id = raw_id.replace (".", "");
-                       _disc_id = (id + raw_id).up ();
+                       raw_id = (id + raw_id).up ();
+
+                       return raw_id;
                }
 
-               if (_disc_id == null)
-                       throw new PlayStationError.INVALID_HEADER (_("Invalid PlayStation header: disc ID not 
found in '%s'."), file.get_uri ());
+               return null;
        }
 
-       private size_t get_boot_offset () throws Error {
+       private size_t? get_boot_offset () throws Error {
                var stream = new StringInputStream (file);
 
                foreach (var offset in BOOT_OFFSETS)
                        if (stream.has_string (offset, BOOT_MAGIC_VALUE))
                                return offset;
 
-               throw new PlayStationError.INVALID_HEADER (_("PlayStation header not found in '%s'."), 
file.get_uri ());
+               return null;
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]