RetroArch/menu/menu.c

295 lines
7.8 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
2014-01-01 01:50:59 +01:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 17:46:50 +01:00
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
2015-06-05 18:23:06 +02:00
#include <file/file_path.h>
2015-01-10 04:53:37 +01:00
#include "menu.h"
#include "menu_cbs.h"
#include "menu_display.h"
#include "menu_hash.h"
2015-06-13 19:12:10 +02:00
#include "../general.h"
2014-10-28 19:54:23 +01:00
#include "../frontend/frontend.h"
2015-12-02 04:04:51 +01:00
#include "../tasks/tasks.h"
static void menu_environment_get(int *argc, char *argv[],
void *args, void *params_data)
{
struct rarch_main_wrap *wrap_args = (struct rarch_main_wrap*)params_data;
2015-03-21 04:43:18 +01:00
global_t *global = global_get_ptr();
2015-03-20 20:43:22 +01:00
settings_t *settings = config_get_ptr();
2015-04-14 12:56:37 +02:00
menu_handle_t *menu = menu_driver_get_ptr();
char *fullpath = NULL;
if (!wrap_args)
return;
2015-11-30 21:42:59 +01:00
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
2015-04-14 12:56:37 +02:00
wrap_args->no_content = menu->load_no_content;
2015-07-27 17:18:10 +02:00
if (!global->has_set.verbosity)
wrap_args->verbose = *retro_main_verbosity();
2015-03-21 04:43:18 +01:00
2015-07-27 17:18:10 +02:00
wrap_args->config_path = *global->path.config ? global->path.config : NULL;
wrap_args->sram_path = *global->dir.savefile ? global->dir.savefile : NULL;
wrap_args->state_path = *global->dir.savestate ? global->dir.savestate : NULL;
wrap_args->content_path = *fullpath ? fullpath : NULL;
2015-03-21 04:43:18 +01:00
2015-07-27 17:18:10 +02:00
if (!global->has_set.libretro)
2015-03-20 20:43:22 +01:00
wrap_args->libretro_path = *settings->libretro ? settings->libretro : NULL;
wrap_args->touched = true;
}
static void menu_push_to_history_playlist(void)
{
2015-03-20 20:43:22 +01:00
settings_t *settings = config_get_ptr();
2015-03-21 04:43:18 +01:00
global_t *global = global_get_ptr();
char *fullpath = NULL;
2015-03-21 04:43:18 +01:00
2015-03-20 20:43:22 +01:00
if (!settings->history_list_enable)
2014-10-17 04:17:28 +02:00
return;
2015-11-30 21:42:59 +01:00
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
if (*fullpath)
{
char tmp[PATH_MAX_LENGTH];
char str[PATH_MAX_LENGTH];
2014-09-12 01:11:14 +02:00
fill_pathname_base(tmp, fullpath, sizeof(tmp));
snprintf(str, sizeof(str), "INFO - Loading %s ...", tmp);
menu_display_msg_queue_push(str, 1, 1, false);
}
2014-10-12 02:31:25 +02:00
content_playlist_push(g_defaults.history,
fullpath,
2015-05-26 00:12:49 +02:00
NULL,
2015-03-20 20:43:22 +01:00
settings->libretro,
2015-05-26 00:12:49 +02:00
global->menu.info.library_name,
NULL,
2015-05-26 00:12:49 +02:00
NULL);
}
2015-01-10 06:09:30 +01:00
/**
* menu_load_content:
*
* Loads content into currently selected core.
* Will also optionally push the content entry to the history playlist.
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool menu_load_content(enum rarch_core_type type)
{
bool msg_force = true;
2015-04-14 12:56:37 +02:00
menu_handle_t *menu = menu_driver_get_ptr();
char *fullpath = NULL;
2015-11-30 21:42:59 +01:00
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
/* redraw menu frame */
menu_display_ctl(MENU_DISPLAY_CTL_SET_MSG_FORCE, &msg_force);
menu_iterate_render();
2015-12-05 08:10:01 +01:00
if (!(main_load_content(0, NULL, NULL, menu_environment_get)))
{
2015-06-13 00:09:09 +02:00
char name[PATH_MAX_LENGTH] = {0};
char msg[PATH_MAX_LENGTH] = {0};
fill_pathname_base(name, fullpath, sizeof(name));
2013-04-30 21:45:02 -04:00
snprintf(msg, sizeof(msg), "Failed to load %s.\n", name);
menu_display_msg_queue_push(msg, 1, 90, false);
return false;
}
2015-04-14 12:56:37 +02:00
menu_shader_manager_init(menu);
event_command(EVENT_CMD_HISTORY_INIT);
2015-03-22 19:17:29 -03:00
if (*fullpath || (menu && menu->load_no_content))
menu_push_to_history_playlist();
2015-03-22 19:17:29 -03:00
event_command(EVENT_CMD_VIDEO_SET_ASPECT_RATIO);
event_command(EVENT_CMD_RESUME);
2014-08-02 18:41:43 +02:00
return true;
}
2015-09-07 02:28:26 +02:00
int menu_common_load_content(
const char *core_path, const char *fullpath,
bool persist, enum rarch_core_type type)
{
2015-09-07 02:34:27 +02:00
enum event_command cmd = EVENT_CMD_NONE;
2015-09-07 02:28:26 +02:00
if (core_path)
{
2015-11-30 21:42:59 +01:00
runloop_ctl(RUNLOOP_CTL_SET_LIBRETRO_PATH, (void*)core_path);
2015-09-07 02:28:26 +02:00
event_command(EVENT_CMD_LOAD_CORE);
}
if (fullpath)
2015-11-30 21:42:59 +01:00
runloop_ctl(RUNLOOP_CTL_SET_CONTENT_PATH, (void*)fullpath);
2015-09-07 02:28:26 +02:00
switch (type)
{
case CORE_TYPE_PLAIN:
case CORE_TYPE_DUMMY:
2015-09-07 02:34:27 +02:00
cmd = persist ? EVENT_CMD_LOAD_CONTENT_PERSIST : EVENT_CMD_LOAD_CONTENT;
break;
#ifdef HAVE_FFMPEG
case CORE_TYPE_FFMPEG:
2015-09-07 02:34:27 +02:00
cmd = EVENT_CMD_LOAD_CONTENT_FFMPEG;
break;
#endif
2015-06-28 17:02:01 +02:00
case CORE_TYPE_IMAGEVIEWER:
2015-06-28 18:55:00 +02:00
#ifdef HAVE_IMAGEVIEWER
2015-09-07 02:34:27 +02:00
cmd = EVENT_CMD_LOAD_CONTENT_IMAGEVIEWER;
2015-06-28 18:55:00 +02:00
#endif
2015-06-28 17:02:01 +02:00
break;
}
2015-09-07 02:34:27 +02:00
if (cmd != EVENT_CMD_NONE)
event_command(cmd);
return -1;
}
/**
* menu_free:
* @menu : Menu handle.
*
* Frees a menu handle
**/
void menu_free(menu_handle_t *menu)
{
global_t *global = global_get_ptr();
2015-09-25 22:01:34 +02:00
if (!menu)
return;
if (menu->playlist)
content_playlist_free(menu->playlist);
menu->playlist = NULL;
menu_shader_free(menu);
menu_input_free();
2015-09-25 19:32:35 +02:00
menu_navigation_free();
menu_driver_free(menu);
#ifdef HAVE_DYNAMIC
libretro_free_system_info(&global->menu.info);
#endif
menu_display_free();
2015-08-21 21:19:29 +02:00
menu_entries_free();
event_command(EVENT_CMD_HISTORY_DEINIT);
if (global->core_info.list)
core_info_list_free(global->core_info.list);
if (global->core_info.current)
free(global->core_info.current);
global->core_info.current = NULL;
free(menu);
}
2015-11-30 12:36:49 -03:00
static void bundle_decompressed(void *task_data, void *user_data, const char *err)
{
settings_t *settings = config_get_ptr();
2015-11-30 12:36:49 -03:00
decompress_task_data_t *dec = (decompress_task_data_t*)task_data;
if (dec && !err)
event_command(EVENT_CMD_REINIT);
if (err)
RARCH_ERR("%s", err);
if (dec)
{
/* delete bundle? */
free(dec->source_file);
free(dec);
}
settings->bundle_assets_extract_last_version = settings->bundle_assets_extract_version_current;
2015-11-30 12:36:49 -03:00
}
2015-01-09 21:54:08 +01:00
/**
* menu_init:
* @data : Menu context handle.
*
* Create and initialize menu handle.
*
* Returns: menu handle on success, otherwise NULL.
**/
void *menu_init(const void *data)
{
2015-03-22 04:48:50 +01:00
menu_handle_t *menu = NULL;
menu_ctx_driver_t *menu_ctx = (menu_ctx_driver_t*)data;
2015-03-22 04:48:50 +01:00
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
2015-08-21 20:54:56 +02:00
if (!menu_ctx)
return NULL;
2014-07-25 23:33:49 +02:00
if (!(menu = (menu_handle_t*)menu_ctx->init()))
return NULL;
2015-03-20 20:43:22 +01:00
strlcpy(settings->menu.driver, menu_ctx->ident,
sizeof(settings->menu.driver));
2015-08-21 21:19:29 +02:00
if (!menu_entries_init(menu))
2015-02-12 19:14:10 +01:00
goto error;
2015-07-27 17:18:10 +02:00
global->core_info.current = (core_info_t*)calloc(1, sizeof(core_info_t));
if (!global->core_info.current)
2015-02-12 19:14:10 +01:00
goto error;
#ifdef HAVE_SHADER_MANAGER
2015-01-19 21:24:08 +01:00
menu->shader = (struct video_shader*)calloc(1, sizeof(struct video_shader));
2015-02-12 19:14:10 +01:00
if (!menu->shader)
goto error;
#endif
2015-06-15 02:08:25 +02:00
menu->push_help_screen = settings->menu_show_start_screen;
menu->help_screen_type = MENU_HELP_WELCOME;
2015-03-20 20:43:22 +01:00
settings->menu_show_start_screen = false;
if (settings->bundle_assets_extract_enable &&
2015-12-02 04:04:51 +01:00
settings->bundle_assets_src_path[0] != '\0' && settings->bundle_assets_dst_path[0] != '\0' &&
settings->bundle_assets_extract_version_current != settings->bundle_assets_extract_last_version
)
{
rarch_task_push_decompress(settings->bundle_assets_src_path, settings->bundle_assets_dst_path,
settings->bundle_assets_dst_path_subdir, NULL, bundle_decompressed, NULL);
}
menu_shader_manager_init(menu);
if (!menu_display_init())
2015-02-12 19:14:10 +01:00
goto error;
2015-02-11 00:40:18 +01:00
return menu;
2015-02-12 19:14:10 +01:00
error:
menu_free(menu);
2015-02-12 19:14:10 +01:00
return NULL;
}