forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
content.c
900 lines (754 loc) · 23.1 KB
/
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
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2016 - Daniel De Matteis
*
* 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 <boolean.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
#include <compat/strl.h>
#include <file/file_path.h>
#include <file/file_archive.h>
#include <string/stdstring.h>
#include <retro_file.h>
#include <retro_stat.h>
#include "msg_hash.h"
#include "content.h"
#include "file_ops.h"
#include "general.h"
#include "dynamic.h"
#include "movie.h"
#include "patch.h"
#include "system.h"
#include "libretro_version_1.h"
#include "verbosity.h"
#ifdef HAVE_CHEEVOS
#include "cheevos.h"
#endif
struct sram_block
{
unsigned type;
void *data;
size_t size;
};
/**
* read_content_file:
* @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 read_content_file(unsigned i, const char *path, void **buf,
ssize_t *length)
{
#ifdef HAVE_ZLIB
uint32_t *content_crc_ptr = NULL;
const struct file_archive_file_backend *stream_backend =
file_archive_get_default_file_backend();
#endif
uint8_t *ret_buf = NULL;
global_t *global = global_get_ptr();
RARCH_LOG("%s: %s.\n",
msg_hash_to_str(MSG_LOADING_CONTENT_FILE), path);
if (!read_file(path, (void**) &ret_buf, length))
return false;
if (*length < 0)
return false;
if (i != 0)
return true;
/* Attempt to apply a patch. */
if (!global->patch.block_patch)
patch_content(&ret_buf, length);
#ifdef HAVE_ZLIB
content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr);
*content_crc_ptr = stream_backend->stream_crc_calculate(
0, ret_buf, *length);
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)*content_crc_ptr);
#endif
*buf = ret_buf;
return true;
}
/**
* dump_to_file_desperate:
* @data : pointer to data buffer.
* @size : size of @data.
* @type : type of file to be saved.
*
* Attempt to save valuable RAM data somewhere.
**/
static bool dump_to_file_desperate(const void *data,
size_t size, unsigned type)
{
time_t time_;
char timebuf[256];
char path[PATH_MAX_LENGTH];
#if defined(_WIN32) && !defined(_XBOX)
const char *base = getenv("APPDATA");
#elif defined(__CELLOS_LV2__) || defined(_XBOX)
const char *base = NULL;
#else
const char *base = getenv("HOME");
#endif
if (!base)
return false;
snprintf(path, sizeof(path), "%s/RetroArch-recovery-%u", base, type);
time(&time_);
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d-%H-%M-%S", localtime(&time_));
strlcat(path, timebuf, sizeof(path));
if (!retro_write_file(path, data, size))
return false;
RARCH_WARN("Succeeded in saving RAM data to \"%s\".\n", path);
return true;
}
/**
* save_state:
* @path : path of saved state that shall be written to.
*
* Save a state from memory to disk.
*
* Returns: true if successful, false otherwise.
**/
static bool content_save_state(const char *path)
{
retro_ctx_serialize_info_t serial_info;
retro_ctx_size_info_t info;
bool ret = false;
void *data = NULL;
core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info);
RARCH_LOG("%s: \"%s\".\n",
msg_hash_to_str(MSG_SAVING_STATE),
path);
if (info.size == 0)
return false;
data = malloc(info.size);
if (!data)
return false;
RARCH_LOG("%s: %d %s.\n",
msg_hash_to_str(MSG_STATE_SIZE),
(int)info.size,
msg_hash_to_str(MSG_BYTES));
serial_info.data = data;
serial_info.size = info.size;
ret = core_ctl(CORE_CTL_RETRO_SERIALIZE, &serial_info);
if (ret)
ret = retro_write_file(path, data, info.size);
else
{
RARCH_ERR("%s \"%s\".\n",
msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO),
path);
}
free(data);
return ret;
}
/**
* content_load_state:
* @path : path that state will be loaded from.
*
* Load a state from disk to memory.
*
* Returns: true if successful, false otherwise.
**/
static bool content_load_state(const char *path)
{
unsigned i;
ssize_t size;
retro_ctx_serialize_info_t serial_info;
unsigned num_blocks = 0;
void *buf = NULL;
struct sram_block *blocks = NULL;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
bool ret = retro_read_file(path, &buf, &size);
RARCH_LOG("%s: \"%s\".\n",
msg_hash_to_str(MSG_LOADING_STATE),
path);
if (!ret || size < 0)
goto error;
RARCH_LOG("%s: %u %s.\n",
msg_hash_to_str(MSG_STATE_SIZE),
(unsigned)size,
msg_hash_to_str(MSG_BYTES));
if (settings->block_sram_overwrite && global->savefiles
&& global->savefiles->size)
{
RARCH_LOG("%s.\n",
msg_hash_to_str(MSG_BLOCKING_SRAM_OVERWRITE));
blocks = (struct sram_block*)
calloc(global->savefiles->size, sizeof(*blocks));
if (blocks)
{
num_blocks = global->savefiles->size;
for (i = 0; i < num_blocks; i++)
blocks[i].type = global->savefiles->elems[i].attr.i;
}
}
for (i = 0; i < num_blocks; i++)
{
retro_ctx_memory_info_t mem_info;
mem_info.id = blocks[i].type;
core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info);
blocks[i].size = mem_info.size;
}
for (i = 0; i < num_blocks; i++)
if (blocks[i].size)
blocks[i].data = malloc(blocks[i].size);
/* Backup current SRAM which is overwritten by unserialize. */
for (i = 0; i < num_blocks; i++)
{
if (blocks[i].data)
{
retro_ctx_memory_info_t mem_info;
const void *ptr = NULL;
mem_info.id = blocks[i].type;
core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info);
ptr = mem_info.data;
if (ptr)
memcpy(blocks[i].data, ptr, blocks[i].size);
}
}
serial_info.data_const = buf;
serial_info.size = size;
ret = core_ctl(CORE_CTL_RETRO_UNSERIALIZE, &serial_info);
/* Flush back. */
for (i = 0; i < num_blocks; i++)
{
if (blocks[i].data)
{
retro_ctx_memory_info_t mem_info;
void *ptr = NULL;
mem_info.id = blocks[i].type;
core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info);
ptr = mem_info.data;
if (ptr)
memcpy(ptr, blocks[i].data, blocks[i].size);
}
}
for (i = 0; i < num_blocks; i++)
free(blocks[i].data);
free(blocks);
free(buf);
if (!ret)
goto error;
return true;
error:
RARCH_ERR("%s \"%s\".\n",
msg_hash_to_str(MSG_FAILED_TO_LOAD_STATE),
path);
return false;
}
/**
* load_ram_file:
* @path : path of RAM state that will be loaded from.
* @type : type of memory
*
* Load a RAM state from disk to memory.
*/
static bool load_ram_file(void *data)
{
ssize_t rc;
retro_ctx_memory_info_t mem_info;
void *buf = NULL;
ram_type_t *ram = (ram_type_t*)data;
if (!ram)
return false;
mem_info.id = ram->type;
core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info);
if (mem_info.size == 0 || !mem_info.data)
return false;
if (!retro_read_file(ram->path, &buf, &rc))
return false;
if (rc > 0)
{
if (rc > (ssize_t)mem_info.size)
{
RARCH_WARN("SRAM is larger than implementation expects, "
"doing partial load (truncating %u %s %s %u).\n",
(unsigned)rc,
msg_hash_to_str(MSG_BYTES),
msg_hash_to_str(MSG_TO),
(unsigned)mem_info.size);
rc = mem_info.size;
}
memcpy(mem_info.data, buf, rc);
}
if (buf)
free(buf);
return true;
}
/**
* save_ram_file:
* @path : path of RAM state that shall be written to.
* @type : type of memory
*
* Save a RAM state from memory to disk.
*
*/
static bool save_ram_file(ram_type_t *ram)
{
retro_ctx_memory_info_t mem_info;
mem_info.id = ram->type;
core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info);
if (!mem_info.data || mem_info.size == 0)
return false;
if (!retro_write_file(ram->path, mem_info.data, mem_info.size))
{
RARCH_ERR("%s.\n",
msg_hash_to_str(MSG_FAILED_TO_SAVE_SRAM));
RARCH_WARN("Attempting to recover ...\n");
/* In case the file could not be written to,
* the fallback function 'dump_to_file_desperate'
* will be called. */
if (!dump_to_file_desperate(mem_info.data, mem_info.size, ram->type))
{
RARCH_WARN("Failed ... Cannot recover save file.\n");
}
return false;
}
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_SAVED_SUCCESSFULLY_TO),
ram->path);
return true;
}
/* Load the content into memory. */
static bool load_content_into_memory(
struct retro_game_info *info,
unsigned i,
const char *path)
{
ssize_t len;
bool ret = false;
if (i == 0)
{
/* First content file is significant, attempt to do patching,
* CRC checking, etc. */
ret = read_content_file(i, path, (void**)&info->data, &len);
}
else
ret = read_file(path, (void**)&info->data, &len);
if (!ret || len < 0)
goto error;
info->size = len;
return true;
error:
RARCH_ERR("%s \"%s\".\n",
msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE),
path);
return false;
}
#ifdef HAVE_COMPRESSION
static bool load_content_from_compressed_archive(
struct string_list *temporary_content,
struct retro_game_info *info, unsigned i,
struct string_list* additional_path_allocs,
bool need_fullpath, const char *path)
{
union string_list_elem_attr attributes;
ssize_t new_path_len;
char new_path[PATH_MAX_LENGTH];
char new_basedir[PATH_MAX_LENGTH];
bool ret = false;
settings_t *settings = config_get_ptr();
rarch_system_info_t *sys_info= NULL;
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &sys_info);
if (sys_info && sys_info->info.block_extract)
return true;
if (!need_fullpath || !path_contains_compressed_file(path))
return true;
RARCH_LOG("Compressed file in case of need_fullpath."
" Now extracting to temporary directory.\n");
strlcpy(new_basedir, settings->cache_directory,
sizeof(new_basedir));
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,
sizeof(new_basedir));
}
attributes.i = 0;
fill_pathname_join(new_path, new_basedir,
path_basename(path), sizeof(new_path));
ret = read_compressed_file(path, NULL, new_path, &new_path_len);
if (!ret || new_path_len < 0)
{
RARCH_ERR("%s \"%s\".\n",
msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE),
path);
return false;
}
RARCH_LOG("New path is: [%s]\n", new_path);
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(temporary_content, new_path, attributes))
return false;
return true;
}
#endif
/**
* load_content:
* @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 load_content(
struct string_list *temporary_content,
struct retro_game_info *info,
const struct string_list *content,
const struct retro_subsystem_info *special,
struct string_list* additional_path_allocs
)
{
unsigned i;
retro_ctx_load_content_info_t load_info;
if (!info || !additional_path_allocs)
return false;
for (i = 0; i < content->size; i++)
{
int attr = content->elems[i].attr.i;
bool need_fullpath = attr & 2;
bool require_content = attr & 4;
const char *path = content->elems[i].data;
if (require_content && string_is_empty(path))
{
RARCH_LOG("libretro core requires content, "
"but nothing was provided.\n");
return false;
}
info[i].path = NULL;
if (*path)
info[i].path = path;
if (!need_fullpath && !string_is_empty(path))
{
if (!load_content_into_memory(&info[i], i, path))
return false;
}
else
{
RARCH_LOG("Content loading skipped. Implementation will"
" load it on its own.\n");
#ifdef HAVE_COMPRESSION
if (!load_content_from_compressed_archive(
temporary_content,
&info[i], i,
additional_path_allocs, need_fullpath, path))
return false;
#endif
}
}
load_info.content = content;
load_info.special = special;
load_info.info = info;
if (!core_ctl(CORE_CTL_RETRO_LOAD_GAME, &load_info))
{
RARCH_ERR("%s.\n", msg_hash_to_str(MSG_FAILED_TO_LOAD_CONTENT));
return false;
}
#ifdef HAVE_CHEEVOS
if (!special)
{
/* Load the achievements into memory if the game has content. */
cheevos_set_cheats();
cheevos_load(*content->elems[0].data ? info : NULL);
}
#endif
return true;
}
static bool init_content_file_subsystem(
const struct retro_subsystem_info *special,
rarch_system_info_t *system
)
{
global_t *global = global_get_ptr();
special = libretro_find_subsystem_info(system->special,
system->num_special, global->subsystem);
if (!special)
{
RARCH_ERR(
"Failed to find subsystem \"%s\" in libretro implementation.\n",
global->subsystem);
return false;
}
if (special->num_roms && !global->subsystem_fullpaths)
{
RARCH_ERR("libretro core requires special content, "
"but none were provided.\n");
return false;
}
else if (special->num_roms && special->num_roms
!= global->subsystem_fullpaths->size)
{
RARCH_ERR("libretro core requires %u content files for "
"subsystem \"%s\", but %u content files were provided.\n",
special->num_roms, special->desc,
(unsigned)global->subsystem_fullpaths->size);
return false;
}
else if (!special->num_roms && global->subsystem_fullpaths
&& global->subsystem_fullpaths->size)
{
RARCH_ERR("libretro core takes no content for subsystem \"%s\", "
"but %u content files were provided.\n",
special->desc,
(unsigned)global->subsystem_fullpaths->size);
return false;
}
return true;
}
#ifdef HAVE_ZLIB
static bool init_content_file_extract(
struct string_list *temporary_content,
struct string_list *content,
rarch_system_info_t *system,
const struct retro_subsystem_info *special,
union string_list_elem_attr *attr
)
{
unsigned i;
settings_t *settings = config_get_ptr();
for (i = 0; i < content->size; i++)
{
const char *ext = NULL;
const char *valid_ext = system->info.valid_extensions;
/* Block extract check. */
if (content->elems[i].attr.i & 1)
continue;
ext = path_get_extension(content->elems[i].data);
if (special)
valid_ext = special->roms[i].valid_extensions;
if (!ext)
continue;
if (string_is_equal_noncase(ext, "zip"))
{
char new_path[PATH_MAX_LENGTH];
char temp_content[PATH_MAX_LENGTH];
strlcpy(temp_content, content->elems[i].data,
sizeof(temp_content));
if (!file_archive_extract_first_content_file(temp_content,
sizeof(temp_content), valid_ext,
*settings->cache_directory ?
settings->cache_directory : NULL,
new_path, sizeof(new_path)))
{
RARCH_ERR("Failed to extract content from zipped file: %s.\n",
temp_content);
return false;
}
string_list_set(content, i, new_path);
if (!string_list_append(temporary_content,
new_path, *attr))
return false;
}
}
return true;
}
#endif
static bool init_content_file_set_attribs(
struct string_list *temporary_content,
struct string_list *content,
rarch_system_info_t *system,
const struct retro_subsystem_info *special)
{
union string_list_elem_attr attr;
global_t *global = global_get_ptr();
attr.i = 0;
if (*global->subsystem)
{
unsigned i;
for (i = 0; i < global->subsystem_fullpaths->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,
global->subsystem_fullpaths->elems[i].data, attr);
}
}
else
{
settings_t *settings = config_get_ptr();
attr.i = system->info.block_extract;
attr.i |= system->info.need_fullpath << 1;
attr.i |= (!system->no_content) << 2;
if (content_ctl(CONTENT_CTL_DOES_NOT_NEED_CONTENT, NULL)
&& settings->set_supports_no_game_enable)
string_list_append(content, "", attr);
else
{
char *fullpath = NULL;
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
string_list_append(content, fullpath, attr);
}
}
#ifdef HAVE_ZLIB
/* Try to extract all content we're going to load if appropriate. */
if (!init_content_file_extract(temporary_content,
content, system, special, &attr))
return false;
#endif
return true;
}
/**
* content_init_file:
*
* Initializes and loads a content file for the currently
* selected libretro core.
*
* Returns : true if successful, otherwise false.
**/
static bool content_init_file(struct string_list *temporary_content)
{
unsigned i;
struct retro_game_info *info = NULL;
bool ret = false;
struct string_list* additional_path_allocs = NULL;
struct string_list *content = NULL;
const struct retro_subsystem_info *special = NULL;
rarch_system_info_t *system = NULL;
global_t *global = global_get_ptr();
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system);
if (*global->subsystem)
if (!init_content_file_subsystem(special, system))
goto error;
content = string_list_new();
if (!content)
goto error;
if (!init_content_file_set_attribs(temporary_content,
content, system, special))
goto error;
info = (struct retro_game_info*)
calloc(content->size, sizeof(*info));
additional_path_allocs = string_list_new();
ret = load_content(temporary_content,
info, content, special, additional_path_allocs);
for (i = 0; i < content->size; i++)
free((void*)info[i].data);
string_list_free(additional_path_allocs);
if (info)
free(info);
error:
if (content)
string_list_free(content);
return ret;
}
bool content_ctl(enum content_ctl_state state, void *data)
{
unsigned i;
static struct string_list *temporary_content = NULL;
static bool content_is_inited = false;
static bool core_does_not_need_content = false;
static uint32_t content_crc = 0;
switch(state)
{
case CONTENT_CTL_LOAD_RAM_FILE:
return load_ram_file(data);
case CONTENT_CTL_SAVE_RAM_FILE:
{
ram_type_t *ram = (ram_type_t*)data;
if (!ram)
return false;
save_ram_file(ram);
}
break;
case CONTENT_CTL_DOES_NOT_NEED_CONTENT:
return core_does_not_need_content;
case CONTENT_CTL_SET_DOES_NOT_NEED_CONTENT:
core_does_not_need_content = true;
break;
case CONTENT_CTL_GET_CRC:
{
uint32_t **content_crc_ptr = (uint32_t**)data;
if (!content_crc_ptr)
return false;
*content_crc_ptr = &content_crc;
}
break;
case CONTENT_CTL_LOAD_STATE:
{
const char *path = (const char*)data;
if (!path)
return false;
return content_load_state(path);
}
case CONTENT_CTL_SAVE_STATE:
{
const char *path = (const char*)data;
if (!path)
return false;
return content_save_state(path);
}
case CONTENT_CTL_IS_INITED:
return content_is_inited;
case CONTENT_CTL_DEINIT:
content_ctl(CONTENT_CTL_TEMPORARY_FREE, NULL);
content_crc = 0;
content_is_inited = false;
core_does_not_need_content = false;
break;
case CONTENT_CTL_INIT:
content_is_inited = false;
temporary_content = string_list_new();
if (!temporary_content)
return false;
if (content_init_file(temporary_content))
{
content_is_inited = true;
return true;
}
content_ctl(CONTENT_CTL_DEINIT, NULL);
return false;
case CONTENT_CTL_TEMPORARY_FREE:
if (!temporary_content)
return false;
for (i = 0; i < temporary_content->size; i++)
{
const char *path = temporary_content->elems[i].data;
RARCH_LOG("%s: %s.\n",
msg_hash_to_str(MSG_REMOVING_TEMPORARY_CONTENT_FILE), path);
if (remove(path) < 0)
RARCH_ERR("%s: %s.\n",
msg_hash_to_str(MSG_FAILED_TO_REMOVE_TEMPORARY_FILE),
path);
}
string_list_free(temporary_content);
temporary_content = NULL;
break;
case CONTENT_CTL_NONE:
default:
break;
}
return true;
}