added setting to retain file browser directory on reboots WIP

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit c86fd2318d1517486e1129348a9abe55b9ace60b
Author: yegor chernyshov <[email protected]>
Date:   Mon Feb 23 22:56:04 2026 -0500

    added setting to retain file browser directory on reboots WIP
    
    I added the setting keep_directory which automatically updates
    the last directory visited and restores it on next boot
    
    --added manual entry
    
    Change-Id: I0ffe6531d591d693806ce0bf56fe22b99e3315e9

diff --git a/apps/filetree.c b/apps/filetree.c
index 95c7e2b77d..77b902db10 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -453,6 +453,13 @@ int ft_load(struct tree_context* c, const char* tempdir)
         check_file_thumbnails(c); /* map .talk to ours */
 
     tree_unlock_cache(c);
+
+    if (global_settings.keep_directory)
+    {
+        path_append(global_status.browse_last_folder, c->currdir, PA_SEP_HARD,
+                    sizeof(global_status.browse_last_folder));
+    }
+
     return 0;
 }
 static void ft_load_font(char *file)
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index c244096637..e765160385 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -17029,3 +17029,17 @@
     general_purpose_led: "Use LED indicators"
   </voice>
 </phrase>
+<phrase>
+  id: LANG_KEEP_DIRECTORY
+  desc: file browser setting
+  user: core
+  <source>
+    *: "Always remember last folder"
+  </source>
+  <dest>
+    *: "Always remember last folder"
+  </dest>
+  <voice>
+    *: "Always remember last folder"
+  </voice>
+</phrase>
diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c
index 1923309269..eece8b280b 100644
--- a/apps/menus/settings_menu.c
+++ b/apps/menus/settings_menu.c
@@ -199,6 +199,7 @@ static int clear_start_directory(void)
     splash(HZ, ID2P(LANG_RESET_DONE_CLEAR));
     return false;
 }
+MENUITEM_SETTING(keep_directory, &global_settings.keep_directory, NULL);
 MENUITEM_FUNCTION(clear_start_directory_item, 0, ID2P(LANG_RESET_START_DIR),
                   clear_start_directory, NULL, Icon_file_view_menu);
 
@@ -209,6 +210,7 @@ MAKE_MENU(file_menu, ID2P(LANG_FILE), filemenu_callback, Icon_file_view_menu,
                 &sort_case, &sort_dir, &sort_file, &interpret_numbers,
                 &dirfilter, &show_filename_ext, &browse_current,
                 &show_path_in_browser,
+                &keep_directory,
                 &clear_start_directory_item
 #ifdef HAVE_HOTKEY
                 ,&hotkey_tree_item
diff --git a/apps/misc.c b/apps/misc.c
index b9a33d8665..40a55d032f 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -2039,6 +2039,12 @@ void validate_start_directory_init(void) /* INIT_ATTR */
         path_append(dirpath, PATH_ROOTSTR,
             PA_SEP_HARD, sizeof(global_settings.start_directory));
     }
+
+    if (!global_settings.keep_directory) /* reset to root / if !keep_directory */
+    {
+        path_append(global_status.browse_last_folder, PATH_ROOTSTR, PA_SEP_HARD,
+                    sizeof(global_status.browse_last_folder));
+    }
 }
 
 #endif /* ndef __PCTOOL__ */
diff --git a/apps/root_menu.c b/apps/root_menu.c
index 4016d78a1b..977a72e80c 100644
--- a/apps/root_menu.c
+++ b/apps/root_menu.c
@@ -118,7 +118,9 @@ static int browser(void* param)
     int filter = SHOW_SUPPORTED;
     char folder[MAX_PATH] = "/";
     /* stuff needed to remember position in file browser */
-    static char last_folder[MAX_PATH] = "/";
+    /*static char last_folder[MAX_PATH] = "/"*/
+    char *last_folder = global_status.browse_last_folder;
+
     /* and stuff for the database browser */
 #ifdef HAVE_TAGCACHE
     static int last_db_dirlevel = 0, last_db_selection = 0, last_ft_dirlevel = 0;
