RetroArch/menu/menu_entries_cbs.c

204 lines
6.2 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
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/>.
*/
2014-10-21 22:23:06 +00:00
#include <file/file_path.h>
2015-01-10 03:53:37 +00:00
#include "menu.h"
#include "menu_entries_cbs.h"
2015-02-14 00:51:28 +00:00
#include "menu_setting.h"
#include "menu_input.h"
#include "menu_navigation.h"
#include <file/file_extract.h>
2014-10-28 18:54:23 +00:00
#include "../config.def.h"
2015-01-09 16:40:47 +00:00
#include "../retroarch.h"
#include "../runloop.h"
#include "../file_ops.h"
void menu_entries_common_load_content(bool persist)
{
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return;
event_command(persist ? EVENT_CMD_LOAD_CONTENT_PERSIST : EVENT_CMD_LOAD_CONTENT);
2015-02-11 22:30:29 +00:00
menu_list_flush_stack(menu->menu_list, MENU_SETTINGS);
menu->msg_force = true;
}
#ifdef HAVE_NETWORKING
2015-01-23 21:00:11 +00:00
/* HACK - we have to find some way to pass state inbetween
* function pointer callback functions that don't necessarily
* call each other. */
#ifdef HAVE_ZLIB
static int zlib_extract_core_callback(const char *name, const char *valid_exts,
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
uint32_t crc32, void *userdata)
{
char path[PATH_MAX_LENGTH];
/* Make directory */
fill_pathname_join(path, (const char*)userdata, name, sizeof(path));
path_basedir(path);
if (!path_mkdir(path))
{
RARCH_ERR("Failed to create directory: %s.\n", path);
return 0;
}
/* Ignore directories. */
if (name[strlen(name) - 1] == '/' || name[strlen(name) - 1] == '\\')
return 1;
fill_pathname_join(path, (const char*)userdata, name, sizeof(path));
RARCH_LOG("path is: %s, CRC32: 0x%x\n", path, crc32);
2015-03-28 20:13:10 +00:00
if (!zlib_perform_mode(path, valid_exts,
cdata, cmode, csize, size, crc32, userdata))
{
2015-03-28 20:13:10 +00:00
if (cmode == 0)
{
RARCH_ERR("Failed to write file: %s.\n", path);
return 0;
}
goto error;
}
return 1;
error:
RARCH_ERR("Failed to deflate to: %s.\n", path);
return 0;
}
#endif
int cb_core_updater_download(void *data, size_t len)
2015-01-23 21:00:11 +00:00
{
const char* file_ext = NULL;
char output_path[PATH_MAX_LENGTH], msg[PATH_MAX_LENGTH];
2015-03-20 20:22:38 +00:00
settings_t *settings = config_get_ptr();
2015-01-23 21:00:11 +00:00
if (!data)
return -1;
2015-03-20 20:22:38 +00:00
fill_pathname_join(output_path, settings->libretro_directory,
2015-02-01 14:57:25 +00:00
core_updater_path, sizeof(output_path));
2015-01-23 21:00:11 +00:00
if (!write_file(output_path, data, len))
2015-01-23 21:00:11 +00:00
return -1;
snprintf(msg, sizeof(msg), "Download complete: %s.",
2015-02-01 14:57:25 +00:00
core_updater_path);
rarch_main_msg_queue_push(msg, 1, 90, true);
#ifdef HAVE_ZLIB
file_ext = path_get_extension(output_path);
2015-03-20 20:22:38 +00:00
if (!settings->network.buildbot_auto_extract_archive)
return 0;
if (!strcasecmp(file_ext,"zip"))
{
if (!zlib_parse_file(output_path, NULL, zlib_extract_core_callback,
2015-03-20 20:22:38 +00:00
(void*)settings->libretro_directory))
RARCH_LOG("Could not process ZIP file.\n");
}
#endif
2015-01-23 21:00:11 +00:00
return 0;
}
2015-01-24 00:31:17 +00:00
#endif
2015-01-23 21:00:11 +00:00
int menu_entries_common_is_settings_entry(const char *label)
2015-01-31 04:28:14 +00:00
{
return (
!strcmp(label, "Driver Settings") ||
!strcmp(label, "General Settings") ||
!strcmp(label, "Video Settings") ||
!strcmp(label, "Recording Settings") ||
!strcmp(label, "Shader Settings") ||
!strcmp(label, "Font Settings") ||
!strcmp(label, "Audio Settings") ||
!strcmp(label, "Input Settings") ||
!strcmp(label, "Overlay Settings") ||
!strcmp(label, "Menu Settings") ||
!strcmp(label, "UI Settings") ||
!strcmp(label, "Patch Settings") ||
!strcmp(label, "Playlist Settings") ||
!strcmp(label, "Onscreen Keyboard Overlay Settings") ||
!strcmp(label, "Core Updater Settings") ||
!strcmp(label, "Network Settings") ||
!strcmp(label, "Archive Settings") ||
!strcmp(label, "User Settings") ||
!strcmp(label, "Path Settings") ||
!strcmp(label, "Privacy Settings"));
2015-01-31 04:28:14 +00:00
}
2014-10-11 23:39:13 +00:00
void menu_entries_cbs_init(void *data,
const char *path, const char *label,
2014-10-20 02:37:52 +00:00
unsigned type, size_t idx)
2014-10-11 23:39:13 +00:00
{
2015-02-01 12:28:41 +00:00
char elem0[PATH_MAX_LENGTH], elem1[PATH_MAX_LENGTH];
struct string_list *str_list = NULL;
const char *menu_label = NULL;
menu_file_list_cbs_t *cbs = NULL;
file_list_t *list = (file_list_t*)data;
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return;
2014-10-11 23:39:13 +00:00
if (!list)
return;
2015-01-26 09:58:47 +00:00
if (!(cbs = (menu_file_list_cbs_t*)list->list[idx].actiondata))
return;
2014-10-11 23:39:13 +00:00
menu_list_get_last_stack(menu->menu_list,
2015-02-01 12:28:41 +00:00
NULL, &menu_label, NULL);
if (label)
str_list = string_split(label, "|");
if (str_list && str_list->size > 0)
strlcpy(elem0, str_list->elems[0].data, sizeof(elem0));
2015-02-12 17:21:13 +00:00
else elem0[0]='\0';
2015-02-01 12:28:41 +00:00
if (str_list && str_list->size > 1)
strlcpy(elem1, str_list->elems[1].data, sizeof(elem1));
2015-02-12 17:21:13 +00:00
else elem1[0]='\0';
2015-02-01 12:28:41 +00:00
if (str_list)
{
string_list_free(str_list);
str_list = NULL;
}
2015-02-01 12:28:41 +00:00
menu_entries_cbs_init_bind_ok(cbs, path, label, type, idx, elem0, elem1, menu_label);
menu_entries_cbs_init_bind_cancel(cbs, path, label, type, idx, elem0, elem1);
menu_entries_cbs_init_bind_start(cbs, path, label, type, idx, elem0, elem1);
menu_entries_cbs_init_bind_select(cbs, path, label, type, idx, elem0, elem1);
menu_entries_cbs_init_bind_content_list_switch(cbs, path, label, type, idx, elem0, elem1);
menu_entries_cbs_init_bind_up_or_down(cbs, path, label, type, idx, elem0, elem1);
menu_entries_cbs_init_bind_toggle(cbs, path, label, type, idx, elem0, elem1, menu_label);
menu_entries_cbs_init_bind_deferred_push(cbs, path, label, type, idx, elem0, elem1);
menu_entries_cbs_init_bind_refresh(cbs, path, label, type, idx, elem0, elem1);
menu_entries_cbs_init_bind_iterate(cbs, path, label, type, idx, elem0, elem1);
menu_entries_cbs_init_bind_get_string_representation(cbs, path, label, type, idx, elem0, elem1);
}