Mercurial > mplayer.hg
annotate libmenu/menu_filesel.c @ 25505:8d329f7bbc3c
Remove redundant option 'auto-close' from cmdlist and filesel.
author | ulion |
---|---|
date | Fri, 28 Dec 2007 03:45:01 +0000 |
parents | 605d4e3e403f |
children | e3f6092fb640 |
rev | line source |
---|---|
8197 | 1 |
2 #include <stdlib.h> | |
3 #include <stdio.h> | |
4 #include <dirent.h> | |
5 #include <errno.h> | |
6 #include <string.h> | |
7 #include <sys/types.h> | |
8 #include <sys/stat.h> | |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
9 #include <fcntl.h> |
8197 | 10 #include <ctype.h> |
11 #include <unistd.h> | |
8291
abe95dde3223
limits.h required to get a PATH_MAX definition (on solaris)
jkeil
parents:
8226
diff
changeset
|
12 #include <limits.h> |
8197 | 13 |
14 | |
16862 | 15 #include "config.h" |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
16 #include "mp_msg.h" |
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
17 #include "help_mp.h" |
8197 | 18 |
16862 | 19 #include "m_struct.h" |
20 #include "m_option.h" | |
8197 | 21 |
19431
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
17994
diff
changeset
|
22 #include "libmpcodecs/img_format.h" |
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
17994
diff
changeset
|
23 #include "libmpcodecs/mp_image.h" |
8197 | 24 |
25 #include "menu.h" | |
26 #include "menu_list.h" | |
16862 | 27 #include "input/input.h" |
28 #include "osdep/keycodes.h" | |
8197 | 29 |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
30 #define MENU_KEEP_PATH "/tmp/mp_current_path" |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
31 |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
32 int menu_keepdir = 0; |
23391
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
33 char *menu_chroot = NULL; |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
34 |
8197 | 35 struct list_entry_s { |
36 struct list_entry p; | |
37 int d; | |
38 }; | |
39 | |
40 struct menu_priv_s { | |
41 menu_list_priv_t p; | |
42 char* dir; // current dir | |
43 /// Cfg fields | |
44 char* path; | |
45 char* title; | |
46 char* file_action; | |
47 char* dir_action; | |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
48 char** actions; |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
49 char* filter; |
8197 | 50 }; |
51 | |
52 static struct menu_priv_s cfg_dflt = { | |
53 MENU_LIST_PRIV_DFLT, | |
54 NULL, | |
55 | |
56 NULL, | |
57 "Select a file: %p", | |
8226 | 58 "loadfile '%p'", |
8197 | 59 NULL, |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
60 NULL, |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
61 NULL |
8197 | 62 }; |
63 | |
64 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m) | |
65 | |
66 static m_option_t cfg_fields[] = { | |
67 MENU_LIST_PRIV_FIELDS, | |
68 { "path", ST_OFF(path), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
69 { "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
70 { "file-action", ST_OFF(file_action), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
71 { "dir-action", ST_OFF(dir_action), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
72 { "actions", ST_OFF(actions), CONF_TYPE_STRING_LIST, 0, 0, 0, NULL}, |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
73 { "filter", ST_OFF(filter), CONF_TYPE_STRING, 0, 0, 0, NULL}, |
8197 | 74 { NULL, NULL, NULL, 0,0,0,NULL } |
75 }; | |
76 | |
77 #define mpriv (menu->priv) | |
78 | |
79 static void free_entry(list_entry_t* entry) { | |
80 free(entry->p.txt); | |
81 free(entry); | |
82 } | |
83 | |
84 static char* replace_path(char* title , char* dir) { | |
85 char *p = strstr(title,"%p"); | |
86 if(p) { | |
87 int tl = strlen(title); | |
88 int dl = strlen(dir); | |
89 int t1l = p-title; | |
90 int l = tl - 2 + dl; | |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
91 char *r, *n, *d = dir; |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
92 char term = *(p-1); |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
93 |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
94 do { |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
95 if (*d == '\\' || *d == term) |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
96 l++; |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
97 } while (*d++); |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
98 r = malloc(l + 1); |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
99 n = r + t1l; |
8197 | 100 memcpy(r,title,t1l); |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
101 do { |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
102 if (*dir == '\\' || *dir == term) |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
103 *n++ = '\\'; |
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
104 } while ((*n++ = *dir++)); |
8197 | 105 if(tl - t1l - 2 > 0) |
10624
cdfd4a43c406
I've juste found a bug which prevent to load a file whose name contain
albeu
parents:
9380
diff
changeset
|
106 strcpy(n-1,p+2); |
8197 | 107 return r; |
108 } else | |
109 return title; | |
110 } | |
111 | |
112 typedef int (*kill_warn)(const void*, const void*); | |
113 | |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
114 static int mylstat(char *dir, char *file,struct stat* st) { |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
115 int l = strlen(dir) + strlen(file); |
8613 | 116 char s[l+2]; |
25311
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
117 if (!strcmp("..", file)) { |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
118 char *slash; |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
119 l -= 3; |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
120 strcpy(s, dir); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
121 #if defined(__MINGW32__) || defined(__CYGWIN__) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
122 if (s[l] == '/' || s[l] == '\\') |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
123 #else |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
124 if (s[l] == '/') |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
125 #endif |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
126 s[l] = '\0'; |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
127 slash = strrchr(s, '/'); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
128 #if defined(__MINGW32__) || defined(__CYGWIN__) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
129 if (!slash) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
130 slash = strrchr(s,'\\'); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
131 #endif |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
132 if (!slash) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
133 return stat(dir,st); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
134 slash[1] = '\0'; |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
135 return stat(s,st); |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
136 } |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
137 sprintf(s,"%s/%s",dir,file); |
9249 | 138 return stat(s,st); |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
139 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
140 |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
141 static int compare(char **a, char **b){ |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
142 if((*a)[strlen(*a) - 1] == '/') { |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
143 if((*b)[strlen(*b) - 1] == '/') |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
144 return strcmp(*b, *a) ; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
145 else |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
146 return 1; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
147 } else { |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
148 if((*b)[strlen(*b) - 1] == '/') |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
149 return -1; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
150 else |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
151 return strcmp(*b, *a); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
152 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
153 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
154 |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
155 static char **get_extensions(menu_t *menu){ |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
156 char **extensions, ext[32]; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
157 FILE *fp; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
158 int n = 1; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
159 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
160 if (!mpriv->filter) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
161 return NULL; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
162 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
163 fp = fopen(mpriv->filter, "r"); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
164 if(!fp) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
165 return NULL; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
166 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
167 extensions = (char **) malloc(sizeof(*extensions)); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
168 *extensions = NULL; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
169 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
170 while(fgets(ext,sizeof(ext),fp)) { |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
171 char **l, *e; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
172 int s = strlen (ext); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
173 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
174 if(ext[s-1] == '\n') { |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
175 ext[s-1] = '\0'; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
176 s--; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
177 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
178 e = (char *) malloc(s+1); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
179 extensions = (char **) realloc(extensions, ++n * sizeof(*extensions)); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
180 extensions = (char **) realloc(extensions, ++n * sizeof(*extensions)); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
181 strcpy (e, ext); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
182 for (l=extensions; *l; l++); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
183 *l++ = e; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
184 *l = NULL; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
185 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
186 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
187 fclose (fp); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
188 return extensions; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
189 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
190 |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
191 static void free_extensions(char **extensions){ |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
192 if (extensions) { |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
193 char **l = extensions; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
194 while (*l) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
195 free (*l++); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
196 free (extensions); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
197 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
198 } |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
199 |
25354
a4c4b56e933d
reverted r25323: deprecated by ulion's recent patches
ben
parents:
25320
diff
changeset
|
200 static int open_dir(menu_t* menu,char* args) { |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
201 char **namelist, **tp; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
202 struct dirent *dp; |
8197 | 203 struct stat st; |
204 int n; | |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
205 int path_fp; |
8197 | 206 char* p = NULL; |
207 list_entry_t* e; | |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
208 DIR* dirp; |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
209 extern int file_filter; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
210 char **extensions, **elem, *ext; |
8197 | 211 |
212 menu_list_init(menu); | |
213 | |
214 if(mpriv->dir) | |
215 free(mpriv->dir); | |
216 mpriv->dir = strdup(args); | |
217 if(mpriv->p.title && mpriv->p.title != mpriv->title && mpriv->p.title != cfg_dflt.p.title) | |
218 free(mpriv->p.title); | |
219 p = strstr(mpriv->title,"%p"); | |
220 | |
221 mpriv->p.title = replace_path(mpriv->title,mpriv->dir); | |
222 | |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
223 if ((dirp = opendir (mpriv->dir)) == NULL){ |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
224 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_OpendirError, strerror(errno)); |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
225 return 0; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
226 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
227 |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
228 if (menu_keepdir) { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
229 path_fp = open (MENU_KEEP_PATH, O_CREAT | O_WRONLY | O_TRUNC, 0666); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
230 if (path_fp >= 0) { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
231 write (path_fp, mpriv->dir, strlen (mpriv->dir)); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
232 close (path_fp); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
233 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
234 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
235 |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
236 namelist = (char **) malloc(sizeof(char *)); |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
237 extensions = get_extensions(menu); |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
238 |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
239 n=0; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
240 while ((dp = readdir(dirp)) != NULL) { |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
241 if(dp->d_name[0] == '.' && strcmp(dp->d_name,"..") != 0) |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
242 continue; |
23391
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
243 if (menu_chroot && !strcmp (dp->d_name,"..")) { |
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
244 int len = strlen (menu_chroot); |
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
245 if ((strlen (mpriv->dir) == len || strlen (mpriv->dir) == len + 1) |
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
246 && !strncmp (mpriv->dir, menu_chroot, len)) |
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
247 continue; |
9bf57f60bf0a
new -menu-chroot option that prevent OSD file selection menu to go to an unwanted location (yeah, chroot ;-))
ben
parents:
23229
diff
changeset
|
248 } |
25311
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
249 if (mylstat(args,dp->d_name,&st)) |
605f00b6a4ae
Fix mylstat() call to parent dir where the subdir has no exec permission.
ulion
parents:
25300
diff
changeset
|
250 continue; |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
251 if (file_filter && extensions && !S_ISDIR(st.st_mode)) { |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
252 if((ext = strrchr(dp->d_name,'.')) == NULL) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
253 continue; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
254 ext++; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
255 elem = extensions; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
256 do { |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
257 if (!strcasecmp(ext, *elem)) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
258 break; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
259 } while (*++elem); |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
260 if (*elem == NULL) |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
261 continue; |
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
262 } |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
263 if(n%20 == 0){ // Get some more mem |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
264 if((tp = (char **) realloc(namelist, (n+20) * sizeof (char *))) |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
265 == NULL) { |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
266 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReallocError, strerror(errno)); |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
267 n--; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
268 goto bailout; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
269 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
270 namelist=tp; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
271 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
272 |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
273 namelist[n] = (char *) malloc(strlen(dp->d_name) + 2); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
274 if(namelist[n] == NULL){ |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
275 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_MallocError, strerror(errno)); |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
276 n--; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
277 goto bailout; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
278 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
279 |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
280 strcpy(namelist[n], dp->d_name); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
281 if(S_ISDIR(st.st_mode)) |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
282 strcat(namelist[n], "/"); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
283 n++; |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
284 } |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
285 |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
286 bailout: |
19491
10d8f2cae948
added new filter option to menu file browser to only display some files according to extension
ben
parents:
19490
diff
changeset
|
287 free_extensions (extensions); |
16061 | 288 closedir(dirp); |
289 | |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
290 qsort(namelist, n, sizeof(char *), (kill_warn)compare); |
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
291 |
8197 | 292 if (n < 0) { |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
293 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ReaddirError,strerror(errno)); |
8197 | 294 return 0; |
295 } | |
296 while(n--) { | |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
297 if((e = calloc(1,sizeof(list_entry_t))) != NULL){ |
8613 | 298 e->p.next = NULL; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
299 e->p.txt = strdup(namelist[n]); |
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
300 if(strchr(namelist[n], '/') != NULL) |
8197 | 301 e->d = 1; |
8358
ecf6a4cf3272
No scandir() an no functions defined within other functions.
arpi
parents:
8291
diff
changeset
|
302 menu_list_add_entry(menu,e); |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
303 }else{ |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
304 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_MallocError, strerror(errno)); |
9104
a0aacfb492a5
Also attached some cleanup to menu_filesel.c, mainly to make it more
arpi
parents:
8853
diff
changeset
|
305 } |
8197 | 306 free(namelist[n]); |
307 } | |
308 free(namelist); | |
309 | |
310 return 1; | |
311 } | |
312 | |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
313 static char *action; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
314 |
8197 | 315 static void read_cmd(menu_t* menu,int cmd) { |
316 switch(cmd) { | |
17945
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
317 case MENU_CMD_LEFT: |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
318 mpriv->p.current = mpriv->p.menu; // Hack : we consider that the first entry is ../ |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
319 case MENU_CMD_RIGHT: |
8197 | 320 case MENU_CMD_OK: { |
321 // Directory | |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
322 if(mpriv->p.current->d && !mpriv->dir_action) { |
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
323 // Default action : open this dirctory ourself |
8197 | 324 int l = strlen(mpriv->dir); |
325 char *slash = NULL, *p = NULL; | |
326 if(strcmp(mpriv->p.current->p.txt,"../") == 0) { | |
327 if(l <= 1) break; | |
328 mpriv->dir[l-1] = '\0'; | |
329 slash = strrchr(mpriv->dir,'/'); | |
20505 | 330 #if defined(__MINGW32__) || defined(__CYGWIN__) |
331 if (!slash) | |
332 slash = strrchr(mpriv->dir,'\\'); | |
333 #endif | |
8197 | 334 if(!slash) break; |
335 slash[1] = '\0'; | |
336 p = strdup(mpriv->dir); | |
337 } else { | |
338 p = malloc(l + strlen(mpriv->p.current->p.txt) + 1); | |
339 sprintf(p,"%s%s",mpriv->dir,mpriv->p.current->p.txt); | |
340 } | |
341 menu_list_uninit(menu,free_entry); | |
342 if(!open_dir(menu,p)) { | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
343 mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_CantOpenDirectory,p); |
8197 | 344 menu->cl = 1; |
345 } | |
346 free(p); | |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
347 } else { // File and directory dealt with action string. |
8197 | 348 int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1; |
349 char filename[fname_len]; | |
350 char *str; | |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
351 char *action = mpriv->p.current->d ? mpriv->dir_action:mpriv->file_action; |
8197 | 352 sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt); |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
353 str = replace_path(action, filename); |
25505
8d329f7bbc3c
Remove redundant option 'auto-close' from cmdlist and filesel.
ulion
parents:
25502
diff
changeset
|
354 mp_input_parse_and_queue_cmds(str); |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
355 if (str != action) |
8197 | 356 free(str); |
25300
b1638a8b9dc6
Combine common code for dealing with file action and dir action.
ulion
parents:
25299
diff
changeset
|
357 } |
8197 | 358 } break; |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
359 case MENU_CMD_ACTION: { |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
360 int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
361 char filename[fname_len]; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
362 char *str; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
363 sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt); |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
364 str = replace_path(action, filename); |
25320
4fbf536cc033
Support to run multiple mplayer commands set in menu.conf
ulion
parents:
25311
diff
changeset
|
365 mp_input_parse_and_queue_cmds(str); |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
366 if(str != action) |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
367 free(str); |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
368 } break; |
8197 | 369 default: |
370 menu_list_read_cmd(menu,cmd); | |
371 } | |
372 } | |
373 | |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25354
diff
changeset
|
374 static int read_key(menu_t* menu,int c){ |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
375 char **str; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
376 for (str=mpriv->actions; str && *str; str++) |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
377 if (c == (*str)[0]) { |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
378 action = &(*str)[2]; |
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
379 read_cmd(menu,MENU_CMD_ACTION); |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25354
diff
changeset
|
380 return 1; |
19490
f57977ac0394
support multiple actions in menu's file browser using key bindings
ben
parents:
19431
diff
changeset
|
381 } |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25134
diff
changeset
|
382 if (menu_dflt_read_key(menu, c)) |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25354
diff
changeset
|
383 return 1; |
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25354
diff
changeset
|
384 return menu_list_jump_to_key(menu, c); |
8197 | 385 } |
386 | |
387 static void clos(menu_t* menu) { | |
388 menu_list_uninit(menu,free_entry); | |
389 free(mpriv->dir); | |
390 } | |
391 | |
392 static int open_fs(menu_t* menu, char* args) { | |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
393 char *path = mpriv->path, *freepath = NULL; |
8197 | 394 int r = 0; |
25134
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
395 char wd[PATH_MAX+1], b[PATH_MAX+1]; |
8197 | 396 args = NULL; // Warning kill |
397 | |
398 menu->draw = menu_list_draw; | |
399 menu->read_cmd = read_cmd; | |
400 menu->read_key = read_key; | |
401 menu->close = clos; | |
402 | |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
403 if (menu_keepdir) { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
404 if (!path || path[0] == '\0') { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
405 struct stat st; |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
406 int path_fp; |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
407 |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
408 path_fp = open (MENU_KEEP_PATH, O_RDONLY); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
409 if (path_fp >= 0) { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
410 if (!fstat (path_fp, &st) && (st.st_size > 0)) { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
411 path = malloc(st.st_size+1); |
25299 | 412 if ((read(path_fp, path, st.st_size) == st.st_size) && path[0] == '/' |
413 && !stat(path, &st) && S_ISDIR(st.st_mode)){ | |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
414 freepath = path; |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
415 path[st.st_size] = '\0'; |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
416 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
417 else { |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
418 free(path); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
419 path = NULL; |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
420 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
421 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
422 close (path_fp); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
423 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
424 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
425 } |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
426 |
8197 | 427 getcwd(wd,PATH_MAX); |
25134
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
428 if (!path || path[0] == '\0') |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
429 path = wd; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
430 if (path[0] != '/') { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
431 if(path[strlen(path)-1] != '/') |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
432 snprintf(b,sizeof(b),"%s/%s/",wd,path); |
8197 | 433 else |
25134
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
434 snprintf(b,sizeof(b),"%s/%s",wd,path); |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
435 path = b; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
436 } else if (path[strlen(path)-1]!='/') { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
437 sprintf(b,"%s/",path); |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
438 path = b; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
439 } |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
440 if (menu_chroot && menu_chroot[0] == '/') { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
441 int l = strlen(menu_chroot); |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
442 if (l > 0 && menu_chroot[l-1] == '/') |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
443 --l; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
444 if (strncmp(menu_chroot, path, l) || (path[l] != '\0' && path[l] != '/')) { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
445 if (menu_chroot[l] == '/') |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
446 path = menu_chroot; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
447 else { |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
448 sprintf(b,"%s/",menu_chroot); |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
449 path = b; |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
450 } |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
451 } |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
452 } |
dcf1bfb29dc8
Fix code to make sure the browse starting path within the menu-chroot path.
ulion
parents:
23391
diff
changeset
|
453 r = open_dir(menu,path); |
8197 | 454 |
23229
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
455 if (freepath) |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
456 free(freepath); |
ae2a2d5ca64b
new -menu-keepdir option that allows libmenu file browser to always restart browsing from the last place we were instead of current dir
ben
parents:
20505
diff
changeset
|
457 |
8197 | 458 return r; |
459 } | |
460 | |
461 const menu_info_t menu_info_filesel = { | |
462 "File seletor menu", | |
463 "filesel", | |
464 "Albeu", | |
465 "", | |
466 { | |
467 "fs_cfg", | |
468 sizeof(struct menu_priv_s), | |
469 &cfg_dflt, | |
470 cfg_fields | |
471 }, | |
472 open_fs | |
473 }; |