Skip to content

Commit 4a90123

Browse files
Add support for .m3u custom labels
1 parent 96797d4 commit 4a90123

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

libretro.c

+29-8
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ struct disk_control_interface_t
8181

8282
unsigned char path[10][MAX_PATH]; /* disk image paths */
8383
unsigned char label[10][MAX_PATH]; /* disk image base name w/o extension */
84+
85+
unsigned g_initial_disc; /* initial disk index */
8486
unsigned char g_initial_disc_path[MAX_PATH]; /* initial disk path */
85-
unsigned g_initial_disc; /* initial disk index */
8687
};
8788

8889
static struct disk_control_interface_t disk;
@@ -359,14 +360,15 @@ static void parse_cmdline(const char *argv);
359360

360361
static bool read_m3u(const char *file)
361362
{
363+
unsigned index = 0;
362364
char line[MAX_PATH];
363365
char name[MAX_PATH];
364366
FILE *f = fopen(file, "r");
365367

366368
if (!f)
367369
return false;
368370

369-
while (fgets(line, sizeof(line), f) && disk.total_images < sizeof(disk.path) / sizeof(disk.path[0]))
371+
while (fgets(line, sizeof(line), f) && index < sizeof(disk.path) / sizeof(disk.path[0]))
370372
{
371373
if (line[0] == '#')
372374
continue;
@@ -389,20 +391,39 @@ static bool read_m3u(const char *file)
389391
if (line[0] != '\0')
390392
{
391393
char image_label[4096];
394+
char *custom_label;
395+
size_t len = 0;
392396

393-
/* write disk image path */
394397
snprintf(name, sizeof(name), "%s%c%s", base_dir, slash, line);
395-
strcpy(disk.path[disk.total_images], name);
396398

397-
/* extract and write disk image base name */
398-
extract_basename(image_label, name, sizeof(image_label));
399-
snprintf(disk.label[disk.total_images], sizeof(disk.label[disk.total_images]), "%s", image_label);
399+
custom_label = strchr(name, '|');
400+
if (custom_label)
401+
{
402+
/* get disk path */
403+
len = custom_label + 1 - name;
404+
strncpy(disk.path[index], name, len - 1);
400405

401-
disk.total_images++;
406+
/* get custom label */
407+
custom_label++;
408+
strncpy(disk.label[index], custom_label, sizeof(disk.label[index]));
409+
}
410+
else
411+
{
412+
/* copy path */
413+
strncpy(disk.path[index], name, sizeof(disk.path[index]));
414+
415+
/* extract base name from path for labels */
416+
extract_basename(image_label, name, sizeof(image_label));
417+
strncpy(disk.label[index], image_label, sizeof(disk.label[index]));
418+
}
419+
420+
index++;
402421
}
403422
}
404423

424+
disk.total_images = index;
405425
fclose(f);
426+
406427
return (disk.total_images != 0);
407428
}
408429

0 commit comments

Comments
 (0)