Skip to content

Commit 6d6aed8

Browse files
Wed 18 Sep 2019 10:20:17 EDT - working on issue #22
1 parent 3136ed1 commit 6d6aed8

File tree

1 file changed

+12
-10
lines changed
  • Launchers/retro-esp32/main

1 file changed

+12
-10
lines changed

Launchers/retro-esp32/main/main.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,16 +561,21 @@
561561
//}#pragma endregion Sort
562562

563563
void get_files() {
564+
ROMS.total = 0;
565+
564566
FILES = (char**)malloc(MAX_FILES * sizeof(void*));
565567

566568
char path[256] = "/sd/roms/";
567569
strcat(&path[strlen(path) - 1], DIRECTORIES[STEP]);
568570
strcpy(ROM.path, path);
569-
bool files = !(directory = opendir(path)) ? false : true;
570-
571-
ROMS.total = 0;
571+
//bool files = !(directory = opendir(path)) ? false : true;
572+
DIR *directory = opendir(path);
572573

573-
if(files) {
574+
if(directory == NULL) {
575+
char message[100] = "no games available";
576+
int center = ceil((320/2)-((strlen(message)*5)/2));
577+
draw_text(center,134,message,false,false);
578+
} else {
574579
while ((file = readdir(directory)) != NULL) {
575580
int rom_length = strlen(file->d_name);
576581
int ext_lext = strlen(EXTENSIONS[STEP]);
@@ -580,19 +585,16 @@
580585
FILES[ROMS.total] = (char*)malloc(len + 1);
581586
strcpy(FILES[ROMS.total], file->d_name);
582587
ROMS.total++;
588+
if(ROMS.total > MAX_FILES) { break; }
583589
}
584590
}
585591
ROMS.pages = ROMS.total/ROMS.limit;
592+
586593
closedir(directory);
587-
}
594+
free(FILES);
588595

589-
if(ROMS.total > 0) {
590596
if(ROMS.total < 500) sort_files(FILES);
591597
draw_files();
592-
} else {
593-
char message[100] = "no games available";
594-
int center = ceil((320/2)-((strlen(message)*5)/2));
595-
draw_text(center,134,message,false,false);
596598
}
597599
}
598600

0 commit comments

Comments
 (0)