2016-01-25 03:32:52 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-25 04:38:22 +00:00
|
|
|
#include <retro_assert.h>
|
2016-01-25 04:43:27 +00:00
|
|
|
#include <retro_file.h>
|
2016-01-25 03:44:54 +00:00
|
|
|
#include <file/file_path.h>
|
2016-01-25 04:43:27 +00:00
|
|
|
#include <string/stdstring.h>
|
2016-01-25 03:44:54 +00:00
|
|
|
|
2016-01-25 03:32:52 +00:00
|
|
|
#include "menu_content.h"
|
2016-01-25 03:44:54 +00:00
|
|
|
#include "menu_driver.h"
|
|
|
|
#include "menu_display.h"
|
2016-01-25 04:38:22 +00:00
|
|
|
#include "menu_hash.h"
|
2016-01-25 03:44:54 +00:00
|
|
|
#include "menu_shader.h"
|
|
|
|
|
2016-01-25 04:38:22 +00:00
|
|
|
#include "../core_info.h"
|
2016-01-25 03:44:54 +00:00
|
|
|
#include "../configuration.h"
|
2016-01-25 04:43:27 +00:00
|
|
|
#include "../dynamic.h"
|
2016-01-25 03:44:54 +00:00
|
|
|
#include "../defaults.h"
|
|
|
|
#include "../frontend/frontend.h"
|
|
|
|
#include "../playlist.h"
|
|
|
|
#include "../retroarch.h"
|
|
|
|
#include "../runloop.h"
|
|
|
|
#include "../verbosity.h"
|
|
|
|
|
|
|
|
static void menu_content_push_to_history_playlist(void)
|
|
|
|
{
|
|
|
|
struct retro_system_info *system = NULL;
|
2016-01-25 17:28:19 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
char *fullpath = NULL;
|
2016-01-25 03:44:54 +00:00
|
|
|
|
2016-01-25 17:28:19 +00:00
|
|
|
/* If the history list is not enabled, early return. */
|
2016-01-25 03:44:54 +00:00
|
|
|
if (!settings->history_list_enable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
|
|
|
|
|
|
|
|
menu_driver_ctl(RARCH_MENU_CTL_SYSTEM_INFO_GET,
|
|
|
|
&system);
|
|
|
|
|
|
|
|
content_playlist_push(g_defaults.history,
|
|
|
|
fullpath,
|
|
|
|
NULL,
|
|
|
|
settings->libretro,
|
|
|
|
system->library_name,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
content_playlist_write_file(g_defaults.history);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2016-02-04 20:20:28 +00:00
|
|
|
char *fullpath = NULL;
|
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
2016-01-25 03:44:54 +00:00
|
|
|
|
|
|
|
if (!wrap_args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
|
|
|
|
|
2016-02-04 20:20:28 +00:00
|
|
|
wrap_args->no_content = menu_driver_ctl(
|
|
|
|
RARCH_MENU_CTL_HAS_LOAD_NO_CONTENT, NULL);
|
|
|
|
|
2016-01-25 03:44:54 +00:00
|
|
|
if (!global->has_set.verbosity)
|
|
|
|
wrap_args->verbose = *retro_main_verbosity();
|
|
|
|
|
2016-02-04 20:20:28 +00:00
|
|
|
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;
|
2016-01-25 03:44:54 +00:00
|
|
|
if (!global->has_set.libretro)
|
2016-02-04 20:20:28 +00:00
|
|
|
wrap_args->libretro_path = *settings->libretro
|
|
|
|
? settings->libretro : NULL;
|
|
|
|
|
2016-01-25 03:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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).
|
|
|
|
**/
|
|
|
|
|
2016-02-04 13:51:01 +00:00
|
|
|
static bool menu_content_load(void)
|
2016-01-25 03:44:54 +00:00
|
|
|
{
|
2016-01-25 17:28:19 +00:00
|
|
|
char name[PATH_MAX_LENGTH];
|
|
|
|
char msg[PATH_MAX_LENGTH];
|
2016-02-04 13:51:01 +00:00
|
|
|
bool msg_force = true;
|
2016-01-25 03:44:54 +00:00
|
|
|
char *fullpath = NULL;
|
|
|
|
|
|
|
|
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
|
|
|
|
/* redraw menu frame */
|
|
|
|
menu_display_ctl(MENU_DISPLAY_CTL_SET_MSG_FORCE, &msg_force);
|
|
|
|
menu_driver_ctl(RARCH_MENU_CTL_RENDER, NULL);
|
|
|
|
|
2016-01-25 17:28:19 +00:00
|
|
|
if (*fullpath)
|
|
|
|
fill_pathname_base(name, fullpath, sizeof(name));
|
|
|
|
|
2016-01-25 03:44:54 +00:00
|
|
|
if (!(main_load_content(0, NULL, NULL, menu_content_environment_get)))
|
|
|
|
{
|
|
|
|
snprintf(msg, sizeof(msg), "Failed to load %s.\n", name);
|
|
|
|
menu_display_msg_queue_push(msg, 1, 90, false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-25 17:28:19 +00:00
|
|
|
if (*fullpath)
|
|
|
|
{
|
|
|
|
snprintf(msg, sizeof(msg), "INFO - Loading %s ...", name);
|
|
|
|
menu_display_msg_queue_push(msg, 1, 1, false);
|
|
|
|
}
|
|
|
|
|
2016-01-25 03:44:54 +00:00
|
|
|
menu_driver_ctl(RARCH_MENU_CTL_SHADER_MANAGER_INIT, NULL);
|
|
|
|
|
|
|
|
event_cmd_ctl(EVENT_CMD_HISTORY_INIT, NULL);
|
|
|
|
|
|
|
|
if (*fullpath || menu_driver_ctl(RARCH_MENU_CTL_HAS_LOAD_NO_CONTENT, NULL))
|
|
|
|
menu_content_push_to_history_playlist();
|
|
|
|
|
|
|
|
event_cmd_ctl(EVENT_CMD_VIDEO_SET_ASPECT_RATIO, NULL);
|
|
|
|
event_cmd_ctl(EVENT_CMD_RESUME, NULL);
|
|
|
|
|
2016-02-04 13:51:01 +00:00
|
|
|
frontend_driver_content_loaded();
|
|
|
|
|
2016-01-25 03:44:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-01-25 04:38:22 +00:00
|
|
|
|
2016-01-25 04:43:27 +00:00
|
|
|
/**
|
2016-02-04 14:00:38 +00:00
|
|
|
* menu_content_load_from_playlist:
|
2016-01-25 04:43:27 +00:00
|
|
|
* @playlist : Playlist handle.
|
|
|
|
* @idx : Index in playlist.
|
|
|
|
*
|
|
|
|
* Initializes core and loads content based on playlist entry.
|
|
|
|
**/
|
2016-02-04 14:00:38 +00:00
|
|
|
static bool menu_content_load_from_playlist(void *data)
|
2016-01-25 04:43:27 +00:00
|
|
|
{
|
2016-02-04 14:00:38 +00:00
|
|
|
unsigned idx;
|
2016-01-25 04:43:27 +00:00
|
|
|
const char *core_path = NULL;
|
|
|
|
const char *path = NULL;
|
2016-02-04 14:00:38 +00:00
|
|
|
menu_content_ctx_playlist_info_t *info =
|
|
|
|
(menu_content_ctx_playlist_info_t *)data;
|
|
|
|
content_playlist_t *playlist = NULL;
|
|
|
|
|
|
|
|
if (!info)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
playlist = (content_playlist_t*)info->data;
|
|
|
|
idx = info->idx;
|
2016-01-25 04:43:27 +00:00
|
|
|
|
|
|
|
if (!playlist)
|
2016-02-04 14:00:38 +00:00
|
|
|
return false;
|
2016-01-25 04:43:27 +00:00
|
|
|
|
|
|
|
content_playlist_get_index(playlist,
|
|
|
|
idx, &path, NULL, &core_path, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (path && !string_is_empty(path))
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
RFILE *fp = NULL;
|
|
|
|
char *path_check = NULL;
|
|
|
|
char *path_tolower = strdup(path);
|
|
|
|
|
|
|
|
for (i = 0; i < strlen(path_tolower); ++i)
|
|
|
|
path_tolower[i] = tolower(path_tolower[i]);
|
|
|
|
|
|
|
|
if (strstr(path_tolower, ".zip"))
|
|
|
|
strstr(path_tolower, ".zip")[4] = '\0';
|
|
|
|
else if (strstr(path_tolower, ".7z"))
|
|
|
|
strstr(path_tolower, ".7z")[3] = '\0';
|
|
|
|
|
|
|
|
path_check = (char *)calloc(strlen(path_tolower) + 1, sizeof(char));
|
|
|
|
strncpy(path_check, path, strlen(path_tolower));
|
|
|
|
|
2016-02-04 14:29:37 +00:00
|
|
|
free(path_tolower);
|
|
|
|
|
2016-01-25 04:43:27 +00:00
|
|
|
fp = retro_fopen(path_check, RFILE_MODE_READ, -1);
|
2016-02-04 14:29:37 +00:00
|
|
|
|
|
|
|
free(path_check);
|
|
|
|
|
2016-01-25 04:43:27 +00:00
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
runloop_msg_queue_push("File could not be loaded.\n", 1, 100, true);
|
2016-02-04 14:00:38 +00:00
|
|
|
return false;
|
2016-01-25 04:43:27 +00:00
|
|
|
}
|
2016-02-04 14:29:37 +00:00
|
|
|
|
2016-01-25 04:43:27 +00:00
|
|
|
retro_fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
runloop_ctl(RUNLOOP_CTL_SET_LIBRETRO_PATH, (void*)core_path);
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
menu_driver_ctl(RARCH_MENU_CTL_UNSET_LOAD_NO_CONTENT, NULL);
|
|
|
|
else
|
|
|
|
menu_driver_ctl(RARCH_MENU_CTL_SET_LOAD_NO_CONTENT, NULL);
|
|
|
|
|
2016-02-07 12:08:14 +00:00
|
|
|
if (!event_cmd_exec((void*)path))
|
|
|
|
return false;
|
2016-01-25 04:43:27 +00:00
|
|
|
|
|
|
|
event_cmd_ctl(EVENT_CMD_LOAD_CORE, NULL);
|
2016-02-04 14:00:38 +00:00
|
|
|
|
|
|
|
return true;
|
2016-01-25 04:43:27 +00:00
|
|
|
}
|
|
|
|
|
2016-01-25 04:38:22 +00:00
|
|
|
/**
|
2016-02-04 14:46:24 +00:00
|
|
|
* menu_content_find_first_core:
|
2016-01-25 04:38:22 +00:00
|
|
|
* @core_info : Core info list handle.
|
|
|
|
* @dir : Directory. Gets joined with @path.
|
|
|
|
* @path : Path. Gets joined with @dir.
|
|
|
|
* @menu_label : Label identifier of menu setting.
|
|
|
|
* @s : Deferred core path. Will be filled in
|
|
|
|
* by function.
|
|
|
|
* @len : Size of @s.
|
|
|
|
*
|
|
|
|
* Gets deferred core.
|
|
|
|
*
|
2016-02-04 14:46:52 +00:00
|
|
|
* Returns: false if there are multiple deferred cores and a
|
2016-01-25 04:38:22 +00:00
|
|
|
* selection needs to be made from a list, otherwise
|
2016-02-04 14:46:52 +00:00
|
|
|
* returns true and fills in @s with path to core.
|
2016-01-25 04:38:22 +00:00
|
|
|
**/
|
2016-02-04 14:46:24 +00:00
|
|
|
static bool menu_content_find_first_core(void *data)
|
2016-01-25 04:38:22 +00:00
|
|
|
{
|
|
|
|
char new_core_path[PATH_MAX_LENGTH];
|
2016-02-04 14:21:42 +00:00
|
|
|
const core_info_t *info = NULL;
|
|
|
|
size_t supported = 0;
|
2016-02-04 20:20:28 +00:00
|
|
|
menu_content_ctx_defer_info_t *def_info =
|
|
|
|
(menu_content_ctx_defer_info_t *)data;
|
|
|
|
core_info_list_t *core_info =
|
|
|
|
(core_info_list_t*)def_info->data;
|
2016-02-04 14:21:42 +00:00
|
|
|
uint32_t menu_label_hash =
|
|
|
|
menu_hash_calculate(def_info->menu_label);
|
2016-01-25 04:38:22 +00:00
|
|
|
|
2016-02-04 14:21:42 +00:00
|
|
|
if (!string_is_empty(def_info->dir) && !string_is_empty(def_info->path))
|
|
|
|
fill_pathname_join(def_info->s,
|
|
|
|
def_info->dir, def_info->path, def_info->len);
|
2016-01-25 04:38:22 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_COMPRESSION
|
2016-02-04 14:21:42 +00:00
|
|
|
if (path_is_compressed_file(def_info->dir))
|
2016-01-25 04:38:22 +00:00
|
|
|
{
|
|
|
|
/* In case of a compressed archive, we have to join with a hash */
|
|
|
|
/* We are going to write at the position of dir: */
|
2016-02-04 14:21:42 +00:00
|
|
|
retro_assert(strlen(def_info->dir) < strlen(def_info->s));
|
|
|
|
def_info->s[strlen(def_info->dir)] = '#';
|
2016-01-25 04:38:22 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (core_info)
|
2016-02-04 14:21:42 +00:00
|
|
|
core_info_list_get_supported_cores(core_info,
|
|
|
|
def_info->s, &info,
|
2016-01-25 04:38:22 +00:00
|
|
|
&supported);
|
|
|
|
|
|
|
|
/* We started the menu with 'Load Content', we are
|
|
|
|
* going to use the current core to load this. */
|
|
|
|
if (menu_label_hash == MENU_LABEL_LOAD_CONTENT)
|
|
|
|
{
|
2016-02-07 01:37:57 +00:00
|
|
|
core_info_ctl(CORE_INFO_CTL_CURRENT_CORE_GET, (void*)&info);
|
2016-01-25 04:38:22 +00:00
|
|
|
if (info)
|
|
|
|
{
|
2016-02-04 20:20:28 +00:00
|
|
|
RARCH_LOG("Use the current core (%s) to load this content...\n",
|
|
|
|
info->path);
|
2016-01-25 04:38:22 +00:00
|
|
|
supported = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There are multiple deferred cores and a
|
|
|
|
* selection needs to be made from a list, return 0. */
|
|
|
|
if (supported != 1)
|
2016-02-04 14:21:42 +00:00
|
|
|
return false;
|
2016-01-25 04:38:22 +00:00
|
|
|
|
|
|
|
if (info)
|
|
|
|
strlcpy(new_core_path, info->path, sizeof(new_core_path));
|
|
|
|
|
2016-02-04 14:21:42 +00:00
|
|
|
runloop_ctl(RUNLOOP_CTL_SET_CONTENT_PATH, def_info->s);
|
2016-01-25 04:38:22 +00:00
|
|
|
|
|
|
|
if (path_file_exists(new_core_path))
|
|
|
|
runloop_ctl(RUNLOOP_CTL_SET_LIBRETRO_PATH, new_core_path);
|
2016-02-04 14:21:42 +00:00
|
|
|
|
|
|
|
return true;
|
2016-01-25 04:38:22 +00:00
|
|
|
}
|
2016-02-04 13:51:01 +00:00
|
|
|
|
|
|
|
bool menu_content_ctl(enum menu_content_ctl_state state, void *data)
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
2016-02-04 14:21:42 +00:00
|
|
|
case MENU_CONTENT_CTL_FIND_FIRST_CORE:
|
2016-02-04 14:46:24 +00:00
|
|
|
return menu_content_find_first_core(data);
|
2016-02-04 13:51:01 +00:00
|
|
|
case MENU_CONTENT_CTL_LOAD:
|
|
|
|
return menu_content_load();
|
2016-02-04 14:00:38 +00:00
|
|
|
case MENU_CONTENT_CTL_LOAD_PLAYLIST:
|
|
|
|
return menu_content_load_from_playlist(data);
|
2016-02-04 13:51:01 +00:00
|
|
|
case MENU_CONTENT_CTL_NONE:
|
|
|
|
default:
|
2016-02-04 16:47:56 +00:00
|
|
|
break;
|
2016-02-04 13:51:01 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 16:47:56 +00:00
|
|
|
return false;
|
2016-02-04 13:51:01 +00:00
|
|
|
}
|