mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 13:20:30 +00:00
(Menu database) Refactor code in menu_database.c and add 'query'
function
This commit is contained in:
parent
dabdd8d1ec
commit
6c8b19f4fa
@ -100,7 +100,7 @@ int main(int argc, char ** argv)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Unkonwn command %s\n", argv[2]);
|
printf("Unknown command %s\n", argv[2]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
libretrodb_close(&db);
|
libretrodb_close(&db);
|
||||||
|
@ -18,38 +18,75 @@
|
|||||||
#include "menu_list.h"
|
#include "menu_list.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBRETRODB
|
||||||
|
static int menu_database_fetch_from_query(libretrodb_t *db,
|
||||||
|
libretrodb_cursor_t *cur, libretrodb_query_t *query,
|
||||||
|
file_list_t *list)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct rmsgpack_dom_value item;
|
||||||
|
|
||||||
|
if ((libretrodb_cursor_open(db, cur, query)) != 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int menu_database_populate_query(file_list_t *list, const char *path,
|
||||||
|
const char *query)
|
||||||
|
{
|
||||||
|
libretrodb_t db;
|
||||||
|
libretrodb_cursor_t cur;
|
||||||
|
libretrodb_query_t *q;
|
||||||
|
const char *error = NULL;
|
||||||
|
|
||||||
|
if ((libretrodb_open(path, &db)) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
q = libretrodb_query_compile(&db, query, strlen(query), &error);
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if ((menu_database_fetch_from_query(&db, &cur, q, list)) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
libretrodb_cursor_close(&cur);
|
||||||
|
libretrodb_close(&db);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int menu_database_populate_list(file_list_t *list, const char *path)
|
int menu_database_populate_list(file_list_t *list, const char *path)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBRETRODB
|
#ifdef HAVE_LIBRETRODB
|
||||||
int rv = 1, i;
|
|
||||||
libretrodb_t db;
|
libretrodb_t db;
|
||||||
libretrodb_cursor_t cur;
|
libretrodb_cursor_t cur;
|
||||||
struct rmsgpack_dom_value item;
|
|
||||||
|
|
||||||
if ((rv = libretrodb_open(path, &db)) != 0)
|
if ((libretrodb_open(path, &db)) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((rv = libretrodb_cursor_open(&db, &cur, NULL)) != 0)
|
if ((menu_database_fetch_from_query(&db, &cur, NULL, list)) != 0)
|
||||||
return -1;
|
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_cursor_close(&cur);
|
||||||
libretrodb_close(&db);
|
libretrodb_close(&db);
|
||||||
|
@ -27,6 +27,9 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int menu_database_populate_list(file_list_t *list, const char *path);
|
int menu_database_populate_list(file_list_t *list, const char *path);
|
||||||
|
|
||||||
|
int menu_database_populate_query(file_list_t *list, const char *path,
|
||||||
|
const char *query);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user