diff --git a/Makefile.common b/Makefile.common
index 6148439490..7fc1759ec3 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -175,7 +175,8 @@ OBJ += libretrodb/bintree.o \
libretrodb/libretrodb.o \
libretrodb/query.o \
libretrodb/rmsgpack.o \
- libretrodb/rmsgpack_dom.o
+ libretrodb/rmsgpack_dom.o \
+ database_info.o
endif
# Miscellaneous
diff --git a/database_info.c b/database_info.c
new file mode 100644
index 0000000000..5f07e7c533
--- /dev/null
+++ b/database_info.c
@@ -0,0 +1,146 @@
+/* RetroArch - A frontend for libretro.
+ * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
+ * Copyright (C) 2011-2015 - Daniel De Matteis
+ * Copyright (C) 2013-2015 - Jason Fetters
+ *
+ * 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 "database_info.h"
+#include "general.h"
+#include
+#include "file_ext.h"
+#include
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+int database_open_cursor(libretrodb_t *db,
+ libretrodb_cursor_t *cur, const char *query)
+{
+ const char *error = NULL;
+ libretrodb_query_t *q = NULL;
+
+ if (query)
+ q = (libretrodb_query_t*)libretrodb_query_compile(db, query,
+ strlen(query), &error);
+
+ if (error)
+ return -1;
+ if ((libretrodb_cursor_open(db, cur, q)) != 0)
+ return -1;
+
+ return 0;
+}
+
+database_info_list_t *database_info_list_new(const char *rdb_path, const char *query)
+{
+ size_t i = 0, j;
+ libretrodb_t db;
+ libretrodb_cursor_t cur;
+ struct rmsgpack_dom_value item;
+ database_info_t *database_info = NULL;
+ database_info_list_t *database_info_list = NULL;
+
+ if ((libretrodb_open(rdb_path, &db)) != 0)
+ return NULL;
+ if ((database_open_cursor(&db, &cur, query) != 0))
+ return NULL;
+
+ database_info_list = (database_info_list_t*)calloc(1, sizeof(*database_info_list));
+ if (!database_info_list)
+ goto error;
+
+ while (libretrodb_cursor_read_item(&cur, &item) == 0)
+ {
+ database_info_t *db_info = NULL;
+ if (item.type != RDT_MAP)
+ continue;
+
+ database_info = (database_info_t*)realloc(database_info, (i+1) * sizeof(database_info_t));
+
+ if (!database_info)
+ goto error;
+
+ db_info = (database_info_t*)&database_info[i];
+
+ db_info->description = NULL;
+ db_info->publisher = NULL;
+ db_info->developer = NULL;
+ db_info->origin = NULL;
+ db_info->franchise = NULL;
+
+ for (j = 0; j < item.map.len; j++)
+ {
+ struct rmsgpack_dom_value *key = &item.map.items[j].key;
+ struct rmsgpack_dom_value *val = &item.map.items[j].value;
+
+ if (!strcmp(key->string.buff, "description"))
+ db_info->description = strdup(val->string.buff);
+
+ if (!strcmp(key->string.buff, "publisher"))
+ db_info->publisher = strdup(val->string.buff);
+
+ if (!strcmp(key->string.buff, "developer"))
+ db_info->developer = strdup(val->string.buff);
+
+ if (!strcmp(key->string.buff, "origin"))
+ db_info->origin = strdup(val->string.buff);
+
+ if (!strcmp(key->string.buff, "franchise"))
+ db_info->franchise = strdup(val->string.buff);
+ }
+i++;
+ }
+
+ database_info_list->list = database_info;
+ database_info_list->count = i;
+
+ return database_info_list;
+
+error:
+ libretrodb_cursor_close(&cur);
+ libretrodb_close(&db);
+ database_info_list_free(database_info_list);
+ return NULL;
+}
+
+void database_info_list_free(database_info_list_t *database_info_list)
+{
+ size_t i, j;
+
+ if (!database_info_list)
+ return;
+
+ for (i = 0; i < database_info_list->count; i++)
+ {
+ database_info_t *info = (database_info_t*)&database_info_list->list[i];
+
+ if (!info)
+ continue;
+
+ if (info->description)
+ free(info->description);
+ if (info->publisher)
+ free(info->publisher);
+ if (info->developer)
+ free(info->developer);
+ if (info->origin)
+ free(info->origin);
+ if (info->franchise)
+ free(info->franchise);
+ }
+
+ free(database_info_list->list);
+ free(database_info_list);
+}
diff --git a/database_info.h b/database_info.h
new file mode 100644
index 0000000000..ac4c9e1f50
--- /dev/null
+++ b/database_info.h
@@ -0,0 +1,55 @@
+/* RetroArch - A frontend for libretro.
+ * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
+ * Copyright (C) 2011-2015 - Daniel De Matteis
+ * Copyright (C) 2013-2015 - Jason Fetters
+ *
+ * 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 .
+ */
+
+#ifndef DATABASE_INFO_H_
+#define DATABASE_INFO_H_
+
+#include
+#include "libretrodb/libretrodb.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct
+{
+ char *description;
+ char *publisher;
+ char *developer;
+ char *origin;
+ char *franchise;
+ void *userdata;
+} database_info_t;
+
+typedef struct
+{
+ database_info_t *list;
+ size_t count;
+} database_info_list_t;
+
+database_info_list_t *database_info_list_new(const char *rdb_path, const char *query);
+
+void database_info_list_free(database_info_list_t *list);
+
+int database_open_cursor(libretrodb_t *db,
+ libretrodb_cursor_t *cur, const char *query);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CORE_INFO_H_ */
diff --git a/griffin/griffin.c b/griffin/griffin.c
index a8a8129c7d..6a262568d4 100644
--- a/griffin/griffin.c
+++ b/griffin/griffin.c
@@ -807,6 +807,7 @@ XML
#include "../libretrodb/rmsgpack.c"
#include "../libretrodb/rmsgpack_dom.c"
#include "../libretrodb/query.c"
+#include "../database_info.c"
#endif
#ifdef __cplusplus
diff --git a/libretrodb/dat_converter.lua b/libretrodb/dat_converter.lua
index 8530679529..0e2a595e5b 100644
--- a/libretrodb/dat_converter.lua
+++ b/libretrodb/dat_converter.lua
@@ -198,6 +198,7 @@ function get_value()
elspa_rating = t.elspa_rating,
pegi_rating = t.pegi_rating,
cero_rating = t.cero_rating,
+ franchise = t.franchise,
developer = t.developer,
publisher = t.publisher,
diff --git a/menu/menu_database.c b/menu/menu_database.c
index c2b9f8b7bd..bc4c30f21c 100644
--- a/menu/menu_database.c
+++ b/menu/menu_database.c
@@ -17,29 +17,9 @@
#include "menu_database.h"
#include "menu_list.h"
#include "menu_entries.h"
+#include "../database_info.h"
#include
-#ifdef HAVE_LIBRETRODB
-static int menu_database_open_cursor(libretrodb_t *db,
- libretrodb_cursor_t *cur, const char *query)
-{
- const char *error = NULL;
- libretrodb_query_t *q = NULL;
-
- if (query)
- q = (libretrodb_query_t*)libretrodb_query_compile(db, query,
- strlen(query), &error);
-
- if (error)
- return -1;
- if ((libretrodb_cursor_open(db, cur, q)) != 0)
- return -1;
-
- return 0;
-}
-
-#endif
-
int menu_database_populate_query(file_list_t *list, const char *path,
const char *query)
{
@@ -49,14 +29,51 @@ int menu_database_populate_query(file_list_t *list, const char *path,
if ((libretrodb_open(path, &db)) != 0)
return -1;
- if ((menu_database_open_cursor(&db, &cur, query) != 0))
+ if ((database_open_cursor(&db, &cur, query) != 0))
return -1;
if ((menu_entries_push_query(&db, &cur, list)) != 0)
return -1;
-
+
libretrodb_cursor_close(&cur);
libretrodb_close(&db);
#endif
return 0;
}
+
+int menu_database_print_info(const char *path,
+ const char *query)
+{
+#ifdef HAVE_LIBRETRODB
+ size_t i;
+ database_info_list_t *db_info = NULL;
+
+ if (!(db_info = database_info_list_new(path, query)))
+ return -1;
+
+ for (i = 0; i < db_info->count; i++)
+ {
+ database_info_t *db_info_entry = (database_info_t*)&db_info->list[i];
+
+ if (!db_info_entry)
+ continue;
+
+ if (db_info_entry->description)
+ RARCH_LOG("Description: %s\n", db_info_entry->description);
+ if (db_info_entry->publisher)
+ RARCH_LOG("Publisher: %s\n", db_info_entry->publisher);
+ if (db_info_entry->developer)
+ RARCH_LOG("Developer: %s\n", db_info_entry->developer);
+ if (db_info_entry->origin)
+ RARCH_LOG("Origin: %s\n", db_info_entry->origin);
+ if (db_info_entry->franchise)
+ RARCH_LOG("Franchise: %s\n", db_info_entry->franchise);
+ RARCH_LOG("\n\n");
+ }
+
+ if (db_info)
+ database_info_list_free(db_info);
+ db_info = NULL;
+#endif
+ return 0;
+}
diff --git a/menu/menu_database.h b/menu/menu_database.h
index bbb802b6b0..b2bf9ec4bb 100644
--- a/menu/menu_database.h
+++ b/menu/menu_database.h
@@ -29,6 +29,9 @@ extern "C" {
int menu_database_populate_query(file_list_t *list, const char *path,
const char *query);
+int menu_database_print_info(const char *path,
+ const char *query);
+
#ifdef __cplusplus
}
#endif