Split up database code to menu_database.c

This commit is contained in:
twinaphex 2015-01-24 04:55:35 +01:00
parent c89e499c97
commit caa7336911
4 changed files with 100 additions and 40 deletions

View File

@ -313,6 +313,7 @@ ifeq ($(HAVE_MENU_COMMON), 1)
menu/menu_common_list.o \
menu/menu_navigation.o \
menu/menu_action.o \
menu/menu_database.o \
menu/menu_shader.o \
menu/menu_entries.o \
menu/menu_entries_cbs.o \

60
menu/menu_database.c Normal file
View File

@ -0,0 +1,60 @@
/* RetroArch - A frontend for libretro.
* 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.h"
#include "menu_database.h"
#include "menu_list.h"
#include <string.h>
int menu_database_populate_list(file_list_t *list, const char *path)
{
#ifdef HAVE_LIBRETRODB
int rv = 1, i;
libretrodb_t db;
libretrodb_cursor_t cur;
struct rmsgpack_dom_value item;
const core_info_t *info = NULL;
if ((rv = libretrodb_open(path, &db)) != 0)
return -1;
if ((rv = libretrodb_cursor_open(&db, &cur, NULL)) != 0)
return -1;
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 (!strcmp(key->string.buff, "description"))
{
menu_list_push(list, val->string.buff, "",
MENU_FILE_RDB_ENTRY, 0);
break;
}
}
}
libretrodb_cursor_close(&cur);
libretrodb_close(&db);
#endif
return 0;
}

36
menu/menu_database.h Normal file
View File

@ -0,0 +1,36 @@
/* RetroArch - A frontend for libretro.
* 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/>.
*/
#ifndef _MENU_DATABASE_H
#define _MENU_DATABASE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#include "../core_info.h"
#include <file/file_list.h>
#ifdef HAVE_LIBRETRODB
#include "../libretrodb/libretrodb.h"
#endif
int menu_database_populate_list(file_list_t *list, const char *path);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -32,9 +32,7 @@
#include "../net_http.h"
#endif
#ifdef HAVE_LIBRETRODB
#include "../libretrodb/libretrodb.h"
#endif
#include "menu_database.h"
#include "../input/input_remapping.h"
@ -1638,53 +1636,18 @@ static int deferred_push_database_manager_list_deferred(void *data, void *userda
const char *path, const char *label, unsigned type)
{
unsigned i;
#ifdef HAVE_LIBRETRODB
int rv = 1;
libretrodb_t db;
libretrodb_cursor_t cur;
struct rmsgpack_dom_value item;
const core_info_t *info = NULL;
#endif
file_list_t *list = (file_list_t*)data;
file_list_t *menu_list = (file_list_t*)userdata;
if (!list || !menu_list)
return -1;
(void)info;
(void)rv;
menu_list_clear(list);
#ifdef HAVE_LIBRETRODB
if ((rv = libretrodb_open(path, &db)) != 0)
return -1;
if ((rv = libretrodb_cursor_open(&db, &cur, NULL)) != 0)
return -1;
menu_database_populate_list(list, path);
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 (!strcmp(key->string.buff, "description"))
{
menu_list_push(list, val->string.buff, "",
MENU_FILE_RDB_ENTRY, 0);
break;
}
}
}
libretrodb_cursor_close(&cur);
libretrodb_close(&db);
#endif
menu_list_sort_on_alt(list);
driver.menu->scroll_indices_size = 0;
menu_entries_build_scroll_indices(list);
menu_entries_refresh(list);