|
561 | 561 | //}#pragma endregion Sort
|
562 | 562 |
|
563 | 563 | void get_files() {
|
| 564 | + ROMS.total = 0; |
| 565 | + |
564 | 566 | FILES = (char**)malloc(MAX_FILES * sizeof(void*));
|
565 | 567 |
|
566 | 568 | char path[256] = "/sd/roms/";
|
567 | 569 | strcat(&path[strlen(path) - 1], DIRECTORIES[STEP]);
|
568 | 570 | 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); |
572 | 573 |
|
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 { |
574 | 579 | while ((file = readdir(directory)) != NULL) {
|
575 | 580 | int rom_length = strlen(file->d_name);
|
576 | 581 | int ext_lext = strlen(EXTENSIONS[STEP]);
|
|
580 | 585 | FILES[ROMS.total] = (char*)malloc(len + 1);
|
581 | 586 | strcpy(FILES[ROMS.total], file->d_name);
|
582 | 587 | ROMS.total++;
|
| 588 | + if(ROMS.total > MAX_FILES) { break; } |
583 | 589 | }
|
584 | 590 | }
|
585 | 591 | ROMS.pages = ROMS.total/ROMS.limit;
|
| 592 | + |
586 | 593 | closedir(directory);
|
587 |
| - } |
| 594 | + free(FILES); |
588 | 595 |
|
589 |
| - if(ROMS.total > 0) { |
590 | 596 | if(ROMS.total < 500) sort_files(FILES);
|
591 | 597 | 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); |
596 | 598 | }
|
597 | 599 | }
|
598 | 600 |
|
|
0 commit comments