[gnome-games/wip/exalm/3ds: 8/17] Implement global snapshot for cores that don't support savestates
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/3ds: 8/17] Implement global snapshot for cores that don't support savestates
- Date: Thu, 10 Dec 2020 22:29:51 +0000 (UTC)
commit d1af82f079e58b1634e1e75399e8fd00389158d5
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sun Nov 8 16:04:52 2020 +0500
Implement global snapshot for cores that don't support savestates
This will be useful for cores like Citra.
src/core/snapshot-manager.vala | 3 +++
src/retro/retro-runner.vala | 43 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 45 insertions(+), 1 deletion(-)
---
diff --git a/src/core/snapshot-manager.vala b/src/core/snapshot-manager.vala
index ceea640b..652a35d7 100644
--- a/src/core/snapshot-manager.vala
+++ b/src/core/snapshot-manager.vala
@@ -30,6 +30,9 @@ public class Games.SnapshotManager : Object {
string snapshot_name = null;
while ((snapshot_name = dir.read_name ()) != null) {
+ if (snapshot_name == "global")
+ continue;
+
var snapshot_path = Path.build_filename (dir_path, snapshot_name);
snapshots += Snapshot.load (game.platform, core_id, snapshot_path);
}
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 12114104..b44e06f2 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -218,7 +218,19 @@ public class Games.RetroRunner : Object, Runner {
var snapshot = snapshot_manager.get_latest_snapshot ();
tmp_save_dir = create_tmp_save_dir ();
- if (snapshot != null)
+ if (!supports_snapshots) {
+ var path = get_fallback_save_directory_path ();
+
+ var save_ram_path = Path.build_filename (path, "save");
+ var save_dir = File.new_for_path (Path.build_filename (path, "save-dir"));
+
+ if (FileUtils.test (save_ram_path, FileTest.EXISTS) &&
+ core.get_memory_size (Retro.MemoryType.SAVE_RAM) > 0)
+ core.load_memory (Retro.MemoryType.SAVE_RAM, save_ram_path);
+
+ FileOperations.copy_contents (save_dir, File.new_for_path (tmp_save_dir));
+ }
+ else if (snapshot != null)
snapshot.copy_save_dir_to (tmp_save_dir);
prepare_core ();
@@ -271,10 +283,39 @@ public class Games.RetroRunner : Object, Runner {
running = false;
}
+ private string get_fallback_save_directory_path () throws Error {
+ var uid = game.uid;
+ var core_id_prefix = get_core_id ().replace (".libretro", "");
+
+ return Path.build_filename (Application.get_data_dir (),
+ "savestates",
+ @"$uid-$core_id_prefix",
+ "global");
+ }
+
public void stop () {
if (!core_loaded)
return;
+ if (!supports_snapshots) {
+ try {
+ var path = get_fallback_save_directory_path ();
+
+ if (core.get_memory_size (Retro.MemoryType.SAVE_RAM) > 0)
+ core.save_memory (Retro.MemoryType.SAVE_RAM,
+ Path.build_filename (path, "save"));
+
+ 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.copy_contents (tmp_dir, dest_dir);
+ }
+ catch (Error e) {
+ critical ("Failed to create snapshot: %s", e.message);
+ }
+ }
+
game.update_last_played ();
deinit ();
stopped ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]