Commit 5ada0133 authored by AndreiLisita's avatar AndreiLisita 🎮

savestate: Append '_' to path when creating if directory already exists

Allow the creation of multiple savestates per second
parent 3bb5ec01
Pipeline #105197 failed with stages
in 19 minutes and 2 seconds
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment