[gnome-games/wip/aplazas/retro-save-dir] retro: Set the save dir of the core



commit 43e45484aae1f953ca4b53a16d54dee9fdb6161a
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu May 18 08:40:53 2017 +0200

    retro: Set the save dir of the core

 flatpak/libretro-cores/libretro-mednafen_gba.json |    2 +-
 src/retro/retro-runner.vala                       |   40 ++++++++++++++------
 2 files changed, 29 insertions(+), 13 deletions(-)
---
diff --git a/flatpak/libretro-cores/libretro-mednafen_gba.json 
b/flatpak/libretro-cores/libretro-mednafen_gba.json
index 686a223..e42671b 100644
--- a/flatpak/libretro-cores/libretro-mednafen_gba.json
+++ b/flatpak/libretro-cores/libretro-mednafen_gba.json
@@ -17,7 +17,7 @@
             "sources": [
                 {
                     "type": "git",
-                    "url": "https://github.com/libretro/beetle-gba-libretro";
+                    "url": "https://github.com/Kekun/beetle-gba-libretro";
                 },
                 {
                     "type": "file",
diff --git a/src/retro/retro-runner.vala b/src/retro/retro-runner.vala
index 77b9b77..c4c9864 100644
--- a/src/retro/retro-runner.vala
+++ b/src/retro/retro-runner.vala
@@ -42,6 +42,7 @@ public class Games.RetroRunner : Object, Runner {
 
        private Gtk.EventBox widget;
 
+       private string save_directory_path;
        private string save_path;
        private string snapshot_path;
        private string screenshot_path;
@@ -119,18 +120,8 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        ~RetroRunner () {
-               if (!is_initialized)
-                       return;
-
-               loop.stop ();
-               running = false;
-
-               try {
-                       save ();
-               }
-               catch (Error e) {
-                       warning (e.message);
-               }
+               pause ();
+               deinit ();
        }
 
        public bool check_is_valid (out string error_message) throws Error {
@@ -235,11 +226,15 @@ public class Games.RetroRunner : Object, Runner {
        }
 
        private void deinit () {
+       warning ("deinit");
                if (!is_initialized)
                        return;
 
                settings.changed["video-filter"].disconnect (on_video_filter_changed);
 
+               // FIXME There is a reference of core floating somewhere which is not
+               // released. Decrementing the ref count manually makes the application
+               // crash, it should be debugged.
                core = null;
                video = null;
                audio = null;
@@ -277,6 +272,16 @@ public class Games.RetroRunner : Object, Runner {
                        var platforms_dir = Application.get_platforms_dir ();
                        var platform = core_source.get_platform ();
                        core.system_directory = @"$platforms_dir/$platform/system";
+
+                       // TODO Set core.libretro_path to the source path of the core in
+                       // retro-gtk.
+
+                       // TODO Set core.content_directory to the source path of the last
+                       // loaded URI in retro-gtk.
+
+                       var save_directory = get_save_directory_path ();
+                       try_make_dir (save_directory);
+                       core.save_directory = save_directory;
                }
 
                core.log.connect (Retro.g_log);
@@ -395,6 +400,17 @@ public class Games.RetroRunner : Object, Runner {
                should_save = false;
        }
 
+       private string get_save_directory_path () throws Error {
+               if (save_directory_path != null)
+                       return save_directory_path;
+
+               var dir = Application.get_saves_dir ();
+               var uid = uid.get_uid ();
+               save_directory_path = @"$dir/$uid";
+
+               return save_directory_path;
+       }
+
        private string get_save_path () throws Error {
                if (save_path != null)
                        return save_path;


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