diff --git a/apps/settings.c b/apps/settings.c
index fea5e9d161..7ed4257084 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -628,6 +628,11 @@ static bool settings_write_config(const char* filename, int options)
             case SETTINGS_SAVE_RESUMEINFO:
                 if (!(setting->flags & F_RESUMESETTING))
                     continue;
+                if (setting->setting == &global_status.browse_last_folder
+                   && (!global_settings.keep_directory))
+                {
+                        continue;
+                }
                 break;
             case SETTINGS_SAVE_ALL:
             {
diff --git a/apps/settings.h b/apps/settings.h
index 6a429f9d13..695af0276d 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -365,6 +365,7 @@ struct system_status
     int font_id[NB_SCREENS]; /* font id of the settings font for each screen */
 
     bool resume_modified; /* playlist is modified (=> warn before erase) */
+    char browse_last_folder[MAX_PATH];/* only saved if keep_directory = true */
 };
 
 struct user_settings
@@ -893,6 +894,7 @@ struct user_settings
 
     char start_directory[MAX_PATHNAME+1];
     /* Has the root been customized from the .cfg file? false = no, true = loaded from cfg */
+    bool keep_directory;  /* this saves the last path visited in the file browser */
     bool root_menu_customized;
 #ifdef HAVE_QUICKSCREEN
     bool shortcuts_replaces_qs;
diff --git a/apps/settings_list.c b/apps/settings_list.c
index dfaede027a..10b56655f8 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -148,6 +148,13 @@
 #define SYSTEM_STATUS(flags,var,default,name)                \
             {flags|F_RESUMESETTING|F_T_INT, &global_status.var,-1, \
              INT(default), name, UNUSED}
+
+#define SYSTEM_STATUS_TEXT_SETTING(flags,var,name,default,prefix,suffix) \
+            {flags|F_RESUMESETTING|F_T_UCHARPTR, &global_status.var,-1,  \
+                CHARPTR(default),name,                                   \
+                {.filename_setting=                                      \
+                    (struct filename_setting[]){                         \
+                        {prefix,suffix,sizeof(global_status.var)}}} }
 /* system_status settings items will be saved to resume.cfg
    Use for int which use the set_sound() function to set them
    These items WILL be included in the users exported settings files
@@ -1498,6 +1505,9 @@ const struct settings_list settings[] = {
 #endif /* HAVE_DISK_STORAGE */
     /* browser */
     TEXT_SETTING(0, start_directory, "start directory", "/", NULL, NULL),
+    SYSTEM_STATUS_TEXT_SETTING(0, browse_last_folder, "last folder", "/", NULL, NULL),
+    OFFON_SETTING(0, keep_directory, LANG_KEEP_DIRECTORY, false, "keep directory", NULL),
+
     CHOICE_SETTING(0, dirfilter, LANG_FILTER, SHOW_SUPPORTED, "show files",
                    "all,supported,music,playlists", NULL, 4, ID2P(LANG_ALL),
                    ID2P(LANG_FILTER_SUPPORTED), ID2P(LANG_FILTER_MUSIC),
diff --git a/docs/CREDITS b/docs/CREDITS
index cf2cb9237b..528fede131 100644
--- a/docs/CREDITS
+++ b/docs/CREDITS
@@ -756,6 +756,7 @@ Nyx Guan
 Arin Kim
 Ingmar Steen
 Lourenço Soares
+Yegor Chernyshov
 
 The libmad team
 The wavpack team
diff --git a/manual/rockbox_interface/browsing_and_playing.tex b/manual/rockbox_interface/browsing_and_playing.tex
index 45a145ad3a..d93c7604ca 100644
--- a/manual/rockbox_interface/browsing_and_playing.tex
+++ b/manual/rockbox_interface/browsing_and_playing.tex
@@ -194,6 +194,9 @@ each option pertains both to files and directories):
     \item [Recording Directory.]
      Save recordings in the selected directory.
   }
+  \item [Always remember last folder.]
+   Saves the last position in the file browser on shutdown.
+   This directory (and if applicable last file) will be restored next boot.
   \item [Start Directory.]
    Set as default start directory for the File Browser.
    \note{If you have \setting{Auto-Change Directory} and
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.