[gnome-games/gnome-40] retro-runner: Ensure save directory doesn't change during the game



commit 7b4066c9b28490f1a1f1fae7c20efed49064baa0
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Mar 22 12:21:58 2021 +0500

    retro-runner: Ensure save directory doesn't change during the game
    
    Currently, we make a new save directory every time we load a state.
    Unfortunately, libretro cores don't really have a good way to track
    the save dir changes, save from polling it every frame and comparing to
    what they have. And, for example, Dolphin doesn't do this.
    
    Instead, create a save directory once per game and never change it, just
    replace its contents when loading the state.

 src/retro/retro-runner.vala | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 42e91adf..c17722d9 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -220,6 +220,11 @@ public class Games.RetroRunner : Object, Runner {
 
                        tmp_save_dir = create_tmp_save_dir ();
 
+                       var tmp_dir = File.new_for_path (tmp_save_dir);
+                       if (tmp_dir.query_exists ())
+                               FileOperations.delete_files (tmp_dir);
+                       tmp_dir.make_directory ();
+
                        if (snapshot != null) {
                                snapshot.copy_save_dir_to (tmp_save_dir);
                        } else {
@@ -319,7 +324,7 @@ public class Games.RetroRunner : Object, Runner {
                                var tmp_dir = File.new_for_path (tmp_save_dir);
                                var dest_dir = File.new_for_path (Path.build_filename (path, "save-dir"));
                                if (dest_dir.query_exists ())
-                                       FileOperations.delete_files (dest_dir, {});
+                                       FileOperations.delete_files (dest_dir);
                                FileOperations.copy_contents (tmp_dir, dest_dir);
                        }
                        catch (Error e) {
@@ -538,9 +543,13 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        protected virtual void load_from_snapshot (Snapshot snapshot) throws Error {
-               tmp_save_dir = create_tmp_save_dir ();
+               File tmp_dir = File.new_for_path (tmp_save_dir);
+
+               if (tmp_dir.query_exists ())
+                       FileOperations.delete_files (tmp_dir);
+               tmp_dir.make_directory ();
+
                snapshot.copy_save_dir_to (tmp_save_dir);
-               core.save_directory = tmp_save_dir;
 
                load_save_ram (snapshot.get_save_ram_path ());
                core.load_state (snapshot.get_snapshot_path ());


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