[gnome-games/wip/exalm/savestates: 6/20] savestate: Automatically load and save extra metadata
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/savestates: 6/20] savestate: Automatically load and save extra metadata
- Date: Sat, 25 Jan 2020 20:01:44 +0000 (UTC)
commit 416d349bdfb68a7c77847a2ab79537ea255a4208
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Sat Jan 25 23:41:52 2020 +0500
savestate: Automatically load and save extra metadata
plugins/nintendo-ds/src/nintendo-ds-runner.vala | 2 --
plugins/nintendo-ds/src/nintendo-ds-savestate.vala | 18 +++++-----------
src/core/savestate.vala | 25 ++++++++++++++++++----
3 files changed, 26 insertions(+), 19 deletions(-)
---
diff --git a/plugins/nintendo-ds/src/nintendo-ds-runner.vala b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
index 67c89c29..1117bedc 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-runner.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-runner.vala
@@ -129,8 +129,6 @@ private class Games.NintendoDsRunner : RetroRunner {
assert (savestate is NintendoDsSavestate);
var ds_savestate = savestate as NintendoDsSavestate;
-
- ds_savestate.load_extra_metadata ();
screen_layout = ds_savestate.screen_layout;
view_bottom_screen = ds_savestate.view_bottom_screen;
}
diff --git a/plugins/nintendo-ds/src/nintendo-ds-savestate.vala
b/plugins/nintendo-ds/src/nintendo-ds-savestate.vala
index a3241a21..3430ab4c 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-savestate.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-savestate.vala
@@ -4,22 +4,14 @@ public class Games.NintendoDsSavestate : Savestate {
public NintendoDsLayout screen_layout { get; set; }
public bool view_bottom_screen { get; set; }
- public void load_extra_metadata () {
- var keyfile = get_metadata ();
+ protected override void load_metadata (KeyFile keyfile) throws KeyFileError {
+ var layout_value = keyfile.get_string ("Nintendo DS", "Screen Layout");
+ view_bottom_screen = keyfile.get_boolean ("Nintendo DS", "View Bottom Screen");
- try {
- var layout_value = keyfile.get_string ("Nintendo DS", "Screen Layout");
- view_bottom_screen = keyfile.get_boolean ("Nintendo DS", "View Bottom Screen");
-
- screen_layout = NintendoDsLayout.from_value (layout_value);
- }
- catch (KeyFileError e) {
- critical ("Failed to get Nintendo DS metadata from metadata file for snapshot at %s:
%s", path, e.message);
- return;
- }
+ screen_layout = NintendoDsLayout.from_value (layout_value);
}
- protected override void save_extra_metadata (KeyFile keyfile) {
+ protected override void save_metadata (KeyFile keyfile) {
keyfile.set_string ("Nintendo DS", "Screen Layout", screen_layout.get_value ());
keyfile.set_boolean ("Nintendo DS", "View Bottom Screen", view_bottom_screen);
}
diff --git a/src/core/savestate.vala b/src/core/savestate.vala
index 581b5646..20afe186 100644
--- a/src/core/savestate.vala
+++ b/src/core/savestate.vala
@@ -2,10 +2,24 @@ public class Games.Savestate : Object {
public string path { get; construct; }
public Platform platform { get; construct; }
- public static Savestate load (Platform platform, string path) {
+ private static Savestate load (Platform platform, string path) {
var type = platform.get_savestate_type ();
- return Object.new (type, "path", path, "platform", platform, null) as Savestate;
+ var savestate = Object.new (type, "path", path, "platform", platform, null) as Savestate;
+ savestate.load_keyfile ();
+
+ return savestate;
+ }
+
+ private void load_keyfile () {
+ var keyfile = get_metadata ();
+
+ try {
+ load_metadata (keyfile);
+ }
+ catch (KeyFileError e) {
+ critical ("Failed to load metadata for snapshot at %s: %s", path, e.message);
+ }
}
protected KeyFile get_metadata () {
@@ -186,7 +200,10 @@ public class Games.Savestate : Object {
set_metadata (false, name, creation_date, platform, core, aspect_ratio);
}
- protected virtual void save_extra_metadata (KeyFile keyfile) {
+ protected virtual void load_metadata (KeyFile keyfile) throws KeyFileError {
+ }
+
+ protected virtual void save_metadata (KeyFile keyfile) {
}
private void set_metadata (bool is_automatic, string? name, DateTime creation_date,
@@ -208,7 +225,7 @@ public class Games.Savestate : Object {
metadata.set_string ("Metadata", "Core", core);
metadata.set_double ("Screenshot", "Aspect Ratio", aspect_ratio);
- save_extra_metadata (metadata);
+ save_metadata (metadata);
metadata.save_to_file (metadata_file_path);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]