-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathplaylist.c
3686 lines (3163 loc) · 118 KB
/
playlist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2019 - Brad Parker
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <libretro.h>
#include <boolean.h>
#include <retro_miscellaneous.h>
#include <compat/posix_string.h>
#include <string/stdstring.h>
#include <streams/interface_stream.h>
#include <file/file_path.h>
#include <file/archive_file.h>
#include <lists/string_list.h>
#include <formats/rjson.h>
#include <array/rbuf.h>
#include "playlist.h"
#include "verbosity.h"
#include "file_path_special.h"
#include "core_info.h"
#if defined(ANDROID)
#include "play_feature_delivery/play_feature_delivery.h"
#endif
#ifndef PLAYLIST_ENTRIES
#define PLAYLIST_ENTRIES 6
#endif
#define WINDOWS_PATH_DELIMITER '\\'
#define POSIX_PATH_DELIMITER '/'
/* Holds all configuration parameters required
* to repeat a manual content scan for a
* previously manual-scan-generated playlist */
typedef struct
{
char *content_dir;
char *file_exts;
char *dat_file_path;
bool search_recursively;
bool search_archives;
bool filter_dat_content;
bool overwrite_playlist;
} playlist_manual_scan_record_t;
enum content_playlist_flags
{
CNT_PLAYLIST_FLG_MOD = (1 << 0),
CNT_PLAYLIST_FLG_OLD_FMT = (1 << 1),
CNT_PLAYLIST_FLG_COMPRESSED = (1 << 2),
CNT_PLAYLIST_FLG_CACHED_EXT = (1 << 3)
};
struct content_playlist
{
char *default_core_path;
char *default_core_name;
char *base_content_directory;
struct playlist_entry *entries;
playlist_manual_scan_record_t scan_record; /* ptr alignment */
playlist_config_t config; /* size_t alignment */
enum playlist_label_display_mode label_display_mode;
enum playlist_thumbnail_mode right_thumbnail_mode;
enum playlist_thumbnail_mode left_thumbnail_mode;
enum playlist_thumbnail_match_mode thumbnail_match_mode;
enum playlist_sort_mode sort_mode;
uint8_t flags;
};
enum json_ctx_flags
{
JSON_CTX_FLG_IN_ITEMS = (1 << 0),
JSON_CTX_FLG_IN_SUBSYSTEM_CONTENT = (1 << 1),
JSON_CTX_FLG_CAPACITY_EXCEEDED = (1 << 2),
JSON_CTX_FLG_OOM = (1 << 3)
};
typedef struct
{
struct playlist_entry *current_entry;
char **current_string_val;
unsigned *current_entry_uint_val;
enum playlist_label_display_mode *current_meta_label_display_mode_val;
enum playlist_thumbnail_mode *current_meta_thumbnail_mode_val;
enum playlist_thumbnail_match_mode *current_meta_thumbnail_match_mode_val;
enum playlist_sort_mode *current_meta_sort_mode_val;
bool *current_meta_bool_val;
playlist_t *playlist;
unsigned array_depth;
unsigned object_depth;
uint8_t flags;
} JSONContext;
/* TODO/FIXME - global state - perhaps move outside this file */
static playlist_t *playlist_cached = NULL;
typedef int (playlist_sort_fun_t)(
const struct playlist_entry *a,
const struct playlist_entry *b);
/* TODO/FIXME - hack for allowing the explore view to switch
* over to a playlist item */
void playlist_set_cached_external(playlist_t* pl)
{
playlist_free_cached();
if (!pl)
return;
playlist_cached = pl;
playlist_cached->flags |= CNT_PLAYLIST_FLG_CACHED_EXT;
}
/* Convenience function: copies specified playlist
* path to specified playlist configuration object */
size_t playlist_config_set_path(playlist_config_t *config, const char *path)
{
if (config)
{
if (!string_is_empty(path))
return strlcpy(config->path, path, sizeof(config->path));
config->path[0] = '\0';
}
return 0;
}
/* Convenience function: copies base content directory
* path to specified playlist configuration object.
* Also sets autofix_paths boolean, depending on base
* content directory value */
size_t playlist_config_set_base_content_directory(
playlist_config_t* config, const char* path)
{
if (config)
{
config->autofix_paths = !string_is_empty(path);
if (config->autofix_paths)
return strlcpy(config->base_content_directory, path,
sizeof(config->base_content_directory));
config->base_content_directory[0] = '\0';
}
return 0;
}
/* Creates a copy of the specified playlist configuration.
* Returns false in the event of an error */
bool playlist_config_copy(const playlist_config_t *src,
playlist_config_t *dst)
{
if (!src || !dst)
return false;
strlcpy(dst->path, src->path, sizeof(dst->path));
strlcpy(dst->base_content_directory, src->base_content_directory,
sizeof(dst->base_content_directory));
dst->capacity = src->capacity;
dst->old_format = src->old_format;
dst->compress = src->compress;
dst->fuzzy_archive_match = src->fuzzy_archive_match;
dst->autofix_paths = src->autofix_paths;
return true;
}
/* Returns internal playlist configuration object
* of specified playlist.
* Returns NULL it the event of an error. */
playlist_config_t *playlist_get_config(playlist_t *playlist)
{
if (!playlist)
return NULL;
return &playlist->config;
}
static void path_replace_base_path_and_convert_to_local_file_system(
char *out_path,
const char *in_path,
const char *in_oldrefpath,
const char *in_refpath,
size_t size)
{
size_t in_oldrefpath_length = strlen(in_oldrefpath);
/* If entry path is inside playlist base path,
* replace it with new base content directory */
if (string_starts_with_size(in_path, in_oldrefpath, in_oldrefpath_length))
{
size_t in_refpath_length = strlen(in_refpath);
memcpy(out_path, in_refpath, in_refpath_length);
memcpy(
out_path + in_refpath_length,
in_path + in_oldrefpath_length,
strlen(in_path) - in_oldrefpath_length + 1);
#ifdef _WIN32
/* If we are running under a Windows filesystem,
* '/' characters are not allowed anywhere.
* We replace with '\' and hope for the best... */
string_replace_all_chars(out_path,
POSIX_PATH_DELIMITER, WINDOWS_PATH_DELIMITER);
#else
/* Under POSIX filesystem, we replace '\' characters with '/' */
string_replace_all_chars(out_path,
WINDOWS_PATH_DELIMITER, POSIX_PATH_DELIMITER);
#endif
}
else
strlcpy(out_path, in_path, size);
}
/* Generates a case insensitive hash for the
* specified path string */
static uint32_t playlist_path_hash(const char *path)
{
unsigned char c;
uint32_t hash = (uint32_t)0x811c9dc5;
while ((c = (unsigned char)*(path++)) != '\0')
hash = ((hash * (uint32_t)0x01000193) ^ (uint32_t)((c >= 'A' && c <= 'Z') ? (c | 0x20) : c));
return (hash ? hash : 1);
}
static void playlist_path_id_free(playlist_path_id_t *path_id)
{
if ( (path_id->archive_path)
&& (path_id->archive_path != path_id->real_path))
free(path_id->archive_path);
if (path_id->real_path)
free(path_id->real_path);
free(path_id);
}
static playlist_path_id_t *playlist_path_id_init(const char *path)
{
playlist_path_id_t *path_id = (playlist_path_id_t*)malloc(sizeof(*path_id));
if (!path_id)
return NULL;
path_id->real_path = NULL;
path_id->archive_path = NULL;
path_id->real_path_hash = 0;
path_id->archive_path_hash = 0;
path_id->is_archive = false;
path_id->is_in_archive = false;
if (!string_is_empty(path))
{
char real_path[PATH_MAX_LENGTH];
const char *archive_delim = NULL;
/* Get real path */
strlcpy(real_path, path, sizeof(real_path));
playlist_resolve_path(PLAYLIST_SAVE, false, real_path,
sizeof(real_path));
path_id->real_path = strdup(real_path);
path_id->real_path_hash = playlist_path_hash(real_path);
/* Check archive status */
path_id->is_archive = path_is_compressed_file(real_path);
archive_delim = path_get_archive_delim(real_path);
/* If path refers to a file inside an archive,
* extract the path of the parent archive */
if (archive_delim)
{
char archive_path[PATH_MAX_LENGTH];
size_t _len = (1 + archive_delim - real_path);
if (_len >= PATH_MAX_LENGTH)
_len = PATH_MAX_LENGTH;
strlcpy(archive_path, real_path, _len * sizeof(char));
path_id->archive_path = strdup(archive_path);
path_id->archive_path_hash = playlist_path_hash(archive_path);
path_id->is_in_archive = true;
}
else if (path_id->is_archive)
{
path_id->archive_path = path_id->real_path;
path_id->archive_path_hash = path_id->real_path_hash;
}
}
return path_id;
}
/**
* playlist_path_equal:
* @real_path : 'Real' search path, generated by path_resolve_realpath()
* @entry_path : Existing playlist entry 'path' value
*
* Returns 'true' if real_path matches entry_path
* (Taking into account relative paths, case insensitive
* filesystems, 'incomplete' archive paths)
**/
static bool playlist_path_equal(const char *real_path,
const char *entry_path, const playlist_config_t *config)
{
bool real_path_is_compressed;
bool entry_real_path_is_compressed;
char entry_real_path[PATH_MAX_LENGTH];
/* Sanity check */
if ( string_is_empty(real_path)
|| string_is_empty(entry_path)
|| !config)
return false;
/* Get entry 'real' path */
strlcpy(entry_real_path, entry_path, sizeof(entry_real_path));
playlist_resolve_path(PLAYLIST_LOAD, false, entry_real_path, sizeof(entry_real_path));
path_resolve_realpath(entry_real_path, sizeof(entry_real_path), true);
if (string_is_empty(entry_real_path))
return false;
/* First pass comparison */
#ifdef _WIN32
/* Handle case-insensitive operating systems*/
if (string_is_equal_noncase(real_path, entry_real_path))
return true;
#else
if (string_is_equal(real_path, entry_real_path))
return true;
#endif
#ifdef RARCH_INTERNAL
/* If fuzzy matching is disabled, we can give up now */
if (!config->fuzzy_archive_match)
return false;
#endif
/* If we reach this point, we have to work
* harder...
* Need to handle a rather awkward archive file
* case where:
* - playlist path contains a properly formatted
* [archive_path][delimiter][rom_file]
* - search path is just [archive_path]
* ...or vice versa.
* This pretty much always happens when a playlist
* is generated via scan content (which handles the
* archive paths correctly), but the user subsequently
* loads an archive file via the command line or some
* external launcher (where the [delimiter][rom_file]
* part is almost always omitted) */
real_path_is_compressed = path_is_compressed_file(real_path);
entry_real_path_is_compressed = path_is_compressed_file(entry_real_path);
if ( (real_path_is_compressed && !entry_real_path_is_compressed)
|| (!real_path_is_compressed && entry_real_path_is_compressed))
{
const char *compressed_path_a = real_path_is_compressed ? real_path : entry_real_path;
const char *full_path = real_path_is_compressed ? entry_real_path : real_path;
const char *delim = path_get_archive_delim(full_path);
if (delim)
{
char compressed_path_b[PATH_MAX_LENGTH];
unsigned len = (unsigned)(1 + delim - full_path);
strlcpy(compressed_path_b, full_path,
(len < PATH_MAX_LENGTH ? len : PATH_MAX_LENGTH) * sizeof(char));
#ifdef _WIN32
/* Handle case-insensitive operating systems*/
if (string_is_equal_noncase(compressed_path_a, compressed_path_b))
return true;
#else
if (string_is_equal(compressed_path_a, compressed_path_b))
return true;
#endif
}
}
return false;
}
/**
* playlist_path_matches_entry:
* @path_id : Path identity, containing 'real' path,
* hash and archive status information
* @entry : Playlist entry to compare with path_id
*
* Returns 'true' if 'path_id' matches path information
* contained in specified 'entry'. Will update path_id
* cache inside specified 'entry', if not already present.
**/
static bool playlist_path_matches_entry(playlist_path_id_t *path_id,
struct playlist_entry *entry, const playlist_config_t *config)
{
/* Sanity check */
if (!path_id || !entry || !config)
return false;
/* Check whether entry contains a path ID cache */
if (!entry->path_id)
{
if (!(entry->path_id = playlist_path_id_init(entry->path)))
return false;
}
/* Ensure we have valid real_path strings */
if ( string_is_empty(path_id->real_path)
|| string_is_empty(entry->path_id->real_path))
return false;
/* First pass comparison */
if (path_id->real_path_hash == entry->path_id->real_path_hash)
{
#ifdef _WIN32
/* Handle case-insensitive operating systems*/
if (string_is_equal_noncase(path_id->real_path,
entry->path_id->real_path))
return true;
#else
if (string_is_equal(path_id->real_path, entry->path_id->real_path))
return true;
#endif
}
#ifdef RARCH_INTERNAL
/* If fuzzy matching is disabled, we can give up now */
if (!config->fuzzy_archive_match)
return false;
#endif
/* If we reach this point, we have to work
* harder...
* Need to handle a rather awkward archive file
* case where:
* - playlist path contains a properly formatted
* [archive_path][delimiter][rom_file]
* - search path is just [archive_path]
* ...or vice versa.
* This pretty much always happens when a playlist
* is generated via scan content (which handles the
* archive paths correctly), but the user subsequently
* loads an archive file via the command line or some
* external launcher (where the [delimiter][rom_file]
* part is almost always omitted) */
if ( ((path_id->is_archive && !path_id->is_in_archive) && entry->path_id->is_in_archive)
|| ((entry->path_id->is_archive && !entry->path_id->is_in_archive) && path_id->is_in_archive))
{
/* Ensure we have valid parent archive path
* strings */
if ( string_is_empty(path_id->archive_path)
|| string_is_empty(entry->path_id->archive_path))
return false;
if (path_id->archive_path_hash == entry->path_id->archive_path_hash)
{
#ifdef _WIN32
/* Handle case-insensitive operating systems*/
if (string_is_equal_noncase(path_id->archive_path,
entry->path_id->archive_path))
return true;
#else
if (string_is_equal(path_id->archive_path,
entry->path_id->archive_path))
return true;
#endif
}
}
return false;
}
/**
* playlist_core_path_equal:
* @real_core_path : 'Real' search path, generated by path_resolve_realpath()
* @entry_core_path : Existing playlist entry 'core path' value
* @config : Playlist config parameters
*
* Returns 'true' if real_core_path matches entry_core_path
* (Taking into account relative paths, case insensitive
* filesystems)
**/
static bool playlist_core_path_equal(const char *real_core_path,
const char *entry_core_path, const playlist_config_t *config)
{
char entry_real_core_path[PATH_MAX_LENGTH];
/* Sanity check */
if ( string_is_empty(real_core_path)
|| string_is_empty(entry_core_path))
return false;
/* Get entry 'real' core path */
strlcpy(entry_real_core_path, entry_core_path, sizeof(entry_real_core_path));
if ( !string_is_equal(entry_real_core_path, FILE_PATH_DETECT)
&& !string_is_equal(entry_real_core_path, FILE_PATH_BUILTIN))
playlist_resolve_path(PLAYLIST_SAVE, true, entry_real_core_path,
sizeof(entry_real_core_path));
if (!string_is_empty(entry_real_core_path))
{
#ifdef _WIN32
/* Handle case-insensitive operating systems*/
if (string_is_equal_noncase(real_core_path, entry_real_core_path))
return true;
#else
if (string_is_equal(real_core_path, entry_real_core_path))
return true;
#endif
if ( config->autofix_paths
&& core_info_core_file_id_is_equal(real_core_path, entry_core_path))
return true;
}
return false;
}
uint32_t playlist_get_size(playlist_t *playlist)
{
if (!playlist)
return 0;
return (uint32_t)RBUF_LEN(playlist->entries);
}
char *playlist_get_conf_path(playlist_t *playlist)
{
if (!playlist)
return NULL;
return playlist->config.path;
}
/**
* playlist_get_index:
* @playlist : Playlist handle.
* @idx : Index of playlist entry.
* @path : Path of playlist entry.
* @core_path : Core path of playlist entry.
* @core_name : Core name of playlist entry.
*
* Gets values of playlist index:
**/
void playlist_get_index(playlist_t *playlist,
size_t idx,
const struct playlist_entry **entry)
{
if (!playlist || !entry || (idx >= RBUF_LEN(playlist->entries)))
return;
*entry = &playlist->entries[idx];
}
/**
* playlist_free_entry:
* @entry : Playlist entry handle.
*
* Frees playlist entry.
**/
static void playlist_free_entry(struct playlist_entry *entry)
{
if (!entry)
return;
if (entry->path)
free(entry->path);
if (entry->label)
free(entry->label);
if (entry->core_path)
free(entry->core_path);
if (entry->core_name)
free(entry->core_name);
if (entry->db_name)
free(entry->db_name);
if (entry->crc32)
free(entry->crc32);
if (entry->subsystem_ident)
free(entry->subsystem_ident);
if (entry->subsystem_name)
free(entry->subsystem_name);
if (entry->runtime_str)
free(entry->runtime_str);
if (entry->last_played_str)
free(entry->last_played_str);
if (entry->subsystem_roms)
string_list_free(entry->subsystem_roms);
if (entry->path_id)
playlist_path_id_free(entry->path_id);
entry->path = NULL;
entry->label = NULL;
entry->core_path = NULL;
entry->core_name = NULL;
entry->db_name = NULL;
entry->crc32 = NULL;
entry->subsystem_ident = NULL;
entry->subsystem_name = NULL;
entry->runtime_str = NULL;
entry->last_played_str = NULL;
entry->subsystem_roms = NULL;
entry->path_id = NULL;
entry->entry_slot = 0;
entry->runtime_status = PLAYLIST_RUNTIME_UNKNOWN;
entry->runtime_hours = 0;
entry->runtime_minutes = 0;
entry->runtime_seconds = 0;
entry->last_played_year = 0;
entry->last_played_month = 0;
entry->last_played_day = 0;
entry->last_played_hour = 0;
entry->last_played_minute = 0;
entry->last_played_second = 0;
}
/**
* playlist_delete_index:
* @playlist : Playlist handle.
* @idx : Index of playlist entry.
*
* Delete the entry at the index:
**/
void playlist_delete_index(playlist_t *playlist,
size_t idx)
{
size_t _len;
struct playlist_entry *entry_to_delete;
if (!playlist)
return;
_len = RBUF_LEN(playlist->entries);
if (idx >= _len)
return;
/* Free unwanted entry */
entry_to_delete = (struct playlist_entry *)(playlist->entries + idx);
if (entry_to_delete)
playlist_free_entry(entry_to_delete);
/* Shift remaining entries to fill the gap */
memmove(playlist->entries + idx, playlist->entries + idx + 1,
(_len - 1 - idx) * sizeof(struct playlist_entry));
RBUF_RESIZE(playlist->entries, _len - 1);
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
/**
* playlist_delete_by_path:
* @playlist : Playlist handle.
* @search_path : Content path.
*
* Deletes all entries with content path
* matching 'search_path'
**/
void playlist_delete_by_path(playlist_t *playlist,
const char *search_path)
{
playlist_path_id_t *path_id = NULL;
size_t i = 0;
if (!playlist || string_is_empty(search_path))
return;
if (!(path_id = playlist_path_id_init(search_path)))
return;
while (i < RBUF_LEN(playlist->entries))
{
if (!playlist_path_matches_entry(path_id,
&playlist->entries[i], &playlist->config))
{
i++;
continue;
}
/* Paths are equal - delete entry */
playlist_delete_index(playlist, i);
/* Entries are shifted up by the delete
* operation - *do not* increment i */
}
playlist_path_id_free(path_id);
}
void playlist_get_index_by_path(playlist_t *playlist,
const char *search_path,
const struct playlist_entry **entry)
{
playlist_path_id_t *path_id = NULL;
size_t i, len;
if (!playlist || !entry || string_is_empty(search_path))
return;
if (!(path_id = playlist_path_id_init(search_path)))
return;
for (i = 0, len = RBUF_LEN(playlist->entries); i < len; i++)
{
if (!playlist_path_matches_entry(path_id,
&playlist->entries[i], &playlist->config))
continue;
*entry = &playlist->entries[i];
break;
}
playlist_path_id_free(path_id);
}
bool playlist_entry_exists(playlist_t *playlist,
const char *path)
{
playlist_path_id_t *path_id = NULL;
size_t i, len;
if (!playlist || string_is_empty(path))
return false;
if (!(path_id = playlist_path_id_init(path)))
return false;
for (i = 0, len = RBUF_LEN(playlist->entries); i < len; i++)
{
if (playlist_path_matches_entry(path_id,
&playlist->entries[i], &playlist->config))
{
playlist_path_id_free(path_id);
return true;
}
}
playlist_path_id_free(path_id);
return false;
}
void playlist_update(playlist_t *playlist, size_t idx,
const struct playlist_entry *update_entry)
{
struct playlist_entry *entry = NULL;
if (!playlist || idx >= RBUF_LEN(playlist->entries))
return;
entry = &playlist->entries[idx];
if (update_entry->path && (update_entry->path != entry->path))
{
if (entry->path)
free(entry->path);
entry->path = strdup(update_entry->path);
if (entry->path_id)
{
playlist_path_id_free(entry->path_id);
entry->path_id = NULL;
}
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->label && (update_entry->label != entry->label))
{
if (entry->label)
free(entry->label);
entry->label = strdup(update_entry->label);
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->core_path && (update_entry->core_path != entry->core_path))
{
if (entry->core_path)
free(entry->core_path);
entry->core_path = strdup(update_entry->core_path);
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->core_name && (update_entry->core_name != entry->core_name))
{
if (entry->core_name)
free(entry->core_name);
entry->core_name = strdup(update_entry->core_name);
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->db_name && (update_entry->db_name != entry->db_name))
{
if (entry->db_name)
free(entry->db_name);
entry->db_name = strdup(update_entry->db_name);
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->crc32 && (update_entry->crc32 != entry->crc32))
{
if (entry->crc32)
free(entry->crc32);
entry->crc32 = strdup(update_entry->crc32);
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
}
void playlist_update_runtime(playlist_t *playlist, size_t idx,
const struct playlist_entry *update_entry,
bool register_update)
{
struct playlist_entry *entry = NULL;
if (!playlist || idx >= RBUF_LEN(playlist->entries))
return;
entry = &playlist->entries[idx];
if (update_entry->path && (update_entry->path != entry->path))
{
if (entry->path)
free(entry->path);
entry->path = strdup(update_entry->path);
if (entry->path_id)
{
playlist_path_id_free(entry->path_id);
entry->path_id = NULL;
}
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->core_path && (update_entry->core_path != entry->core_path))
{
if (entry->core_path)
free(entry->core_path);
entry->core_path = strdup(update_entry->core_path);
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->runtime_status != entry->runtime_status)
{
entry->runtime_status = update_entry->runtime_status;
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->runtime_hours != entry->runtime_hours)
{
entry->runtime_hours = update_entry->runtime_hours;
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->runtime_minutes != entry->runtime_minutes)
{
entry->runtime_minutes = update_entry->runtime_minutes;
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->runtime_seconds != entry->runtime_seconds)
{
entry->runtime_seconds = update_entry->runtime_seconds;
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->last_played_year != entry->last_played_year)
{
entry->last_played_year = update_entry->last_played_year;
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->last_played_month != entry->last_played_month)
{
entry->last_played_month = update_entry->last_played_month;
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->last_played_day != entry->last_played_day)
{
entry->last_played_day = update_entry->last_played_day;
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->last_played_hour != entry->last_played_hour)
{
entry->last_played_hour = update_entry->last_played_hour;
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->last_played_minute != entry->last_played_minute)
{
entry->last_played_minute = update_entry->last_played_minute;
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->last_played_second != entry->last_played_second)
{
entry->last_played_second = update_entry->last_played_second;
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->runtime_str && (update_entry->runtime_str != entry->runtime_str))
{
if (entry->runtime_str)
free(entry->runtime_str);
entry->runtime_str = strdup(update_entry->runtime_str);
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
if (update_entry->last_played_str && (update_entry->last_played_str != entry->last_played_str))
{
if (entry->last_played_str)
free(entry->last_played_str);
entry->last_played_str = NULL;
entry->last_played_str = strdup(update_entry->last_played_str);
if (register_update)
playlist->flags |= CNT_PLAYLIST_FLG_MOD;
}
}
bool playlist_push_runtime(playlist_t *playlist,
const struct playlist_entry *entry)
{
playlist_path_id_t *path_id = NULL;
size_t i, len;
char real_core_path[PATH_MAX_LENGTH];
if (!playlist || !entry)
goto error;
if (string_is_empty(entry->core_path))
{
RARCH_ERR("Cannot push NULL or empty core path into the playlist.\n");
goto error;
}
/* Get path ID */
if (!(path_id = playlist_path_id_init(entry->path)))
goto error;
/* Get 'real' core path */
strlcpy(real_core_path, entry->core_path, sizeof(real_core_path));
if ( !string_is_equal(real_core_path, FILE_PATH_DETECT)
&& !string_is_equal(real_core_path, FILE_PATH_BUILTIN))
playlist_resolve_path(PLAYLIST_SAVE, true, real_core_path,
sizeof(real_core_path));
if (string_is_empty(real_core_path))
{
RARCH_ERR("Cannot push NULL or empty core path into the playlist.\n");
goto error;
}
len = RBUF_LEN(playlist->entries);
for (i = 0; i < len; i++)
{
struct playlist_entry tmp;
bool equal_path = (string_is_empty(path_id->real_path)
&& string_is_empty(playlist->entries[i].path));
equal_path = equal_path || playlist_path_matches_entry(
path_id, &playlist->entries[i], &playlist->config);
if (!equal_path)
continue;
/* Core name can have changed while still being the same core.
* Differentiate based on the core path only. */
if (!playlist_core_path_equal(real_core_path, playlist->entries[i].core_path, &playlist->config))