forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
task_content.c
2139 lines (1784 loc) · 63.8 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-2017 - 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/>.
*/
/* 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>
#include <errno.h>
#include <file/file_path.h>
#include <string/stdstring.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 <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 <string/stdstring.h>
#include <retro_miscellaneous.h>
#include <streams/file_stream.h>
#include <retro_assert.h>
#include <lists/string_list.h>
#include <string/stdstring.h>
#ifdef HAVE_MENU
#include "../menu/menu_driver.h"
#endif
#include "../menu/menu_shader.h"
#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 "../configuration.h"
#include "../defaults.h"
#include "../frontend/frontend.h"
#include "../playlist.h"
#include "../paths.h"
#include "../retroarch.h"
#include "../verbosity.h"
#include "../msg_hash.h"
#include "../content.h"
#include "../dynamic.h"
#include "../retroarch.h"
#include "../file_path_special.h"
#include "../core.h"
#include "../dirs.h"
#include "../paths.h"
#include "../verbosity.h"
#include "../discord/discord.h"
#include "task_patch.c"
extern bool discord_is_inited;
#define MAX_ARGS 32
typedef struct content_stream content_stream_t;
typedef struct content_information_ctx content_information_ctx_t;
struct content_stream
{
uint32_t a;
const uint8_t *b;
size_t c;
uint32_t crc;
};
struct content_information_ctx
{
struct
{
struct retro_subsystem_info *data;
unsigned size;
} subsystem;
char *name_ips;
char *name_bps;
char *name_ups;
char *valid_extensions;
char *directory_cache;
char *directory_system;
bool is_ips_pref;
bool is_bps_pref;
bool is_ups_pref;
bool history_list_enable;
bool block_extract;
bool need_fullpath;
bool set_supports_no_game_enable;
bool patch_is_blocked;
bool bios_is_missing;
bool check_firmware_before_loading;
struct string_list *temporary_content;
};
static struct string_list *temporary_content = NULL;
static bool _launched_from_cli = true;
static bool _content_is_inited = false;
static bool core_does_not_need_content = false;
static uint32_t content_rom_crc = 0;
static bool pending_subsystem_init = false;
static int pending_subsystem_rom_num = 0;
static int pending_subsystem_id = 0;
static unsigned pending_subsystem_rom_id = 0;
static char pending_subsystem_ident[255];
#if 0
static char pending_subsystem_extensions[PATH_MAX_LENGTH];
#endif
static char *pending_subsystem_roms[RARCH_MAX_SUBSYSTEM_ROMS];
static int64_t content_file_read(const char *path, void **buf, int64_t *length)
{
#ifdef HAVE_COMPRESSION
if (path_contains_compressed_file(path))
{
if (file_archive_compressed_read(path, buf, NULL, length))
return 1;
}
#endif
return filestream_read_file(path, buf, length);
}
/**
* content_load_init_wrap:
* @args : Input arguments.
* @argc : Count of arguments.
* @argv : Arguments.
*
* Generates an @argc and @argv pair based on @args
* of type rarch_main_wrap.
**/
static void content_load_init_wrap(
const struct rarch_main_wrap *args,
int *argc, char **argv)
{
#ifdef HAVE_FILE_LOGGER
int i;
#endif
*argc = 0;
argv[(*argc)++] = strdup("retroarch");
if (args->content_path)
{
RARCH_LOG("Using content: %s.\n", args->content_path);
argv[(*argc)++] = strdup(args->content_path);
}
#ifdef HAVE_MENU
else
{
RARCH_LOG("%s\n",
msg_hash_to_str(MSG_NO_CONTENT_STARTING_DUMMY_CORE));
argv[(*argc)++] = strdup("--menu");
}
#endif
if (args->sram_path)
{
argv[(*argc)++] = strdup("-s");
argv[(*argc)++] = strdup(args->sram_path);
}
if (args->state_path)
{
argv[(*argc)++] = strdup("-S");
argv[(*argc)++] = strdup(args->state_path);
}
if (args->config_path)
{
argv[(*argc)++] = strdup("-c");
argv[(*argc)++] = strdup(args->config_path);
}
#ifdef HAVE_DYNAMIC
if (args->libretro_path)
{
argv[(*argc)++] = strdup("-L");
argv[(*argc)++] = strdup(args->libretro_path);
}
#endif
if (args->verbose)
argv[(*argc)++] = strdup("-v");
#ifdef HAVE_FILE_LOGGER
for (i = 0; i < *argc; i++)
RARCH_LOG("arg #%d: %s\n", i, argv[i]);
#endif
}
/**
* content_load:
*
* Loads content file and starts up RetroArch.
* If no content file can be loaded, will start up RetroArch
* as-is.
*
* Returns: false (0) if retroarch_main_init failed,
* otherwise true (1).
**/
static bool content_load(content_ctx_info_t *info)
{
unsigned i;
bool retval = true;
int rarch_argc = 0;
char *rarch_argv[MAX_ARGS] = {NULL};
char *argv_copy [MAX_ARGS] = {NULL};
char **rarch_argv_ptr = (char**)info->argv;
int *rarch_argc_ptr = (int*)&info->argc;
struct rarch_main_wrap *wrap_args = (struct rarch_main_wrap*)
calloc(1, sizeof(*wrap_args));
if (!wrap_args)
return false;
retro_assert(wrap_args);
if (info->environ_get)
info->environ_get(rarch_argc_ptr,
rarch_argv_ptr, info->args, wrap_args);
if (wrap_args->touched)
{
content_load_init_wrap(wrap_args, &rarch_argc, rarch_argv);
memcpy(argv_copy, rarch_argv, sizeof(rarch_argv));
rarch_argv_ptr = (char**)rarch_argv;
rarch_argc_ptr = (int*)&rarch_argc;
}
rarch_ctl(RARCH_CTL_MAIN_DEINIT, NULL);
wrap_args->argc = *rarch_argc_ptr;
wrap_args->argv = rarch_argv_ptr;
if (!retroarch_main_init(wrap_args->argc, wrap_args->argv))
{
retval = false;
goto end;
}
if (pending_subsystem_init)
{
command_event(CMD_EVENT_CORE_INIT, NULL);
content_clear_subsystem();
}
menu_shader_manager_init();
command_event(CMD_EVENT_HISTORY_INIT, NULL);
command_event(CMD_EVENT_RESUME, NULL);
command_event(CMD_EVENT_VIDEO_SET_ASPECT_RATIO, NULL);
dir_check_defaults();
frontend_driver_process_args(rarch_argc_ptr, rarch_argv_ptr);
frontend_driver_content_loaded();
end:
for (i = 0; i < ARRAY_SIZE(argv_copy); i++)
free(argv_copy[i]);
free(wrap_args);
return retval;
}
/**
* load_content_into_memory:
* @path : buffer of the content file.
* @buf : size of the content file.
* @length : size of the content file that has been read from.
*
* Read the content file. If read into memory, also performs soft patching
* (see patch_content function) in case soft patching has not been
* blocked by the enduser.
*
* Returns: true if successful, false on error.
**/
static bool load_content_into_memory(
content_information_ctx_t *content_ctx,
unsigned i, const char *path, void **buf,
int64_t *length)
{
uint8_t *ret_buf = NULL;
RARCH_LOG("%s: %s.\n",
msg_hash_to_str(MSG_LOADING_CONTENT_FILE), path);
if (!content_file_read(path, (void**) &ret_buf, length))
return false;
if (*length < 0)
return false;
if (i == 0)
{
enum rarch_content_type type = path_is_media_type(path);
/* If we have a media type, ignore CRC32 calculation. */
if (type == RARCH_CONTENT_NONE)
{
/* First content file is significant, attempt to do patching,
* CRC checking, etc. */
/* Attempt to apply a patch. */
if (!content_ctx->patch_is_blocked)
patch_content(
content_ctx->is_ips_pref,
content_ctx->is_bps_pref,
content_ctx->is_ups_pref,
content_ctx->name_ips,
content_ctx->name_bps,
content_ctx->name_ups,
(uint8_t**)&ret_buf,
(void*)length);
content_rom_crc = encoding_crc32(0, ret_buf, (size_t)*length);
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)content_rom_crc);
}
else
content_rom_crc = 0;
}
*buf = ret_buf;
return true;
}
#ifdef HAVE_COMPRESSION
static bool load_content_from_compressed_archive(
content_information_ctx_t *content_ctx,
struct retro_game_info *info,
unsigned i,
struct string_list* additional_path_allocs,
bool need_fullpath,
const char *path,
char **error_string)
{
union string_list_elem_attr attributes;
int64_t new_path_len = 0;
size_t new_basedir_size = PATH_MAX_LENGTH * sizeof(char);
size_t new_path_size = PATH_MAX_LENGTH * sizeof(char);
char *new_basedir = (char*)malloc(new_basedir_size);
char *new_path = (char*)malloc(new_path_size);
bool ret = false;
new_path[0] = '\0';
new_basedir[0] = '\0';
attributes.i = 0;
RARCH_LOG("Compressed file in case of need_fullpath."
" Now extracting to temporary directory.\n");
if (!string_is_empty(content_ctx->directory_cache))
strlcpy(new_basedir, content_ctx->directory_cache, new_basedir_size);
if (string_is_empty(new_basedir) || !path_is_directory(new_basedir))
{
RARCH_WARN("Tried extracting to cache directory, but "
"cache directory was not set or found. "
"Setting cache directory to directory "
"derived by basename...\n");
fill_pathname_basedir(new_basedir, path, new_basedir_size);
}
new_path[0] = '\0';
new_basedir[0] = '\0';
fill_pathname_join(new_path, new_basedir,
path_basename(path), new_path_size);
ret = file_archive_compressed_read(path,
NULL, new_path, &new_path_len);
if (!ret || new_path_len < 0)
{
size_t path_size = 1024 * sizeof(char);
char *str = (char*)malloc(path_size);
snprintf(str,
path_size,
"%s \"%s\".\n",
msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE),
path);
*error_string = strdup(str);
free(str);
goto error;
}
string_list_append(additional_path_allocs, new_path, attributes);
info[i].path =
additional_path_allocs->elems[additional_path_allocs->size -1 ].data;
if (!string_list_append(content_ctx->temporary_content,
new_path, attributes))
goto error;
free(new_basedir);
free(new_path);
return true;
error:
free(new_basedir);
free(new_path);
return false;
}
/* Try to extract all content we're going to load if appropriate. */
static bool content_file_init_extract(
struct string_list *content,
content_information_ctx_t *content_ctx,
const struct retro_subsystem_info *special,
char **error_string,
union string_list_elem_attr *attr
)
{
unsigned i;
char *new_path = NULL;
for (i = 0; i < content->size; i++)
{
bool block_extract = content->elems[i].attr.i & 1;
const char *path = content->elems[i].data;
bool contains_compressed = path_contains_compressed_file(path);
/* Block extract check. */
if (block_extract)
continue;
/* just use the first file in the archive */
if (!contains_compressed && !path_is_compressed_file(path))
continue;
{
size_t temp_content_size = PATH_MAX_LENGTH * sizeof(char);
size_t new_path_size = PATH_MAX_LENGTH * sizeof(char);
char *temp_content = (char*)malloc(temp_content_size);
const char *valid_ext = special ?
special->roms[i].valid_extensions :
content_ctx->valid_extensions;
new_path = (char*)malloc(new_path_size);
temp_content[0] = new_path[0] = '\0';
if (!string_is_empty(path))
strlcpy(temp_content, path, temp_content_size);
if (!valid_ext || !file_archive_extract_file(
temp_content,
temp_content_size,
valid_ext,
!string_is_empty(content_ctx->directory_cache) ?
content_ctx->directory_cache : NULL,
new_path,
new_path_size
))
{
size_t path_size = 1024 * sizeof(char);
char *str = (char*)malloc(path_size);
snprintf(str, path_size,
"%s: %s.\n",
msg_hash_to_str(
MSG_FAILED_TO_EXTRACT_CONTENT_FROM_COMPRESSED_FILE),
temp_content);
free(temp_content);
free(str);
goto error;
}
string_list_set(content, i, new_path);
free(temp_content);
if (!string_list_append(content_ctx->temporary_content,
new_path, *attr))
goto error;
free(new_path);
}
}
return true;
error:
free(new_path);
return false;
}
#endif
/**
* content_file_load:
* @special : subsystem of content to be loaded. Can be NULL.
* content :
*
* Load content file (for libretro core).
*
* Returns : true if successful, otherwise false.
**/
static bool content_file_load(
struct retro_game_info *info,
const struct string_list *content,
content_information_ctx_t *content_ctx,
char **error_string,
const struct retro_subsystem_info *special,
struct string_list *additional_path_allocs
)
{
unsigned i;
retro_ctx_load_content_info_t load_info;
size_t msg_size = 1024 * sizeof(char);
char *msg = (char*)malloc(msg_size);
bool used_vfs_fallback_copy = false;
#ifdef __WINRT__
rarch_system_info_t *system = runloop_get_system_info();
#endif
msg[0] = '\0';
for (i = 0; i < content->size; i++)
{
int attr = content->elems[i].attr.i;
const char *path = content->elems[i].data;
bool need_fullpath = attr & 2;
bool require_content = attr & 4;
if (require_content && string_is_empty(path))
{
strlcpy(msg,
msg_hash_to_str(MSG_ERROR_LIBRETRO_CORE_REQUIRES_CONTENT),
msg_size
);
*error_string = strdup(msg);
goto error;
}
info[i].path = NULL;
if (!string_is_empty(path))
info[i].path = path;
if (!need_fullpath && !string_is_empty(path))
{
/* Load the content into memory. */
int64_t len = 0;
if (!load_content_into_memory(
content_ctx,
i, path, (void**)&info[i].data, &len))
{
snprintf(msg,
msg_size,
"%s \"%s\".\n",
msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE),
path);
*error_string = strdup(msg);
goto error;
}
info[i].size = len;
}
else
{
#ifdef HAVE_COMPRESSION
if ( !content_ctx->block_extract
&& need_fullpath
&& path_contains_compressed_file(path)
&& !load_content_from_compressed_archive(
content_ctx,
&info[i], i,
additional_path_allocs, need_fullpath, path,
error_string))
goto error;
#endif
#ifdef __WINRT__
/* TODO: When support for the 'actual' VFS is added, there will need to be some more logic here */
if (!system->supports_vfs && !uwp_is_path_accessible_using_standard_io(path))
{
/* Fallback to a file copy into an accessible directory */
char* buf;
int64_t len;
union string_list_elem_attr attributes;
size_t new_basedir_size = PATH_MAX_LENGTH * sizeof(char);
size_t new_path_size = PATH_MAX_LENGTH * sizeof(char);
char *new_basedir = (char*)malloc(new_basedir_size);
char *new_path = (char*)malloc(new_path_size);
new_path[0] = '\0';
new_basedir[0] = '\0';
attributes.i = 0;
RARCH_LOG("Core does not support VFS - copying to cache directory\n");
if (!string_is_empty(content_ctx->directory_cache))
strlcpy(new_basedir, content_ctx->directory_cache, new_basedir_size);
if (string_is_empty(new_basedir) || !path_is_directory(new_basedir) || !uwp_is_path_accessible_using_standard_io(new_basedir))
{
RARCH_WARN("Tried copying to cache directory, but "
"cache directory was not set or found. "
"Setting cache directory to root of "
"writable app directory...\n");
strlcpy(new_basedir, uwp_dir_data, new_basedir_size);
}
fill_pathname_join(new_path, new_basedir,
path_basename(path), new_path_size);
/* TODO: This may fail on very large files...
* but copying large files is not a good idea anyway */
if (!filestream_read_file(path, &buf, &len))
{
snprintf(msg,
msg_size,
"%s \"%s\". (during copy read)\n",
msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE),
path);
*error_string = strdup(msg);
goto error;
}
if (!filestream_write_file(new_path, buf, len))
{
free(buf);
snprintf(msg,
msg_size,
"%s \"%s\". (during copy write)\n",
msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE),
path);
*error_string = strdup(msg);
goto error;
}
free(buf);
string_list_append(additional_path_allocs, new_path, attributes);
info[i].path =
additional_path_allocs->elems[additional_path_allocs->size - 1].data;
string_list_append(content_ctx->temporary_content,
new_path, attributes);
free(new_basedir);
free(new_path);
used_vfs_fallback_copy = true;
}
#endif
/* It adds up to 10 seconds when loading large roms.
* It's mainly used for network play which isn't available for these platforms. */
#if !defined(GEKKO)
RARCH_LOG("%s\n", msg_hash_to_str(
MSG_CONTENT_LOADING_SKIPPED_IMPLEMENTATION_WILL_DO_IT));
content_rom_crc = file_crc32(0, path);
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)content_rom_crc);
#endif
}
}
load_info.content = content;
load_info.special = special;
load_info.info = info;
if (!core_load_game(&load_info))
{
/* This is probably going to fail on multifile ROMs etc.
* so give a visible explanation of what is likely wrong */
if (used_vfs_fallback_copy)
snprintf(msg,
msg_size,
"%s.", msg_hash_to_str(MSG_ERROR_LIBRETRO_CORE_REQUIRES_VFS));
else
snprintf(msg,
msg_size,
"%s.", msg_hash_to_str(MSG_FAILED_TO_LOAD_CONTENT));
*error_string = strdup(msg);
goto error;
}
#ifdef HAVE_CHEEVOS
if (!special)
{
const char *content_path = content->elems[0].data;
enum rarch_content_type type = path_is_media_type(content_path);
cheevos_set_cheats();
if (type == RARCH_CONTENT_NONE && !string_is_empty(content_path))
cheevos_load(info);
}
#endif
free(msg);
return true;
error:
free(msg);
return false;
}
static const struct
retro_subsystem_info *content_file_init_subsystem(
const struct retro_subsystem_info *subsystem_data,
size_t subsystem_current_count,
char **error_string,
bool *ret)
{
size_t path_size = 1024 * sizeof(char);
char *msg = (char*)malloc(path_size);
struct string_list *subsystem = path_get_subsystem_list();
const struct retro_subsystem_info *special = libretro_find_subsystem_info(
subsystem_data, subsystem_current_count,
path_get(RARCH_PATH_SUBSYSTEM));
msg[0] = '\0';
if (!special)
{
snprintf(msg, path_size,
"Failed to find subsystem \"%s\" in libretro implementation.\n",
path_get(RARCH_PATH_SUBSYSTEM));
*error_string = strdup(msg);
goto error;
}
if (special->num_roms && !subsystem)
{
strlcpy(msg,
msg_hash_to_str(MSG_ERROR_LIBRETRO_CORE_REQUIRES_SPECIAL_CONTENT),
path_size
);
*error_string = strdup(msg);
goto error;
}
else if (special->num_roms && (special->num_roms != subsystem->size))
{
snprintf(msg,
path_size,
"Libretro core requires %u content files for "
"subsystem \"%s\", but %u content files were provided.\n",
special->num_roms, special->desc,
(unsigned)subsystem->size);
*error_string = strdup(msg);
goto error;
}
else if (!special->num_roms && subsystem && subsystem->size)
{
snprintf(msg,
path_size,
"Libretro core takes no content for subsystem \"%s\", "
"but %u content files were provided.\n",
special->desc,
(unsigned)subsystem->size);
*error_string = strdup(msg);
goto error;
}
*ret = true;
free(msg);
return special;
error:
*ret = false;
free(msg);
return NULL;
}
static void content_file_init_set_attribs(
struct string_list *content,
const struct retro_subsystem_info *special,
content_information_ctx_t *content_ctx,
char **error_string,
union string_list_elem_attr *attr)
{
struct string_list *subsystem = path_get_subsystem_list();
attr->i = 0;
if (!path_is_empty(RARCH_PATH_SUBSYSTEM) && special)
{
unsigned i;
for (i = 0; i < subsystem->size; i++)
{
attr->i = special->roms[i].block_extract;
attr->i |= special->roms[i].need_fullpath << 1;
attr->i |= special->roms[i].required << 2;
string_list_append(content, subsystem->elems[i].data, *attr);
}
}
else
{
bool contentless = false;
bool is_inited = false;
content_get_status(&contentless, &is_inited);
attr->i = content_ctx->block_extract;
attr->i |= content_ctx->need_fullpath << 1;
attr->i |= (!contentless) << 2;
if (path_is_empty(RARCH_PATH_CONTENT)
&& contentless
&& content_ctx->set_supports_no_game_enable)
string_list_append(content, "", *attr);
else
{
if (!path_is_empty(RARCH_PATH_CONTENT))
string_list_append(content, path_get(RARCH_PATH_CONTENT), *attr);
}
}
}
/**
* content_init_file:
*
* Initializes and loads a content file for the currently
* selected libretro core.
*
* Returns : true if successful, otherwise false.
**/
static bool content_file_init(
content_information_ctx_t *content_ctx,
struct string_list *content,
char **error_string)
{
union string_list_elem_attr attr;
struct retro_game_info *info = NULL;
bool ret =
path_is_empty(RARCH_PATH_SUBSYSTEM)
? true : false;
const struct retro_subsystem_info *special =
path_is_empty(RARCH_PATH_SUBSYSTEM)
? NULL : content_file_init_subsystem(content_ctx->subsystem.data,
content_ctx->subsystem.size, error_string, &ret);
if (!ret)
return false;
content_file_init_set_attribs(content, special, content_ctx, error_string, &attr);
#ifdef HAVE_COMPRESSION
content_file_init_extract(content, content_ctx, special, error_string, &attr);
#endif
if (content->size > 0)
info = (struct retro_game_info*)
calloc(content->size, sizeof(*info));
if (info)
{
unsigned i;
struct string_list *additional_path_allocs = string_list_new();
ret = content_file_load(info, content, content_ctx, error_string,
special, additional_path_allocs);
string_list_free(additional_path_allocs);
for (i = 0; i < content->size; i++)
free((void*)info[i].data);
free(info);
}
else if (!special)
{
*error_string = strdup(msg_hash_to_str(MSG_ERROR_LIBRETRO_CORE_REQUIRES_CONTENT));
ret = false;
}
return ret;
}
static void menu_content_environment_get(int *argc, char *argv[],
void *args, void *params_data)
{
struct rarch_main_wrap *wrap_args = (struct rarch_main_wrap*)params_data;
rarch_system_info_t *sys_info = runloop_get_system_info();
if (!wrap_args)
return;
wrap_args->no_content = sys_info->load_no_content;
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_VERBOSITY, NULL))
wrap_args->verbose = verbosity_is_enabled();
wrap_args->touched = true;
wrap_args->config_path = NULL;
wrap_args->sram_path = NULL;
wrap_args->state_path = NULL;
wrap_args->content_path = NULL;
if (!path_is_empty(RARCH_PATH_CONFIG))
wrap_args->config_path = path_get(RARCH_PATH_CONFIG);
if (!dir_is_empty(RARCH_DIR_SAVEFILE))
wrap_args->sram_path = dir_get(RARCH_DIR_SAVEFILE);
if (!dir_is_empty(RARCH_DIR_SAVESTATE))
wrap_args->state_path = dir_get(RARCH_DIR_SAVESTATE);
if (!path_is_empty(RARCH_PATH_CONTENT))
wrap_args->content_path = path_get(RARCH_PATH_CONTENT);
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_LIBRETRO, NULL))
wrap_args->libretro_path = string_is_empty(path_get(RARCH_PATH_CORE)) ? NULL :
path_get(RARCH_PATH_CORE);
}
/**
* task_load_content:
*
* Loads content into currently selected core.
* Will also optionally push the content entry to the history playlist.
*
* Returns: true (1) if successful, otherwise false (0).
**/
static bool task_load_content(content_ctx_info_t *content_info,
content_information_ctx_t *content_ctx,
bool launched_from_menu,
bool launched_from_cli,
char **error_string)
{
bool contentless = false;
bool is_inited = false;
if (!content_load(content_info))
return false;
content_get_status(&contentless, &is_inited);
/* Push entry to top of history playlist */
if (is_inited || contentless)
{
size_t tmp_size = PATH_MAX_LENGTH * sizeof(char);
char *tmp = (char*)malloc(tmp_size);
const char *path_content = path_get(RARCH_PATH_CONTENT);
struct retro_system_info *info = runloop_get_libretro_system_info();
tmp[0] = '\0';
if (!string_is_empty(path_content))
strlcpy(tmp, path_content, tmp_size);
if (!launched_from_menu)