1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 Daniel Stenberg
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include "applimits.h"
#include "dir.h"
#include "file.h"
#include "lcd.h"
#include "font.h"
#include "backlight.h"
#include "button.h"
#include "kernel.h"
#include "usb.h"
#include "tree.h"
#include "main_menu.h"
#include "sprintf.h"
#include "mpeg.h"
#include "playlist.h"
#include "menu.h"
#include "wps.h"
#include "wps-display.h"
#include "settings.h"
#include "status.h"
#include "debug.h"
#include "ata.h"
#include "rolo.h"
#include "icons.h"
#include "lang.h"
#include "language.h"
#include "screens.h"
#include "keyboard.h"
#include "bookmark.h"
#include "onplay.h"
#include "buffer.h"
#include "plugin.h"
#include "power.h"
#ifdef HAVE_LCD_BITMAP
#include "widgets.h"
#define BOOTFILE "ajbrec.ajz"
#else
#define BOOTFILE "archos.mod"
#endif
/* a table for the know file types */
static struct
{
char* extension; /* extension for which the file type is recognized */
int tree_attr; /* which identifier */
int icon; /* the icon which shall be used for it, -1 if unknown */
/* To have it extendable, there could be more useful stuff in here,
like handler functions, plugin name, etc. */
} filetypes[] = {
{ ".mp3", TREE_ATTR_MPA, File },
{ ".mp2", TREE_ATTR_MPA, File },
{ ".mpa", TREE_ATTR_MPA, File },
{ ".m3u", TREE_ATTR_M3U, Playlist },
{ ".cfg", TREE_ATTR_CFG, Config },
{ ".wps", TREE_ATTR_WPS, Wps, },
{ ".txt", TREE_ATTR_TXT, Text },
{ ".lng", TREE_ATTR_LNG, Language },
{ ".rock",TREE_ATTR_ROCK,Plugin },
#ifdef HAVE_LCD_BITMAP
{ ".fnt", TREE_ATTR_FONT,Font },
{ ".ch8", TREE_ATTR_CH8, Chip8 },
{ ".rvf", TREE_ATTR_RVF, Video },
{ ".bmark",TREE_ATTR_BMARK,Bookmark },
#else
{ ".bmark", TREE_ATTR_BMARK, -1 },
#endif
#ifndef SIMULATOR
#ifdef HAVE_LCD_BITMAP
{ ".ucl", TREE_ATTR_UCL, Flashfile},
{ ".ajz", TREE_ATTR_MOD, Mod_Ajz },
#else
{ ".mod", TREE_ATTR_MOD, Mod_Ajz },
#endif
#endif /* #ifndef SIMULATOR */
};
/* Boot value of global_settings.max_files_in_dir */
static int max_files_in_dir;
static char *name_buffer;
static int name_buffer_size; /* Size of allocated buffer */
static int name_buffer_length; /* Currently used amount */
static struct entry *dircache;
static int dircursor;
static int dirstart;
static int dirlevel;
static int filesindir;
static int dirpos[MAX_DIR_LEVELS];
static int cursorpos[MAX_DIR_LEVELS];
static char lastdir[MAX_PATH];
static char lastfile[MAX_PATH];
static char currdir[MAX_PATH];
static char currdir_save[MAX_PATH];
static bool reload_dir = false;
static int boot_size = 0;
static int boot_cluster;
static bool boot_changed = false;
static bool start_wps = false;
static bool dirbrowse(char *root, int *dirfilter);
void browse_root(void)
{
#ifndef SIMULATOR
dirbrowse("/", &global_settings.dirfilter);
#else
if (!dirbrowse("/", &global_settings.dirfilter)) {
DEBUGF("No filesystem found. Have you forgotten to create it?\n");
}
#endif
}
#ifdef HAVE_LCD_BITMAP
/* pixel margins */
#define MARGIN_X (global_settings.scrollbar && \
filesindir > tree_max_on_screen ? SCROLLBAR_WIDTH : 0) + \
CURSOR_WIDTH + (global_settings.show_icons && ICON_WIDTH > 0 ? ICON_WIDTH :0)
#define MARGIN_Y (global_settings.statusbar ? STATUSBAR_HEIGHT : 0)
/* position the entry-list starts at */
#define LINE_X 0
#define LINE_Y (global_settings.statusbar ? 1 : 0)
#define CURSOR_X (global_settings.scrollbar && \
filesindir > tree_max_on_screen ? 1 : 0)
#define CURSOR_Y 0 /* the cursor is not positioned in regard to
the margins, so this is the amount of lines
we add to the cursor Y position to position
it on a line */
#define CURSOR_WIDTH (global_settings.invert_cursor ? 0 : 4)
#define ICON_WIDTH 6
#define SCROLLBAR_X 0
#define SCROLLBAR_Y lcd_getymargin()
#define SCROLLBAR_WIDTH 6
extern unsigned char bitmap_icons_6x8[LastIcon][6];
#else /* HAVE_LCD_BITMAP */
#define TREE_MAX_ON_SCREEN 2
#define TREE_MAX_LEN_DISPLAY 11 /* max length that fits on screen */
#define LINE_X 2 /* X position the entry-list starts at */
#define LINE_Y 0 /* Y position the entry-list starts at */
#define CURSOR_X 0
#define CURSOR_Y 0 /* not really used for players */
#endif /* HAVE_LCD_BITMAP */
#ifdef HAVE_RECORDER_KEYPAD
#define TREE_NEXT BUTTON_DOWN
#define TREE_PREV BUTTON_UP
#define TREE_EXIT BUTTON_LEFT
#define TREE_ENTER BUTTON_RIGHT
#define TREE_MENU BUTTON_F1
#else
#define TREE_NEXT BUTTON_RIGHT
#define TREE_PREV BUTTON_LEFT
#define TREE_EXIT BUTTON_STOP
#define TREE_ENTER BUTTON_PLAY
#define TREE_MENU BUTTON_MENU
#endif /* HAVE_RECORDER_KEYPAD */
static int build_playlist(int start_index)
{
int i;
int start=start_index;
for(i = 0;i < filesindir;i++)
{
if((dircache[i].attr & TREE_ATTR_MASK) == TREE_ATTR_MPA)
{
DEBUGF("Adding %s\n", dircache[i].name);
if (playlist_add(dircache[i].name) < 0)
break;
}
else
{
/* Adjust the start index when se skip non-MP3 entries */
if(i < start)
start_index--;
}
}
return start_index;
}
static int compare(const void* p1, const void* p2)
{
struct entry* e1 = (struct entry*)p1;
struct entry* e2 = (struct entry*)p2;
if (( e1->attr & ATTR_DIRECTORY ) == ( e2->attr & ATTR_DIRECTORY ))
if (global_settings.sort_case)
return strncmp(e1->name, e2->name, MAX_PATH);
else
return strncasecmp(e1->name, e2->name, MAX_PATH);
else
return ( e2->attr & ATTR_DIRECTORY ) - ( e1->attr & ATTR_DIRECTORY );
}
static void showfileline(int line, int direntry, bool scroll, int *dirfilter)
{
char* name = dircache[direntry].name;
int xpos = LINE_X;
#ifdef HAVE_LCD_CHARCELLS
if (!global_settings.show_icons)
xpos--;
#endif
/* if any file filter is on, strip the extension */
if (*dirfilter != SHOW_ALL &&
!(dircache[direntry].attr & ATTR_DIRECTORY))
{
char* dotpos = strrchr(name, '.');
char temp=0;
if (dotpos) {
temp = *dotpos;
*dotpos = 0;
}
if(scroll)
#ifdef HAVE_LCD_BITMAP
if (global_settings.invert_cursor)
lcd_puts_scroll_style(xpos, line, name, STYLE_INVERT);
else
#endif
lcd_puts_scroll(xpos, line, name);
else
lcd_puts(xpos, line, name);
if (temp)
*dotpos = temp;
}
else {
if(scroll)
#ifdef HAVE_LCD_BITMAP
if (global_settings.invert_cursor)
lcd_puts_scroll_style(xpos, line, name, STYLE_INVERT);
else
#endif
lcd_puts_scroll(xpos, line, name);
else
lcd_puts(xpos, line, name);
}
}
/* load sorted directory into dircache. returns NULL on failure. */
struct entry* load_and_sort_directory(char *dirname, int *dirfilter,
int *num_files, bool *buffer_full)
{
int i;
DIR *dir = opendir(dirname);
if(!dir)
return NULL; /* not a directory */
name_buffer_length = 0;
*buffer_full = false;
for ( i=0; i < max_files_in_dir; i++ ) {
int len;
struct dirent *entry = readdir(dir);
struct entry* dptr = &dircache[i];
if (!entry)
break;
len = strlen(entry->d_name);
/* skip directories . and .. */
if ((entry->attribute & ATTR_DIRECTORY) &&
(((len == 1) &&
(!strncmp(entry->d_name, ".", 1))) ||
((len == 2) &&
(!strncmp(entry->d_name, "..", 2))))) {
i--;
continue;
}
/* Skip FAT volume ID */
if (entry->attribute & ATTR_VOLUME_ID) {
i--;
continue;
}
/* filter out dotfiles and hidden files */
if (*dirfilter != SHOW_ALL &&
((entry->d_name[0]=='.') ||
(entry->attribute & ATTR_HIDDEN))) {
i--;
continue;
}
dptr->attr = entry->attribute;
/* check for known file types */
if ( !(dptr->attr & ATTR_DIRECTORY) && (len > 4) )
{
unsigned j;
for (j=0; j<sizeof(filetypes)/sizeof(*filetypes); j++)
{
if (!strcasecmp(
&entry->d_name[len-strlen(filetypes[j].extension)],
filetypes[j].extension))
{
dptr->attr |= filetypes[j].tree_attr;
break;
}
}
}
/* memorize/compare details about the boot file */
if ((currdir[1] == 0) && !strcasecmp(entry->d_name, BOOTFILE)) {
if (boot_size) {
if ((entry->size != boot_size) ||
(entry->startcluster != boot_cluster))
boot_changed = true;
}
boot_size = entry->size;
boot_cluster = entry->startcluster;
}
/* filter out non-visible files */
if (!(dptr->attr & ATTR_DIRECTORY) && (
(*dirfilter == SHOW_PLAYLIST &&
(dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_M3U) ||
((*dirfilter == SHOW_MUSIC &&
(dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_MPA) &&
(dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_M3U) ||
(*dirfilter == SHOW_SUPPORTED && !(dptr->attr & TREE_ATTR_MASK)) ||
(*dirfilter == SHOW_WPS && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_WPS) ||
(*dirfilter == SHOW_CFG && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_CFG) ||
(*dirfilter == SHOW_LNG && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_LNG) ||
(*dirfilter == SHOW_MOD && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_MOD) ||
(*dirfilter == SHOW_FONT && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_FONT) ||
(*dirfilter == SHOW_PLUGINS && (dptr->attr & TREE_ATTR_MASK) != TREE_ATTR_ROCK)))
{
i--;
continue;
}
if (len > name_buffer_size - name_buffer_length - 1) {
/* Tell the world that we ran out of buffer space */
*buffer_full = true;
break;
}
dptr->name = &name_buffer[name_buffer_length];
strcpy(dptr->name,entry->d_name);
name_buffer_length += len + 1;
}
*num_files = i;
closedir(dir);
strncpy(lastdir,dirname,sizeof(lastdir));
lastdir[sizeof(lastdir)-1] = 0;
qsort(dircache,i,sizeof(struct entry),compare);
return dircache;
}
static int showdir(char *path, int start, int *dirfilter)
{
int icon_type = 0;
int i;
int tree_max_on_screen;
bool dir_buffer_full;
#ifdef HAVE_LCD_BITMAP
int line_height;
int fw, fh;
lcd_setfont(FONT_UI);
lcd_getstringsize("A", &fw, &fh);
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
line_height = fh;
#else
tree_max_on_screen = TREE_MAX_ON_SCREEN;
#endif
/* new dir? cache it */
if (strncmp(path,lastdir,sizeof(lastdir)) || reload_dir) {
if (!load_and_sort_directory(path, dirfilter,
&filesindir, &dir_buffer_full))
return -1;
if ( dir_buffer_full || filesindir == max_files_in_dir ) {
#ifdef HAVE_LCD_CHARCELLS
lcd_double_height(false);
#endif
lcd_clear_display();
lcd_puts(0,0,str(LANG_SHOWDIR_ERROR_BUFFER));
lcd_puts(0,1,str(LANG_SHOWDIR_ERROR_FULL));
lcd_update();
sleep(HZ*2);
lcd_clear_display();
}
}
if (start == -1)
{
int diff_files;
/* use lastfile to determine start (default=0) */
start = 0;
for (i=0; i<filesindir; i++)
{
if (!strcasecmp(dircache[i].name, lastfile))
{
start = i;
break;
}
}
diff_files = filesindir - start;
if (diff_files < tree_max_on_screen)
{
int oldstart = start;
start -= (tree_max_on_screen - diff_files);
if (start < 0)
start = 0;
dircursor = oldstart - start;
}
dirstart = start;
}
/* The cursor might point to an invalid line, for example if someone
deleted the last file in the dir */
if(filesindir)
{
while(start + dircursor >= filesindir)
{
if(start)
start--;
else
if(dircursor)
dircursor--;
}
dirstart = start;
}
#ifdef HAVE_LCD_CHARCELLS
lcd_stop_scroll();
lcd_double_height(false);
#endif
lcd_clear_display();
#ifdef HAVE_LCD_BITMAP
lcd_setmargins(MARGIN_X,MARGIN_Y); /* leave room for cursor and icon */
lcd_setfont(FONT_UI);
#endif
for ( i=start; i < start+tree_max_on_screen; i++ ) {
int len;
unsigned j;
if ( i >= filesindir )
break;
len = strlen(dircache[i].name);
if (dircache[i].attr & ATTR_DIRECTORY)
{
icon_type = Folder;
}
else
{
/* search which icon to use */
icon_type = -1; /* default to none */
for (j=0; j<sizeof(filetypes)/sizeof(*filetypes); j++)
{
if ((dircache[i].attr & TREE_ATTR_MASK) == filetypes[j].tree_attr)
{
icon_type = filetypes[j].icon;
break;
}
}
if (icon_type == -1)
{
#ifdef HAVE_LCD_BITMAP
icon_type = 0;
#else
icon_type = Unknown;
#endif
}
}
if (icon_type && global_settings.show_icons) {
#ifdef HAVE_LCD_BITMAP
int offset=0;
if ( line_height > 8 )
offset = (line_height - 8) / 2;
lcd_bitmap(bitmap_icons_6x8[icon_type],
CURSOR_X * 6 + CURSOR_WIDTH,
MARGIN_Y+(i-start)*line_height + offset,
6, 8, true);
#else
lcd_putc(LINE_X-1, i-start, icon_type);
#endif
}
showfileline(i-start, i, false, dirfilter); /* no scroll */
}
#ifdef HAVE_LCD_BITMAP
if (global_settings.scrollbar && (filesindir > tree_max_on_screen))
scrollbar(SCROLLBAR_X, SCROLLBAR_Y, SCROLLBAR_WIDTH - 1,
LCD_HEIGHT - SCROLLBAR_Y, filesindir, start,
start + tree_max_on_screen, VERTICAL);
#endif
status_draw(true);
return filesindir;
}
static bool ask_resume(bool ask_once)
{
bool stop = false;
#ifdef HAVE_LCD_CHARCELLS
lcd_double_height(false);
#endif
if (usb_detect()) {
usb_screen();
return false;
}
/* always resume? */
if ( global_settings.resume == RESUME_ON )
return true;
lcd_clear_display();
lcd_puts(0,0,str(LANG_RESUME_ASK));
#ifdef HAVE_LCD_CHARCELLS
status_draw(false);
lcd_puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER));
#else
lcd_puts(0,1,str(LANG_CONFIRM_WITH_PLAY_RECORDER));
lcd_puts(0,2,str(LANG_CANCEL_WITH_ANY_RECORDER));
#endif
lcd_update();
while (!stop) {
switch (button_get(true)) {
case BUTTON_PLAY:
#ifdef BUTTON_RC_PLAY
case BUTTON_RC_PLAY:
#endif
return true;
#ifdef BUTTON_ON
/* ignore the ON button, since it might
still be pressed since booting */
case BUTTON_ON:
case BUTTON_ON | BUTTON_REL:
case BUTTON_ON | BUTTON_REPEAT:
break;
#endif
case SYS_USB_CONNECTED:
usb_screen();
stop = true;
break;
default:
stop = true;
break;
}
}
if ( global_settings.resume == RESUME_ASK_ONCE && ask_once) {
global_settings.resume_index = -1;
settings_save();
}
return false;
}
/* load tracks from specified directory to resume play */
void resume_directory(char *dir)
{
bool buffer_full;
if (!load_and_sort_directory(dir, &global_settings.dirfilter, &filesindir,
&buffer_full))
return;
lastdir[0] = 0;
build_playlist(0);
}
/* Returns the current working directory and also writes cwd to buf if
non-NULL. In case of error, returns NULL. */
char *getcwd(char *buf, int size)
{
if (!buf)
return currdir;
else if (size > 0)
{
strncpy(buf, currdir, size);
return buf;
}
else
return NULL;
}
/* Force a reload of the directory next time directory browser is called */
void reload_directory(void)
{
reload_dir = true;
}
static void start_resume(bool ask_once)
{
if ( global_settings.resume &&
global_settings.resume_index != -1 ) {
DEBUGF("Resume index %X offset %X\n",
global_settings.resume_index,
global_settings.resume_offset);
if (!ask_resume(ask_once))
return;
if (playlist_resume() != -1)
{
playlist_start(global_settings.resume_index,
global_settings.resume_offset);
start_wps = true;
}
else
return;
}
}
void set_current_file(char *path)
{
char *name;
unsigned int i;
/* separate directory from filename */
name = strrchr(path+1,'/');
if (name)
{
*name = 0;
strcpy(currdir, path);
*name = '/';
name++;
}
else
{
strcpy(currdir, "/");
name = path+1;
}
strcpy(lastfile, name);
dircursor = 0;
dirstart = -1;
if (strncmp(currdir,lastdir,sizeof(lastdir)))
{
dirlevel = 0;
dirpos[dirlevel] = -1;
cursorpos[dirlevel] = 0;
/* use '/' to calculate dirlevel */
for (i=1; i<strlen(path)+1; i++)
{
if (path[i] == '/')
{
dirlevel++;
dirpos[dirlevel] = -1;
cursorpos[dirlevel] = 0;
}
}
}
}
#ifdef BUTTON_ON
static bool handle_on(int *ds, int *dc, int numentries, int tree_max_on_screen, int *dirfilter)
{
bool exit = false;
bool used = false;
int dirstart = *ds;
int dircursor = *dc;
char buf[MAX_PATH];
#ifdef HAVE_LCD_BITMAP
int fw, fh;
lcd_getstringsize("A", &fw, &fh);
#endif
while (!exit) {
switch (button_get(true)) {
case TREE_PREV:
#ifdef BUTTON_RC_LEFT
case BUTTON_RC_LEFT:
#endif
#ifdef BUTTON_ON
case BUTTON_ON | TREE_PREV:
case BUTTON_ON | TREE_PREV | BUTTON_REPEAT:
#endif
used = true;
if ( dirstart ) {
dirstart -= tree_max_on_screen;
if ( dirstart < 0 )
dirstart = 0;
}
else
dircursor = 0;
break;
case TREE_NEXT:
#ifdef BUTTON_RC_RIGHT
case BUTTON_RC_RIGHT:
#endif
#ifdef BUTTON_ON
case BUTTON_ON | TREE_NEXT:
case BUTTON_ON | TREE_NEXT | BUTTON_REPEAT:
#endif
used = true;
if ( dirstart < numentries - tree_max_on_screen ) {
dirstart += tree_max_on_screen;
if ( dirstart >
numentries - tree_max_on_screen )
dirstart = numentries - tree_max_on_screen;
}
else
dircursor = numentries - dirstart - 1;
break;
case BUTTON_PLAY:
#ifdef BUTTON_RC_PLAY
case BUTTON_RC_PLAY:
#endif
#ifdef BUTTON_ON
case BUTTON_ON | BUTTON_PLAY:
#endif
{
int onplay_result;
if(!numentries)
onplay_result = onplay(NULL, 0);
else {
if (currdir[1])
snprintf(buf, sizeof buf, "%s/%s",
currdir, dircache[dircursor+dirstart].name);
else
snprintf(buf, sizeof buf, "/%s",
dircache[dircursor+dirstart].name);
onplay_result = onplay(buf,
dircache[dircursor+dirstart].attr);
}
switch (onplay_result)
{
case ONPLAY_OK:
used = true;
break;
case ONPLAY_RELOAD_DIR:
reload_dir = 1;
used = true;
break;
case ONPLAY_START_PLAY:
used = false; /* this will enable the wps */
break;
}
exit = true;
break;
}
#ifdef BUTTON_ON
case BUTTON_ON | BUTTON_REL:
case BUTTON_ON | TREE_PREV | BUTTON_REL:
case BUTTON_ON | TREE_NEXT | BUTTON_REL:
exit = true;
break;
#endif
}
if ( used && !exit ) {
#ifdef HAVE_LCD_BITMAP
int xpos,ypos;
#endif
showdir(currdir, dirstart, dirfilter);
#ifdef HAVE_LCD_BITMAP
if (global_settings.invert_cursor) {
xpos = lcd_getxmargin();
ypos = (CURSOR_Y + dircursor) * fh + lcd_getymargin();
lcd_invertrect(xpos, ypos, LCD_WIDTH-xpos, fh);
}
else
#endif
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
lcd_update();
}
}
*ds = dirstart;
*dc = dircursor;
return used;
}
#endif
static bool dirbrowse(char *root, int *dirfilter)
{
int numentries=0;
char buf[MAX_PATH];
int i;
int lasti=-1;
int button;
int tree_max_on_screen;
bool reload_root = false;
int lastfilter = *dirfilter;
bool lastsortcase = global_settings.sort_case;
int lastdircursor=-1;
bool need_update = true;
bool exit_func = false;
bool update_all = false; /* set this to true when the whole file list
has been refreshed on screen */
#ifdef HAVE_LCD_BITMAP
int fw, fh;
lcd_setfont(FONT_UI);
lcd_getstringsize("A", &fw, &fh);
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
#else
tree_max_on_screen = TREE_MAX_ON_SCREEN;
#endif
dircursor=0;
dirstart=0;
dirlevel=0;
memcpy(currdir,root,sizeof(currdir));
if (*dirfilter < NUM_FILTER_MODES)
start_resume(true);
numentries = showdir(currdir, dirstart, dirfilter);
if (numentries == -1)
return false; /* currdir is not a directory */
if (*dirfilter > NUM_FILTER_MODES && numentries==0)
{
splash(HZ*2, true, str(LANG_NO_FILES));
return false; /* No files found for rockbox_browser() */
}
update_all = true;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
while(1) {
struct entry* file = &dircache[dircursor+dirstart];
bool restore = false;
button = button_get_w_tmo(HZ/5);
#ifndef SIMULATOR
if (boot_changed) {
lcd_clear_display();
lcd_puts(0,0,str(LANG_BOOT_CHANGED));
lcd_puts(0,1,str(LANG_REBOOT_NOW));
#ifdef HAVE_LCD_BITMAP
lcd_puts(0,3,str(LANG_CONFIRM_WITH_PLAY_RECORDER));
lcd_puts(0,4,str(LANG_CANCEL_WITH_ANY_RECORDER));
lcd_update();
#endif
if (button_get(true) == BUTTON_PLAY)
rolo_load("/" BOOTFILE);
restore = true;
boot_changed = false;
}
#endif
switch ( button ) {
case TREE_EXIT:
#ifdef BUTTON_RC_STOP
case BUTTON_RC_STOP:
#endif
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_LEFT | BUTTON_REPEAT:
#endif
i=strlen(currdir);
if (i>1) {
while (currdir[i-1]!='/')
i--;
strcpy(buf,&currdir[i]);
if (i==1)
currdir[i]=0;
else
currdir[i-1]=0;
dirlevel--;
if ( dirlevel < MAX_DIR_LEVELS ) {
dirstart = dirpos[dirlevel];
dircursor = cursorpos[dirlevel];
}
else
dirstart = dircursor = 0;
if (dirstart == -1)
strcpy(lastfile, buf);
restore = true;
}
if (*dirfilter > NUM_FILTER_MODES)
exit_func = true;
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_OFF:
bookmark_autobookmark();
mpeg_stop();
status_set_playmode(STATUS_STOP);
status_draw(false);
restore = true;
break;
case BUTTON_OFF | BUTTON_REL:
#else
case BUTTON_STOP | BUTTON_REL:
#endif
settings_save();
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_OFF | BUTTON_REPEAT:
#else
case BUTTON_STOP | BUTTON_REPEAT:
#endif
if (charger_inserted()) {
charging_splash();
restore = true;
}
break;
case TREE_ENTER:
case TREE_ENTER | BUTTON_REPEAT:
#ifdef BUTTON_RC_PLAY
case BUTTON_RC_PLAY:
#endif
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_PLAY:
case BUTTON_PLAY | BUTTON_REPEAT:
#endif
if ( !numentries )
break;
if (currdir[1])
snprintf(buf,sizeof(buf),"%s/%s",currdir, file->name);
else
snprintf(buf,sizeof(buf),"/%s",file->name);
if (file->attr & ATTR_DIRECTORY) {
memcpy(currdir,buf,sizeof(currdir));
if ( dirlevel < MAX_DIR_LEVELS ) {
dirpos[dirlevel] = dirstart;
cursorpos[dirlevel] = dircursor;
}
dirlevel++;
dircursor=0;
dirstart=0;
}
else {
int seed = current_tick;
bool play = false;
int start_index=0;
lcd_stop_scroll();
switch ( file->attr & TREE_ATTR_MASK ) {
case TREE_ATTR_M3U:
if (bookmark_autoload(buf))
{
restore = true;
break;
}
if (playlist_create(currdir, file->name) != -1)
{
if (global_settings.playlist_shuffle)
playlist_shuffle(seed, -1);
start_index = 0;
playlist_start(start_index,0);
play = true;
}
break;
case TREE_ATTR_MPA:
if (bookmark_autoload(currdir))
{
restore = true;
break;
}
if (playlist_create(currdir, NULL) != -1)
{
start_index =
build_playlist(dircursor+dirstart);
if (global_settings.playlist_shuffle)
{
start_index =
playlist_shuffle(seed,start_index);
/* when shuffling dir.: play all files
even if the file selected by user is
not the first one */
if (!global_settings.play_selected)
start_index = 0;
}
playlist_start(start_index, 0);
play = true;
}
break;
/* wps config file */
case TREE_ATTR_WPS:
wps_load(buf,true);
set_file(buf, global_settings.wps_file,
MAX_FILENAME);
restore = true;
break;
case TREE_ATTR_CFG:
if (!settings_load_config(buf))
break;
lcd_clear_display();
lcd_puts(0,0,str(LANG_SETTINGS_LOADED1));
lcd_puts(0,1,str(LANG_SETTINGS_LOADED2));
#ifdef HAVE_LCD_BITMAP
lcd_update();
/* maybe we have a new font */
lcd_getstringsize("A", &fw, &fh);
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
/* make sure cursor is on screen */
while ( dircursor > tree_max_on_screen )
{
dircursor--;
dirstart++;
}
#endif
sleep(HZ/2);
restore = true;
break;
case TREE_ATTR_BMARK:
bookmark_load(buf, false);
restore = true;
reload_dir = true;
break;
case TREE_ATTR_TXT:
plugin_load("/.rockbox/rocks/viewer.rock",buf);
restore = true;
break;
case TREE_ATTR_LNG:
if(!lang_load(buf)) {
set_file(buf, global_settings.lang_file,
MAX_FILENAME);
splash(HZ, true, str(LANG_LANGUAGE_LOADED));
restore = true;
}
break;
#ifdef HAVE_LCD_BITMAP
/* chip-8 game */
case TREE_ATTR_CH8:
plugin_load("/.rockbox/rocks/chip8.rock",buf);
break;
/* "movie" animation */
case TREE_ATTR_RVF:
plugin_load("/.rockbox/rocks/video.rock",buf);
break;
case TREE_ATTR_FONT:
font_load(buf);
set_file(buf, global_settings.font_file,
MAX_FILENAME);
lcd_getstringsize("A", &fw, &fh);
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
/* make sure cursor is on screen */
while ( dircursor > tree_max_on_screen ) {
dircursor--;
dirstart++;
}
restore = true;
break;
#endif
#ifndef SIMULATOR
/* firmware file */
case TREE_ATTR_MOD:
rolo_load(buf);
break;
/* ucl flash file */
case TREE_ATTR_UCL:
plugin_load("/.rockbox/rocks/rockbox_flash.rock",buf);
break;
#endif
/* plugin file */
case TREE_ATTR_ROCK:
if (plugin_load(buf,NULL) == PLUGIN_USB_CONNECTED)
reload_root = true;
else
restore = true;
break;
}
if ( play ) {
if ( global_settings.resume ) {
/* the resume_index must always be the index in the
shuffled list in case shuffle is enabled */
global_settings.resume_index = start_index;
global_settings.resume_offset = 0;
settings_save();
}
start_wps = true;
}
else if (*dirfilter > NUM_FILTER_MODES)
exit_func = true;
}
restore = true;
break;
case TREE_PREV:
case TREE_PREV | BUTTON_REPEAT:
#ifdef BUTTON_RC_LEFT
case BUTTON_RC_LEFT:
#endif
if(filesindir) {
if(dircursor) {
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, false);
dircursor--;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
}
else {
if (dirstart) {
dirstart--;
numentries = showdir(currdir, dirstart, dirfilter);
update_all=true;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
}
else {
if (numentries < tree_max_on_screen) {
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor,
false);
dircursor = numentries - 1;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor,
true);
}
else {
dirstart = numentries - tree_max_on_screen;
dircursor = tree_max_on_screen - 1;
numentries = showdir(currdir, dirstart, dirfilter);
update_all = true;
put_cursorxy(CURSOR_X, CURSOR_Y +
tree_max_on_screen - 1, true);
}
}
}
need_update = true;
}
break;
case TREE_NEXT:
case TREE_NEXT | BUTTON_REPEAT:
#ifdef BUTTON_RC_RIGHT
case BUTTON_RC_RIGHT:
#endif
if(filesindir)
{
if (dircursor + dirstart + 1 < numentries ) {
if(dircursor+1 < tree_max_on_screen) {
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, false);
dircursor++;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
}
else {
dirstart++;
numentries = showdir(currdir, dirstart, dirfilter);
update_all = true;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
}
}
else {
if(numentries < tree_max_on_screen) {
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, false);
dirstart = dircursor = 0;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
}
else {
dirstart = dircursor = 0;
numentries = showdir(currdir, dirstart, dirfilter);
update_all=true;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
}
}
need_update = true;
}
break;
case TREE_MENU:
if (*dirfilter < NUM_FILTER_MODES)
{
lcd_stop_scroll();
if (main_menu())
reload_root = true;
restore = true;
}
break;
#ifdef BUTTON_ON /* I bet the folks without ON-button want this to
work on a different button */
case BUTTON_ON:
if (handle_on(&dirstart, &dircursor, numentries,
tree_max_on_screen, dirfilter))
{
/* start scroll */
restore = true;
}
else
{
if (mpeg_status() & MPEG_STATUS_PLAY)
{
start_wps=true;
}
else
{
start_resume(false);
restore = true;
}
}
break;
#endif
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_F2:
if (*dirfilter < NUM_FILTER_MODES)
{
if (f2_screen())
reload_root = true;
restore = true;
break;
}
case BUTTON_F3:
if (*dirfilter < NUM_FILTER_MODES)
{
if (f3_screen())
reload_root = true;
#ifdef HAVE_LCD_BITMAP
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
#endif
restore = true;
}
break;
#endif
case SYS_USB_CONNECTED:
status_set_playmode(STATUS_STOP);
usb_screen();
reload_root = true;
break;
case BUTTON_NONE:
status_draw(false);
break;
}
if ( button )
ata_spin();
if (start_wps)
{
lcd_stop_scroll();
if (wps_show() == SYS_USB_CONNECTED)
reload_root = true;
#ifdef HAVE_LCD_BITMAP
tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
#endif
restore = true;
start_wps=false;
}
/* do we need to rescan dir? */
if (reload_dir || reload_root ||
lastfilter != *dirfilter ||
lastsortcase != global_settings.sort_case)
{
if ( reload_root ) {
strcpy(currdir, "/");
dirlevel = 0;
reload_root = false;
}
if (! reload_dir )
{
dircursor = 0;
dirstart = 0;
lastdir[0] = 0;
}
lastfilter = *dirfilter;
lastsortcase = global_settings.sort_case;
restore = true;
while (button_get(false)); /* clear button queue */
}
if (exit_func)
break;
if (restore || reload_dir) {
/* restore display */
/* We need to adjust if the number of lines on screen have
changed because of a status bar change */
if(CURSOR_Y+LINE_Y+dircursor>tree_max_on_screen) {
dirstart++;
dircursor--;
}
#ifdef HAVE_LCD_BITMAP
/* the sub-screen might've ruined the margins */
lcd_setmargins(MARGIN_X,MARGIN_Y); /* leave room for cursor and
icon */
lcd_setfont(FONT_UI);
#endif
numentries = showdir(currdir, dirstart, dirfilter);
update_all = true;
put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
need_update = true;
reload_dir = false;
}
if ( numentries && need_update) {
i = dirstart+dircursor;
/* if MP3 filter is on, cut off the extension */
if(lasti!=i || restore) {
lcd_stop_scroll();
/* So if lastdircursor and dircursor differ, and then full
screen was not refreshed, restore the previous line */
if ((lastdircursor != dircursor) && !update_all ) {
showfileline(lastdircursor, lasti, false, dirfilter); /* no scroll */
}
lasti=i;
lastdircursor=dircursor;
showfileline(dircursor, i, true, dirfilter); /* scroll please */
need_update = true;
}
}
if(need_update) {
lcd_update();
need_update = false;
update_all = false;
}
}
return true;
}
static int plsize = 0;
static bool add_dir(char* dirname, int fd)
{
bool abort = false;
char buf[MAX_PATH/2]; /* saving a little stack... */
DIR* dir;
/* check for user abort */
#ifdef BUTTON_STOP
if (button_get(false) == BUTTON_STOP)
#else
if (button_get(false) == BUTTON_OFF)
#endif
return true;
dir = opendir(dirname);
if(!dir)
return true;
while (true) {
struct dirent *entry;
entry = readdir(dir);
if (!entry)
break;
if (entry->attribute & ATTR_DIRECTORY) {
if (!strcmp(entry->d_name, ".") ||
!strcmp(entry->d_name, ".."))
continue;
if (dirname[1])
snprintf(buf, sizeof buf, "%s/%s", dirname, entry->d_name);
else
snprintf(buf, sizeof buf, "/%s", entry->d_name);
if (add_dir(buf,fd)) {
abort = true;
break;
}
}
else {
int x = strlen(entry->d_name);
if ((!strcasecmp(&entry->d_name[x-4], ".mp3")) ||
(!strcasecmp(&entry->d_name[x-4], ".mp2")) ||
(!strcasecmp(&entry->d_name[x-4], ".mpa")))
{
write(fd, dirname, strlen(dirname));
write(fd, "/", 1);
write(fd, entry->d_name, x);
write(fd, "\n", 1);
plsize++;
snprintf(buf, sizeof buf, "%d", plsize);
#ifdef HAVE_LCD_BITMAP
lcd_puts(0,4,buf);
lcd_update();
#else
x = 10;
if (plsize > 999)
x=7;
else {
if (plsize > 99)
x=8;
else {
if (plsize > 9)
x=9;
}
}
lcd_puts(x,0,buf);
#endif
}
}
}
closedir(dir);
return abort;
}
bool create_playlist(void)
{
int fd;
char filename[MAX_PATH];
snprintf(filename, sizeof filename, "%s.m3u",
currdir[1] ? currdir : "/root");
lcd_clear_display();
lcd_puts(0,0,str(LANG_CREATING));
lcd_puts_scroll(0,1,filename);
lcd_update();
fd = creat(filename,0);
if (fd < 0)
return false;
plsize = 0;
add_dir(currdir[1] ? currdir : "/", fd);
close(fd);
sleep(HZ);
return true;
}
bool rockbox_browse(char *root, int dirfilter)
{
bool rc;
int dircursor_save = dircursor;
int dirstart_save = dirstart;
int dirlevel_save = dirlevel;
int dirpos_save = dirpos[0];
int cursorpos_save = cursorpos[0];
memcpy(currdir_save, currdir, sizeof(currdir));
reload_dir = true;
start_wps = false;
rc = dirbrowse(root, &dirfilter);
memcpy(currdir, currdir_save, sizeof(currdir));
reload_dir = true;
dirstart = dirstart_save;
cursorpos[0] = cursorpos_save;
dirlevel = dirlevel_save;
dircursor = dircursor_save;
dirpos[0] = dirpos_save;
return false;
}
void tree_init(void)
{
/* We copy the settings value in case it is changed by the user. We can't
use it until the next reboot. */
max_files_in_dir = global_settings.max_files_in_dir;
name_buffer_size = AVERAGE_FILENAME_LENGTH * max_files_in_dir;
name_buffer = buffer_alloc(name_buffer_size);
dircache = buffer_alloc(max_files_in_dir * sizeof(struct entry));
}
void bookmark_play(char *resume_file, int index, int offset, int seed)
{
int len=strlen(resume_file);
if (!strcasecmp(&resume_file[len-4], ".m3u"))
{
char* slash;
// check that the file exists
int fd = open(resume_file, O_RDONLY);
if(fd<0)
return;
close(fd);
slash = strrchr(resume_file,'/');
if (slash)
{
char* cp;
*slash=0;
cp=resume_file;
if (!cp[0])
cp="/";
if (playlist_create(cp, slash+1) != -1)
{
if (global_settings.playlist_shuffle)
playlist_shuffle(seed, -1);
playlist_start(index,offset);
}
*slash='/';
}
}
else
{
lastdir[0]='\0';
if (playlist_create(resume_file, NULL) != -1)
{
resume_directory(resume_file);
if (global_settings.playlist_shuffle)
playlist_shuffle(seed, -1);
playlist_start(index,offset);
}
}
status_set_playmode(STATUS_PLAY);
start_wps=true;
}
|