[gnome-games] savestate: Append '_' to path when creating if directory already exists



commit 5ada01331c7d6cac580687ba9e23bf75aba841ac
Author: Yetizone <andreii lisita gmail com>
Date:   Fri Aug 16 13:14:24 2019 +0300

    savestate: Append '_' to path when creating if directory already exists
    
    Allow the creation of multiple savestates per second

 src/core/savestate.vala     | 9 ++++++++-
 src/retro/retro-runner.vala | 6 +-----
 2 files changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/src/core/savestate.vala b/src/core/savestate.vala
index fe1e98a4..192a85a1 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -158,7 +158,7 @@ public class Games.Savestate : Object {
        // inside the savestates directory of a game
        // It names the newly created savestate using the creation date in the
        // metadata file
-       public void save_in (string game_savestates_dir_path) throws Error {
+       public Savestate save_in (string game_savestates_dir_path) throws Error {
                var metadata = get_metadata ();
 
                var creation_date = metadata.get_string ("Metadata", "Creation Date");
@@ -166,7 +166,14 @@ public class Games.Savestate : Object {
                var new_savestate_dir_path = Path.build_filename (game_savestates_dir_path, creation_date);
                var new_savestate_dir = File.new_for_path (new_savestate_dir_path);
 
+               while (new_savestate_dir.query_exists ()) {
+                       new_savestate_dir_path += "_";
+                       new_savestate_dir = File.new_for_path (new_savestate_dir_path);
+               }
+
                FileOperations.copy_dir (copied_dir, new_savestate_dir);
+
+               return Savestate.load (platform, new_savestate_dir_path);
        }
 
        // Set the metadata for an automatic savestate
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index b31bc245..fd2e980b 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -501,11 +501,7 @@ public class Games.RetroRunner : Object, Runner {
 
                // Save the tmp_live_savestate into the game savestates directory
                var game_savestates_dir_path = get_game_savestates_dir_path ();
-               tmp_live_savestate.save_in (game_savestates_dir_path);
-
-               // Instantiate the Savestate object
-               var savestate_path = Path.build_filename (game_savestates_dir_path, now_time.to_string ());
-               var savestate = Savestate.load (platform, savestate_path);
+               var savestate = tmp_live_savestate.save_in (game_savestates_dir_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]