[gnome-games/wip/exalm/ds: 1/2] savestate: Store screenshot aspect ratio



commit 8b5e84db13e2ce0765e30893dd6e32f7dad17163
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Aug 11 16:00:40 2019 +0500

    savestate: Store screenshot aspect ratio
    
    This will be used in the next commit to use proper scpect ratio for
    thumbnails.

 src/core/savestate.vala     | 25 ++++++++++++++++++++-----
 src/retro/retro-runner.vala |  7 ++++---
 2 files changed, 24 insertions(+), 8 deletions(-)
---
diff --git a/src/core/savestate.vala b/src/core/savestate.vala
index 77deb3f1..ced5a121 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -40,6 +40,20 @@ public class Games.Savestate : Object {
                }
        }
 
+       public double get_screenshot_aspect_ratio () {
+               var metadata = new KeyFile ();
+               var metadata_file_path = Path.build_filename (path, "metadata");
+
+               try {
+                       metadata.load_from_file (metadata_file_path, KeyFileFlags.NONE);
+                       return metadata.get_double ("Screenshot", "Aspect Ratio");
+               }
+               catch (Error e) {
+                       critical ("Failed to get aspect ratio from metadata file for savestate at %s: %s", 
path, e.message);
+                       return 0;
+               }
+       }
+
        public void set_snapshot_data (Bytes snapshot_data) throws Error {
                var buffer = snapshot_data.get_data ();
                var snapshot_path = Path.build_filename (path, "snapshot");
@@ -132,17 +146,17 @@ public class Games.Savestate : Object {
        }
 
        // Set the metadata for an automatic savestate
-       public void set_metadata_automatic (DateTime creation_date, string platform, string core) throws 
Error {
-               set_metadata (true, null, creation_date, platform, core);
+       public void set_metadata_automatic (DateTime creation_date, string platform, string core, double 
aspect_ratio) throws Error {
+               set_metadata (true, null, creation_date, platform, core, aspect_ratio);
        }
 
        // Set the metadata for a manual savestate
-       public void set_metadata_manual (string name, DateTime creation_date, string platform, string core) 
throws Error {
-               set_metadata (false, name, creation_date, platform, core);
+       public void set_metadata_manual (string name, DateTime creation_date, string platform, string core, 
double aspect_ratio) throws Error {
+               set_metadata (false, name, creation_date, platform, core, aspect_ratio);
        }
 
        private void set_metadata (bool is_automatic, string? name, DateTime creation_date,
-                                  string platform, string core) throws Error {
+                                  string platform, string core, double aspect_ratio) throws Error {
                var metadata_file_path = Path.build_filename (path, "metadata");
                var metadata_file = File.new_for_path (metadata_file_path);
                var metadata = new KeyFile ();
@@ -158,6 +172,7 @@ public class Games.Savestate : Object {
                metadata.set_string ("Metadata", "Creation Date", creation_date.to_string ());
                metadata.set_string ("Metadata", "Platform", platform);
                metadata.set_string ("Metadata", "Core", core);
+               metadata.set_double ("Screenshot", "Aspect Ratio", aspect_ratio);
                metadata.save_to_file (metadata_file_path);
        }
 
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 7000f52a..5948f0cd 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -471,12 +471,13 @@ public class Games.RetroRunner : Object, Runner {
                // Populate the metadata file
                var now_time = new DateTime.now ();
                var platform_prefix = platform.get_uid_prefix ();
+               var ratio = (double) core.get_aspect_ratio ();
                if (is_automatic)
-                       tmp_live_savestate.set_metadata_automatic (now_time, platform_prefix, get_core_id ());
+                       tmp_live_savestate.set_metadata_automatic (now_time, platform_prefix, get_core_id (), 
ratio);
                else {
                        var savestate_name = create_new_savestate_name ();
 
-                       tmp_live_savestate.set_metadata_manual (savestate_name, now_time, platform_prefix, 
get_core_id ());
+                       tmp_live_savestate.set_metadata_manual (savestate_name, now_time, platform_prefix, 
get_core_id (), ratio);
                }
 
                // Save the tmp_live_savestate into the game savestates directory
@@ -485,7 +486,7 @@ public class Games.RetroRunner : Object, Runner {
 
                // Instantiate the Savestate object
                var savestate_path = Path.build_filename (game_savestates_dir_path, now_time.to_string ());
-               Savestate savestate = new Savestate (savestate_path);
+               var savestate = new Savestate (savestate_path);
 
                // Update the game_savestates array
                // Insert the new savestate at the beginning of the array since it's the latest savestate


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