/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* 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 .
*/
#include "menu_entries.h"
#include "menu_action.h"
#include
#include
#include "../file_extract.h"
#include "../file_ops.h"
#include
int menu_entries_setting_set_flags(rarch_setting_t *setting)
{
if (!setting)
return 0;
if (setting->flags & SD_FLAG_IS_DRIVER)
return MENU_SETTING_DRIVER;
switch (setting->type)
{
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;
}
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;
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
int menu_entries_push_list(menu_handle_t *menu,
file_list_t *list,
const char *path, const char *label,
unsigned type, unsigned setting_flags)
{
rarch_setting_t *setting = NULL;
settings_list_free(menu->list_settings);
menu->list_settings = (rarch_setting_t *)setting_data_new(setting_flags);
if (!(setting = (rarch_setting_t*)menu_action_find_setting(label)))
return -1;
menu_list_clear(list);
/* Hack - should come up with something cleaner
* here. */
if (!strcmp(label, "Video Options"))
{
#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;
menu_list_push(list, setting->short_description,
setting->name, menu_entries_setting_set_flags(setting), 0);
}
if (driver.menu_ctx && driver.menu_ctx->populate_entries)
driver.menu_ctx->populate_entries(menu, path, label, type);
return 0;
}
static void menu_entries_content_list_push(
file_list_t *list, core_info_t *info, const char* path)
{
unsigned j;
struct string_list *str_list = NULL;
if (!info)
return;
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;
if (!name)
continue;
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);
}
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++)
{
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;
core_info_list_t *info_list = (core_info_list_t*)g_extern.core_info;
if (!info_list)
return -1;
info = (core_info_t*)&info_list->list[driver.menu->cat_selection_ptr - 1];
if (!info)
return -1;
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)
{
size_t i = 0;
(void)i;
#if defined(GEKKO)
#ifdef HW_RVL
menu_list_push(list,
"sd:/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"usb:/", "", MENU_FILE_DIRECTORY, 0);
#endif
menu_list_push(list,
"carda:/", "", MENU_FILE_DIRECTORY, 0);
menu_list_push(list,
"cardb:/", "", MENU_FILE_DIRECTORY, 0);
#elif defined(_XBOX1)
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);
#elif defined(_XBOX360)
menu_list_push(list,
"game:", "", MENU_FILE_DIRECTORY, 0);
#elif defined(_WIN32)
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);
}
#elif defined(__CELLOS_LV2__)
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);
#elif defined(PSP)
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);
#elif defined(IOS)
menu_list_push(list,
"/var/mobile/Documents/", "", MENU_FILE_DIRECTORY, 0);
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);
#else
menu_list_push(list, "/", "",
MENU_FILE_DIRECTORY, 0);
#endif
}
int menu_entries_parse_list(
file_list_t *list, file_list_t *menu_list,
const char *dir, const char *label, unsigned type,
unsigned default_type_plain, const char *exts,
rarch_setting_t *setting)
{
size_t i, list_size;
bool path_is_compressed, push_dir;
int device = 0;
struct string_list *str_list = NULL;
(void)device;
if (!list || !menu_list)
return -1;
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);
return 0;
}
#if defined(GEKKO) && defined(HW_RVL)
LWP_MutexLock(gx_device_mutex);
device = gx_get_device_from_path(dir);
if (device != -1 && !gx_devices[device].mounted &&
gx_devices[device].interface->isInserted())
fatMountSimple(gx_devices[device].name, gx_devices[device].interface);
LWP_MutexUnlock(gx_device_mutex);
#endif
path_is_compressed = path_is_compressed_file(dir);
push_dir = (setting && setting->browser_selection_type == ST_DIR);
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);
if (!str_list)
return -1;
dir_list_sort(str_list, true);
if (push_dir)
menu_list_push(list, "