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



commit 9cb41248fc3ca062bddf466b44e63a30d6489e97
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                       |   45 +++++++++++++++------
 2 files changed, 34 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..04eff73 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,20 @@ 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.
+               // TODO Remove video from the window?
+               warning ("%u", core.ref_count);
+               video.set_core (null);
+               warning ("%u", core.ref_count);
+//             core.unref ();
                core = null;
                video = null;
                audio = null;
@@ -277,6 +277,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 +405,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]