159159 RESTART ? restart () : SPLASH ? splash () : NULL ;
160160 draw_background ();
161161 restore_layout ();
162- xTaskCreate (launcher , "launcher" , 8192 , NULL , 5 , NULL );
162+ //xTaskCreate(launcher, "launcher", 8192, NULL, 5, NULL);
163+ launcher ();
163164 }
164165//}#pragma endregion Main
165166
892893 //}#pragma endregion Sort
893894
894895 void get_files () {
895- ROMS .total = 0 ;
896896
897897 char path [256 ] = "/sd/roms/" ;
898898 strcat (& path [strlen (path ) - 1 ], DIRECTORIES [STEP ]);
899899 strcat (& path [strlen (path ) - 1 ],folder_path );
900- printf ("\npath:%s" , path );
901-
902900 strcpy (ROM .path , path );
903901
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+
904916 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+ }
905961
962+ printf ("\n---------------------\n" );
963+
964+ /*
906965 if(directory == NULL) {
907966 char message[100] = "no games available";
908967 int center = ceil((320/2)-((strlen(message)*5)/2));
916975 bool extenstion = strcmp(&file->d_name[rom_length - ext_lext], EXTENSIONS[STEP]) == 0 && file->d_name[0] != '.';
917976 if(extenstion || (file->d_type == 2)) {
918977 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);
925979 //if(FILES[ROMS.total]) {}
926980 //FILES[ROMS.total] = (file->d_type == 2) ? (char*)malloc(len + 5) : (char*)malloc(len + 1);
927981 if((file->d_type == 2)) {
9471001
9481002 //free(FILES);
9491003 }
1004+ */
9501005 }
9511006
9521007 void draw_files () {
9701025 draw_text (x + 24 ,y ,FILES [n ],true,n == ROMS .offset ? true : false);
9711026
9721027 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);
9741031 if (n == ROMS .offset ) {
9751032 strcpy (ROM .name , FILES [n ]);
9761033 ROM .ready = true;
12601317 draw_speaker ();
12611318 draw_contrast ();
12621319
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-
12681320 //{#pragma region Gamepad
12691321 while (true) {
12701322 /*
12831335 }
12841336
12851337 ROMS .offset = 0 ;
1286- ROMS .total = 0 ;
12871338 animate (-1 );
12881339 } else {
12891340 if (SETTING == 2 ) {
13161367 STEP = 0 ;
13171368 }
13181369 ROMS .offset = 0 ;
1319- ROMS .total = 0 ;
13201370 animate (1 );
13211371 } else {
13221372 if (SETTING == 2 ) {
14781528 FOLDER = true;
14791529 PREVIOUS = ROMS .offset ;
14801530 ROMS .offset = 0 ;
1481- ROMS .total = 0 ;
14821531
14831532 sprintf (folder_path , "/%s" , ROM .name );
14841533 folder_path [strlen (folder_path )- (strlen (EXTENSIONS [STEP ]) == 3 ? 4 : 3 )] = 0 ;
15261575 if (FOLDER ) {
15271576 FOLDER = false;
15281577 ROMS .offset = PREVIOUS ;
1529- ROMS .total = 0 ;
15301578 PREVIOUS = 0 ;
15311579 folder_path [0 ] = 0 ;
15321580 get_files ();
15531601 }
15541602 //}#pragma endregion GamePad
15551603 }
1556- //}#pragma endregion Launcher
1604+ //}#pragma endregion Launcher
0 commit comments