RetroArch/tasks/task_content.c

2626 lines
82 KiB
C
Raw Normal View History

2016-01-24 00:40:34 +01:00
/* RetroArch - A frontend for libretro.
2017-01-22 13:40:32 +01:00
* Copyright (C) 2011-2017 - Daniel De Matteis
2019-02-22 16:31:54 -05:00
* Copyright (C) 2016-2019 - Brad Parker
* Copyright (C) 2016-2019 - Andrés Suárez
2016-01-24 00:40:34 +01:00
*
* 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 */
2016-05-16 16:42:33 +02:00
#include <stdio.h>
#include <stdint.h>
2016-01-24 00:40:34 +01:00
#include <stdlib.h>
2016-05-16 16:42:33 +02:00
#include <sys/types.h>
#include <string.h>
#include <time.h>
#include <errno.h>
2016-01-24 00:40:34 +01:00
2016-05-16 15:09:04 +02:00
#include <file/file_path.h>
2020-02-02 03:00:51 +01:00
#include <queues/task_queue.h>
#include <string/stdstring.h>
2016-05-16 15:09:04 +02:00
2016-05-16 16:42:33 +02:00
#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
2016-09-19 01:12:39 +02:00
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
2016-05-16 16:42:33 +02:00
#include <boolean.h>
2016-09-19 21:18:49 -04:00
#include <encodings/crc32.h>
2016-05-16 16:42:33 +02:00
#include <compat/strl.h>
#include <compat/posix_string.h>
#include <file/file_path.h>
#include <file/archive_file.h>
#include <string/stdstring.h>
#include <vfs/vfs_implementation.h>
#ifdef HAVE_CDROM
#include <vfs/vfs_implementation_cdrom.h>
#endif
2016-05-16 16:42:33 +02:00
#include <retro_miscellaneous.h>
#include <streams/file_stream.h>
#include <retro_assert.h>
#include <lists/string_list.h>
#include <string/stdstring.h>
2016-09-19 01:12:39 +02:00
#ifdef HAVE_MENU
#include "../menu/menu_driver.h"
#ifdef HAVE_GFX_WIDGETS
#include "../gfx/gfx_widgets.h"
2019-07-08 15:32:12 -04:00
#endif
2016-09-19 01:12:39 +02:00
#endif
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
2019-01-06 23:03:28 -05:00
#include "../menu/menu_shader.h"
#endif
2019-01-06 23:03:28 -05:00
2016-09-19 01:12:39 +02:00
#ifdef HAVE_CHEEVOS
2020-05-21 23:23:01 +02:00
#include "../cheevos/cheevos.h"
2016-09-19 01:12:39 +02:00
#endif
2019-01-20 03:16:58 +01:00
#include "task_content.h"
2016-09-19 01:12:39 +02:00
#include "tasks_internal.h"
#include "../command.h"
#include "../core_info.h"
2016-09-19 01:12:39 +02:00
#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"
2016-05-16 16:42:33 +02:00
#include "../msg_hash.h"
#include "../content.h"
#include "../dynamic.h"
#include "../retroarch.h"
#include "../file_path_special.h"
#include "../core.h"
2016-09-17 12:35:29 +02:00
#include "../paths.h"
2016-05-16 16:42:33 +02:00
#include "../verbosity.h"
2020-05-20 15:27:27 +02:00
#include "../network/discord.h"
2020-05-20 15:27:27 +02:00
/* TODO/FIXME - get rid of this public global */
extern bool discord_is_inited;
2016-09-18 10:38:15 -04:00
#define MAX_ARGS 32
2017-05-13 22:35:10 +02:00
typedef struct content_stream content_stream_t;
typedef struct content_information_ctx content_information_ctx_t;
2019-07-08 15:32:12 -04:00
#ifdef HAVE_CDROM
enum cdrom_dump_state
{
DUMP_STATE_TOC_PENDING = 0,
2019-07-08 15:32:12 -04:00
DUMP_STATE_WRITE_CUE,
DUMP_STATE_NEXT_TRACK,
DUMP_STATE_READ_TRACK
};
typedef struct
{
bool next;
enum cdrom_dump_state state;
2019-07-08 15:32:12 -04:00
unsigned char cur_track;
int64_t cur_track_bytes;
int64_t track_written_bytes;
int64_t disc_total_bytes;
int64_t disc_read_bytes;
char drive_letter[2];
char cdrom_path[64];
char title[512];
const cdrom_toc_t *toc;
RFILE *file;
RFILE *output_file;
libretro_vfs_implementation_file *stream;
2019-07-08 15:32:12 -04:00
} task_cdrom_dump_state_t;
#endif
2017-05-13 22:35:10 +02:00
struct content_stream
2016-05-16 16:42:33 +02:00
{
const uint8_t *b;
size_t c;
uint32_t a;
2016-05-16 16:42:33 +02:00
uint32_t crc;
2017-05-13 22:35:10 +02:00
};
2016-05-16 16:42:33 +02:00
2017-05-13 22:35:10 +02:00
struct content_information_ctx
{
bool block_extract;
bool need_fullpath;
bool set_supports_no_game_enable;
#ifdef HAVE_PATCH
bool is_ips_pref;
bool is_bps_pref;
bool is_ups_pref;
bool patch_is_blocked;
#endif
bool bios_is_missing;
bool check_firmware_before_loading;
2016-12-20 23:39:31 +01:00
struct
{
struct retro_subsystem_info *data;
unsigned size;
} subsystem;
2017-05-14 04:52:34 +02:00
char *name_ips;
char *name_bps;
char *name_ups;
char *valid_extensions;
char *directory_cache;
char *directory_system;
2016-12-21 15:21:11 +01:00
struct string_list *temporary_content;
2017-05-13 22:35:10 +02:00
};
2019-07-08 15:32:12 -04:00
#ifdef HAVE_CDROM
static void task_cdrom_dump_handler(retro_task_t *task)
{
2020-01-20 05:06:51 +01:00
task_cdrom_dump_state_t *state = (task_cdrom_dump_state_t*)task->state;
settings_t *settings = config_get_ptr();
const char *directory_core_assets = settings
? settings->paths.directory_core_assets : NULL;
2019-07-08 15:32:12 -04:00
if (task_get_progress(task) == 100)
{
if (state->file)
filestream_close(state->file);
if (state->output_file)
filestream_close(state->output_file);
state->file = NULL;
state->output_file = NULL;
2019-07-08 15:32:12 -04:00
task_set_finished(task, true);
2019-07-10 20:56:23 -04:00
RARCH_LOG("[CDROM]: Dump finished.\n");
2019-07-08 15:32:12 -04:00
return;
}
switch (state->state)
{
case DUMP_STATE_TOC_PENDING:
2020-01-20 05:06:51 +01:00
{
/* open cuesheet file from drive */
char cue_path[PATH_MAX_LENGTH] = {0};
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
cdrom_device_fillpath(cue_path, sizeof(cue_path), state->drive_letter[0], 0, true);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
state->file = filestream_open(cue_path, RETRO_VFS_FILE_ACCESS_READ, 0);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
if (!state->file)
{
RARCH_ERR("[CDROM]: Error opening file for reading: %s\n", cue_path);
task_set_progress(task, 100);
task_free_title(task);
task_set_title(task, strdup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FILE_READ_OPEN_FAILED)));
return;
}
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
state->state = DUMP_STATE_WRITE_CUE;
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
break;
}
2019-07-08 15:32:12 -04:00
case DUMP_STATE_WRITE_CUE:
2020-01-20 05:06:51 +01:00
{
char output_file[PATH_MAX_LENGTH];
char cue_filename[PATH_MAX_LENGTH];
/* write cuesheet to a file */
int64_t cue_size = filestream_get_size(state->file);
char *cue_data = (char*)calloc(1, cue_size);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
output_file[0] = cue_filename[0] = '\0';
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
filestream_read(state->file, cue_data, cue_size);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
state->stream = filestream_get_vfs_handle(state->file);
state->toc = retro_vfs_file_get_cdrom_toc();
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
if (cdrom_has_atip(state->stream))
RARCH_LOG("[CDROM]: This disc is not genuine.\n");
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
filestream_close(state->file);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
snprintf(cue_filename, sizeof(cue_filename), "%s.cue", state->title);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
fill_pathname_join(output_file,
directory_core_assets, cue_filename, sizeof(output_file));
2019-07-08 15:32:12 -04:00
{
2020-01-20 05:06:51 +01:00
RFILE *file = filestream_open(output_file, RETRO_VFS_FILE_ACCESS_WRITE, 0);
unsigned char point = 0;
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
if (!file)
{
RARCH_ERR("[CDROM]: Error opening file for writing: %s\n", output_file);
task_set_progress(task, 100);
task_free_title(task);
task_set_title(task, strdup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FILE_WRITE_OPEN_FAILED)));
return;
}
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
for (point = 1; point <= state->toc->num_tracks; point++)
{
const char *track_type = "MODE1/2352";
char track_filename[PATH_MAX_LENGTH];
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
state->disc_total_bytes += state->toc->track[point - 1].track_bytes;
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
track_filename[0] = '\0';
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
if (state->toc->track[point - 1].audio)
track_type = "AUDIO";
else if (state->toc->track[point - 1].mode == 1)
track_type = "MODE1/2352";
else if (state->toc->track[point - 1].mode == 2)
track_type = "MODE2/2352";
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
snprintf(track_filename, sizeof(track_filename), "%s (Track %02d).bin", state->title, point);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
filestream_printf(file, "FILE \"%s\" BINARY\n", track_filename);
filestream_printf(file, " TRACK %02d %s\n", point, track_type);
2019-07-08 15:32:12 -04:00
{
2020-01-20 05:06:51 +01:00
unsigned pregap_lba_len = state->toc->track[point - 1].lba - state->toc->track[point - 1].lba_start;
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
if (state->toc->track[point - 1].audio && pregap_lba_len > 0)
{
unsigned char min = 0;
unsigned char sec = 0;
unsigned char frame = 0;
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
cdrom_lba_to_msf(pregap_lba_len, &min, &sec, &frame);
filestream_printf(file, " INDEX 00 00:00:00\n");
filestream_printf(file, " INDEX 01 %02u:%02u:%02u\n", (unsigned)min, (unsigned)sec, (unsigned)frame);
}
else
filestream_printf(file, " INDEX 01 00:00:00\n");
2019-07-08 15:32:12 -04:00
}
}
2020-01-20 05:06:51 +01:00
filestream_close(file);
}
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
state->file = NULL;
state->state = DUMP_STATE_NEXT_TRACK;
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
free(cue_data);
}
break;
2019-07-08 15:32:12 -04:00
case DUMP_STATE_NEXT_TRACK:
{
2020-01-20 05:06:51 +01:00
/* no file is open as we either just started or just finished a track, need to start dumping the next track */
state->cur_track++;
/* no more tracks to dump, we're done */
if (state->toc && state->cur_track > state->toc->num_tracks)
{
task_set_progress(task, 100);
return;
}
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
RARCH_LOG("[CDROM]: Dumping track %d...\n", state->cur_track);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
memset(state->cdrom_path, 0, sizeof(state->cdrom_path));
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
cdrom_device_fillpath(state->cdrom_path, sizeof(state->cdrom_path), state->drive_letter[0], state->cur_track, false);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
state->track_written_bytes = 0;
state->file = filestream_open(state->cdrom_path, RETRO_VFS_FILE_ACCESS_READ, 0);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
/* open a new file for writing for this next track */
if (state->file)
{
char output_path[PATH_MAX_LENGTH];
char track_filename[PATH_MAX_LENGTH];
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
output_path[0] = track_filename[0] = '\0';
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
snprintf(track_filename, sizeof(track_filename), "%s (Track %02d).bin", state->title, state->cur_track);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
state->cur_track_bytes = filestream_get_size(state->file);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
fill_pathname_join(output_path,
directory_core_assets, track_filename, sizeof(output_path));
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
state->output_file = filestream_open(output_path, RETRO_VFS_FILE_ACCESS_WRITE, 0);
2019-07-08 15:32:12 -04:00
2020-01-20 05:06:51 +01:00
if (!state->output_file)
{
RARCH_ERR("[CDROM]: Error opening file for writing: %s\n", output_path);
task_set_progress(task, 100);
task_free_title(task);
task_set_title(task, strdup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FILE_WRITE_OPEN_FAILED)));
return;
}
}
else
2019-07-08 15:32:12 -04:00
{
2020-01-20 05:06:51 +01:00
RARCH_ERR("[CDROM]: Error opening file for writing: %s\n", state->cdrom_path);
2019-07-08 15:32:12 -04:00
task_set_progress(task, 100);
task_free_title(task);
task_set_title(task, strdup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FILE_WRITE_OPEN_FAILED)));
return;
}
2020-01-20 05:06:51 +01:00
state->state = DUMP_STATE_READ_TRACK;
}
break;
2019-07-08 15:32:12 -04:00
case DUMP_STATE_READ_TRACK:
/* read data from track and write it to a file in chunks */
if (state->cur_track_bytes > state->track_written_bytes)
{
char data[2352 * 2] = {0};
2020-01-20 05:06:51 +01:00
int64_t read_bytes = filestream_read(state->file, data, sizeof(data));
int progress = 0;
2019-07-08 15:32:12 -04:00
if (read_bytes <= 0)
{
task_set_progress(task, 100);
task_free_title(task);
2019-07-09 11:17:10 -04:00
task_set_title(task, strdup(msg_hash_to_str(MSG_DISC_DUMP_FAILED_TO_READ_FROM_DRIVE)));
2019-07-08 15:32:12 -04:00
return;
}
state->track_written_bytes += read_bytes;
state->disc_read_bytes += read_bytes;
progress = (state->disc_read_bytes / (double)state->disc_total_bytes) * 100.0;
#ifdef CDROM_DEBUG
2019-07-10 20:56:23 -04:00
RARCH_LOG("[CDROM]: Read %" PRId64 " bytes, totalling %" PRId64 " of %" PRId64 " bytes. Progress: %d%%\n", read_bytes, state->track_written_bytes, state->cur_track_bytes, progress);
2019-07-08 15:32:12 -04:00
#endif
if (filestream_write(state->output_file, data, read_bytes) <= 0)
{
task_set_progress(task, 100);
task_free_title(task);
2019-07-09 11:17:10 -04:00
task_set_title(task, strdup(msg_hash_to_str(MSG_DISC_DUMP_FAILED_TO_WRITE_TO_DISK)));
2019-07-08 15:32:12 -04:00
return;
}
task_set_progress(task, progress);
}
else if (state->cur_track_bytes == state->track_written_bytes)
{
/* TODO: FIXME: this stops after only the first track */
if (state->file)
{
filestream_close(state->file);
state->file = NULL;
}
if (state->output_file)
{
filestream_close(state->output_file);
state->file = NULL;
}
state->state = DUMP_STATE_NEXT_TRACK;
}
break;
}
}
static void task_cdrom_dump_callback(retro_task_t *task,
void *task_data,
void *user_data, const char *error)
{
task_cdrom_dump_state_t *state = (task_cdrom_dump_state_t*)task->state;
if (state)
free(state);
}
void task_push_cdrom_dump(const char *drive)
{
2020-01-20 05:06:51 +01:00
retro_task_t *task = task_init();
2019-07-08 15:32:12 -04:00
task_cdrom_dump_state_t *state = (task_cdrom_dump_state_t*)calloc(1, sizeof(*state));
2020-01-20 05:06:51 +01:00
state->drive_letter[0] = drive[0];
state->next = true;
state->cur_track = 0;
state->state = DUMP_STATE_TOC_PENDING;
2019-07-08 15:32:12 -04:00
fill_str_dated_filename(state->title, "cdrom", NULL, sizeof(state->title));
2020-01-20 05:06:51 +01:00
task->state = state;
task->handler = task_cdrom_dump_handler;
task->callback = task_cdrom_dump_callback;
task->title = strdup(msg_hash_to_str(MSG_DUMPING_DISC));
2019-07-08 15:32:12 -04:00
2019-07-10 20:56:23 -04:00
RARCH_LOG("[CDROM]: Starting disc dump...\n");
2019-07-08 15:32:12 -04:00
task_queue_push(task);
}
#endif
static int64_t content_file_read(const char *path, void **buf, int64_t *length)
2016-05-16 16:42:33 +02:00
{
#ifdef HAVE_COMPRESSION
2020-01-20 05:06:51 +01:00
if ( path_contains_compressed_file(path)
&& file_archive_compressed_read(path, buf, NULL, length))
return 1;
2016-05-16 16:42:33 +02:00
#endif
return filestream_read_file(path, buf, length);
2016-05-16 16:42:33 +02:00
}
/**
* 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)
{
int i;
*argc = 0;
argv[(*argc)++] = strdup("retroarch");
if (args->content_path)
2016-05-16 16:42:33 +02:00
{
2020-06-08 19:11:43 +02:00
RARCH_LOG("[CORE]: Using content: %s.\n", args->content_path);
argv[(*argc)++] = strdup(args->content_path);
}
2016-05-16 16:42:33 +02:00
#ifdef HAVE_MENU
else
{
2020-06-08 19:11:43 +02:00
RARCH_LOG("[CORE]: %s\n",
msg_hash_to_str(MSG_NO_CONTENT_STARTING_DUMMY_CORE));
argv[(*argc)++] = strdup("--menu");
2016-05-16 16:42:33 +02:00
}
#endif
2016-05-16 16:42:33 +02:00
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");
for (i = 0; i < *argc; i++)
2020-06-08 19:11:43 +02:00
RARCH_LOG("[CORE]: Arg #%d: %s\n", i, argv[i]);
2016-05-16 16:42:33 +02:00
}
/**
* 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,
2016-05-16 16:42:33 +02:00
* otherwise true (1).
**/
2020-03-12 07:14:44 +01:00
static bool content_load(content_ctx_info_t *info,
content_state_t *p_content)
2016-05-16 16:42:33 +02:00
{
unsigned i = 0;
2016-05-16 16:42:33 +02:00
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 = NULL;
2020-01-20 05:06:51 +01:00
if (!(wrap_args = (struct rarch_main_wrap*)
2020-06-24 19:35:07 +02:00
malloc(sizeof(*wrap_args))))
2016-05-16 16:42:33 +02:00
return false;
retro_assert(wrap_args);
2020-06-24 19:35:07 +02:00
wrap_args->argv = NULL;
wrap_args->content_path = NULL;
wrap_args->sram_path = NULL;
wrap_args->state_path = NULL;
wrap_args->config_path = NULL;
wrap_args->libretro_path = NULL;
wrap_args->verbose = false;
wrap_args->no_content = false;
wrap_args->touched = false;
wrap_args->argc = 0;
2016-05-16 16:42:33 +02:00
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))
{
for (i = 0; i < ARRAY_SIZE(argv_copy); i++)
free(argv_copy[i]);
free(wrap_args);
return false;
2016-05-16 16:42:33 +02:00
}
2018-02-11 00:14:40 -05:00
if (p_content->pending_subsystem_init)
2018-02-11 10:00:08 -05:00
{
2018-02-11 15:18:40 -05:00
command_event(CMD_EVENT_CORE_INIT, NULL);
2018-02-11 10:00:08 -05:00
content_clear_subsystem();
2018-02-11 00:14:40 -05:00
}
2016-05-16 16:42:33 +02:00
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
menu_shader_manager_init();
#endif
2019-01-06 23:03:28 -05:00
2016-05-16 16:42:33 +02:00
command_event(CMD_EVENT_HISTORY_INIT, NULL);
rarch_favorites_init();
2016-05-16 16:42:33 +02:00
command_event(CMD_EVENT_RESUME, NULL);
command_event(CMD_EVENT_VIDEO_SET_ASPECT_RATIO, NULL);
2016-09-19 00:56:00 +02:00
dir_check_defaults();
2016-05-16 16:42:33 +02:00
frontend_driver_process_args(rarch_argc_ptr, rarch_argv_ptr);
frontend_driver_content_loaded();
for (i = 0; i < ARRAY_SIZE(argv_copy); i++)
free(argv_copy[i]);
free(wrap_args);
return true;
2016-05-16 16:42:33 +02:00
}
/**
2016-09-21 04:09:24 +02:00
* load_content_into_memory:
2016-05-16 16:42:33 +02:00
* @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.
**/
2017-01-23 21:03:12 +01:00
static bool load_content_into_memory(
content_information_ctx_t *content_ctx,
2020-03-12 07:14:44 +01:00
content_state_t *p_content,
2017-01-23 21:03:12 +01:00
unsigned i, const char *path, void **buf,
int64_t *length)
2016-05-16 16:42:33 +02:00
{
uint8_t *ret_buf = NULL;
2016-05-16 16:42:33 +02:00
2020-06-08 19:11:43 +02:00
RARCH_LOG("[CONTENT LOAD]: %s: %s.\n",
2016-05-16 16:42:33 +02:00
msg_hash_to_str(MSG_LOADING_CONTENT_FILE), path);
2017-05-14 04:50:57 +02:00
2016-05-16 16:42:33 +02:00
if (!content_file_read(path, (void**) &ret_buf, length))
return false;
if (*length < 0)
return false;
2016-09-21 04:03:31 +02:00
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)
{
#ifdef HAVE_PATCH
bool has_patch = false;
/* First content file is significant, attempt to do patching,
* CRC checking, etc. */
/* Attempt to apply a patch. */
if (!content_ctx->patch_is_blocked)
has_patch = 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);
if (has_patch)
{
p_content->rom_crc = encoding_crc32(0, ret_buf, (size_t)*length);
2020-06-08 19:11:43 +02:00
RARCH_LOG("[CONTENT LOAD]: CRC32: 0x%x .\n", (unsigned)p_content->rom_crc);
}
else
#endif
{
strlcpy(p_content->pending_rom_crc_path,
path, sizeof(p_content->pending_rom_crc_path));
2020-03-12 07:29:04 +01:00
p_content->pending_rom_crc = true;
}
}
else
p_content->rom_crc = 0;
2016-09-21 04:03:31 +02:00
}
2016-05-16 16:42:33 +02:00
*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,
2016-05-16 16:42:33 +02:00
struct string_list* additional_path_allocs,
bool need_fullpath,
const char *path,
2016-12-27 01:32:58 +01:00
char **error_string)
2016-05-16 16:42:33 +02:00
{
union string_list_elem_attr attributes;
int64_t new_path_len = 0;
2018-10-29 04:48:22 +01:00
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';
2017-02-23 21:49:51 +01:00
new_basedir[0] = '\0';
attributes.i = 0;
2020-06-08 18:58:18 +02:00
RARCH_LOG("[CONTENT LOAD]: Compressed file in case of need_fullpath."
2016-05-16 16:42:33 +02:00
" Now extracting to temporary directory.\n");
2017-02-21 20:30:52 +01:00
if (!string_is_empty(content_ctx->directory_cache))
2018-10-29 04:48:22 +01:00
strlcpy(new_basedir, content_ctx->directory_cache, new_basedir_size);
2016-05-16 16:42:33 +02:00
if (!path_is_directory(new_basedir))
2016-05-16 16:42:33 +02:00
{
2020-06-08 18:58:18 +02:00
RARCH_WARN("[CONTENT LOAD]: Tried extracting to cache directory, but "
2016-05-16 16:42:33 +02:00
"cache directory was not set or found. "
"Setting cache directory to directory "
"derived by basename...\n");
2018-10-29 04:48:22 +01:00
fill_pathname_basedir(new_basedir, path, new_basedir_size);
2016-05-16 16:42:33 +02:00
}
new_path[0] = '\0';
new_basedir[0] = '\0';
2016-10-09 09:56:03 +02:00
2016-05-16 16:42:33 +02:00
fill_pathname_join(new_path, new_basedir,
2018-10-29 04:48:22 +01:00
path_basename(path), new_path_size);
free(new_basedir);
2016-05-16 16:42:33 +02:00
2019-05-31 09:20:37 +02:00
if (!file_archive_compressed_read(path,
NULL, new_path, &new_path_len) || new_path_len < 0)
2016-05-16 16:42:33 +02:00
{
2018-10-29 04:43:05 +01:00
size_t path_size = 1024 * sizeof(char);
char *str = (char*)malloc(path_size);
snprintf(str,
2018-10-29 04:43:05 +01:00
path_size,
"%s \"%s\".\n",
2016-05-16 16:42:33 +02:00
msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE),
path);
2016-12-27 01:32:58 +01:00
*error_string = strdup(str);
free(str);
free(new_path);
return false;
2016-05-16 16:42:33 +02:00
}
string_list_append(additional_path_allocs, new_path, attributes);
info[i].path =
additional_path_allocs->elems[additional_path_allocs->size - 1].data;
2016-05-16 16:42:33 +02:00
if (!string_list_append(content_ctx->temporary_content,
new_path, attributes))
{
free(new_path);
return false;
}
2016-05-16 16:42:33 +02:00
free(new_path);
2016-05-16 16:42:33 +02:00
return true;
}
2016-09-19 00:56:58 +02:00
2018-10-29 04:59:54 +01:00
/* Try to extract all content we're going to load if appropriate. */
static bool content_file_init_extract(
2016-09-19 00:56:58 +02:00
struct string_list *content,
content_information_ctx_t *content_ctx,
2016-09-19 00:56:58 +02:00
const struct retro_subsystem_info *special,
2018-10-29 04:59:54 +01:00
char **error_string,
union string_list_elem_attr *attr
2016-09-19 00:56:58 +02:00
)
{
unsigned i;
2017-09-27 23:55:54 +02:00
char *new_path = NULL;
2016-09-19 00:56:58 +02:00
for (i = 0; i < content->size; i++)
{
bool block_extract = content->elems[i].attr.i & 1;
2016-12-21 15:23:31 +01:00
const char *path = content->elems[i].data;
2016-12-21 15:27:08 +01:00
bool contains_compressed = path_contains_compressed_file(path);
2016-09-19 00:56:58 +02:00
/* Block extract check. */
if (block_extract)
2016-09-19 00:56:58 +02:00
continue;
2016-12-21 15:31:55 +01:00
/* just use the first file in the archive */
if (!contains_compressed && !path_is_compressed_file(path))
continue;
2016-09-19 00:56:58 +02:00
{
2018-10-29 04:48:22 +01:00
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;
2018-10-29 04:48:22 +01:00
new_path = (char*)malloc(new_path_size);
2017-09-27 23:55:54 +02:00
temp_content[0] = new_path[0] = '\0';
2017-12-28 05:56:45 +01:00
if (!string_is_empty(path))
2018-10-29 04:48:22 +01:00
strlcpy(temp_content, path, temp_content_size);
if (!valid_ext || !file_archive_extract_file(
temp_content,
2018-10-29 04:48:22 +01:00
temp_content_size,
valid_ext,
!string_is_empty(content_ctx->directory_cache) ?
content_ctx->directory_cache : NULL,
new_path,
2018-10-29 04:48:22 +01:00
new_path_size
))
{
2018-10-29 04:43:05 +01:00
size_t path_size = 1024 * sizeof(char);
char *str = (char*)malloc(path_size);
2018-10-29 04:43:05 +01:00
snprintf(str, path_size,
"%s: %s.\n",
msg_hash_to_str(
MSG_FAILED_TO_EXTRACT_CONTENT_FROM_COMPRESSED_FILE),
temp_content);
*error_string = strdup(str);
free(temp_content);
free(str);
free(new_path);
return false;
}
string_list_set(content, i, new_path);
2016-09-19 00:56:58 +02:00
free(temp_content);
2016-12-21 15:27:08 +01:00
{
2020-03-12 07:29:04 +01:00
bool append_success = string_list_append(
content_ctx->temporary_content,
new_path, *attr);
2019-05-29 16:35:51 +02:00
free(new_path);
2019-05-29 16:35:51 +02:00
if (!append_success)
return false;
}
}
2016-09-19 00:56:58 +02:00
}
return true;
}
2016-05-16 16:42:33 +02:00
#endif
/**
2016-12-20 22:35:59 +01:00
* content_file_load:
2016-05-16 16:42:33 +02:00
* @special : subsystem of content to be loaded. Can be NULL.
* content :
*
* Load content file (for libretro core).
*
* Returns : true if successful, otherwise false.
**/
2016-12-20 22:35:59 +01:00
static bool content_file_load(
2016-05-16 16:42:33 +02:00
struct retro_game_info *info,
2020-03-12 07:14:44 +01:00
content_state_t *p_content,
2016-05-16 16:42:33 +02:00
const struct string_list *content,
content_information_ctx_t *content_ctx,
2016-12-27 01:32:58 +01:00
char **error_string,
2017-05-14 05:06:01 +02:00
const struct retro_subsystem_info *special,
struct string_list *additional_path_allocs
2016-05-16 16:42:33 +02:00
)
{
unsigned i;
retro_ctx_load_content_info_t load_info;
bool used_vfs_fallback_copy = false;
2019-01-31 21:24:13 +01:00
#ifdef __WINRT__
rarch_system_info_t *system = runloop_get_system_info();
#endif
2016-05-16 16:42:33 +02:00
for (i = 0; i < content->size; i++)
{
int attr = content->elems[i].attr.i;
const char *path = content->elems[i].data;
2016-05-16 16:42:33 +02:00
bool need_fullpath = attr & 2;
bool require_content = attr & 4;
2019-05-23 11:48:32 +02:00
bool path_empty = string_is_empty(path);
2016-05-16 16:42:33 +02:00
2019-05-23 11:48:32 +02:00
if (require_content && path_empty)
2016-05-16 16:42:33 +02:00
{
*error_string = strdup(msg_hash_to_str(MSG_ERROR_LIBRETRO_CORE_REQUIRES_CONTENT));
return false;
2016-05-16 16:42:33 +02:00
}
info[i].path = NULL;
2019-05-23 11:48:32 +02:00
if (!path_empty)
2016-05-16 16:42:33 +02:00
info[i].path = path;
2019-05-23 11:48:32 +02:00
if (!need_fullpath && !path_empty)
2016-05-16 16:42:33 +02:00
{
2016-09-21 04:09:24 +02:00
/* Load the content into memory. */
int64_t len = 0;
2017-01-23 21:03:12 +01:00
if (!load_content_into_memory(
2020-03-12 07:14:44 +01:00
content_ctx, p_content,
2017-01-23 21:03:12 +01:00
i, path, (void**)&info[i].data, &len))
2016-09-21 04:09:24 +02:00
{
size_t msg_size = 1024 * sizeof(char);
char *msg = (char*)malloc(msg_size);
msg[0] = '\0';
snprintf(msg,
msg_size,
"%s \"%s\".\n",
2016-09-21 04:09:24 +02:00
msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE),
path);
2016-12-27 01:32:58 +01:00
*error_string = strdup(msg);
free(msg);
return false;
2016-09-21 04:09:24 +02:00
}
info[i].size = len;
2016-05-16 16:42:33 +02:00
}
else
{
#ifdef HAVE_COMPRESSION
if ( !content_ctx->block_extract
&& need_fullpath
&& path_contains_compressed_file(path)
&& !load_content_from_compressed_archive(
content_ctx,
2016-05-16 16:42:33 +02:00
&info[i], i,
additional_path_allocs, need_fullpath, path,
error_string))
return false;
2016-05-16 16:42:33 +02:00
#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 && !is_path_accessible_using_standard_io(path))
{
/* Fallback to a file copy into an accessible directory */
char* buf;
int64_t len;
2019-01-31 21:24:13 +01:00
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;
2020-06-08 18:58:18 +02:00
RARCH_LOG("[CONTENT LOAD]: 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) || !is_path_accessible_using_standard_io(new_basedir))
{
2020-06-08 18:58:18 +02:00
RARCH_WARN("[CONTENT LOAD]: 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);
2019-05-22 10:23:34 +02:00
free(new_basedir);
2019-02-03 15:49:35 -08:00
/* TODO: This may fail on very large files...
2019-01-31 21:24:13 +01:00
* but copying large files is not a good idea anyway */
if (!filestream_read_file(path, &buf, &len))
{
size_t msg_size = 1024 * sizeof(char);
char *msg = (char*)malloc(msg_size);
msg[0] = '\0';
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);
free(msg);
return false;
}
if (!filestream_write_file(new_path, buf, len))
{
size_t msg_size = 1024 * sizeof(char);
char *msg = (char*)malloc(msg_size);
msg[0] = '\0';
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);
free(msg);
return false;
}
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_path);
used_vfs_fallback_copy = true;
}
#endif
2020-06-08 18:58:18 +02:00
RARCH_LOG("[CONTENT LOAD]: %s\n", msg_hash_to_str(
2019-01-31 21:24:13 +01:00
MSG_CONTENT_LOADING_SKIPPED_IMPLEMENTATION_WILL_DO_IT));
strlcpy(p_content->pending_rom_crc_path,
path, sizeof(p_content->pending_rom_crc_path));
2020-03-12 07:29:04 +01:00
p_content->pending_rom_crc = true;
2016-05-16 16:42:33 +02:00
}
}
load_info.content = content;
load_info.special = special;
load_info.info = info;
if (!core_load_game(&load_info))
{
2019-02-03 15:49:35 -08:00
/* This is probably going to fail on multifile ROMs etc.
2019-01-31 21:24:13 +01:00
* so give a visible explanation of what is likely wrong */
if (used_vfs_fallback_copy)
*error_string = strdup(msg_hash_to_str(
MSG_ERROR_LIBRETRO_CORE_REQUIRES_VFS));
else
*error_string = strdup(msg_hash_to_str(
MSG_FAILED_TO_LOAD_CONTENT));
2019-01-31 21:24:13 +01:00
return false;
2016-05-16 16:42:33 +02:00
}
#ifdef HAVE_CHEEVOS
if (!special)
{
const char *content_path = content->elems[0].data;
enum rarch_content_type type = path_is_media_type(content_path);
if (type == RARCH_CONTENT_NONE && !string_is_empty(content_path))
2019-05-29 14:26:22 -03:00
rcheevos_load(info);
else
rcheevos_hardcore_paused = true;
}
else
rcheevos_hardcore_paused = true;
2016-05-16 16:42:33 +02:00
#endif
return true;
}
static const struct
retro_subsystem_info *content_file_init_subsystem(
2018-10-29 04:04:03 +01:00
const struct retro_subsystem_info *subsystem_data,
size_t subsystem_current_count,
2016-12-27 01:32:58 +01:00
char **error_string,
bool *ret)
2016-05-16 16:42:33 +02:00
{
size_t path_size = 1024 * sizeof(char);
char *msg = (char*)malloc(path_size);
2016-09-25 15:49:09 +02:00
struct string_list *subsystem = path_get_subsystem_list();
2016-12-20 23:39:31 +01:00
const struct retro_subsystem_info *special = libretro_find_subsystem_info(
2019-06-22 13:44:10 +02:00
subsystem_data, (unsigned)subsystem_current_count,
path_get(RARCH_PATH_SUBSYSTEM));
2016-05-16 16:42:33 +02:00
msg[0] = '\0';
2016-05-16 16:42:33 +02:00
if (!special)
{
snprintf(msg, path_size,
2016-05-16 16:42:33 +02:00
"Failed to find subsystem \"%s\" in libretro implementation.\n",
2016-09-29 08:23:41 +02:00
path_get(RARCH_PATH_SUBSYSTEM));
2016-12-27 01:32:58 +01:00
*error_string = strdup(msg);
goto error;
2016-05-16 16:42:33 +02:00
}
2016-09-25 15:49:09 +02:00
if (special->num_roms && !subsystem)
2016-05-16 16:42:33 +02:00
{
strlcpy(msg,
msg_hash_to_str(MSG_ERROR_LIBRETRO_CORE_REQUIRES_SPECIAL_CONTENT),
path_size
);
*error_string = strdup(msg);
goto error;
2016-05-16 16:42:33 +02:00
}
2016-09-25 15:49:09 +02:00
else if (special->num_roms && (special->num_roms != subsystem->size))
2016-05-16 16:42:33 +02:00
{
snprintf(msg,
path_size,
2016-12-21 00:19:22 +01:00
"Libretro core requires %u content files for "
2016-05-16 16:42:33 +02:00
"subsystem \"%s\", but %u content files were provided.\n",
special->num_roms, special->desc,
2016-09-25 15:49:09 +02:00
(unsigned)subsystem->size);
2016-12-27 01:32:58 +01:00
*error_string = strdup(msg);
goto error;
2016-05-16 16:42:33 +02:00
}
2016-09-25 15:49:09 +02:00
else if (!special->num_roms && subsystem && subsystem->size)
2016-05-16 16:42:33 +02:00
{
snprintf(msg,
path_size,
2016-12-21 00:19:22 +01:00
"Libretro core takes no content for subsystem \"%s\", "
2016-05-16 16:42:33 +02:00
"but %u content files were provided.\n",
special->desc,
2016-09-25 15:49:09 +02:00
(unsigned)subsystem->size);
2016-12-27 01:32:58 +01:00
*error_string = strdup(msg);
goto error;
2016-05-16 16:42:33 +02:00
}
*ret = true;
free(msg);
2016-05-16 16:42:33 +02:00
return special;
error:
*ret = false;
free(msg);
return NULL;
2016-05-16 16:42:33 +02:00
}
2018-10-29 04:59:54 +01:00
static void content_file_init_set_attribs(
2016-05-16 16:42:33 +02:00
struct string_list *content,
const struct retro_subsystem_info *special,
content_information_ctx_t *content_ctx,
2018-10-29 04:59:54 +01:00
char **error_string,
union string_list_elem_attr *attr)
2016-05-16 16:42:33 +02:00
{
2016-09-25 15:49:09 +02:00
struct string_list *subsystem = path_get_subsystem_list();
2016-05-16 16:42:33 +02:00
2018-10-29 04:59:54 +01:00
attr->i = 0;
2016-05-16 16:42:33 +02:00
2016-09-30 04:43:16 +02:00
if (!path_is_empty(RARCH_PATH_SUBSYSTEM) && special)
2016-05-16 16:42:33 +02:00
{
unsigned i;
2016-09-25 15:49:09 +02:00
for (i = 0; i < subsystem->size; i++)
2016-05-16 16:42:33 +02:00
{
2018-10-29 04:59:54 +01:00
attr->i = special->roms[i].block_extract;
attr->i |= special->roms[i].need_fullpath << 1;
attr->i |= special->roms[i].required << 2;
2016-05-16 16:42:33 +02:00
2018-10-29 04:59:54 +01:00
string_list_append(content, subsystem->elems[i].data, *attr);
2016-05-16 16:42:33 +02:00
}
}
else
{
2019-04-21 05:33:41 +02:00
bool contentless = false;
bool is_inited = false;
bool content_path_is_empty = path_is_empty(RARCH_PATH_CONTENT);
2017-01-25 15:44:21 +01:00
content_get_status(&contentless, &is_inited);
2017-01-25 15:44:21 +01:00
2018-10-29 04:59:54 +01:00
attr->i = content_ctx->block_extract;
attr->i |= content_ctx->need_fullpath << 1;
attr->i |= (!contentless) << 2;
2016-05-16 16:42:33 +02:00
2019-04-21 05:33:41 +02:00
if (content_path_is_empty
&& contentless
&& content_ctx->set_supports_no_game_enable)
2018-10-29 04:59:54 +01:00
string_list_append(content, "", *attr);
2019-04-21 05:33:41 +02:00
else if (!content_path_is_empty)
string_list_append(content, path_get(RARCH_PATH_CONTENT), *attr);
2016-05-16 16:42:33 +02:00
}
}
/**
* content_init_file:
*
* Initializes and loads a content file for the currently
* selected libretro core.
*
* Returns : true if successful, otherwise false.
**/
2016-12-21 15:21:11 +01:00
static bool content_file_init(
content_information_ctx_t *content_ctx,
2020-03-12 07:14:44 +01:00
content_state_t *p_content,
2017-05-14 20:23:10 +02:00
struct string_list *content,
2016-12-27 01:32:58 +01:00
char **error_string)
2016-05-16 16:42:33 +02:00
{
2018-10-29 04:59:54 +01:00
union string_list_elem_attr attr;
2016-05-16 16:42:33 +02:00
struct retro_game_info *info = NULL;
2019-04-21 05:33:41 +02:00
bool subsystem_path_is_empty = path_is_empty(RARCH_PATH_SUBSYSTEM);
bool ret = subsystem_path_is_empty;
const struct retro_subsystem_info *special =
2019-04-21 05:33:41 +02:00
subsystem_path_is_empty
? NULL : content_file_init_subsystem(content_ctx->subsystem.data,
content_ctx->subsystem.size, error_string, &ret);
2018-10-29 04:59:54 +01:00
if (!ret)
2017-05-14 04:50:57 +02:00
return false;
2016-05-16 16:42:33 +02:00
2018-10-29 04:59:54 +01:00
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)
2018-05-28 10:58:04 -05:00
info = (struct retro_game_info*)
calloc(content->size, sizeof(*info));
2016-05-16 16:42:33 +02:00
2016-09-29 12:02:45 +02:00
if (info)
2016-09-29 19:24:18 +02:00
{
unsigned i;
2017-05-14 05:06:01 +02:00
struct string_list *additional_path_allocs = string_list_new();
2018-02-10 21:42:41 -05:00
2020-03-12 07:14:44 +01:00
ret = content_file_load(info, p_content,
content, content_ctx, error_string,
2017-05-14 05:06:01 +02:00
special, additional_path_allocs);
string_list_free(additional_path_allocs);
2016-05-16 16:42:33 +02:00
2016-09-29 19:24:18 +02:00
for (i = 0; i < content->size; i++)
free((void*)info[i].data);
2016-05-16 16:42:33 +02:00
free(info);
2016-09-29 19:24:18 +02:00
}
2018-10-29 04:59:54 +01:00
else if (!special)
{
*error_string = strdup(msg_hash_to_str(MSG_ERROR_LIBRETRO_CORE_REQUIRES_CONTENT));
ret = false;
}
2016-05-16 16:42:33 +02:00
return ret;
}
void menu_content_environment_get(int *argc, char *argv[],
void *args, void *params_data);
2016-05-17 07:53:38 +02:00
2016-05-16 15:09:04 +02:00
/**
* task_push_to_history_list:
2016-05-16 15:09:04 +02:00
*
* Will push the content entry to the history playlist.
2016-05-16 15:09:04 +02:00
**/
static void task_push_to_history_list(
2020-03-12 07:14:44 +01:00
content_state_t *p_content,
bool launched_from_menu,
bool launched_from_cli,
bool launched_from_companion_ui)
2016-05-16 15:09:04 +02:00
{
bool contentless = false;
bool is_inited = false;
2016-10-09 09:56:03 +02:00
content_get_status(&contentless, &is_inited);
/* Push entry to top of history playlist */
if (is_inited || contentless)
{
2018-10-29 04:48:22 +01:00
size_t tmp_size = PATH_MAX_LENGTH * sizeof(char);
char *tmp = (char*)malloc(tmp_size);
2017-12-28 05:56:45 +01:00
const char *path_content = path_get(RARCH_PATH_CONTENT);
2018-10-30 08:21:32 +01:00
struct retro_system_info *info = runloop_get_libretro_system_info();
2016-10-09 09:56:03 +02:00
tmp[0] = '\0';
2017-12-28 05:56:45 +01:00
if (!string_is_empty(path_content))
2018-10-29 04:48:22 +01:00
strlcpy(tmp, path_content, tmp_size);
2019-05-23 11:48:32 +02:00
/* Path can be relative here.
* Ensure we're pushing absolute path. */
if (!launched_from_menu && !string_is_empty(tmp))
path_resolve_realpath(tmp, tmp_size, true);
#ifdef HAVE_MENU
/* Push quick menu onto menu stack */
if (launched_from_cli)
menu_driver_ctl(RARCH_MENU_CTL_SET_PENDING_QUICK_MENU, NULL);
#endif
2016-12-21 00:06:34 +01:00
if (info && !string_is_empty(tmp))
{
2016-12-21 00:06:34 +01:00
const char *core_path = NULL;
const char *core_name = NULL;
const char *label = NULL;
const char *crc32 = NULL;
const char *db_name = NULL;
playlist_t *playlist_hist = g_defaults.content_history;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
2016-07-30 21:27:40 +02:00
switch (path_is_media_type(tmp))
2016-07-30 22:57:32 +02:00
{
case RARCH_CONTENT_MOVIE:
2016-07-30 22:57:32 +02:00
#ifdef HAVE_FFMPEG
playlist_hist = g_defaults.video_history;
2016-12-21 00:06:34 +01:00
core_name = "movieplayer";
core_path = "builtin";
#endif
break;
case RARCH_CONTENT_MUSIC:
playlist_hist = g_defaults.music_history;
2016-12-21 00:06:34 +01:00
core_name = "musicplayer";
core_path = "builtin";
2016-07-30 22:57:32 +02:00
break;
case RARCH_CONTENT_IMAGE:
2016-07-30 22:57:32 +02:00
#ifdef HAVE_IMAGEVIEWER
playlist_hist = g_defaults.image_history;
2016-12-21 00:06:34 +01:00
core_name = "imageviewer";
core_path = "builtin";
2016-07-30 22:57:32 +02:00
#endif
break;
default:
{
core_info_t *core_info = NULL;
/* Set core display name
* (As far as I can tell, core_info_get_current_core()
* should always provide a valid pointer here...) */
core_info_get_current_core(&core_info);
2019-07-14 18:52:51 +02:00
/* Set core path */
core_path = path_get(RARCH_PATH_CORE);
if (core_info)
core_name = core_info->display_name;
if (string_is_empty(core_name))
core_name = info->library_name;
if (launched_from_companion_ui)
{
/* Database name + checksum are supplied
* by the companion UI itself */
if (!string_is_empty(p_content->companion_ui_crc32))
crc32 = p_content->companion_ui_crc32;
if (!string_is_empty(p_content->companion_ui_db_name))
db_name = p_content->companion_ui_db_name;
}
#ifdef HAVE_MENU
else
{
2019-08-16 15:17:02 +02:00
menu_handle_t *menu = menu_driver_get_ptr();
2019-07-14 18:52:51 +02:00
/* Set database name + checksum */
2019-08-16 15:17:02 +02:00
if (menu)
{
2019-07-14 18:52:51 +02:00
playlist_t *playlist_curr = playlist_get_cached();
if (playlist_index_is_valid(playlist_curr, menu->rpl_entry_selection_ptr, tmp, core_path))
{
playlist_get_crc32(playlist_curr, menu->rpl_entry_selection_ptr, &crc32);
playlist_get_db_name(playlist_curr, menu->rpl_entry_selection_ptr, &db_name);
}
}
}
#endif
2016-07-30 22:57:32 +02:00
break;
}
2016-07-30 22:57:32 +02:00
}
if (global && !string_is_empty(global->name.label))
label = global->name.label;
if (
settings && settings->bools.history_list_enable
&& playlist_hist)
{
char subsystem_name[PATH_MAX_LENGTH];
struct playlist_entry entry = {0};
subsystem_name[0] = '\0';
content_get_subsystem_friendly_name(path_get(RARCH_PATH_SUBSYSTEM), subsystem_name, sizeof(subsystem_name));
/* the push function reads our entry as const, so these casts are safe */
2019-05-22 10:27:46 +02:00
entry.path = (char*)tmp;
entry.label = (char*)label;
entry.core_path = (char*)core_path;
entry.core_name = (char*)core_name;
entry.crc32 = (char*)crc32;
entry.db_name = (char*)db_name;
2019-06-22 14:25:32 +02:00
entry.subsystem_ident = (char*)path_get(RARCH_PATH_SUBSYSTEM);
2019-05-22 10:27:46 +02:00
entry.subsystem_name = (char*)subsystem_name;
entry.subsystem_roms = (struct string_list*)path_get_subsystem_list();
2020-06-26 15:39:03 +01:00
command_playlist_push_write(playlist_hist, &entry);
}
}
free(tmp);
2016-05-16 15:09:04 +02:00
}
}
#ifdef HAVE_MENU
2020-03-12 07:14:44 +01:00
static bool command_event_cmd_exec(
content_state_t *p_content,
const char *data,
content_information_ctx_t *content_ctx,
bool launched_from_cli,
2016-12-27 01:32:58 +01:00
char **error_string)
{
2016-05-26 06:41:28 +02:00
#if defined(HAVE_DYNAMIC)
content_ctx_info_t content_info;
content_info.argc = 0;
content_info.argv = NULL;
content_info.args = NULL;
content_info.environ_get = menu_content_environment_get;
2016-05-17 08:02:13 +02:00
#endif
if (path_get(RARCH_PATH_CONTENT) != data)
{
2016-09-30 04:31:19 +02:00
path_clear(RARCH_PATH_CONTENT);
if (!string_is_empty(data))
2016-09-29 07:40:14 +02:00
path_set(RARCH_PATH_CONTENT, data);
}
#if defined(HAVE_DYNAMIC)
/* Loads content into currently selected core. */
2020-03-12 07:14:44 +01:00
if (!content_load(&content_info, p_content))
return false;
2020-03-12 07:14:44 +01:00
task_push_to_history_list(p_content, true, launched_from_cli, false);
#else
frontend_driver_set_fork(FRONTEND_FORK_CORE_WITH_ARGS);
#endif
return true;
}
#endif
2017-02-21 18:58:03 +01:00
static bool firmware_update_status(
content_information_ctx_t *content_ctx)
{
core_info_ctx_firmware_t firmware_info;
bool set_missing_firmware = false;
core_info_t *core_info = NULL;
size_t s_size = PATH_MAX_LENGTH * sizeof(char);
2019-05-23 11:48:32 +02:00
char *s = NULL;
core_info_get_current_core(&core_info);
if (!core_info)
2019-05-23 11:48:32 +02:00
return false;
s = (char*)malloc(s_size);
firmware_info.path = core_info->path;
2016-12-20 22:51:29 +01:00
if (!string_is_empty(content_ctx->directory_system))
firmware_info.directory.system = content_ctx->directory_system;
else
{
strlcpy(s, path_get(RARCH_PATH_CONTENT), s_size);
path_basedir_wrapper(s);
firmware_info.directory.system = s;
}
2020-06-08 19:11:43 +02:00
RARCH_LOG("[CONTENT LOAD]: Updating firmware status for: %s on %s\n",
core_info->path,
firmware_info.directory.system);
rarch_ctl(RARCH_CTL_UNSET_MISSING_BIOS, NULL);
2019-05-23 11:48:32 +02:00
core_info_list_update_missing_firmware(&firmware_info,
&set_missing_firmware);
free(s);
if (set_missing_firmware)
rarch_ctl(RARCH_CTL_SET_MISSING_BIOS, NULL);
2017-02-21 18:51:47 +01:00
2020-03-01 21:57:57 +01:00
if (
content_ctx->bios_is_missing &&
content_ctx->check_firmware_before_loading)
2017-02-21 18:51:47 +01:00
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_FIRMWARE),
2019-05-23 11:48:32 +02:00
100, 500, true, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
2020-06-08 18:58:18 +02:00
RARCH_LOG("[CONTENT LOAD]: Load content blocked. Reason: %s\n",
msg_hash_to_str(MSG_FIRMWARE));
2017-02-21 18:51:47 +01:00
return true;
}
return false;
}
2017-02-21 16:50:39 +01:00
bool task_push_start_dummy_core(content_ctx_info_t *content_info)
{
content_information_ctx_t content_ctx;
content_state_t *p_content = content_state_get_ptr();
2017-05-14 05:00:24 +02:00
bool ret = true;
char *error_string = NULL;
2017-05-14 05:00:24 +02:00
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
rarch_system_info_t *sys_info = runloop_get_system_info();
2020-03-02 20:10:24 +01:00
const char *path_dir_system = settings->paths.directory_system;
bool check_firmware_before_loading = settings->bools.check_firmware_before_loading;
if (!content_info)
return false;
2020-03-02 20:10:24 +01:00
content_ctx.check_firmware_before_loading = check_firmware_before_loading;
#ifdef HAVE_PATCH
content_ctx.is_ips_pref = rarch_ctl(RARCH_CTL_IS_IPS_PREF, NULL);
content_ctx.is_bps_pref = rarch_ctl(RARCH_CTL_IS_BPS_PREF, NULL);
content_ctx.is_ups_pref = rarch_ctl(RARCH_CTL_IS_UPS_PREF, NULL);
content_ctx.patch_is_blocked = rarch_ctl(RARCH_CTL_IS_PATCH_BLOCKED, NULL);
#endif
2017-05-15 05:06:23 +02:00
content_ctx.bios_is_missing = rarch_ctl(RARCH_CTL_IS_MISSING_BIOS, NULL);
content_ctx.directory_system = NULL;
content_ctx.directory_cache = NULL;
2017-05-14 04:52:34 +02:00
content_ctx.name_ips = NULL;
content_ctx.name_bps = NULL;
content_ctx.name_ups = NULL;
content_ctx.valid_extensions = NULL;
content_ctx.block_extract = false;
content_ctx.need_fullpath = false;
content_ctx.set_supports_no_game_enable = false;
content_ctx.subsystem.data = NULL;
content_ctx.subsystem.size = 0;
2017-05-14 05:00:24 +02:00
if (global)
{
if (!string_is_empty(global->name.ips))
content_ctx.name_ips = strdup(global->name.ips);
if (!string_is_empty(global->name.bps))
content_ctx.name_bps = strdup(global->name.bps);
if (!string_is_empty(global->name.ups))
content_ctx.name_ups = strdup(global->name.ups);
}
2020-03-02 20:10:24 +01:00
if (!string_is_empty(path_dir_system))
content_ctx.directory_system = strdup(path_dir_system);
if (!content_info->environ_get)
content_info->environ_get = menu_content_environment_get;
/* Clear content path */
path_clear(RARCH_PATH_CONTENT);
/* Preliminary stuff that has to be done before we
* load the actual content. Can differ per mode. */
sys_info->load_no_content = false;
2017-05-15 05:06:23 +02:00
rarch_ctl(RARCH_CTL_STATE_FREE, NULL);
2020-02-02 03:00:51 +01:00
task_queue_deinit();
2020-02-02 02:16:00 +01:00
retroarch_init_task_queue();
/* Loads content into currently selected core. */
2020-03-12 07:14:44 +01:00
if (!content_load(content_info, p_content))
2017-05-14 04:50:57 +02:00
{
if (error_string)
{
runloop_msg_queue_push(error_string, 2, 90, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
2020-06-08 18:58:18 +02:00
RARCH_ERR("[CONTENT LOAD]: %s\n", error_string);
2017-05-14 04:50:57 +02:00
free(error_string);
}
2017-05-14 05:00:24 +02:00
ret = false;
}
else
2020-03-12 07:14:44 +01:00
task_push_to_history_list(p_content, false, false, false);
2017-05-14 05:00:24 +02:00
if (content_ctx.name_ips)
free(content_ctx.name_ips);
if (content_ctx.name_bps)
free(content_ctx.name_bps);
if (content_ctx.name_ups)
free(content_ctx.name_ups);
if (content_ctx.directory_system)
free(content_ctx.directory_system);
2017-05-14 05:00:24 +02:00
return ret;
}
2017-02-21 18:55:11 +01:00
#ifdef HAVE_MENU
2017-02-21 18:36:38 +01:00
bool task_push_load_content_from_playlist_from_menu(
const char *core_path,
const char *fullpath,
const char *label,
content_ctx_info_t *content_info,
retro_task_callback_t cb,
void *user_data)
{
content_information_ctx_t content_ctx;
content_state_t *p_content = content_state_get_ptr();
2017-05-14 05:00:24 +02:00
bool ret = true;
char *error_string = NULL;
2017-05-14 05:00:24 +02:00
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
rarch_system_info_t *sys_info = runloop_get_system_info();
2020-03-02 20:10:24 +01:00
const char *path_dir_system = settings->paths.directory_system;
#ifndef HAVE_DYNAMIC
bool force_core_reload = settings->bools.always_reload_core_on_run_content;
#endif
2017-04-28 13:43:47 +02:00
content_ctx.check_firmware_before_loading = settings->bools.check_firmware_before_loading;
#ifdef HAVE_PATCH
content_ctx.is_ips_pref = rarch_ctl(RARCH_CTL_IS_IPS_PREF, NULL);
content_ctx.is_bps_pref = rarch_ctl(RARCH_CTL_IS_BPS_PREF, NULL);
content_ctx.is_ups_pref = rarch_ctl(RARCH_CTL_IS_UPS_PREF, NULL);
content_ctx.patch_is_blocked = rarch_ctl(RARCH_CTL_IS_PATCH_BLOCKED, NULL);
#endif
2017-05-15 05:06:23 +02:00
content_ctx.bios_is_missing = rarch_ctl(RARCH_CTL_IS_MISSING_BIOS, NULL);
content_ctx.directory_system = NULL;
content_ctx.directory_cache = NULL;
2017-05-14 04:52:34 +02:00
content_ctx.name_ips = NULL;
content_ctx.name_bps = NULL;
content_ctx.name_ups = NULL;
content_ctx.valid_extensions = NULL;
content_ctx.block_extract = false;
content_ctx.need_fullpath = false;
content_ctx.set_supports_no_game_enable = false;
content_ctx.subsystem.data = NULL;
content_ctx.subsystem.size = 0;
2017-05-14 05:00:24 +02:00
if (global)
{
if (!string_is_empty(global->name.ips))
content_ctx.name_ips = strdup(global->name.ips);
if (!string_is_empty(global->name.bps))
content_ctx.name_bps = strdup(global->name.bps);
if (!string_is_empty(global->name.ups))
content_ctx.name_ups = strdup(global->name.ups);
if (label)
strlcpy(global->name.label, label, sizeof(global->name.label));
else
global->name.label[0] = '\0';
2017-05-14 05:00:24 +02:00
}
2020-03-02 20:10:24 +01:00
if (!string_is_empty(path_dir_system))
content_ctx.directory_system = strdup(path_dir_system);
/* Is content required by this core? */
if (fullpath)
sys_info->load_no_content = false;
else
sys_info->load_no_content = true;
#ifndef HAVE_DYNAMIC
/* Check whether specified core is already loaded
* > If so, content can be launched directly with
* the currently loaded core */
if (!force_core_reload &&
rarch_ctl(RARCH_CTL_IS_CORE_LOADED, (void*)core_path))
2017-05-14 04:50:57 +02:00
{
if (!content_info->environ_get)
content_info->environ_get = menu_content_environment_get;
2017-05-14 04:50:57 +02:00
/* Register content path */
path_clear(RARCH_PATH_CONTENT);
if (!string_is_empty(fullpath))
path_set(RARCH_PATH_CONTENT, fullpath);
/* Load content */
ret = content_load(content_info, p_content);
if (!ret)
goto end;
/* Update content history */
task_push_to_history_list(p_content, true, false, false);
2017-05-14 04:50:57 +02:00
2017-05-14 05:00:24 +02:00
goto end;
2017-05-14 04:50:57 +02:00
}
#endif
2017-05-14 04:50:57 +02:00
/* Specified core is not loaded
* > Load it */
path_set(RARCH_PATH_CORE, core_path);
#ifdef HAVE_DYNAMIC
command_event(CMD_EVENT_LOAD_CORE, NULL);
#endif
/* Load content
* > On targets that do not support dynamic core loading,
* command_event_cmd_exec() will fork a new instance */
ret = command_event_cmd_exec(p_content,
fullpath, &content_ctx, false, &error_string);
if (!ret)
goto end;
#ifdef HAVE_COCOATOUCH
/* This seems to be needed for iOS for some reason
* to show the quick menu after the menu is shown */
menu_driver_ctl(RARCH_MENU_CTL_SET_PENDING_QUICK_MENU, NULL);
#endif
#ifndef HAVE_DYNAMIC
/* No dynamic core loading support: if we reach
* this point then a new instance has been
* forked - have to shut down this one */
2019-05-21 04:55:29 +02:00
rarch_ctl(RARCH_CTL_SET_SHUTDOWN, NULL);
retroarch_menu_running_finished(true);
#endif
2017-05-14 05:00:24 +02:00
end:
/* Handle load content failure */
if (!ret)
{
if (error_string)
{
runloop_msg_queue_push(error_string, 2, 90, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_ERR("[CONTENT LOAD]: %s\n", error_string);
free(error_string);
}
retroarch_menu_running();
}
2017-05-14 05:00:24 +02:00
if (content_ctx.name_ips)
free(content_ctx.name_ips);
if (content_ctx.name_bps)
free(content_ctx.name_bps);
if (content_ctx.name_ups)
free(content_ctx.name_ups);
if (content_ctx.directory_system)
free(content_ctx.directory_system);
2017-05-14 05:00:24 +02:00
return ret;
}
2017-02-21 18:55:11 +01:00
#endif
2017-02-21 16:50:39 +01:00
bool task_push_start_current_core(content_ctx_info_t *content_info)
{
content_information_ctx_t content_ctx;
content_state_t *p_content = content_state_get_ptr();
2017-05-14 05:00:24 +02:00
bool ret = true;
char *error_string = NULL;
2017-05-14 05:00:24 +02:00
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
2020-03-02 20:10:24 +01:00
const char *path_dir_system = settings->paths.directory_system;
bool check_firmware_before_loading = settings->bools.check_firmware_before_loading;
if (!content_info)
return false;
2020-03-02 20:10:24 +01:00
content_ctx.check_firmware_before_loading = check_firmware_before_loading;
#ifdef HAVE_PATCH
content_ctx.is_ips_pref = rarch_ctl(RARCH_CTL_IS_IPS_PREF, NULL);
content_ctx.is_bps_pref = rarch_ctl(RARCH_CTL_IS_BPS_PREF, NULL);
content_ctx.is_ups_pref = rarch_ctl(RARCH_CTL_IS_UPS_PREF, NULL);
content_ctx.patch_is_blocked = rarch_ctl(RARCH_CTL_IS_PATCH_BLOCKED, NULL);
#endif
2017-05-15 05:06:23 +02:00
content_ctx.bios_is_missing = rarch_ctl(RARCH_CTL_IS_MISSING_BIOS, NULL);
content_ctx.directory_system = NULL;
content_ctx.directory_cache = NULL;
2017-05-14 04:52:34 +02:00
content_ctx.name_ips = NULL;
content_ctx.name_bps = NULL;
content_ctx.name_ups = NULL;
content_ctx.valid_extensions = NULL;
content_ctx.block_extract = false;
content_ctx.need_fullpath = false;
content_ctx.set_supports_no_game_enable = false;
content_ctx.subsystem.data = NULL;
content_ctx.subsystem.size = 0;
2017-05-14 05:00:24 +02:00
if (global)
{
if (!string_is_empty(global->name.ips))
content_ctx.name_ips = strdup(global->name.ips);
if (!string_is_empty(global->name.bps))
content_ctx.name_bps = strdup(global->name.bps);
if (!string_is_empty(global->name.ups))
content_ctx.name_ups = strdup(global->name.ups);
}
2020-03-02 20:10:24 +01:00
if (!string_is_empty(path_dir_system))
content_ctx.directory_system = strdup(path_dir_system);
if (!content_info->environ_get)
content_info->environ_get = menu_content_environment_get;
/* Clear content path */
path_clear(RARCH_PATH_CONTENT);
/* Preliminary stuff that has to be done before we
* load the actual content. Can differ per mode. */
retroarch_set_current_core_type(CORE_TYPE_PLAIN, true);
/* Load content */
2017-02-21 18:58:03 +01:00
if (firmware_update_status(&content_ctx))
2017-10-11 22:49:13 +02:00
goto end;
/* Loads content into currently selected core. */
2020-03-12 07:14:44 +01:00
if (!content_load(content_info, p_content))
2017-05-14 04:50:57 +02:00
{
if (error_string)
{
runloop_msg_queue_push(error_string, 2, 90, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
2020-06-08 18:58:18 +02:00
RARCH_ERR("[CONTENT LOAD]: %s\n", error_string);
2017-05-14 04:50:57 +02:00
free(error_string);
}
retroarch_menu_running();
2017-05-14 05:00:24 +02:00
ret = false;
goto end;
}
else
2020-03-12 07:14:44 +01:00
task_push_to_history_list(p_content, true, false, false);
#ifdef HAVE_MENU
2017-05-14 04:50:57 +02:00
/* Push quick menu onto menu stack */
menu_driver_ctl(RARCH_MENU_CTL_SET_PENDING_QUICK_MENU, NULL);
#endif
2017-05-14 05:00:24 +02:00
end:
if (content_ctx.name_ips)
free(content_ctx.name_ips);
if (content_ctx.name_bps)
free(content_ctx.name_bps);
if (content_ctx.name_ups)
free(content_ctx.name_ups);
if (content_ctx.directory_system)
free(content_ctx.directory_system);
2017-05-14 05:00:24 +02:00
return ret;
}
2017-02-21 16:53:02 +01:00
bool task_push_load_new_core(
const char *core_path,
const char *fullpath,
content_ctx_info_t *content_info,
enum rarch_core_type type,
retro_task_callback_t cb,
void *user_data)
{
2019-04-21 06:03:02 +02:00
path_set(RARCH_PATH_CORE, core_path);
/* Load core */
command_event(CMD_EVENT_LOAD_CORE, NULL);
#ifndef HAVE_DYNAMIC
/* Fork core? */
if (!frontend_driver_set_fork(FRONTEND_FORK_CORE))
return false;
#endif
/* Preliminary stuff that has to be done before we
* load the actual content. Can differ per mode. */
retroarch_set_current_core_type(type, true);
return true;
}
2017-02-21 18:55:11 +01:00
#ifdef HAVE_MENU
2017-02-21 18:36:38 +01:00
bool task_push_load_content_with_new_core_from_menu(
const char *core_path,
const char *fullpath,
content_ctx_info_t *content_info,
enum rarch_core_type type,
retro_task_callback_t cb,
void *user_data)
{
content_information_ctx_t content_ctx;
content_state_t *p_content = content_state_get_ptr();
2017-05-14 05:00:24 +02:00
bool ret = true;
char *error_string = NULL;
2017-05-14 05:00:24 +02:00
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
2020-03-02 20:10:24 +01:00
bool check_firmware_before_loading = settings->bools.check_firmware_before_loading;
const char *path_dir_system = settings->paths.directory_system;
#ifndef HAVE_DYNAMIC
bool force_core_reload = settings->bools.always_reload_core_on_run_content;
/* Check whether specified core is already loaded
* > If so, we can skip loading the core and
* just load the content directly */
if (!force_core_reload &&
(type == CORE_TYPE_PLAIN) &&
rarch_ctl(RARCH_CTL_IS_CORE_LOADED, (void*)core_path))
return task_push_load_content_with_core_from_menu(
fullpath, content_info,
type, cb, user_data);
#endif
2020-03-02 20:10:24 +01:00
content_ctx.check_firmware_before_loading = check_firmware_before_loading;
#ifdef HAVE_PATCH
content_ctx.is_ips_pref = rarch_ctl(RARCH_CTL_IS_IPS_PREF, NULL);
content_ctx.is_bps_pref = rarch_ctl(RARCH_CTL_IS_BPS_PREF, NULL);
content_ctx.is_ups_pref = rarch_ctl(RARCH_CTL_IS_UPS_PREF, NULL);
content_ctx.patch_is_blocked = rarch_ctl(RARCH_CTL_IS_PATCH_BLOCKED, NULL);
#endif
2017-05-15 05:06:23 +02:00
content_ctx.bios_is_missing = rarch_ctl(RARCH_CTL_IS_MISSING_BIOS, NULL);
content_ctx.directory_system = NULL;
content_ctx.directory_cache = NULL;
2017-05-14 04:52:34 +02:00
content_ctx.name_ips = NULL;
content_ctx.name_bps = NULL;
content_ctx.name_ups = NULL;
content_ctx.valid_extensions = NULL;
content_ctx.block_extract = false;
content_ctx.need_fullpath = false;
content_ctx.set_supports_no_game_enable = false;
content_ctx.subsystem.data = NULL;
content_ctx.subsystem.size = 0;
2017-05-14 05:00:24 +02:00
if (global)
{
if (!string_is_empty(global->name.ips))
content_ctx.name_ips = strdup(global->name.ips);
if (!string_is_empty(global->name.bps))
content_ctx.name_bps = strdup(global->name.bps);
if (!string_is_empty(global->name.ups))
content_ctx.name_ups = strdup(global->name.ups);
global->name.label[0] = '\0';
2017-05-14 05:00:24 +02:00
}
2020-03-02 20:10:24 +01:00
if (!string_is_empty(path_dir_system))
content_ctx.directory_system = strdup(path_dir_system);
path_set(RARCH_PATH_CONTENT, fullpath);
2019-04-21 06:03:02 +02:00
path_set(RARCH_PATH_CORE, core_path);
#ifdef HAVE_DYNAMIC
2017-02-21 05:07:53 +01:00
/* Load core */
command_event(CMD_EVENT_LOAD_CORE, NULL);
/* Load content */
if (!content_info->environ_get)
content_info->environ_get = menu_content_environment_get;
2017-02-21 05:07:53 +01:00
2017-02-21 18:58:03 +01:00
if (firmware_update_status(&content_ctx))
2017-10-11 22:49:13 +02:00
goto end;
/* Loads content into currently selected core. */
2020-03-12 07:14:44 +01:00
if (!content_load(content_info, p_content))
{
if (error_string)
{
runloop_msg_queue_push(error_string, 2, 90, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
2020-06-08 18:58:18 +02:00
RARCH_ERR("[CONTENT LOAD]: %s\n", error_string);
free(error_string);
}
retroarch_menu_running();
2017-05-14 05:00:24 +02:00
ret = false;
goto end;
}
else
2020-03-12 07:14:44 +01:00
task_push_to_history_list(p_content, true, false, false);
#else
2020-03-12 07:14:44 +01:00
command_event_cmd_exec(p_content,
path_get(RARCH_PATH_CONTENT), &content_ctx,
false, &error_string);
command_event(CMD_EVENT_QUIT, NULL);
#endif
/* Push quick menu onto menu stack */
if (type != CORE_TYPE_DUMMY)
menu_driver_ctl(RARCH_MENU_CTL_SET_PENDING_QUICK_MENU, NULL);
2017-05-28 18:33:44 +02:00
#ifdef HAVE_DYNAMIC
2017-05-14 05:00:24 +02:00
end:
2017-05-28 18:33:44 +02:00
#endif
2017-05-14 05:00:24 +02:00
if (content_ctx.name_ips)
free(content_ctx.name_ips);
if (content_ctx.name_bps)
free(content_ctx.name_bps);
if (content_ctx.name_ups)
free(content_ctx.name_ups);
if (content_ctx.directory_system)
free(content_ctx.directory_system);
2017-05-14 05:00:24 +02:00
return ret;
}
2017-02-21 18:55:11 +01:00
#endif
2020-06-13 08:19:49 +02:00
static bool task_load_content_internal(
content_ctx_info_t *content_info,
bool loading_from_menu,
bool loading_from_cli,
bool loading_from_companion_ui)
{
content_information_ctx_t content_ctx;
content_state_t *p_content = content_state_get_ptr();
bool ret = false;
char *error_string = NULL;
2017-05-14 05:00:24 +02:00
global_t *global = global_get_ptr();
2018-02-12 21:13:06 -05:00
rarch_system_info_t *sys_info = runloop_get_system_info();
2020-03-02 20:10:24 +01:00
settings_t *settings = config_get_ptr();
bool check_firmware_before_loading = settings->bools.check_firmware_before_loading;
bool set_supports_no_game_enable = settings->bools.set_supports_no_game_enable;
const char *path_dir_system = settings->paths.directory_system;
const char *path_dir_cache = settings->paths.directory_cache;
2020-03-02 20:10:24 +01:00
content_ctx.check_firmware_before_loading = check_firmware_before_loading;
#ifdef HAVE_PATCH
content_ctx.is_ips_pref = rarch_ctl(RARCH_CTL_IS_IPS_PREF, NULL);
content_ctx.is_bps_pref = rarch_ctl(RARCH_CTL_IS_BPS_PREF, NULL);
content_ctx.is_ups_pref = rarch_ctl(RARCH_CTL_IS_UPS_PREF, NULL);
content_ctx.patch_is_blocked = rarch_ctl(RARCH_CTL_IS_PATCH_BLOCKED, NULL);
#endif
2017-05-15 05:06:23 +02:00
content_ctx.bios_is_missing = rarch_ctl(RARCH_CTL_IS_MISSING_BIOS, NULL);
content_ctx.directory_system = NULL;
content_ctx.directory_cache = NULL;
2017-05-14 04:52:34 +02:00
content_ctx.name_ips = NULL;
content_ctx.name_bps = NULL;
content_ctx.name_ups = NULL;
content_ctx.valid_extensions = NULL;
content_ctx.block_extract = false;
content_ctx.need_fullpath = false;
content_ctx.set_supports_no_game_enable = false;
content_ctx.subsystem.data = NULL;
content_ctx.subsystem.size = 0;
2018-02-11 00:14:40 -05:00
if (sys_info)
{
struct retro_system_info *system = runloop_get_libretro_system_info();
2020-03-02 20:10:24 +01:00
content_ctx.set_supports_no_game_enable = set_supports_no_game_enable;
2018-02-11 00:14:40 -05:00
2020-03-02 20:10:24 +01:00
if (!string_is_empty(path_dir_cache))
content_ctx.directory_cache = strdup(path_dir_cache);
if (!string_is_empty(system->valid_extensions))
content_ctx.valid_extensions = strdup(system->valid_extensions);
2018-02-11 00:14:40 -05:00
content_ctx.block_extract = system->block_extract;
content_ctx.need_fullpath = system->need_fullpath;
2018-02-11 00:14:40 -05:00
content_ctx.subsystem.data = sys_info->subsystem.data;
content_ctx.subsystem.size = sys_info->subsystem.size;
}
2017-05-14 05:00:24 +02:00
if (global)
{
if (!string_is_empty(global->name.ips))
content_ctx.name_ips = strdup(global->name.ips);
if (!string_is_empty(global->name.bps))
content_ctx.name_bps = strdup(global->name.bps);
if (!string_is_empty(global->name.ups))
content_ctx.name_ups = strdup(global->name.ups);
}
2020-03-02 20:10:24 +01:00
if (!string_is_empty(path_dir_system))
content_ctx.directory_system = strdup(path_dir_system);
if (!content_info->environ_get)
content_info->environ_get = menu_content_environment_get;
2017-02-21 18:58:03 +01:00
if (firmware_update_status(&content_ctx))
2017-10-11 22:49:13 +02:00
goto end;
#ifdef HAVE_DISCORD
if (discord_is_inited)
{
discord_userdata_t userdata;
userdata.status = DISCORD_PRESENCE_NETPLAY_NETPLAY_STOPPED;
command_event(CMD_EVENT_DISCORD_UPDATE, &userdata);
userdata.status = DISCORD_PRESENCE_MENU;
command_event(CMD_EVENT_DISCORD_UPDATE, &userdata);
}
#endif
/* Loads content into currently selected core. */
2020-03-12 07:14:44 +01:00
ret = content_load(content_info, p_content);
if (ret)
2020-03-12 07:14:44 +01:00
task_push_to_history_list(p_content,
true, loading_from_cli, loading_from_companion_ui);
2017-10-11 22:49:13 +02:00
end:
2017-05-14 05:00:24 +02:00
if (content_ctx.name_ips)
free(content_ctx.name_ips);
if (content_ctx.name_bps)
free(content_ctx.name_bps);
if (content_ctx.name_ups)
free(content_ctx.name_ups);
if (content_ctx.directory_system)
free(content_ctx.directory_system);
2018-08-18 01:07:57 -04:00
if (content_ctx.directory_cache)
free(content_ctx.directory_cache);
if (content_ctx.valid_extensions)
free(content_ctx.valid_extensions);
if (!ret)
{
if (error_string)
{
runloop_msg_queue_push(error_string, 2, 90, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
2020-06-08 18:58:18 +02:00
RARCH_ERR("[CONTENT LOAD]: %s\n", error_string);
free(error_string);
}
return false;
}
return true;
}
2017-02-21 18:58:03 +01:00
bool task_push_load_content_with_new_core_from_companion_ui(
const char *core_path,
const char *fullpath,
const char *label,
const char *db_name,
const char *crc32,
content_ctx_info_t *content_info,
retro_task_callback_t cb,
void *user_data)
{
global_t *global = global_get_ptr();
content_state_t *p_content = content_state_get_ptr();
path_set(RARCH_PATH_CONTENT, fullpath);
2019-04-21 06:03:02 +02:00
path_set(RARCH_PATH_CORE, core_path);
p_content->companion_ui_db_name[0] = '\0';
p_content->companion_ui_crc32[0] = '\0';
if (!string_is_empty(db_name))
strlcpy(p_content->companion_ui_db_name,
db_name, sizeof(p_content->companion_ui_db_name));
if (!string_is_empty(crc32))
strlcpy(p_content->companion_ui_crc32,
crc32, sizeof(p_content->companion_ui_crc32));
#ifdef HAVE_DYNAMIC
command_event(CMD_EVENT_LOAD_CORE, NULL);
#endif
2020-06-13 08:19:49 +02:00
global->launched_from_cli = false;
if (global)
{
if (label)
strlcpy(global->name.label, label, sizeof(global->name.label));
else
global->name.label[0] = '\0';
}
/* Load content */
2020-06-13 08:19:49 +02:00
if (!task_load_content_internal(content_info, true, false, true))
return false;
#ifdef HAVE_MENU
/* Push quick menu onto menu stack */
menu_driver_ctl(RARCH_MENU_CTL_SET_PENDING_QUICK_MENU, NULL);
#endif
return true;
}
2017-02-21 16:59:48 +01:00
bool task_push_load_content_from_cli(
const char *core_path,
const char *fullpath,
content_ctx_info_t *content_info,
enum rarch_core_type type,
retro_task_callback_t cb,
void *user_data)
{
/* Load content */
2020-06-13 08:19:49 +02:00
if (!task_load_content_internal(content_info, true, true, false))
2017-02-21 16:59:48 +01:00
return false;
return true;
}
2017-02-21 17:22:04 +01:00
bool task_push_start_builtin_core(
content_ctx_info_t *content_info,
enum rarch_core_type type,
retro_task_callback_t cb,
void *user_data)
2016-01-24 00:40:34 +01:00
{
2016-06-03 19:02:19 +02:00
/* Clear content path */
2017-02-21 17:22:04 +01:00
path_clear(RARCH_PATH_CONTENT);
/* Preliminary stuff that has to be done before we
* load the actual content. Can differ per mode. */
retroarch_set_current_core_type(type, true);
2017-02-21 17:22:04 +01:00
/* Load content */
2020-06-13 08:19:49 +02:00
if (!task_load_content_internal(content_info, true, false, false))
2016-05-29 00:03:15 +02:00
{
retroarch_menu_running();
2017-02-21 17:22:04 +01:00
return false;
2016-05-29 00:03:15 +02:00
}
2017-02-21 17:22:04 +01:00
/* Push quick menu onto menu stack */
#ifdef HAVE_MENU
menu_driver_ctl(RARCH_MENU_CTL_SET_PENDING_QUICK_MENU, NULL);
#endif
return true;
}
bool task_push_load_content_with_current_core_from_companion_ui(
const char *fullpath,
content_ctx_info_t *content_info,
enum rarch_core_type type,
retro_task_callback_t cb,
void *user_data)
{
content_state_t *p_content = content_state_get_ptr();
path_set(RARCH_PATH_CONTENT, fullpath);
/* TODO/FIXME: Enable setting of these values
* via function arguments */
p_content->companion_ui_db_name[0] = '\0';
p_content->companion_ui_crc32[0] = '\0';
/* Load content
* > TODO/FIXME: Set loading_from_companion_ui 'false' for
* now, until someone can implement the required higher
* level functionality in 'win32_common.c' and 'ui_cocoa.m' */
2020-06-13 08:19:49 +02:00
if (!task_load_content_internal(content_info, true, false, false))
return false;
/* Push quick menu onto menu stack */
#ifdef HAVE_MENU
if (type != CORE_TYPE_DUMMY)
menu_driver_ctl(RARCH_MENU_CTL_SET_PENDING_QUICK_MENU, NULL);
#endif
return true;
}
2017-02-21 18:36:38 +01:00
bool task_push_load_content_with_core_from_menu(
2017-02-21 17:22:04 +01:00
const char *fullpath,
content_ctx_info_t *content_info,
enum rarch_core_type type,
retro_task_callback_t cb,
void *user_data)
{
2017-02-21 18:36:38 +01:00
path_set(RARCH_PATH_CONTENT, fullpath);
2016-05-28 23:56:07 +02:00
/* Load content */
2020-06-13 08:19:49 +02:00
if (!task_load_content_internal(content_info, true, false, false))
{
retroarch_menu_running();
2017-02-21 18:36:38 +01:00
return false;
}
#ifdef HAVE_MENU
/* Push quick menu onto menu stack */
2017-02-21 16:59:48 +01:00
if (type != CORE_TYPE_DUMMY)
menu_driver_ctl(RARCH_MENU_CTL_SET_PENDING_QUICK_MENU, NULL);
#endif
2016-05-16 14:23:13 +02:00
2016-11-29 22:21:44 -05:00
return true;
2016-01-24 00:40:34 +01:00
}
2018-02-11 00:14:40 -05:00
bool task_push_load_subsystem_with_core_from_menu(
const char *fullpath,
content_ctx_info_t *content_info,
enum rarch_core_type type,
retro_task_callback_t cb,
void *user_data)
{
content_state_t *p_content = content_state_get_ptr();
p_content->pending_subsystem_init = true;
2018-02-11 10:00:08 -05:00
2018-02-11 00:14:40 -05:00
/* Load content */
2020-06-13 08:19:49 +02:00
if (!task_load_content_internal(content_info, true, false, false))
2018-02-11 00:14:40 -05:00
{
retroarch_menu_running();
2018-02-11 00:14:40 -05:00
return false;
}
#ifdef HAVE_MENU
2018-02-11 00:14:40 -05:00
/* Push quick menu onto menu stack */
if (type != CORE_TYPE_DUMMY)
menu_driver_ctl(RARCH_MENU_CTL_SET_PENDING_QUICK_MENU, NULL);
#endif
2018-02-11 00:14:40 -05:00
return true;
}
void content_get_status(
bool *contentless,
bool *is_inited)
{
content_state_t *p_content = content_state_get_ptr();
*contentless = p_content->core_does_not_need_content;
*is_inited = p_content->is_inited;
}
/* Clears the pending subsystem rom buffer*/
void content_clear_subsystem(void)
{
unsigned i;
content_state_t *p_content = content_state_get_ptr();
p_content->pending_subsystem_rom_id = 0;
p_content->pending_subsystem_init = false;
2018-02-12 21:13:06 -05:00
for (i = 0; i < RARCH_MAX_SUBSYSTEM_ROMS; i++)
2018-02-12 22:10:44 -05:00
{
if (p_content->pending_subsystem_roms[i])
2018-02-12 22:10:44 -05:00
{
free(p_content->pending_subsystem_roms[i]);
p_content->pending_subsystem_roms[i] = NULL;
2018-02-12 22:10:44 -05:00
}
}
}
/* Set the current subsystem*/
2018-02-11 10:00:08 -05:00
void content_set_subsystem(unsigned idx)
{
2018-12-10 23:27:04 -05:00
const struct retro_subsystem_info *subsystem;
rarch_system_info_t *system = runloop_get_system_info();
content_state_t *p_content = content_state_get_ptr();
2018-12-10 23:27:04 -05:00
/* Core fully loaded, use the subsystem data */
if (system->subsystem.data)
subsystem = system->subsystem.data + idx;
/* Core not loaded completely, use the data we peeked on load core */
else
subsystem = subsystem_data + idx;
p_content->pending_subsystem_id = idx;
2018-12-10 23:27:04 -05:00
if (subsystem && subsystem_current_count > 0)
2018-08-18 01:07:51 -04:00
{
strlcpy(p_content->pending_subsystem_ident,
subsystem->ident, sizeof(p_content->pending_subsystem_ident));
2018-02-11 10:00:08 -05:00
p_content->pending_subsystem_rom_num = subsystem->num_roms;
2018-08-18 01:07:51 -04:00
}
2020-06-08 18:58:18 +02:00
RARCH_LOG("[Subsystem]: Setting current subsystem to: %d(%s) Content amount: %d\n",
p_content->pending_subsystem_id,
p_content->pending_subsystem_ident,
p_content->pending_subsystem_rom_num);
}
/* Sets the subsystem by name */
bool content_set_subsystem_by_name(const char* subsystem_name)
{
rarch_system_info_t *system = runloop_get_system_info();
const struct retro_subsystem_info *subsystem;
unsigned i = 0;
/* Core fully loaded, use the subsystem data */
if (system->subsystem.data)
subsystem = system->subsystem.data;
/* Core not loaded completely, use the data we peeked on load core */
else
subsystem = subsystem_data;
for (i = 0; i < subsystem_current_count; i++, subsystem++)
{
if (string_is_equal(subsystem_name, subsystem->ident))
{
content_set_subsystem(i);
return true;
}
}
return false;
}
void content_get_subsystem_friendly_name(const char* subsystem_name, char* subsystem_friendly_name, size_t len)
{
rarch_system_info_t *system = runloop_get_system_info();
const struct retro_subsystem_info *subsystem;
unsigned i = 0;
/* Core fully loaded, use the subsystem data */
if (system->subsystem.data)
subsystem = system->subsystem.data;
/* Core not loaded completely, use the data we peeked on load core */
else
subsystem = subsystem_data;
for (i = 0; i < subsystem_current_count; i++, subsystem++)
{
if (string_is_equal(subsystem_name, subsystem->ident))
2019-04-12 13:04:59 -04:00
{
strlcpy(subsystem_friendly_name, subsystem->desc, len);
2019-04-12 13:04:59 -04:00
break;
}
}
return;
}
/* Add a rom to the subsystem rom buffer */
void content_add_subsystem(const char* path)
{
content_state_t *p_content = content_state_get_ptr();
size_t pending_size = PATH_MAX_LENGTH * sizeof(char);
p_content->pending_subsystem_roms[p_content->pending_subsystem_rom_id] = (char*)malloc(pending_size);
strlcpy(p_content->pending_subsystem_roms[
p_content->pending_subsystem_rom_id],
path, pending_size);
2020-06-08 18:58:18 +02:00
RARCH_LOG("[Subsystem]: Subsystem id: %d Subsystem ident:"
" %s Content ID: %d, Content Path: %s\n",
p_content->pending_subsystem_id,
p_content->pending_subsystem_ident,
p_content->pending_subsystem_rom_id,
p_content->pending_subsystem_roms[
p_content->pending_subsystem_rom_id]);
p_content->pending_subsystem_rom_id++;
}
void content_set_does_not_need_content(void)
{
content_state_t *p_content = content_state_get_ptr();
p_content->core_does_not_need_content = true;
}
void content_unset_does_not_need_content(void)
{
content_state_t *p_content = content_state_get_ptr();
p_content->core_does_not_need_content = false;
}
2017-05-06 16:41:22 +02:00
uint32_t content_get_crc(void)
{
content_state_t *p_content = content_state_get_ptr();
if (p_content->pending_rom_crc)
{
p_content->pending_rom_crc = false;
p_content->rom_crc = file_crc32(0,
(const char*)p_content->pending_rom_crc_path);
2020-06-08 18:58:18 +02:00
RARCH_LOG("[CONTENT LOAD]: CRC32: 0x%x .\n", (unsigned)p_content->rom_crc);
}
return p_content->rom_crc;
}
2018-12-16 11:39:38 -05:00
char* content_get_subsystem_rom(unsigned index)
{
content_state_t *p_content = content_state_get_ptr();
return p_content->pending_subsystem_roms[index];
2018-12-16 11:39:38 -05:00
}
bool content_is_inited(void)
{
content_state_t *p_content = content_state_get_ptr();
return p_content->is_inited;
}
void content_deinit(void)
{
unsigned i;
content_state_t *p_content = content_state_get_ptr();
if (p_content->temporary_content)
{
for (i = 0; i < p_content->temporary_content->size; i++)
{
const char *path = p_content->temporary_content->elems[i].data;
2020-06-08 18:58:18 +02:00
RARCH_LOG("[CONTENT LOAD]: %s: %s.\n",
msg_hash_to_str(MSG_REMOVING_TEMPORARY_CONTENT_FILE), path);
if (filestream_delete(path) != 0)
2020-06-08 18:58:18 +02:00
RARCH_ERR("[CONTENT LOAD]: %s: %s.\n",
msg_hash_to_str(MSG_FAILED_TO_REMOVE_TEMPORARY_FILE),
path);
}
string_list_free(p_content->temporary_content);
}
p_content->temporary_content = NULL;
p_content->rom_crc = 0;
p_content->is_inited = false;
p_content->core_does_not_need_content = false;
p_content->pending_rom_crc = false;
}
2018-02-11 15:18:40 -05:00
/* Set environment variables before a subsystem load */
void content_set_subsystem_info(void)
{
content_state_t *p_content = content_state_get_ptr();
if (!p_content->pending_subsystem_init)
return;
path_set(RARCH_PATH_SUBSYSTEM, p_content->pending_subsystem_ident);
path_set_special(p_content->pending_subsystem_roms,
p_content->pending_subsystem_rom_num);
2018-02-11 15:18:40 -05:00
}
/* Initializes and loads a content file for the currently
* selected libretro core. */
bool content_init(void)
{
content_information_ctx_t content_ctx;
content_state_t *p_content = content_state_get_ptr();
2016-12-21 15:21:11 +01:00
bool ret = true;
char *error_string = NULL;
2017-05-14 20:23:10 +02:00
struct string_list *content = NULL;
2017-05-14 05:00:24 +02:00
global_t *global = global_get_ptr();
2017-04-23 16:41:26 +02:00
rarch_system_info_t *sys_info = runloop_get_system_info();
2020-03-02 20:10:24 +01:00
settings_t *settings = config_get_ptr();
bool check_firmware_before_loading = settings->bools.check_firmware_before_loading;
bool set_supports_no_game_enable = settings->bools.set_supports_no_game_enable;
const char *path_dir_system = settings->paths.directory_system;
const char *path_dir_cache = settings->paths.directory_cache;
p_content->temporary_content = string_list_new();
2017-02-21 19:56:32 +01:00
2020-03-02 20:10:24 +01:00
content_ctx.check_firmware_before_loading = check_firmware_before_loading;
#ifdef HAVE_PATCH
content_ctx.is_ips_pref = rarch_ctl(RARCH_CTL_IS_IPS_PREF, NULL);
content_ctx.is_bps_pref = rarch_ctl(RARCH_CTL_IS_BPS_PREF, NULL);
content_ctx.is_ups_pref = rarch_ctl(RARCH_CTL_IS_UPS_PREF, NULL);
content_ctx.patch_is_blocked = rarch_ctl(RARCH_CTL_IS_PATCH_BLOCKED, NULL);
#endif
content_ctx.temporary_content = p_content->temporary_content;
content_ctx.directory_system = NULL;
content_ctx.directory_cache = NULL;
2017-05-14 04:52:34 +02:00
content_ctx.name_ips = NULL;
content_ctx.name_bps = NULL;
content_ctx.name_ups = NULL;
content_ctx.valid_extensions = NULL;
content_ctx.block_extract = false;
content_ctx.need_fullpath = false;
content_ctx.set_supports_no_game_enable = false;
content_ctx.subsystem.data = NULL;
content_ctx.subsystem.size = 0;
2017-05-14 05:00:24 +02:00
if (global)
{
if (!string_is_empty(global->name.ips))
content_ctx.name_ips = strdup(global->name.ips);
if (!string_is_empty(global->name.bps))
content_ctx.name_bps = strdup(global->name.bps);
if (!string_is_empty(global->name.ups))
content_ctx.name_ups = strdup(global->name.ups);
}
if (sys_info)
{
struct retro_system_info *system = runloop_get_libretro_system_info();
2020-03-02 20:10:24 +01:00
content_ctx.set_supports_no_game_enable = set_supports_no_game_enable;
2020-03-02 20:10:24 +01:00
if (!string_is_empty(path_dir_system))
content_ctx.directory_system = strdup(path_dir_system);
if (!string_is_empty(path_dir_cache))
content_ctx.directory_cache = strdup(path_dir_cache);
if (!string_is_empty(system->valid_extensions))
content_ctx.valid_extensions = strdup(system->valid_extensions);
content_ctx.block_extract = system->block_extract;
content_ctx.need_fullpath = system->need_fullpath;
content_ctx.subsystem.data = sys_info->subsystem.data;
content_ctx.subsystem.size = sys_info->subsystem.size;
}
p_content->is_inited = true;
content = string_list_new();
2017-05-14 04:50:57 +02:00
if ( !p_content->temporary_content
2020-03-12 07:14:44 +01:00
|| !content_file_init(&content_ctx, p_content,
content, &error_string))
{
content_deinit();
2017-05-14 04:50:57 +02:00
ret = false;
}
2017-05-14 20:23:10 +02:00
string_list_free(content);
2017-05-14 05:00:24 +02:00
if (content_ctx.name_ips)
free(content_ctx.name_ips);
if (content_ctx.name_bps)
free(content_ctx.name_bps);
if (content_ctx.name_ups)
free(content_ctx.name_ups);
if (content_ctx.directory_system)
free(content_ctx.directory_system);
if (content_ctx.directory_cache)
free(content_ctx.directory_cache);
if (content_ctx.valid_extensions)
free(content_ctx.valid_extensions);
if (error_string)
{
if (ret)
{
2020-06-08 18:58:18 +02:00
RARCH_LOG("[CONTENT LOAD]: %s\n", error_string);
}
else
{
2020-06-08 18:58:18 +02:00
RARCH_ERR("[CONTENT LOAD]: %s\n", error_string);
}
/* Do not flush the message queue here
* > This allows any core-generated error messages
* to propagate through to the frontend */
runloop_msg_queue_push(error_string, 2, ret ? 1 : 180, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
free(error_string);
}
return ret;
}