Skip to content

Commit 41bfc1d

Browse files
[#89] Fix recursive playback
1 parent dd54e4e commit 41bfc1d

2 files changed

Lines changed: 72 additions & 3 deletions

File tree

src/libhrmp/utils.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ hrmp_get_files(char* base, bool recursive, struct list* files)
484484
{
485485
DIR* dir = NULL;
486486
struct dirent* entry;
487+
char** names = NULL;
488+
size_t names_size = 0;
487489

488490
if (base == NULL || files == NULL)
489491
{
@@ -498,19 +500,39 @@ hrmp_get_files(char* base, bool recursive, struct list* files)
498500

499501
while ((entry = readdir(dir)) != NULL)
500502
{
501-
char* d = NULL;
502-
503503
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
504504
{
505505
continue;
506506
}
507507

508+
char** tmp = realloc(names, (names_size + 1) * sizeof(char*));
509+
if (tmp == NULL)
510+
{
511+
goto error;
512+
}
513+
514+
names = tmp;
515+
names[names_size] = strdup(entry->d_name);
516+
if (names[names_size] == NULL)
517+
{
518+
goto error;
519+
}
520+
521+
names_size++;
522+
}
523+
524+
hrmp_sort(names_size, names);
525+
526+
for (size_t i = 0; i < names_size; i++)
527+
{
528+
char* d = NULL;
529+
508530
d = hrmp_append(d, base);
509531
if (!hrmp_ends_with(d, "/"))
510532
{
511533
d = hrmp_append_char(d, '/');
512534
}
513-
d = hrmp_append(d, entry->d_name);
535+
d = hrmp_append(d, names[i]);
514536

515537
if (hrmp_is_file(d))
516538
{
@@ -522,8 +544,11 @@ hrmp_get_files(char* base, bool recursive, struct list* files)
522544
}
523545

524546
free(d);
547+
free(names[i]);
525548
}
526549

550+
free(names);
551+
527552
closedir(dir);
528553

529554
return 0;
@@ -535,6 +560,15 @@ hrmp_get_files(char* base, bool recursive, struct list* files)
535560
closedir(dir);
536561
}
537562

563+
if (names != NULL)
564+
{
565+
for (size_t i = 0; i < names_size; i++)
566+
{
567+
free(names[i]);
568+
}
569+
free(names);
570+
}
571+
538572
return 1;
539573
}
540574

src/main.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,40 @@ main(int argc, char** argv)
421421
}
422422
}
423423

424+
/* Filter unsupported files: display them, but don't keep them in the list. */
425+
struct list* supported_files = NULL;
426+
if (hrmp_list_create(&supported_files))
427+
{
428+
printf("Error creating files list\n");
429+
goto error;
430+
}
431+
432+
for (files_entry = hrmp_list_head(files);
433+
files_entry != NULL;
434+
files_entry = hrmp_list_next(files_entry))
435+
{
436+
struct file_metadata* fm = NULL;
437+
438+
if (hrmp_file_metadata(files_entry->value, &fm))
439+
{
440+
printf("Not supported: %s\n", files_entry->value);
441+
continue;
442+
}
443+
444+
if (hrmp_list_append(supported_files, files_entry->value))
445+
{
446+
free(fm);
447+
hrmp_list_destroy(supported_files);
448+
printf("Error creating files list\n");
449+
goto error;
450+
}
451+
452+
free(fm);
453+
}
454+
455+
hrmp_list_destroy(files);
456+
files = supported_files;
457+
424458
/* Keyboard */
425459
hrmp_keyboard_mode(true);
426460

@@ -446,6 +480,7 @@ main(int argc, char** argv)
446480
if (hrmp_file_metadata(files_entry->value, &fm))
447481
{
448482
printf("Not supported: %s\n", files_entry->value);
483+
files_entry = hrmp_list_next(files_entry);
449484
continue;
450485
}
451486

0 commit comments

Comments
 (0)