-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathtask_content.c
3183 lines (2733 loc) · 102 KB
/
task_content.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) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2019 - Brad Parker
* Copyright (C) 2016-2019 - Andrés Suárez
*
* 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/>.
*/
/* TODO/FIXME - turn this into actual task */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <time.h>
#ifdef _WIN32
#ifdef _XBOX
#include <xtl.h>
#define setmode _setmode
#define INVALID_FILE_ATTRIBUTES -1
#else
#include <io.h>
#include <fcntl.h>
#include <windows.h>
#endif
#endif
#ifdef __WINRT__
#include <Fileapifromapp.h>
#include <uwp/uwp_func.h>
#endif
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include <boolean.h>
#include <encodings/crc32.h>
#include <compat/strl.h>
#include <compat/posix_string.h>
#include <file/file_path.h>
#include <file/archive_file.h>
#include <streams/file_stream.h>
#include <string/stdstring.h>
#include <lists/string_list.h>
#include <lists/dir_list.h>
#include <vfs/vfs_implementation.h>
#include <array/rbuf.h>
#include <retro_miscellaneous.h>
#ifdef HAVE_MENU
#include "../menu/menu_driver.h"
#endif
#ifdef HAVE_GFX_WIDGETS
#include "../gfx/gfx_widgets.h"
#endif
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
#include "../menu/menu_shader.h"
#endif
#ifdef HAVE_CHEEVOS
#include "../cheevos/cheevos.h"
#endif
#include "task_content.h"
#include "tasks_internal.h"
#include "../command.h"
#include "../core_info.h"
#include "../content.h"
#include "../core.h"
#include "../configuration.h"
#include "../defaults.h"
#include "../dynamic.h"
#include "../file_path_special.h"
#include "../frontend/frontend.h"
#include "../msg_hash.h"
#include "../playlist.h"
#include "../paths.h"
#include "../retroarch.h"
#include "../runloop.h"
#include "../verbosity.h"
#ifdef HAVE_PRESENCE
#include "../network/presence.h"
#endif
#define MAX_ARGS 32
typedef struct content_stream content_stream_t;
typedef struct content_information_ctx content_information_ctx_t;
struct content_stream
{
const uint8_t *b;
size_t c;
uint32_t a;
uint32_t crc;
};
enum content_information_flags
{
CONTENT_INFO_FLAG_BLOCK_EXTRACT = (1 << 0),
CONTENT_INFO_FLAG_NEED_FULLPATH = (1 << 1),
CONTENT_INFO_FLAG_SET_SUPPORTS_NO_GAME_ENABLE = (1 << 2),
CONTENT_INFO_FLAG_IS_IPS_PREF = (1 << 3),
CONTENT_INFO_FLAG_IS_BPS_PREF = (1 << 4),
CONTENT_INFO_FLAG_IS_UPS_PREF = (1 << 5),
CONTENT_INFO_FLAG_PATCH_IS_BLOCKED = (1 << 6),
CONTENT_INFO_FLAG_BIOS_IS_MISSING = (1 << 7),
CONTENT_INFO_FLAG_CHECK_FW_BEFORE_LOADING = (1 << 8),
CONTENT_INFO_FLAG_IS_XDELTA_PREF = (1 << 9)
};
struct content_information_ctx
{
char *name_ips;
char *name_bps;
char *name_ups;
char *name_xdelta;
char *valid_extensions;
char *directory_cache;
char *directory_system;
struct
{
struct retro_subsystem_info *data;
unsigned size;
} subsystem;
uint16_t flags;
};
/*************************************/
/* Content file info functions START */
/*************************************/
static void content_file_override_free(
content_state_t *p_content)
{
size_t i;
if (!p_content->content_override_list)
return;
for (i = 0; i < RBUF_LEN(p_content->content_override_list); i++)
{
content_file_override_t *override =
&p_content->content_override_list[i];
if (override && override->ext)
free(override->ext);
}
RBUF_FREE(p_content->content_override_list);
}
/* Returns true if an override for content files
* of extension 'ext' has been set */
static bool content_file_override_get_ext(
content_state_t *p_content,
const char *ext,
const content_file_override_t **override)
{
size_t num_overrides;
size_t i;
if (p_content && !string_is_empty(ext))
{
if ((num_overrides = RBUF_LEN(p_content->content_override_list)) >= 1)
{
for (i = 0; i < num_overrides; i++)
{
content_file_override_t *content_override =
&p_content->content_override_list[i];
if (!content_override ||
!content_override->ext)
continue;
if (string_is_equal_noncase(
content_override->ext, ext))
{
if (override)
*override = content_override;
return true;
}
}
}
}
return false;
}
bool content_file_override_set(
const struct retro_system_content_info_override *overrides)
{
content_state_t *p_content = content_state_get_ptr();
size_t i;
if (!p_content || !overrides)
return false;
/* Free any existing override list */
content_file_override_free(p_content);
for (i = 0; overrides[i].extensions; i++)
{
struct string_list ext_list = {0};
size_t j;
/* Get list of extensions affected by override */
string_list_initialize(&ext_list);
if (!string_split_noalloc(&ext_list,
overrides[i].extensions, "|"))
{
string_list_deinitialize(&ext_list);
continue;
}
for (j = 0; j < ext_list.size; j++)
{
const char *ext = ext_list.elems[j].data;
content_file_override_t *override = NULL;
size_t num_entries;
/* Check whether extension has already been
* registered */
if (string_is_empty(ext) ||
content_file_override_get_ext(p_content, ext, NULL))
continue;
/* Add current override to the list */
num_entries = RBUF_LEN(p_content->content_override_list);
if (!RBUF_TRYFIT(p_content->content_override_list,
num_entries + 1))
{
string_list_deinitialize(&ext_list);
return false;
}
RBUF_RESIZE(p_content->content_override_list,
num_entries + 1);
RARCH_LOG("[Content Override]: File Extension: '%3s' - need_fullpath: %s, persistent_data: %s\n",
ext, overrides[i].need_fullpath ? "TRUE" : "FALSE",
overrides[i].persistent_data ? "TRUE" : "FALSE");
override = &p_content->content_override_list[num_entries];
override->ext = strdup(ext);
override->need_fullpath = overrides[i].need_fullpath;
override->persistent_data = overrides[i].persistent_data;
}
string_list_deinitialize(&ext_list);
}
return true;
}
/* Frees any content data that is not flagged
* as 'persistent'. Should be called after
* content_file_load() */
static void content_file_list_free_transient_data(
content_file_list_t *file_list)
{
size_t i;
if (!file_list)
return;
for (i = 0; i < file_list->size; i++)
{
content_file_info_t *file_info = &file_list->entries[i];
if (file_info->data &&
!file_info->persistent_data)
{
free((void*)file_info->data);
file_info->data = NULL;
file_info->data_size = 0;
}
}
}
static void content_file_list_free_entry(
content_file_info_t *file_info)
{
if (!file_info)
return;
if (file_info->full_path)
{
free(file_info->full_path);
file_info->full_path = NULL;
}
if (file_info->archive_path)
{
free(file_info->archive_path);
file_info->archive_path = NULL;
}
if (file_info->archive_file)
{
free(file_info->archive_file);
file_info->archive_file = NULL;
}
if (file_info->dir)
{
free(file_info->dir);
file_info->dir = NULL;
}
if (file_info->name)
{
free(file_info->name);
file_info->name = NULL;
}
if (file_info->ext)
{
free(file_info->ext);
file_info->ext = NULL;
}
if (file_info->meta)
{
free(file_info->meta);
file_info->meta = NULL;
}
if (file_info->data)
{
free((void*)file_info->data);
file_info->data = NULL;
}
file_info->data_size = 0;
file_info->file_in_archive = false;
file_info->persistent_data = false;
}
static void content_file_list_free(
content_file_list_t *file_list)
{
if (!file_list)
return;
if (file_list->entries)
{
size_t i;
for (i = 0; i < file_list->size; i++)
{
content_file_info_t *file_info = &file_list->entries[i];
content_file_list_free_entry(file_info);
}
free(file_list->entries);
}
if (file_list->temporary_files)
{
size_t i;
/* Remove any temporary content files from
* the file system */
for (i = 0; i < file_list->temporary_files->size; i++)
{
const char *path = file_list->temporary_files->elems[i].data;
if (string_is_empty(path))
continue;
RARCH_LOG("[Content]: %s: \"%s\".\n",
msg_hash_to_str(MSG_REMOVING_TEMPORARY_CONTENT_FILE),
path);
if (filestream_delete(path) != 0)
RARCH_ERR("[Content]: %s: \"%s\".\n",
msg_hash_to_str(MSG_FAILED_TO_REMOVE_TEMPORARY_FILE),
path);
}
string_list_free(file_list->temporary_files);
}
if (file_list->game_info)
free(file_list->game_info);
if (file_list->game_info_ext)
free(file_list->game_info_ext);
free(file_list);
}
static content_file_list_t *content_file_list_init(size_t size)
{
content_file_list_t *file_list = NULL;
if ((file_list = (content_file_list_t *)malloc(sizeof(*file_list))))
{
/* Set initial 'values' */
file_list->entries = NULL;
file_list->size = 0;
file_list->game_info = NULL;
file_list->game_info_ext = NULL;
file_list->temporary_files = string_list_new();
if (file_list->temporary_files)
{
/* Create entries list */
if ((file_list->entries = (content_file_info_t *)
calloc(size, sizeof(content_file_info_t))))
{
file_list->size = size;
/* Create retro_game_info object */
if ((file_list->game_info = (struct retro_game_info *)
calloc(size, sizeof(struct retro_game_info))))
{
/* Create retro_game_info_ext object */
if ((file_list->game_info_ext =
(struct retro_game_info_ext *)
calloc(size, sizeof(struct retro_game_info_ext))))
return file_list;
}
}
}
}
content_file_list_free(file_list);
return NULL;
}
/* Convenience function: Adds an entry to the
* temporary (i.e. extracted) content file list.
* Returns pointer to allocated char array. */
static const char *content_file_list_append_temporary(
content_file_list_t *file_list,
const char *path)
{
union string_list_elem_attr attr;
if (!file_list ||
string_is_empty(path))
return NULL;
attr.i = 0;
if (string_list_append(file_list->temporary_files,
path, attr))
return file_list->temporary_files->elems[
file_list->temporary_files->size - 1].data;
return NULL;
}
/* Note: Takes ownership of supplied 'data' buffer */
static bool content_file_list_set_info(
content_file_list_t *file_list,
const char *path,
void *data,
size_t data_size,
bool persistent_data,
size_t idx)
{
content_file_info_t *file_info = NULL;
struct retro_game_info *game_info = NULL;
struct retro_game_info_ext *game_info_ext = NULL;
if ( !file_list
|| (idx >= file_list->size))
return false;
if (!(file_info = &file_list->entries[idx]))
return false;
if (!(game_info = &file_list->game_info[idx]))
return false;
if (!(game_info_ext = &file_list->game_info_ext[idx]))
return false;
/* Clear any existing info */
content_file_list_free_entry(file_info);
game_info->path = NULL;
game_info->data = NULL;
game_info->size = 0;
game_info->meta = NULL;
game_info_ext->full_path = NULL;
game_info_ext->archive_path = NULL;
game_info_ext->archive_file = NULL;
game_info_ext->dir = NULL;
game_info_ext->name = NULL;
game_info_ext->ext = NULL;
game_info_ext->meta = NULL;
game_info_ext->data = NULL;
game_info_ext->size = 0;
game_info_ext->file_in_archive = false;
game_info_ext->persistent_data = false;
/* Assign data */
if (( data && !data_size) ||
(!data && data_size))
return false;
file_info->data = data;
file_info->data_size = data_size;
file_info->persistent_data = persistent_data;
/* Assign paths
* > There is some degree of redundant data
* here, but we need it in this format
* (persistent copies of each parameter)
* to minimise complications when passing
* extended path info to cores */
if (!string_is_empty(path))
{
char dir [PATH_MAX_LENGTH];
char name[NAME_MAX_LENGTH];
const char *archive_delim = NULL;
const char *ext = NULL;
/* 'Full' path - may point to a file
* inside an archive */
file_info->full_path = strdup(path);
/* File extension - may be used core-side
* to differentiate content types */
if ((ext = path_get_extension(path)))
{
file_info->ext = strdup(ext);
/* File extension is always presented
* core-side in lowercase format */
string_to_lower(file_info->ext);
}
/* Check whether path corresponds to a file
* inside an archive */
if ((archive_delim = path_get_archive_delim(path)))
{
char archive_path[PATH_MAX_LENGTH];
size_t len = 0;
/* Extract path of parent archive */
if ((len = (size_t)(1 + archive_delim - path))
>= PATH_MAX_LENGTH)
len = PATH_MAX_LENGTH;
strlcpy(archive_path, path, len * sizeof(char));
if (!string_is_empty(archive_path))
file_info->archive_path = strdup(archive_path);
/* Extract name of file in archive */
archive_delim++;
if (!string_is_empty(archive_delim))
file_info->archive_file = strdup(archive_delim);
/* Extract parent directory - may be used
* core-side as a reference point for searching
* related content (e.g. same file name, different
* extension) */
fill_pathname_parent_dir(dir, archive_path, sizeof(dir));
/* Extract 'canonical' name/id of content file -
* may be used core-side as a reference point for
* searching related content. For archived content,
* this is the basename of the archive file without
* extension */
fill_pathname_base(name, archive_path, sizeof(name));
path_remove_extension(name);
file_info->file_in_archive = true;
}
else
{
/* If path corresponds to a 'normal' file,
* just extract parent directory */
fill_pathname_parent_dir(dir, path, sizeof(dir));
/* For uncompressed content, 'canonical' name/id
* is the basename of the content file, without
* extension */
fill_pathname_base(name, path, sizeof(name));
path_remove_extension(name);
}
if (!string_is_empty(dir))
{
/* Remove any trailing slash */
char *last_slash = find_last_slash(dir);
if (last_slash && (last_slash[1] == '\0'))
*last_slash = '\0';
if (!string_is_empty(dir))
file_info->dir = strdup(dir);
}
if (!string_is_empty(name))
file_info->name = strdup(name);
}
/* Assign retro_game_info pointers */
game_info->path = file_info->full_path;
game_info->data = file_info->data;
game_info->size = file_info->data_size;
game_info->meta = file_info->meta;
/* Assign retro_game_info_ext pointers */
game_info_ext->full_path = file_info->full_path;
game_info_ext->archive_path = file_info->archive_path;
game_info_ext->archive_file = file_info->archive_file;
game_info_ext->dir = file_info->dir;
game_info_ext->name = file_info->name;
game_info_ext->ext = file_info->ext;
game_info_ext->meta = file_info->meta;
game_info_ext->data = file_info->data;
game_info_ext->size = file_info->data_size;
game_info_ext->file_in_archive = file_info->file_in_archive;
game_info_ext->persistent_data = file_info->persistent_data;
return true;
}
/***********************************/
/* Content file info functions END */
/***********************************/
/********************************/
/* Content file functions START */
/********************************/
#define CONTENT_FILE_ATTR_RESET(attr) (attr.i = 0)
#define CONTENT_FILE_ATTR_SET_BLOCK_EXTRACT(attr, block_extract) (attr.i |= ((block_extract) ? 1 : 0))
#define CONTENT_FILE_ATTR_SET_NEED_FULLPATH(attr, need_fullpath) (attr.i |= ((need_fullpath) ? 2 : 0))
#define CONTENT_FILE_ATTR_SET_REQUIRED(attr, required) (attr.i |= ((required) ? 4 : 0))
#define CONTENT_FILE_ATTR_SET_PERSISTENT(attr, persistent) (attr.i |= ((persistent) ? 8 : 0))
#define CONTENT_FILE_ATTR_GET_BLOCK_EXTRACT(attr) ((attr.i & 1) != 0)
#define CONTENT_FILE_ATTR_GET_NEED_FULLPATH(attr) ((attr.i & 2) != 0)
#define CONTENT_FILE_ATTR_GET_REQUIRED(attr) ((attr.i & 4) != 0)
#define CONTENT_FILE_ATTR_GET_PERSISTENT(attr) ((attr.i & 8) != 0)
/**
* content_file_load_into_memory:
* @content_path : path of the content file.
* @data : buffer into which the content file will be read.
* @data_size : size of the resultant content buffer.
*
* Reads the content file into memory. Also performs soft patching
* (see patch_content function) if soft patching has not been
* blocked by the user.
*
* Returns: true if successful, false on error.
**/
static bool content_file_load_into_memory(
content_information_ctx_t *content_ctx,
content_state_t *p_content,
const char *content_path,
bool content_compressed,
size_t idx,
enum rarch_content_type first_content_type,
uint8_t **data,
size_t *data_size)
{
uint8_t *content_data = NULL;
int64_t content_size = 0;
*data = NULL;
*data_size = 0;
RARCH_LOG("[Content]: %s: \"%s\".\n",
msg_hash_to_str(MSG_LOADING_CONTENT_FILE), content_path);
/* Read content from file into memory buffer */
#ifdef HAVE_COMPRESSION
if (content_compressed)
{
if (!file_archive_compressed_read(content_path,
(void**)&content_data, NULL, &content_size))
return false;
}
else
#endif
if (!filestream_read_file(content_path,
(void**)&content_data, &content_size))
return false;
if (content_size < 0)
return false;
/* First content file is significant: attempt to do
* soft patching, CRC checking, etc. */
if (idx == 0)
{
/* If we have a media type, ignore patches/CRC32
* calculation. */
if (first_content_type == RARCH_CONTENT_NONE)
{
bool has_patch = false;
#ifdef HAVE_PATCH
/* Attempt to apply a patch. */
if (!(content_ctx->flags & CONTENT_INFO_FLAG_PATCH_IS_BLOCKED))
has_patch = patch_content(
content_ctx->flags & CONTENT_INFO_FLAG_IS_IPS_PREF,
content_ctx->flags & CONTENT_INFO_FLAG_IS_BPS_PREF,
content_ctx->flags & CONTENT_INFO_FLAG_IS_UPS_PREF,
content_ctx->flags & CONTENT_INFO_FLAG_IS_XDELTA_PREF,
content_ctx->name_ips,
content_ctx->name_bps,
content_ctx->name_ups,
content_ctx->name_xdelta,
(uint8_t**)&content_data,
(void*)&content_size);
#endif
/* If content is compressed or a patch has been
* applied, must determine CRC value using the
* actual data buffer, since the content path
* cannot be used for this purpose...
* In all other cases, cache the content path
* and defer CRC calculation until the value is
* actually needed */
if (content_compressed || has_patch)
{
p_content->rom_crc = encoding_crc32(0, content_data,
(size_t)content_size);
RARCH_LOG("[Content]: CRC32: 0x%x.\n",
(unsigned)p_content->rom_crc);
}
else
{
/* We don't have the content ready inside a memory buffer,
so we have to read it from file later (deferred)
and then encode the CRC32 hash */
strlcpy(p_content->pending_rom_crc_path, content_path,
sizeof(p_content->pending_rom_crc_path));
p_content->flags |= CONTENT_ST_FLAG_PENDING_ROM_CRC;
}
}
else
p_content->rom_crc = 0;
}
*data = content_data;
*data_size = (size_t)content_size;
return true;
}
#ifdef HAVE_COMPRESSION
static bool content_file_extract_from_archive(
content_information_ctx_t *content_ctx,
content_state_t *p_content,
const char *valid_exts,
const char **content_path,
char **error_string)
{
const char *tmp_path_ptr = NULL;
char tmp_path[PATH_MAX_LENGTH];
char msg[1024];
tmp_path[0] = '\0';
msg[0] = '\0';
/* TODO/FIXME - localize */
RARCH_LOG("[Content]: Core requires uncompressed content - "
"extracting archive to temporary directory.\n");
/* Attempt to extract file */
if (!file_archive_extract_file(
*content_path, valid_exts,
string_is_empty(content_ctx->directory_cache) ?
NULL : content_ctx->directory_cache,
tmp_path, sizeof(tmp_path)))
{
snprintf(msg, sizeof(msg), "%s: \"%s\".\n",
msg_hash_to_str(MSG_FAILED_TO_EXTRACT_CONTENT_FROM_COMPRESSED_FILE),
*content_path);
*error_string = strdup(msg);
return false;
}
/* Add path of extracted file to temporary content
* list (so it can be deleted when deinitialising
* the core) */
if (!(tmp_path_ptr = content_file_list_append_temporary(
p_content->content_list, tmp_path)))
return false;
/* Update content path pointer */
*content_path = tmp_path_ptr;
/* TODO/FIXME - localize */
RARCH_LOG("[Content]: Content successfully extracted to: \"%s\".\n",
tmp_path);
return true;
}
#endif
static void content_file_get_path(
struct string_list *content,
size_t idx,
const char *valid_exts,
const char **path,
bool *path_is_compressed)
{
const char *content_path = content->elems[idx].data;
bool path_is_archive;
bool path_is_inside_archive;
*path = NULL;
*path_is_compressed = false;
if (string_is_empty(content_path))
return;
#ifdef HAVE_COMPRESSION
/* Check whether we are dealing with a
* compressed file */
path_is_archive = path_is_compressed_file(content_path);
path_is_inside_archive = path_contains_compressed_file(content_path);
*path_is_compressed = path_is_archive || path_is_inside_archive;
/* If extraction is permitted and content is a
* 'parent' archive file, must determine which
* internal file to load
* > file_archive_compressed_read() requires
* a 'complete' file path:
* <parent_archive>#<internal_file> */
if (!CONTENT_FILE_ATTR_GET_BLOCK_EXTRACT(content->elems[idx].attr) &&
path_is_archive &&
!path_is_inside_archive)
{
/* Get internal archive file list */
struct string_list *archive_list =
file_archive_get_file_list(content_path, valid_exts);
if (archive_list &&
(archive_list->size > 0))
{
const char *archive_file = NULL;
/* Ensure that list is sorted alphabetically */
if (archive_list->size > 1)
dir_list_sort(archive_list, true);
archive_file = archive_list->elems[0].data;
if (!string_is_empty(archive_file))
{
char info_path[PATH_MAX_LENGTH];
/* Build 'complete' archive file path */
size_t _len = strlcpy(info_path,
content_path, sizeof(info_path));
info_path[_len ] = '#';
info_path[_len+1] = '\0';
_len += 1;
strlcpy(info_path + _len, archive_file, sizeof(info_path) - _len);
/* Update 'content' string_list */
string_list_set(content, (unsigned)idx, info_path);
content_path = content->elems[idx].data;
string_list_free(archive_list);
}
}
}
#endif
*path = content_path;
}
static void content_file_apply_overrides(
content_state_t *p_content,
struct string_list *content,
size_t idx,
const char *path)
{
const content_file_override_t *override = NULL;
/* Check whether an override has been set
* for files of this type */
if (content_file_override_get_ext(p_content,
path_get_extension(path), &override))
{
/* Get existing attributes */
bool block_extract = CONTENT_FILE_ATTR_GET_BLOCK_EXTRACT(content->elems[idx].attr);
bool required = CONTENT_FILE_ATTR_GET_REQUIRED(content->elems[idx].attr);
bool persistent = CONTENT_FILE_ATTR_GET_PERSISTENT(content->elems[idx].attr);
CONTENT_FILE_ATTR_RESET(content->elems[idx].attr);
/* Apply updates
* > Note that 'persistent' attribute must not
* be set false by an override if it is already
* true (frontend may require persistence for
* other purposes, e.g. runahead) */
CONTENT_FILE_ATTR_SET_BLOCK_EXTRACT(content->elems[idx].attr,
block_extract);
CONTENT_FILE_ATTR_SET_NEED_FULLPATH(content->elems[idx].attr,
override->need_fullpath);
CONTENT_FILE_ATTR_SET_REQUIRED(content->elems[idx].attr,
required);
CONTENT_FILE_ATTR_SET_PERSISTENT(content->elems[idx].attr,
(persistent || override->persistent_data));
}
}
/**
* content_file_load:
* @special : subsystem of content to be loaded. Can be NULL.
*
* Load content file (for libretro core).
*
* Returns : true if successful, otherwise false.
**/
static bool content_file_load(
content_state_t *p_content,
struct string_list *content,
content_information_ctx_t *content_ctx,
enum msg_hash_enums *error_enum,
char **error_string,
const struct retro_subsystem_info *special)
{
size_t i;
char msg[1024];
retro_ctx_load_content_info_t load_info;
bool used_vfs_fallback_copy = false;
#ifdef __WINRT__
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
#endif
enum rarch_content_type first_content_type = RARCH_CONTENT_NONE;
msg[0] = '\0';
for (i = 0; i < content->size; i++)
{
const char *content_path = NULL;
uint8_t *content_data = NULL;
size_t content_size = 0;
const char *valid_exts = special
? special->roms[i].valid_extensions
: content_ctx->valid_extensions;
bool content_compressed = false;
/* Get content path */
content_file_get_path(content, i, valid_exts,
&content_path, &content_compressed);
/* If content is missing and core requires content,
* return an error */
if (string_is_empty(content_path))
{
if (CONTENT_FILE_ATTR_GET_REQUIRED(content->elems[i].attr))
{
*error_enum = MSG_ERROR_LIBRETRO_CORE_REQUIRES_CONTENT;
return false;
}
}
else
{
/* If this is the first item of content,
* get content type */
if (i == 0)
first_content_type = path_is_media_type(content_path);
/* Apply any file-type-specific content
* handling overrides */
if (p_content->content_override_list)
content_file_apply_overrides(p_content, content, i, content_path);
/* If core does not require 'fullpath', load
* the content into memory */
if (!CONTENT_FILE_ATTR_GET_NEED_FULLPATH(content->elems[i].attr))
{
if (!content_file_load_into_memory(