[gnome-games/wip/exalm/runner-refactor: 29/56] retro-runner: Get rid of tmp_live_savestate



commit 3d8e8d13bfb5c490533063b269bc1322341a770a
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Mar 6 18:23:57 2020 +0500

    retro-runner: Get rid of tmp_live_savestate
    
    Use a temporary save dir instead.

 src/core/savestate.vala     |  7 +++++++
 src/retro/retro-runner.vala | 33 ++++++++++++++++++++-------------
 2 files changed, 27 insertions(+), 13 deletions(-)
---
diff --git a/src/core/savestate.vala b/src/core/savestate.vala
index 8729edc5..fd7bba89 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -206,6 +206,13 @@ public class Games.Savestate : Object {
                return Savestate.load (platform, core, dest);
        }
 
+       public void copy_save_dir_to (string dest) throws Error {
+               var save_dir_file = File.new_for_path (get_save_directory_path ());
+               var dest_file = File.new_for_path (dest);
+
+               FileOperations.copy_contents (save_dir_file, dest_file);
+       }
+
        // Returns the path of the newly created dir in tmp
        private static string prepare_empty_savestate_in_tmp () throws Error {
                var tmp_savestate_path = DirUtils.make_tmp ("games_savestate_XXXXXX");
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 4be554e6..64b846eb 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -44,9 +44,10 @@ public class Games.RetroRunner : Object, Runner {
 
        private Savestate[] game_savestates;
        private Savestate latest_savestate;
-       private Savestate tmp_live_savestate;
        private Savestate previewed_savestate;
 
+       private string tmp_save_dir;
+
        private Gdk.Pixbuf current_state_pixbuf;
 
        private bool _running;
@@ -120,6 +121,10 @@ public class Games.RetroRunner : Object, Runner {
                        return core_source.get_core_id ();
        }
 
+       private string create_tmp_save_dir () throws Error {
+               return DirUtils.make_tmp ("games_save_dir_XXXXXX");
+       }
+
        public void prepare () throws RunnerError {
                try {
                        snapshot_manager = new SnapshotManager (game, get_core_id ());
@@ -129,14 +134,11 @@ public class Games.RetroRunner : Object, Runner {
                        if (game_savestates.length != 0)
                                latest_savestate = game_savestates[0];
 
-                       // Step 2) Instantiate the core
-                       // This is needed to check if the core supports savestates
+                       tmp_save_dir = create_tmp_save_dir ();
                        if (latest_savestate != null)
-                               tmp_live_savestate = latest_savestate.clone_in_tmp ();
-                       else
-                               tmp_live_savestate = Savestate.create_empty_in_tmp (game.platform, 
get_core_id ());
+                               latest_savestate.copy_save_dir_to (tmp_save_dir);
 
-                       instantiate_core (tmp_live_savestate.get_save_directory_path ());
+                       instantiate_core (tmp_save_dir);
 
                        if (latest_savestate != null)
                                load_savestate_metadata (latest_savestate);
@@ -194,8 +196,10 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        public void load_previewed_savestate () throws Error {
-               tmp_live_savestate = previewed_savestate.clone_in_tmp ();
-               core.save_directory = tmp_live_savestate.get_save_directory_path ();
+               tmp_save_dir = create_tmp_save_dir ();
+               previewed_savestate.copy_save_dir_to (tmp_save_dir);
+               core.save_directory = tmp_save_dir;
+
                load_save_ram (previewed_savestate.get_save_ram_path ());
                core.load_state (previewed_savestate.get_snapshot_path ());
 
@@ -218,12 +222,11 @@ public class Games.RetroRunner : Object, Runner {
                reset_metadata (latest_savestate);
 
                if (!is_initialized) {
+                       tmp_save_dir = create_tmp_save_dir ();
                        if (latest_savestate != null)
-                               tmp_live_savestate = latest_savestate.clone_in_tmp ();
-                       else
-                               tmp_live_savestate = Savestate.create_empty_in_tmp (game.platform, 
get_core_id ());
+                               latest_savestate.copy_save_dir_to (tmp_save_dir);
 
-                       instantiate_core (tmp_live_savestate.get_save_directory_path ());
+                       instantiate_core (tmp_save_dir);
                }
 
                if (!is_ready) {
@@ -532,6 +535,10 @@ public class Games.RetroRunner : Object, Runner {
                        core.save_memory (Retro.MemoryType.SAVE_RAM,
                                          savestate.get_save_ram_path ());
 
+               var tmp_dir = File.new_for_path (tmp_save_dir);
+               var dest_dir = File.new_for_path (savestate.get_save_directory_path ());
+               FileOperations.copy_contents (tmp_dir, dest_dir);
+
                if (media_set.get_size () > 1)
                        savestate.set_media_data (media_set);
 


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