159
159
RESTART ? restart () : SPLASH ? splash () : NULL ;
160
160
draw_background ();
161
161
restore_layout ();
162
- xTaskCreate (launcher , "launcher" , 8192 , NULL , 5 , NULL );
162
+ //xTaskCreate(launcher, "launcher", 8192, NULL, 5, NULL);
163
+ launcher ();
163
164
}
164
165
//}#pragma endregion Main
165
166
892
893
//}#pragma endregion Sort
893
894
894
895
void get_files () {
895
- ROMS .total = 0 ;
896
896
897
897
char path [256 ] = "/sd/roms/" ;
898
898
strcat (& path [strlen (path ) - 1 ], DIRECTORIES [STEP ]);
899
899
strcat (& path [strlen (path ) - 1 ],folder_path );
900
- printf ("\npath:%s" , path );
901
-
902
900
strcpy (ROM .path , path );
903
901
902
+ printf ("\n----- %s -----" , __func__ );
903
+ if (ROMS .total != 0 ) {
904
+ printf ("\nprevious ROMS.total:%d" , ROMS .total );
905
+ while (ROMS .total -- ) {
906
+ free (FILES [ROMS .total ]);
907
+ if (ROMS .total == 0 ){
908
+ free (FILES );
909
+ break ;
910
+ }
911
+ }
912
+ printf ("\ncurrent ROMS.total:%d" , ROMS .total );
913
+ }
914
+ printf ("\npath:%s" , path );
915
+
904
916
DIR * directory = opendir (path );
917
+ if (!directory ) {
918
+ printf ("\nopendir(%s):failed\nERR: %d\n" , path , errno );
919
+ return NULL ;
920
+ } else {
921
+ if (directory == NULL ) {
922
+ printf ("\nno files found in:\t%s" , path );
923
+ } else {
924
+ printf ("\nfiles found in:\t%s" , path );
925
+ FILES = (char * * )malloc (MAX_FILES * sizeof (void * ));
926
+ rewinddir (directory );
927
+ struct dirent * file ;
928
+ while ((file = readdir (directory )) != NULL ) {
929
+ int rom_length = strlen (file -> d_name );
930
+ int ext_length = strlen (EXTENSIONS [STEP ]);
931
+ bool extenstion = strcmp (& file -> d_name [rom_length - ext_length ], EXTENSIONS [STEP ]) == 0 && file -> d_name [0 ] != '.' ;
932
+ if (extenstion || (file -> d_type == 2 )) {
933
+ //if(ROMS.total >= MAX_FILES) { break; }
934
+ size_t len = strlen (file -> d_name );
935
+ FILES [ROMS .total ] = (file -> d_type == 2 ) ? (char * )malloc (len + 5 ) : (char * )malloc (len + 1 );
936
+ if ((file -> d_type == 2 )) {
937
+ char dir [256 ];
938
+ strcpy (dir , file -> d_name );
939
+ char dd [8 ];
940
+ sprintf (dd , "%s" , ext_length == 2 ? "dir" : ".dir" );
941
+ strcat (& dir [strlen (dir ) - 1 ], dd );
942
+ strcpy (FILES [ROMS .total ], dir );
943
+ } else {
944
+ strcpy (FILES [ROMS .total ], file -> d_name );
945
+ }
946
+ ROMS .total ++ ;
947
+ }
948
+ }
949
+ free (file );
950
+ printf ("\nnumber of files:\t%d" , ROMS .total );
951
+ }
952
+ free (directory );
953
+ closedir (directory );
954
+ printf ("\n%s: freed & closed" , path );
955
+
956
+ ROMS .pages = ROMS .total /ROMS .limit ;
957
+ if (ROMS .offset > ROMS .total ) { ROMS .offset = 0 ;}
958
+ draw_files ();
959
+
960
+ }
905
961
962
+ printf ("\n---------------------\n" );
963
+
964
+ /*
906
965
if(directory == NULL) {
907
966
char message[100] = "no games available";
908
967
int center = ceil((320/2)-((strlen(message)*5)/2));
916
975
bool extenstion = strcmp(&file->d_name[rom_length - ext_lext], EXTENSIONS[STEP]) == 0 && file->d_name[0] != '.';
917
976
if(extenstion || (file->d_type == 2)) {
918
977
if(ROMS.total >= MAX_FILES) { break; }
919
- char * name = file -> d_name ;
920
- size_t length = strlen (name );
921
- if (length > MAX_LENGTH ) {
922
- char * sub = name .substr (0 , MAX_LENGTH );
923
- printf ("\nname:%s length:%d" , name , length );
924
- }
978
+ size_t length = strlen(file->d_name);
925
979
//if(FILES[ROMS.total]) {}
926
980
//FILES[ROMS.total] = (file->d_type == 2) ? (char*)malloc(len + 5) : (char*)malloc(len + 1);
927
981
if((file->d_type == 2)) {
947
1001
948
1002
//free(FILES);
949
1003
}
1004
+ */
950
1005
}
951
1006
952
1007
void draw_files () {
970
1025
draw_text (x + 24 ,y ,FILES [n ],true,n == ROMS .offset ? true : false);
971
1026
972
1027
bool directory = strcmp (& FILES [n ][strlen (FILES [n ]) - 3 ], "dir" ) == 0 ;
973
- directory ? draw_folder (x ,y - 6 ,n == ROMS .offset ? true : false) : draw_media (x ,y - 6 ,n == ROMS .offset ? true : false);
1028
+ directory ?
1029
+ draw_folder (x ,y - 6 ,n == ROMS .offset ? true : false) :
1030
+ draw_media (x ,y - 6 ,n == ROMS .offset ? true : false);
974
1031
if (n == ROMS .offset ) {
975
1032
strcpy (ROM .name , FILES [n ]);
976
1033
ROM .ready = true;
1260
1317
draw_speaker ();
1261
1318
draw_contrast ();
1262
1319
1263
- FILES = (char * * )malloc (MAX_FILES * sizeof (void * ));
1264
- for (int n = 0 ; n < MAX_FILES ; n ++ ) {
1265
- FILES [n ] = (char * )malloc (MAX_LENGTH );
1266
- }
1267
-
1268
1320
//{#pragma region Gamepad
1269
1321
while (true) {
1270
1322
/*
1283
1335
}
1284
1336
1285
1337
ROMS .offset = 0 ;
1286
- ROMS .total = 0 ;
1287
1338
animate (-1 );
1288
1339
} else {
1289
1340
if (SETTING == 2 ) {
1316
1367
STEP = 0 ;
1317
1368
}
1318
1369
ROMS .offset = 0 ;
1319
- ROMS .total = 0 ;
1320
1370
animate (1 );
1321
1371
} else {
1322
1372
if (SETTING == 2 ) {
1478
1528
FOLDER = true;
1479
1529
PREVIOUS = ROMS .offset ;
1480
1530
ROMS .offset = 0 ;
1481
- ROMS .total = 0 ;
1482
1531
1483
1532
sprintf (folder_path , "/%s" , ROM .name );
1484
1533
folder_path [strlen (folder_path )- (strlen (EXTENSIONS [STEP ]) == 3 ? 4 : 3 )] = 0 ;
1526
1575
if (FOLDER ) {
1527
1576
FOLDER = false;
1528
1577
ROMS .offset = PREVIOUS ;
1529
- ROMS .total = 0 ;
1530
1578
PREVIOUS = 0 ;
1531
1579
folder_path [0 ] = 0 ;
1532
1580
get_files ();
1553
1601
}
1554
1602
//}#pragma endregion GamePad
1555
1603
}
1556
- //}#pragma endregion Launcher
1604
+ //}#pragma endregion Launcher
0 commit comments