[gnome-games/wip/exalm/runner-refactor: 27/56] retro-runner: Make create_savestate() not depend on tmp_live_savestate
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/runner-refactor: 27/56] retro-runner: Make create_savestate() not depend on tmp_live_savestate
- Date: Sat, 7 Mar 2020 12:42:56 +0000 (UTC)
commit 6b4185b0b5b90dc5f595b28b3026a4c59c04a1c2
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Fri Mar 6 17:46:36 2020 +0500
retro-runner: Make create_savestate() not depend on tmp_live_savestate
This will allow it to be moved into SnapshotManager in the next commit.
src/core/savestate.vala | 28 ++++++++++++++++++++++++++++
src/retro/retro-runner.vala | 27 ++++++++++++---------------
2 files changed, 40 insertions(+), 15 deletions(-)
---
diff --git a/src/core/savestate.vala b/src/core/savestate.vala
index 50d73d6c..8729edc5 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -178,6 +178,34 @@ public class Games.Savestate : Object {
return Savestate.load (platform, core_id, prepare_empty_savestate_in_tmp ());
}
+ public static Savestate create_empty (Game game, string core_id, string path) throws Error {
+ var random = Random.next_int ();
+ var tmp_path = @"$(path)_$random";
+
+ var dir = File.new_for_path (tmp_path);
+ dir.make_directory ();
+
+ var save_dir = dir.get_child ("save-dir");
+ save_dir.make_directory ();
+
+ return Savestate.load (game.platform, core_id, tmp_path);
+ }
+
+ public Savestate move_to (string dest_path) throws Error {
+ var current_dir = File.new_for_path (path);
+ var dest_dir = File.new_for_path (dest_path);
+
+ var dest = dest_path;
+ while (dest_dir.query_exists ()) {
+ dest += "_";
+ dest_dir = File.new_for_path (dest);
+ }
+
+ current_dir.move (dest_dir, FileCopyFlags.ALL_METADATA);
+
+ return Savestate.load (platform, core, dest);
+ }
+
// 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 3146741a..4ee4e56d 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -479,35 +479,32 @@ public class Games.RetroRunner : Object, Runner {
if (is_automatic)
trim_autosaves ();
- // Populate the metadata file
- tmp_live_savestate.is_automatic = is_automatic;
+ var creation_date = new DateTime.now ();
+ var path = Path.build_filename (get_game_savestates_dir_path (),
+ creation_date.to_string ());
- if (is_automatic)
- tmp_live_savestate.name = null;
- else
- tmp_live_savestate.name = create_new_savestate_name ();
-
- tmp_live_savestate.creation_date = new DateTime.now ();
+ var snapshot = Savestate.create_empty (game, get_core_id (), path);
- save_to_snapshot (tmp_live_savestate);
+ snapshot.is_automatic = is_automatic;
+ snapshot.name = is_automatic ? null : create_new_savestate_name ();
+ snapshot.creation_date = creation_date;
- tmp_live_savestate.write_metadata ();
+ save_to_snapshot (snapshot);
+ snapshot.write_metadata ();
- // Save the tmp_live_savestate into the game savestates directory
- var game_savestates_dir_path = get_game_savestates_dir_path ();
- var savestate = tmp_live_savestate.save_in (game_savestates_dir_path);
+ snapshot = snapshot.move_to (path);
// Update the game_savestates array
// Insert the new savestate at the beginning of the array since it's the latest savestate
Savestate[] new_game_savestates = {};
- new_game_savestates += savestate;
+ new_game_savestates += snapshot;
foreach (var existing_savestate in game_savestates)
new_game_savestates += existing_savestate;
game_savestates = new_game_savestates;
- return savestate;
+ return snapshot;
}
public void delete_savestate (Savestate savestate) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]