[gnome-games] retro: Make media data persistent
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] retro: Make media data persistent
- Date: Fri, 19 Aug 2016 21:10:06 +0000 (UTC)
commit 7f2d89065d19b9eff4f26d599f31d7d4eea2bb3b
Author: Ricard Gascons <gascons1995 gmail com>
Date: Thu Aug 18 17:26:23 2016 +0200
retro: Make media data persistent
This commit makes the data of the media used by multi-source games
persistent across sessions.
This is part of a series of commits to add multi-source support.
src/retro/retro-runner.vala | 44 +++++++++++++++++++++++++++++++++++++++++++
src/ui/application.vala | 6 +++++
2 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 4f8457e..cbe8765 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -126,6 +126,7 @@ public class Games.RetroRunner : Object, Runner {
}
public void check_is_valid () throws Error {
+ load_media_data ();
init ();
}
@@ -134,6 +135,8 @@ public class Games.RetroRunner : Object, Runner {
}
public void start () throws Error {
+ load_media_data ();
+
if (!is_initialized)
init();
@@ -360,6 +363,13 @@ public class Games.RetroRunner : Object, Runner {
var uri = media.uri;
try_load_game (core, uri);
+
+ try {
+ save_media_data ();
+ }
+ catch (Error e) {
+ warning (e.message);
+ }
}
private void save () throws Error {
@@ -368,6 +378,9 @@ public class Games.RetroRunner : Object, Runner {
save_ram ();
+ if (media_set.get_size () > 1)
+ save_media_data ();
+
if (!core_supports_snapshotting)
return;
@@ -468,6 +481,37 @@ public class Games.RetroRunner : Object, Runner {
throw new RetroError.COULDNT_LOAD_SNAPSHOT ("Could not load snapshot");
}
+ private void save_media_data () throws Error {
+ var dir = Application.get_medias_dir ();
+ try_make_dir (dir);
+
+ var medias_path = get_medias_path ();
+
+ string contents = media_set.selected_media_number.to_string();
+
+ FileUtils.set_contents (medias_path, contents, contents.length);
+ }
+
+ private void load_media_data () throws Error {
+ var medias_path = get_medias_path ();
+
+ if (!FileUtils.test (medias_path, FileTest.EXISTS))
+ return;
+
+ string contents;
+ FileUtils.get_contents (medias_path, out contents);
+
+ int disc_num = int.parse(contents);
+ media_set.selected_media_number = disc_num;
+ }
+
+ private string get_medias_path () throws Error {
+ var dir = Application.get_medias_dir ();
+ var uid = uid.get_uid ();
+
+ return @"$dir/$uid.media";
+ }
+
private string get_screenshot_path () throws Error {
if (screenshot_path != null)
return screenshot_path;
diff --git a/src/ui/application.vala b/src/ui/application.vala
index 712057b..0d752d7 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -87,6 +87,12 @@ public class Games.Application : Gtk.Application {
}
}
+ public static string get_medias_dir () {
+ var data_dir = get_data_dir ();
+
+ return @"$data_dir/medias";
+ }
+
protected override void activate () {
Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]