mirror of
https://github.com/libretro/RetroArch
synced 2025-04-07 13:23:32 +00:00
Refactor content task code
This commit is contained in:
parent
a687c47f7e
commit
9c33d91e68
@ -38,101 +38,6 @@
|
||||
|
||||
#include "../tasks/tasks_internal.h"
|
||||
|
||||
static void menu_content_environment_get(int *argc, char *argv[],
|
||||
void *args, void *params_data)
|
||||
{
|
||||
struct rarch_main_wrap *wrap_args = (struct rarch_main_wrap*)params_data;
|
||||
char *fullpath = NULL;
|
||||
global_t *global = global_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
if (!wrap_args)
|
||||
return;
|
||||
|
||||
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
|
||||
|
||||
wrap_args->no_content = menu_driver_ctl(
|
||||
RARCH_MENU_CTL_HAS_LOAD_NO_CONTENT, NULL);
|
||||
|
||||
if (!global->has_set.verbosity)
|
||||
wrap_args->verbose = *retro_main_verbosity();
|
||||
|
||||
wrap_args->touched = true;
|
||||
wrap_args->config_path = NULL;
|
||||
wrap_args->sram_path = NULL;
|
||||
wrap_args->state_path = NULL;
|
||||
wrap_args->content_path = NULL;
|
||||
|
||||
if (*global->path.config)
|
||||
wrap_args->config_path = global->path.config;
|
||||
if (*global->dir.savefile)
|
||||
wrap_args->sram_path = global->dir.savefile;
|
||||
if (*global->dir.savestate)
|
||||
wrap_args->state_path = global->dir.savestate;
|
||||
if (*fullpath)
|
||||
wrap_args->content_path = fullpath;
|
||||
if (!global->has_set.libretro)
|
||||
wrap_args->libretro_path = *settings->path.libretro
|
||||
? settings->path.libretro : NULL;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* menu_content_load:
|
||||
*
|
||||
* Loads content into currently selected core.
|
||||
* Will also optionally push the content entry to the history playlist.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
|
||||
static bool menu_content_load(void)
|
||||
{
|
||||
content_ctx_info_t content_info;
|
||||
char name[PATH_MAX_LENGTH];
|
||||
char msg[PATH_MAX_LENGTH];
|
||||
char *fullpath = NULL;
|
||||
|
||||
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
|
||||
/* redraw menu frame */
|
||||
menu_display_set_msg_force(true);
|
||||
menu_driver_ctl(RARCH_MENU_CTL_RENDER, NULL);
|
||||
|
||||
if (*fullpath)
|
||||
fill_pathname_base(name, fullpath, sizeof(name));
|
||||
|
||||
content_info.argc = 0;
|
||||
content_info.argv = NULL;
|
||||
content_info.args = NULL;
|
||||
content_info.environ_get = menu_content_environment_get;
|
||||
|
||||
if (!content_load(&content_info))
|
||||
goto error;
|
||||
|
||||
if (*fullpath)
|
||||
{
|
||||
snprintf(msg, sizeof(msg), "INFO - Loading %s ...", name);
|
||||
runloop_msg_queue_push(msg, 1, 1, false);
|
||||
}
|
||||
|
||||
if (*fullpath ||
|
||||
menu_driver_ctl(RARCH_MENU_CTL_HAS_LOAD_NO_CONTENT, NULL))
|
||||
{
|
||||
struct retro_system_info *info = NULL;
|
||||
menu_driver_ctl(RARCH_MENU_CTL_SYSTEM_INFO_GET,
|
||||
&info);
|
||||
content_push_to_history_playlist(true, fullpath, info);
|
||||
playlist_write_file(g_defaults.history);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
snprintf(msg, sizeof(msg), "Failed to load %s.\n", name);
|
||||
runloop_msg_queue_push(msg, 1, 90, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* menu_content_load_from_playlist:
|
||||
* @playlist : Playlist handle.
|
||||
@ -288,8 +193,6 @@ bool menu_content_ctl(enum menu_content_ctl_state state, void *data)
|
||||
{
|
||||
case MENU_CONTENT_CTL_FIND_FIRST_CORE:
|
||||
return menu_content_find_first_core(data);
|
||||
case MENU_CONTENT_CTL_LOAD:
|
||||
return menu_content_load();
|
||||
case MENU_CONTENT_CTL_LOAD_PLAYLIST:
|
||||
return menu_content_load_from_playlist(data);
|
||||
case MENU_CONTENT_CTL_NONE:
|
||||
|
@ -29,11 +29,6 @@ enum menu_content_ctl_state
|
||||
{
|
||||
MENU_CONTENT_CTL_NONE = 0,
|
||||
|
||||
/* Loads content into currently selected core.
|
||||
* Will also optionally push the content entry
|
||||
* to the history playlist. */
|
||||
MENU_CONTENT_CTL_LOAD,
|
||||
|
||||
/* Initializes core and loads content
|
||||
* (based on playlist entry). */
|
||||
MENU_CONTENT_CTL_LOAD_PLAYLIST,
|
||||
|
@ -15,19 +15,123 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <file/file_path.h>
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
#include "../menu/menu_driver.h"
|
||||
#include "../menu/menu_display.h"
|
||||
#include "../menu/menu_content.h"
|
||||
#endif
|
||||
|
||||
#include "tasks_internal.h"
|
||||
|
||||
#include "../command.h"
|
||||
#include "../content.h"
|
||||
#include "../defaults.h"
|
||||
#include "../configuration.h"
|
||||
#include "../frontend/frontend.h"
|
||||
#include "../retroarch.h"
|
||||
#include "../verbosity.h"
|
||||
|
||||
/* TODO/FIXME - turn this into actual task */
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
static void menu_content_environment_get(int *argc, char *argv[],
|
||||
void *args, void *params_data)
|
||||
{
|
||||
struct rarch_main_wrap *wrap_args = (struct rarch_main_wrap*)params_data;
|
||||
char *fullpath = NULL;
|
||||
global_t *global = global_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
if (!wrap_args)
|
||||
return;
|
||||
|
||||
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
|
||||
|
||||
wrap_args->no_content = menu_driver_ctl(
|
||||
RARCH_MENU_CTL_HAS_LOAD_NO_CONTENT, NULL);
|
||||
|
||||
if (!global->has_set.verbosity)
|
||||
wrap_args->verbose = *retro_main_verbosity();
|
||||
|
||||
wrap_args->touched = true;
|
||||
wrap_args->config_path = NULL;
|
||||
wrap_args->sram_path = NULL;
|
||||
wrap_args->state_path = NULL;
|
||||
wrap_args->content_path = NULL;
|
||||
|
||||
if (*global->path.config)
|
||||
wrap_args->config_path = global->path.config;
|
||||
if (*global->dir.savefile)
|
||||
wrap_args->sram_path = global->dir.savefile;
|
||||
if (*global->dir.savestate)
|
||||
wrap_args->state_path = global->dir.savestate;
|
||||
if (*fullpath)
|
||||
wrap_args->content_path = fullpath;
|
||||
if (!global->has_set.libretro)
|
||||
wrap_args->libretro_path = *settings->path.libretro
|
||||
? settings->path.libretro : NULL;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* menu_content_load:
|
||||
*
|
||||
* Loads content into currently selected core.
|
||||
* Will also optionally push the content entry to the history playlist.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
|
||||
static bool menu_content_load(void)
|
||||
{
|
||||
content_ctx_info_t content_info;
|
||||
char name[PATH_MAX_LENGTH];
|
||||
char msg[PATH_MAX_LENGTH];
|
||||
char *fullpath = NULL;
|
||||
|
||||
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
|
||||
/* redraw menu frame */
|
||||
menu_display_set_msg_force(true);
|
||||
menu_driver_ctl(RARCH_MENU_CTL_RENDER, NULL);
|
||||
|
||||
if (*fullpath)
|
||||
fill_pathname_base(name, fullpath, sizeof(name));
|
||||
|
||||
content_info.argc = 0;
|
||||
content_info.argv = NULL;
|
||||
content_info.args = NULL;
|
||||
content_info.environ_get = menu_content_environment_get;
|
||||
|
||||
if (!content_load(&content_info))
|
||||
goto error;
|
||||
|
||||
if (*fullpath)
|
||||
{
|
||||
snprintf(msg, sizeof(msg), "INFO - Loading %s ...", name);
|
||||
runloop_msg_queue_push(msg, 1, 1, false);
|
||||
}
|
||||
|
||||
if (*fullpath ||
|
||||
menu_driver_ctl(RARCH_MENU_CTL_HAS_LOAD_NO_CONTENT, NULL))
|
||||
{
|
||||
struct retro_system_info *info = NULL;
|
||||
menu_driver_ctl(RARCH_MENU_CTL_SYSTEM_INFO_GET,
|
||||
&info);
|
||||
content_push_to_history_playlist(true, fullpath, info);
|
||||
playlist_write_file(g_defaults.history);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
snprintf(msg, sizeof(msg), "Failed to load %s.\n", name);
|
||||
runloop_msg_queue_push(msg, 1, 90, false);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool command_event_cmd_exec(void *data)
|
||||
{
|
||||
char *fullpath = NULL;
|
||||
@ -43,7 +147,7 @@ static bool command_event_cmd_exec(void *data)
|
||||
|
||||
#if defined(HAVE_DYNAMIC)
|
||||
#ifdef HAVE_MENU
|
||||
if (!menu_content_ctl(MENU_CONTENT_CTL_LOAD, NULL))
|
||||
if (!menu_content_load())
|
||||
{
|
||||
rarch_ctl(RARCH_CTL_MENU_RUNNING, NULL);
|
||||
return false;
|
||||
@ -74,7 +178,7 @@ bool rarch_task_push_content_load_default(
|
||||
case CONTENT_MODE_LOAD_NOTHING_WITH_CURRENT_CORE_FROM_MENU:
|
||||
runloop_ctl(RUNLOOP_CTL_CLEAR_CONTENT_PATH, NULL);
|
||||
#ifdef HAVE_MENU
|
||||
if (!menu_content_ctl(MENU_CONTENT_CTL_LOAD, NULL))
|
||||
if (!menu_content_load())
|
||||
goto error;
|
||||
#endif
|
||||
break;
|
||||
@ -86,7 +190,7 @@ bool rarch_task_push_content_load_default(
|
||||
command_event(CMD_EVENT_LOAD_CORE, NULL);
|
||||
#endif
|
||||
#ifdef HAVE_MENU
|
||||
if (!menu_content_ctl(MENU_CONTENT_CTL_LOAD, NULL))
|
||||
if (!menu_content_load())
|
||||
goto error;
|
||||
#endif
|
||||
break;
|
||||
@ -95,11 +199,11 @@ bool rarch_task_push_content_load_default(
|
||||
runloop_ctl(RUNLOOP_CTL_SET_CONTENT_PATH, (void*)fullpath);
|
||||
runloop_ctl(RUNLOOP_CTL_SET_LIBRETRO_PATH, (void*)core_path);
|
||||
#ifdef HAVE_MENU
|
||||
if (!menu_content_ctl(MENU_CONTENT_CTL_LOAD, NULL))
|
||||
if (!menu_content_load())
|
||||
goto error;
|
||||
#endif
|
||||
#ifdef HAVE_MENU
|
||||
if (!menu_content_ctl(MENU_CONTENT_CTL_LOAD, NULL))
|
||||
if (!menu_content_load())
|
||||
goto error;
|
||||
#endif
|
||||
break;
|
||||
@ -111,7 +215,7 @@ bool rarch_task_push_content_load_default(
|
||||
command_event(CMD_EVENT_LOAD_CORE, NULL);
|
||||
#endif
|
||||
#ifdef HAVE_MENU
|
||||
if (!menu_content_ctl(MENU_CONTENT_CTL_LOAD, NULL))
|
||||
if (!menu_content_load())
|
||||
goto error;
|
||||
#endif
|
||||
break;
|
||||
@ -123,7 +227,7 @@ bool rarch_task_push_content_load_default(
|
||||
#endif
|
||||
runloop_ctl(RUNLOOP_CTL_SET_CONTENT_PATH, (void*)fullpath);
|
||||
#ifdef HAVE_MENU
|
||||
if (!menu_content_ctl(MENU_CONTENT_CTL_LOAD, NULL))
|
||||
if (!menu_content_load())
|
||||
goto error;
|
||||
#endif
|
||||
break;
|
||||
@ -133,7 +237,7 @@ bool rarch_task_push_content_load_default(
|
||||
#ifdef HAVE_DYNAMIC
|
||||
command_event(CMD_EVENT_LOAD_CORE, NULL);
|
||||
#ifdef HAVE_MENU
|
||||
if (!menu_content_ctl(MENU_CONTENT_CTL_LOAD, NULL))
|
||||
if (!menu_content_load())
|
||||
goto error;
|
||||
#endif
|
||||
#else
|
||||
|
Loading…
x
Reference in New Issue
Block a user