[gnome-games/wip/exalm/savestates: 19/20] savestate: Make core property construct-only



commit da21d67f89fee0a0449236470209f927fc2d1dbf
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sun Jan 26 01:00:32 2020 +0500

    savestate: Make core property construct-only

 src/core/savestate.vala     | 22 ++++++++++++----------
 src/retro/retro-runner.vala |  5 ++---
 2 files changed, 14 insertions(+), 13 deletions(-)
---
diff --git a/src/core/savestate.vala b/src/core/savestate.vala
index 85633fc2..43e84c01 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -1,19 +1,23 @@
 public class Games.Savestate : Object {
        public string path { get; construct; }
        public Platform platform { get; construct; }
+       public string core { get; construct; }
 
        // Automatic means whether the savestate was created automatically when
        // quitting/loading the game or manually by the user using the Save button
        public bool is_automatic { get; set; }
        public string name { get; set; }
        public DateTime? creation_date { get; set; }
-       public string core { get; set; }
        public double screenshot_aspect_ratio { get; set; }
 
-       private static Savestate load (Platform platform, string path) {
+       private static Savestate load (Platform platform, string core_id, string path) {
                var type = platform.get_savestate_type ();
 
-               var savestate = Object.new (type, "path", path, "platform", platform, null) as Savestate;
+               var savestate = Object.new (type,
+                                           "path", path,
+                                           "platform", platform,
+                                           "core", core_id,
+                                           null) as Savestate;
 
                savestate.load_keyfile ();
 
@@ -110,7 +114,7 @@ public class Games.Savestate : Object {
 
                FileOperations.copy_contents (cloned_savestate_dir, tmp_savestate_dir);
 
-               return Savestate.load (platform, tmp_savestate_path);
+               return Savestate.load (platform, core, tmp_savestate_path);
        }
 
        // This method is used to save the savestate in /tmp as a regular savestate
@@ -129,7 +133,7 @@ public class Games.Savestate : Object {
 
                FileOperations.copy_dir (copied_dir, new_savestate_dir);
 
-               return Savestate.load (platform, new_savestate_dir_path);
+               return Savestate.load (platform, core, new_savestate_dir_path);
        }
 
        protected virtual void load_metadata (KeyFile keyfile) throws KeyFileError {
@@ -143,8 +147,6 @@ public class Games.Savestate : Object {
                var creation_date_str = keyfile.get_string ("Metadata", "Creation Date");
                creation_date = new DateTime.from_iso8601 (creation_date_str, new TimeZone.local ());
 
-               core = keyfile.get_string ("Metadata", "Core");
-
                screenshot_aspect_ratio = keyfile.get_double ("Screenshot", "Aspect Ratio");
        }
 
@@ -208,7 +210,7 @@ public class Games.Savestate : Object {
 
                while ((savestate_name = game_savestates_dir.read_name ()) != null) {
                        var savestate_path = Path.build_filename (game_savestates_dir_path, savestate_name);
-                       game_savestates += Savestate.load (platform, savestate_path);
+                       game_savestates += Savestate.load (platform, core_id, savestate_path);
                }
 
                // Sort the savestates array by creation dates
@@ -228,8 +230,8 @@ public class Games.Savestate : Object {
                return -1;
        }
 
-       public static Savestate create_empty_in_tmp (Platform platform) throws Error {
-               return Savestate.load (platform, prepare_empty_savestate_in_tmp ());
+       public static Savestate create_empty_in_tmp (Platform platform, string core_id) throws Error {
+               return Savestate.load (platform, core_id, prepare_empty_savestate_in_tmp ());
        }
 
        // Returns the path of the newly created dir in tmp
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 6fc7037e..9cdafd6d 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -150,7 +150,7 @@ public class Games.RetroRunner : Object, Runner {
                if (latest_savestate != null)
                        tmp_live_savestate = latest_savestate.clone_in_tmp ();
                else
-                       tmp_live_savestate = Savestate.create_empty_in_tmp (platform);
+                       tmp_live_savestate = Savestate.create_empty_in_tmp (platform, get_core_id ());
                instantiate_core (tmp_live_savestate.get_save_directory_path ());
 
                // Step 4) Preview the latest savestate --------------------------------
@@ -228,7 +228,7 @@ public class Games.RetroRunner : Object, Runner {
                        if (latest_savestate != null)
                                tmp_live_savestate = latest_savestate.clone_in_tmp ();
                        else
-                               tmp_live_savestate = Savestate.create_empty_in_tmp (platform);
+                               tmp_live_savestate = Savestate.create_empty_in_tmp (platform, get_core_id ());
 
                        instantiate_core (tmp_live_savestate.get_save_directory_path ());
                }
@@ -487,7 +487,6 @@ public class Games.RetroRunner : Object, Runner {
                        tmp_live_savestate.name = create_new_savestate_name ();
 
                tmp_live_savestate.creation_date = new DateTime.now ();
-               tmp_live_savestate.core = get_core_id ();
                tmp_live_savestate.screenshot_aspect_ratio = Retro.pixbuf_get_aspect_ratio 
(current_state_pixbuf);
 
                save_savestate_metadata (tmp_live_savestate);


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