[gnome-games/wip/exalm/savestates: 18/22] savestate: Write metadata manually



commit d70654588bc9cfbec002565fc0995f4335ed766e
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sun Jan 26 00:50:17 2020 +0500

    savestate: Write metadata manually

 plugins/nintendo-ds/src/nintendo-ds-runner.vala | 4 ++--
 src/core/savestate.vala                         | 6 +-----
 src/retro/retro-runner.vala                     | 7 +++----
 src/ui/savestate-listbox-row.vala               | 7 +++++++
 4 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/plugins/nintendo-ds/src/nintendo-ds-runner.vala b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
index 1117bedc..037424a9 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-runner.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
@@ -114,13 +114,13 @@ private class Games.NintendoDsRunner : RetroRunner {
        }
 
        protected override void save_savestate_metadata (Savestate savestate) throws Error {
-               base.save_savestate_metadata (savestate);
-
                assert (savestate is NintendoDsSavestate);
 
                var ds_savestate = savestate as NintendoDsSavestate;
                ds_savestate.screen_layout = screen_layout;
                ds_savestate.view_bottom_screen = view_bottom_screen;
+
+               base.save_savestate_metadata (savestate);
        }
 
        protected override void load_savestate_metadata (Savestate savestate) throws Error {
diff --git a/src/core/savestate.vala b/src/core/savestate.vala
index 60df07b0..17c1f1df 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -139,8 +139,6 @@ public class Games.Savestate : Object {
                this.creation_date = creation_date;
                this.core = core;
                this.screenshot_aspect_ratio = aspect_ratio;
-
-               set_metadata ();
        }
 
        // Set the metadata for a manual savestate
@@ -150,8 +148,6 @@ public class Games.Savestate : Object {
                this.creation_date = creation_date;
                this.core = core;
                this.screenshot_aspect_ratio = aspect_ratio;
-
-               set_metadata ();
        }
 
        protected virtual void load_metadata (KeyFile keyfile) throws KeyFileError {
@@ -183,7 +179,7 @@ public class Games.Savestate : Object {
                keyfile.set_double ("Screenshot", "Aspect Ratio", screenshot_aspect_ratio);
        }
 
-       private void set_metadata () throws Error {
+       public void write_metadata () throws Error {
                var metadata_file_path = Path.build_filename (path, "metadata");
                var metadata_file = File.new_for_path (metadata_file_path);
                var metadata = new KeyFile ();
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 5d664233..b93f3812 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -482,10 +482,6 @@ public class Games.RetroRunner : Object, Runner {
                var now_time = new DateTime.now ();
                var ratio = Retro.pixbuf_get_aspect_ratio (current_state_pixbuf);
 
-               // FIXME: Because of how saving metadata is done currently, saving
-               // any additional data has to be done before the keyfile is written
-               save_savestate_metadata (tmp_live_savestate);
-
                if (is_automatic)
                        tmp_live_savestate.set_metadata_automatic (now_time,
                                                                   get_core_id (), ratio);
@@ -496,6 +492,8 @@ public class Games.RetroRunner : Object, Runner {
                                                                get_core_id (), ratio);
                }
 
+               save_savestate_metadata (tmp_live_savestate);
+
                // 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);
@@ -655,6 +653,7 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        protected virtual void save_savestate_metadata (Savestate savestate) throws Error {
+               tmp_live_savestate.write_metadata ();
        }
 
        protected virtual void load_savestate_metadata (Savestate savestate) throws Error {
diff --git a/src/ui/savestate-listbox-row.vala b/src/ui/savestate-listbox-row.vala
index 21cf3dff..325edd9a 100644
--- a/src/ui/savestate-listbox-row.vala
+++ b/src/ui/savestate-listbox-row.vala
@@ -88,6 +88,13 @@ private class Games.SavestateListBoxRow : Gtk.ListBoxRow {
        public void set_name (string name) {
                name_label.label = name;
                savestate.name = name;
+
+               try {
+                       savestate.write_metadata ();
+               }
+               catch (Error e) {
+                       critical ("Couldn't update snapshot name: %s", e.message);
+               }
        }
 
        public void reveal () {


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