RetroArch/menu/menu_entries.c

530 lines
14 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 16:46:50 +00: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/>.
*/
#include "menu_entries.h"
2015-01-25 05:30:51 +00:00
#include "menu_action.h"
#include "menu_navigation.h"
2014-10-21 22:23:06 +00:00
#include <file/file_list.h>
#include <file/file_path.h>
#include "../file_extract.h"
2014-10-28 18:54:23 +00:00
#include "../file_ops.h"
2014-10-21 23:13:05 +00:00
#include <file/dir_list.h>
int menu_entries_setting_set_flags(rarch_setting_t *setting)
{
if (!setting)
return 0;
2014-09-11 04:28:52 +00:00
if (setting->flags & SD_FLAG_IS_DRIVER)
2014-10-28 05:31:34 +00:00
return MENU_SETTING_DRIVER;
switch (setting->type)
2014-10-28 20:17:01 +00:00
{
case ST_ACTION:
return MENU_SETTING_ACTION;
case ST_PATH:
return MENU_FILE_PATH;
case ST_GROUP:
return MENU_SETTING_GROUP;
case ST_SUB_GROUP:
return MENU_SETTING_SUBGROUP;
default:
break;
2014-10-28 20:17:01 +00:00
}
return 0;
}
#ifdef HAVE_LIBRETRODB
int menu_entries_push_query(libretrodb_t *db,
libretrodb_cursor_t *cur, file_list_t *list)
{
unsigned i;
struct rmsgpack_dom_value item;
while (libretrodb_cursor_read_item(cur, &item) == 0)
{
if (item.type != RDT_MAP)
continue;
for (i = 0; i < item.map.len; i++)
{
struct rmsgpack_dom_value *key = &item.map.items[i].key;
struct rmsgpack_dom_value *val = &item.map.items[i].value;
2015-02-10 22:26:21 +00:00
if (!key || !val)
continue;
if (!strcmp(key->string.buff, "name"))
{
menu_list_push(list, val->string.buff, db->path,
MENU_FILE_RDB_ENTRY, 0);
break;
}
}
}
return 0;
}
#endif
2015-01-25 05:30:51 +00:00
int menu_entries_push_list(menu_handle_t *menu,
file_list_t *list,
2014-08-31 17:41:28 +00:00
const char *path, const char *label,
2015-01-25 05:30:51 +00:00
unsigned type, unsigned setting_flags)
{
2015-01-10 03:06:56 +00:00
rarch_setting_t *setting = NULL;
2015-01-25 04:39:08 +00:00
settings_list_free(menu->list_settings);
2015-01-25 05:30:51 +00:00
menu->list_settings = (rarch_setting_t *)setting_data_new(setting_flags);
2014-08-31 17:29:42 +00:00
2015-01-25 05:30:51 +00:00
if (!(setting = (rarch_setting_t*)menu_action_find_setting(label)))
return -1;
2014-10-17 18:36:02 +00:00
menu_list_clear(list);
2015-01-25 05:30:51 +00:00
/* Hack - should come up with something cleaner
* here. */
if (!strcmp(label, "Video Settings"))
2015-01-25 05:30:51 +00:00
{
#if defined(GEKKO) || defined(__CELLOS_LV2__)
menu_list_push(list, "Screen Resolution", "",
MENU_SETTINGS_VIDEO_RESOLUTION, 0);
#endif
menu_list_push(list, "Custom Ratio", "",
MENU_SETTINGS_CUSTOM_VIEWPORT, 0);
}
for (; setting->type != ST_END_GROUP; setting++)
{
if (
setting->type == ST_GROUP ||
setting->type == ST_SUB_GROUP ||
setting->type == ST_END_SUB_GROUP
)
continue;
2014-10-17 18:36:02 +00:00
menu_list_push(list, setting->short_description,
setting->name, menu_entries_setting_set_flags(setting), 0);
2014-08-31 17:29:42 +00:00
}
if (driver.menu_ctx && driver.menu_ctx->populate_entries)
2015-01-25 05:30:51 +00:00
driver.menu_ctx->populate_entries(menu, path, label, type);
return 0;
}
static void menu_entries_content_list_push(
2015-01-11 17:47:56 +00:00
file_list_t *list, core_info_t *info, const char* path)
{
unsigned j;
2015-01-11 17:47:56 +00:00
struct string_list *str_list = NULL;
if (!info)
return;
2015-01-26 05:08:18 +00:00
str_list = (struct string_list*)dir_list_new(path,
info->supported_extensions, true);
if (!str_list)
return;
dir_list_sort(str_list, true);
for (j = 0; j < str_list->size; j++)
{
const char *name = str_list->elems[j].data;
2015-02-10 22:26:21 +00:00
if (!name)
continue;
2015-01-11 17:47:56 +00:00
if (str_list->elems[j].attr.i == RARCH_DIRECTORY)
menu_entries_content_list_push(list, info, name);
else
menu_list_push(
list, name,
"content_actions",
MENU_FILE_CONTENTLIST_ENTRY, 0);
}
2015-01-11 17:47:56 +00:00
string_list_free(str_list);
}
int menu_entries_push_cores_list(file_list_t *list, core_info_t *info,
const char *path, bool push_databases_enable)
{
size_t i;
if (!info->supports_no_game)
menu_entries_content_list_push(list, info, path);
else
menu_list_push(list, info->display_name, "content_actions",
MENU_FILE_CONTENTLIST_ENTRY, 0);
if (!push_databases_enable)
return 0;
if (!info->databases_list)
return 0;
for (i = 0; i < info->databases_list->size; i++)
{
2015-02-02 17:33:39 +00:00
char db_path[PATH_MAX_LENGTH];
struct string_list *str_list = (struct string_list*)info->databases_list;
if (!str_list)
continue;
fill_pathname_join(db_path, g_settings.content_database,
str_list->elems[i].data, sizeof(db_path));
strlcat(db_path, ".rdb", sizeof(db_path));
if (!path_file_exists(db_path))
continue;
menu_list_push(list, path_basename(db_path), "core_database",
MENU_FILE_RDB, 0);
}
return 0;
}
int menu_entries_push_horizontal_menu_list(menu_handle_t *menu,
file_list_t *list,
const char *path, const char *label,
unsigned menu_type)
{
core_info_t *info = NULL;
2015-02-02 17:33:39 +00:00
core_info_list_t *info_list = (core_info_list_t*)g_extern.core_info;
if (!info_list)
return -1;
2015-02-11 20:43:16 +00:00
info = (core_info_t*)&info_list->list[driver.menu->categories.selection_ptr - 1];
if (!info)
return -1;
2015-02-02 17:33:39 +00:00
strlcpy(g_settings.libretro, info->path, sizeof(g_settings.libretro));
menu_list_clear(list);
menu_entries_push_cores_list(list, info, g_settings.content_directory, true);
menu_list_populate_generic(menu, list, path, label, menu_type);
return 0;
}
/**
* menu_entries_parse_drive_list:
* @list : File list handle.
*
* Generates default directory drive list.
* Platform-specific.
*
**/
static void menu_entries_parse_drive_list(file_list_t *list)
2014-10-13 00:08:39 +00:00
{
2015-01-09 17:04:29 +00:00
size_t i = 0;
2014-12-23 02:01:23 +00:00
(void)i;
2014-10-13 00:08:39 +00:00
#if defined(GEKKO)
#ifdef HW_RVL
2014-12-21 22:44:33 +00:00
menu_list_push(list,
"sd:/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"usb:/", "", MENU_FILE_DIRECTORY, 0);
2014-10-13 00:08:39 +00:00
#endif
2014-12-21 22:44:33 +00:00
menu_list_push(list,
"carda:/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"cardb:/", "", MENU_FILE_DIRECTORY, 0);
2014-10-13 00:08:39 +00:00
#elif defined(_XBOX1)
2014-12-21 22:44:33 +00:00
menu_list_push(list,
"C:", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"D:", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"E:", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"F:", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"G:", "", MENU_FILE_DIRECTORY, 0);
2014-10-13 00:08:39 +00:00
#elif defined(_XBOX360)
2014-12-21 22:44:33 +00:00
menu_list_push(list,
"game:", "", MENU_FILE_DIRECTORY, 0);
2014-10-13 00:08:39 +00:00
#elif defined(_WIN32)
2014-12-21 22:44:33 +00:00
unsigned drives = GetLogicalDrives();
char drive[] = " :\\";
for (i = 0; i < 32; i++)
{
drive[0] = 'A' + i;
if (drives & (1 << i))
menu_list_push(list,
drive, "", MENU_FILE_DIRECTORY, 0);
}
2014-10-13 00:08:39 +00:00
#elif defined(__CELLOS_LV2__)
2014-12-21 22:44:33 +00:00
menu_list_push(list,
"/app_home/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"/dev_hdd0/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"/dev_hdd1/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"/host_root/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"/dev_usb000/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"/dev_usb001/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"/dev_usb002/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"/dev_usb003/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"/dev_usb004/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"/dev_usb005/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"/dev_usb006/", "", MENU_FILE_DIRECTORY, 0);
2014-10-13 00:08:39 +00:00
#elif defined(PSP)
2014-12-21 22:44:33 +00:00
menu_list_push(list,
"ms0:/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"ef0:/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"host0:/", "", MENU_FILE_DIRECTORY, 0);
2014-10-13 00:08:39 +00:00
#elif defined(IOS)
menu_list_push(list,
"/var/mobile/Documents/", "", MENU_FILE_DIRECTORY, 0);
2014-12-21 22:44:33 +00:00
menu_list_push(list,
"/var/mobile/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
g_defaults.core_dir, "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list, "/", "",
MENU_FILE_DIRECTORY, 0);
2014-10-13 00:08:39 +00:00
#else
2014-12-21 22:44:33 +00:00
menu_list_push(list, "/", "",
MENU_FILE_DIRECTORY, 0);
2014-10-13 00:08:39 +00:00
#endif
2014-12-21 22:44:33 +00:00
}
int menu_entries_parse_list(
file_list_t *list, file_list_t *menu_list,
2014-12-21 22:44:33 +00:00
const char *dir, const char *label, unsigned type,
2015-01-10 04:25:37 +00:00
unsigned default_type_plain, const char *exts,
rarch_setting_t *setting)
2014-12-21 22:44:33 +00:00
{
size_t i, list_size;
2015-01-10 03:06:56 +00:00
bool path_is_compressed, push_dir;
2015-01-12 21:35:34 +00:00
int device = 0;
2014-12-21 22:44:33 +00:00
struct string_list *str_list = NULL;
(void)device;
if (!list || !menu_list)
return -1;
2014-12-21 22:44:33 +00:00
menu_list_clear(list);
if (!*dir)
{
menu_entries_parse_drive_list(list);
if (driver.menu_ctx && driver.menu_ctx->populate_entries)
driver.menu_ctx->populate_entries(driver.menu, dir, label, type);
2014-10-13 00:08:39 +00:00
return 0;
}
#if defined(GEKKO) && defined(HW_RVL)
LWP_MutexLock(gx_device_mutex);
device = gx_get_device_from_path(dir);
2014-10-13 00:08:39 +00:00
if (device != -1 && !gx_devices[device].mounted &&
gx_devices[device].interface->isInserted())
fatMountSimple(gx_devices[device].name, gx_devices[device].interface);
2014-10-13 00:08:39 +00:00
LWP_MutexUnlock(gx_device_mutex);
#endif
2015-01-10 03:06:56 +00:00
path_is_compressed = path_is_compressed_file(dir);
2015-01-10 04:25:37 +00:00
push_dir = (setting && setting->browser_selection_type == ST_DIR);
2014-10-13 00:08:39 +00:00
if (path_is_compressed)
str_list = compressed_file_list_new(dir,exts);
else
str_list = dir_list_new(dir,
g_settings.menu.navigation.browser.filter.supported_extensions_enable
? exts : NULL, true);
2014-10-13 00:08:39 +00:00
if (!str_list)
return -1;
dir_list_sort(str_list, true);
2014-10-16 04:01:59 +00:00
if (push_dir)
2014-10-17 18:36:02 +00:00
menu_list_push(list, "<Use this directory>", "",
2014-10-13 00:08:39 +00:00
MENU_FILE_USE_DIRECTORY, 0);
list_size = str_list->size;
for (i = 0; i < str_list->size; i++)
{
2015-01-10 03:06:56 +00:00
bool is_dir;
const char *path = NULL;
2014-10-13 00:08:39 +00:00
menu_file_type_t file_type = MENU_FILE_NONE;
2015-01-10 03:06:56 +00:00
2014-10-13 00:08:39 +00:00
switch (str_list->elems[i].attr.i)
{
case RARCH_DIRECTORY:
file_type = MENU_FILE_DIRECTORY;
break;
case RARCH_COMPRESSED_ARCHIVE:
file_type = MENU_FILE_CARCHIVE;
break;
case RARCH_COMPRESSED_FILE_IN_ARCHIVE:
file_type = MENU_FILE_IN_CARCHIVE;
break;
case RARCH_PLAIN_FILE:
default:
if (!strcmp(label, "detect_core_list"))
{
if (path_is_compressed_file(str_list->elems[i].data))
{
/* in case of deferred_core_list we have to interpret
* every archive as an archive to disallow instant loading
*/
file_type = MENU_FILE_CARCHIVE;
break;
}
}
file_type = (menu_file_type_t)default_type_plain;
break;
}
2015-01-10 03:06:56 +00:00
is_dir = (file_type == MENU_FILE_DIRECTORY);
2014-10-13 00:08:39 +00:00
2014-10-16 04:01:59 +00:00
if (push_dir && !is_dir)
2014-10-13 00:08:39 +00:00
continue;
/* Need to preserve slash first time. */
2015-01-10 03:06:56 +00:00
path = str_list->elems[i].data;
2014-10-13 00:08:39 +00:00
if (*dir && !path_is_compressed)
path = path_basename(path);
#ifdef HAVE_LIBRETRO_MANAGEMENT
#ifdef RARCH_CONSOLE
if (!strcmp(label, "core_list") && (is_dir ||
strcasecmp(path, SALAMANDER_FILE) == 0))
continue;
#endif
#endif
/* Push type further down in the chain.
* Needed for shader manager currently. */
if (!strcmp(label, "core_list"))
{
/* Compressed cores are unsupported */
if (file_type == MENU_FILE_CARCHIVE)
continue;
2014-10-17 18:36:02 +00:00
menu_list_push(list, path, "",
2014-10-13 00:08:39 +00:00
is_dir ? MENU_FILE_DIRECTORY : MENU_FILE_CORE, 0);
}
else
2014-10-17 18:36:02 +00:00
menu_list_push(list, path, "",
2014-10-13 00:08:39 +00:00
file_type, 0);
}
string_list_free(str_list);
if (!strcmp(label, "core_list"))
{
menu_list_get_last_stack(driver.menu->menu_list, &dir, NULL, NULL);
2014-10-13 00:08:39 +00:00
list_size = file_list_get_size(list);
for (i = 0; i < list_size; i++)
{
char core_path[PATH_MAX_LENGTH], display_name[PATH_MAX_LENGTH];
2014-10-13 00:08:39 +00:00
const char *path = NULL;
2014-10-17 21:28:33 +00:00
menu_list_get_at_offset(list, i, &path, NULL, &type);
2014-10-13 00:08:39 +00:00
if (type != MENU_FILE_CORE)
continue;
fill_pathname_join(core_path, dir, path, sizeof(core_path));
if (g_extern.core_info &&
core_info_list_get_display_name(g_extern.core_info,
core_path, display_name, sizeof(display_name)))
menu_list_set_alt_at_offset(list, i, display_name);
2014-10-13 00:08:39 +00:00
}
2014-10-17 21:46:53 +00:00
menu_list_sort_on_alt(list);
2014-10-13 00:08:39 +00:00
}
menu_list_populate_generic(driver.menu, list, dir, label, type);
2014-10-13 00:08:39 +00:00
return 0;
}
int menu_entries_deferred_push(file_list_t *list, file_list_t *menu_list)
2014-10-12 16:15:03 +00:00
{
2015-01-10 03:06:56 +00:00
unsigned type = 0;
const char *path = NULL;
const char *label = NULL;
menu_file_list_cbs_t *cbs = NULL;
2014-10-12 16:15:03 +00:00
menu_list_get_last_stack(driver.menu->menu_list, &path, &label, &type);
2014-10-12 16:15:03 +00:00
2014-10-15 19:04:21 +00:00
if (!strcmp(label, "Main Menu"))
2015-01-25 05:30:51 +00:00
return menu_entries_push_list(driver.menu, list, path, label, type,
SL_FLAG_MAIN_MENU);
else if (!strcmp(label, "Horizontal Menu"))
return menu_entries_push_horizontal_menu_list(driver.menu, list, path, label, type);
2014-10-15 18:39:11 +00:00
cbs = (menu_file_list_cbs_t*)
menu_list_get_last_stack_actiondata(driver.menu->menu_list);
if (!cbs->action_deferred_push)
return 0;
2014-10-12 16:15:03 +00:00
return cbs->action_deferred_push(list, menu_list, path, label, type);
}
/**
* menu_entries_init:
* @menu : Menu handle.
*
* Creates and initializes menu entries.
*
* Returns: true (1) if successful, otherwise false (0).
**/
2014-10-13 00:08:39 +00:00
bool menu_entries_init(menu_handle_t *menu)
{
if (!menu)
return false;
2015-01-25 05:11:57 +00:00
menu->list_settings = setting_data_new(SL_FLAG_ALL);
2014-10-13 00:08:39 +00:00
menu_list_push_stack(menu->menu_list, "", "Main Menu", MENU_SETTINGS, 0);
menu_navigation_clear(menu, true);
2015-01-25 05:30:51 +00:00
menu_entries_push_list(menu, menu->menu_list->selection_buf,
"", "Main Menu", 0, SL_FLAG_MAIN_MENU);
2014-10-13 00:08:39 +00:00
return true;
}