2015-01-27 17:09:19 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2016-01-10 03:06:50 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2015-01-27 17:09:19 +00:00
|
|
|
* Copyright (C) 2013-2015 - Jason Fetters
|
2016-10-27 15:47:10 +00:00
|
|
|
* Copyright (C) 2016 - Brad Parker
|
2016-09-25 04:13:33 +00:00
|
|
|
*
|
2015-01-27 17:09:19 +00:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-09-05 23:02:25 +00:00
|
|
|
#include <stdio.h>
|
2015-09-05 17:24:21 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2016-09-05 22:56:00 +00:00
|
|
|
#include <compat/strl.h>
|
2015-09-14 01:33:50 +00:00
|
|
|
#include <retro_endianness.h>
|
2016-09-25 04:13:33 +00:00
|
|
|
#include <file/file_path.h>
|
|
|
|
#include <file/archive_file.h>
|
2015-05-05 16:43:51 +00:00
|
|
|
|
2016-09-29 08:37:31 +00:00
|
|
|
#include "libretro-db/libretrodb.h"
|
|
|
|
|
2016-03-20 16:28:24 +00:00
|
|
|
#include "list_special.h"
|
2015-01-27 17:09:19 +00:00
|
|
|
#include "database_info.h"
|
2015-07-01 22:56:51 +00:00
|
|
|
#include "msg_hash.h"
|
2015-11-23 11:03:38 +00:00
|
|
|
#include "verbosity.h"
|
2015-01-27 17:09:19 +00:00
|
|
|
|
2015-06-03 06:48:20 +00:00
|
|
|
#define DB_QUERY_ENTRY 0x1c310956U
|
|
|
|
#define DB_QUERY_ENTRY_PUBLISHER 0x125e594dU
|
|
|
|
#define DB_QUERY_ENTRY_DEVELOPER 0xcbd89be5U
|
|
|
|
#define DB_QUERY_ENTRY_ORIGIN 0x4ebaa767U
|
|
|
|
#define DB_QUERY_ENTRY_FRANCHISE 0x77f9eff2U
|
|
|
|
#define DB_QUERY_ENTRY_RATING 0x68eba20fU
|
|
|
|
#define DB_QUERY_ENTRY_BBFC_RATING 0x0a8e67f0U
|
|
|
|
#define DB_QUERY_ENTRY_ELSPA_RATING 0x8bf6ab18U
|
|
|
|
#define DB_QUERY_ENTRY_PEGI_RATING 0x5fc77328U
|
|
|
|
#define DB_QUERY_ENTRY_CERO_RATING 0x24f6172cU
|
|
|
|
#define DB_QUERY_ENTRY_ENHANCEMENT_HW 0x9866bda3U
|
|
|
|
#define DB_QUERY_ENTRY_EDGE_MAGAZINE_RATING 0x1c7f8a43U
|
|
|
|
#define DB_QUERY_ENTRY_EDGE_MAGAZINE_ISSUE 0xaaeebde7U
|
|
|
|
#define DB_QUERY_ENTRY_FAMITSU_MAGAZINE_RATING 0xbf7ff5e7U
|
|
|
|
#define DB_QUERY_ENTRY_RELEASEDATE_MONTH 0x2b36ce66U
|
|
|
|
#define DB_QUERY_ENTRY_RELEASEDATE_YEAR 0x9c7c6e91U
|
|
|
|
#define DB_QUERY_ENTRY_MAX_USERS 0xbfcba816U
|
|
|
|
|
2015-06-07 16:55:58 +00:00
|
|
|
#define DB_CURSOR_ROM_NAME 0x16bbcf13U
|
2015-06-05 08:10:40 +00:00
|
|
|
#define DB_CURSOR_NAME 0x7c9b0c46U
|
|
|
|
#define DB_CURSOR_DESCRIPTION 0x91b0c789U
|
2016-02-04 14:20:56 +00:00
|
|
|
#define DB_CURSOR_GENRE 0x0f802156U
|
2015-06-05 08:10:40 +00:00
|
|
|
#define DB_CURSOR_PUBLISHER 0x5e099013U
|
|
|
|
#define DB_CURSOR_DEVELOPER 0x1783d2abU
|
|
|
|
#define DB_CURSOR_ORIGIN 0x1315e3edU
|
|
|
|
#define DB_CURSOR_FRANCHISE 0xc3a526b8U
|
|
|
|
#define DB_CURSOR_BBFC_RATING 0xede26836U
|
|
|
|
#define DB_CURSOR_ESRB_RATING 0x4c3fa255U
|
|
|
|
#define DB_CURSOR_ELSPA_RATING 0xd9cab41eU
|
|
|
|
#define DB_CURSOR_CERO_RATING 0x084a1772U
|
|
|
|
#define DB_CURSOR_PEGI_RATING 0x431b736eU
|
|
|
|
#define DB_CURSOR_CHECKSUM_CRC32 0x0b88671dU
|
|
|
|
#define DB_CURSOR_CHECKSUM_SHA1 0x7c9de632U
|
|
|
|
#define DB_CURSOR_CHECKSUM_MD5 0x0b888fabU
|
|
|
|
#define DB_CURSOR_ENHANCEMENT_HW 0xab612029U
|
|
|
|
#define DB_CURSOR_EDGE_MAGAZINE_REVIEW 0xd3573eabU
|
|
|
|
#define DB_CURSOR_EDGE_MAGAZINE_RATING 0xd30dc4feU
|
|
|
|
#define DB_CURSOR_EDGE_MAGAZINE_ISSUE 0xa0f30d42U
|
|
|
|
#define DB_CURSOR_FAMITSU_MAGAZINE_RATING 0x0a50ca62U
|
2016-02-04 10:55:08 +00:00
|
|
|
#define DB_CURSOR_TGDB_RATING 0x8d61458aU
|
2015-06-05 08:10:40 +00:00
|
|
|
#define DB_CURSOR_MAX_USERS 0x1084ff77U
|
|
|
|
#define DB_CURSOR_RELEASEDATE_MONTH 0x790ad76cU
|
|
|
|
#define DB_CURSOR_RELEASEDATE_YEAR 0x7fd06ed7U
|
|
|
|
#define DB_CURSOR_RUMBLE_SUPPORTED 0x1a4dc3ecU
|
2016-02-03 12:35:59 +00:00
|
|
|
#define DB_CURSOR_COOP_SUPPORTED 0x7c953ff6U
|
2015-06-05 08:10:40 +00:00
|
|
|
#define DB_CURSOR_ANALOG_SUPPORTED 0xf220fc17U
|
2015-06-07 16:55:58 +00:00
|
|
|
#define DB_CURSOR_SIZE 0x7c9dede0U
|
|
|
|
#define DB_CURSOR_SERIAL 0x1b843ec5U
|
2015-06-05 08:10:40 +00:00
|
|
|
|
2015-06-12 16:20:34 +00:00
|
|
|
static void database_info_build_query_add_quote(char *s, size_t len)
|
|
|
|
{
|
|
|
|
strlcat(s, "\"", len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void database_info_build_query_add_bracket_open(char *s, size_t len)
|
|
|
|
{
|
|
|
|
strlcat(s, "{'", len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void database_info_build_query_add_bracket_close(char *s, size_t len)
|
|
|
|
{
|
|
|
|
strlcat(s, "}", len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void database_info_build_query_add_colon(char *s, size_t len)
|
|
|
|
{
|
|
|
|
strlcat(s, "':", len);
|
|
|
|
}
|
|
|
|
|
2015-06-12 16:26:39 +00:00
|
|
|
static void database_info_build_query_add_glob_open(char *s, size_t len)
|
|
|
|
{
|
|
|
|
strlcat(s, "glob('*", len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void database_info_build_query_add_glob_close(char *s, size_t len)
|
|
|
|
{
|
|
|
|
strlcat(s, "*')", len);
|
|
|
|
}
|
|
|
|
|
2015-06-03 06:22:50 +00:00
|
|
|
int database_info_build_query(char *s, size_t len,
|
|
|
|
const char *label, const char *path)
|
2015-05-24 17:36:28 +00:00
|
|
|
{
|
2015-06-03 06:22:50 +00:00
|
|
|
uint32_t value = 0;
|
2015-05-24 17:36:28 +00:00
|
|
|
bool add_quotes = true;
|
2015-06-12 16:26:39 +00:00
|
|
|
bool add_glob = false;
|
2015-05-24 17:36:28 +00:00
|
|
|
|
2015-06-12 16:20:34 +00:00
|
|
|
database_info_build_query_add_bracket_open(s, len);
|
2015-06-03 06:22:50 +00:00
|
|
|
|
2015-07-01 22:56:51 +00:00
|
|
|
value = msg_hash_calculate(label);
|
2015-05-24 17:36:28 +00:00
|
|
|
|
2015-06-03 06:22:50 +00:00
|
|
|
switch (value)
|
2015-06-02 22:36:49 +00:00
|
|
|
{
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "name", len);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_PUBLISHER:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "publisher", len);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_DEVELOPER:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "developer", len);
|
2015-06-12 16:26:39 +00:00
|
|
|
add_glob = true;
|
|
|
|
add_quotes = false;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_ORIGIN:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "origin", len);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_FRANCHISE:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "franchise", len);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_RATING:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "esrb_rating", len);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_BBFC_RATING:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "bbfc_rating", len);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_ELSPA_RATING:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "elspa_rating", len);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_PEGI_RATING:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "pegi_rating", len);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_CERO_RATING:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "cero_rating", len);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_ENHANCEMENT_HW:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "enhancement_hw", len);
|
2015-06-03 06:48:20 +00:00
|
|
|
break;
|
|
|
|
case DB_QUERY_ENTRY_EDGE_MAGAZINE_RATING:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "edge_rating", len);
|
|
|
|
add_quotes = false;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_EDGE_MAGAZINE_ISSUE:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "edge_issue", len);
|
|
|
|
add_quotes = false;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_FAMITSU_MAGAZINE_RATING:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "famitsu_rating", len);
|
|
|
|
add_quotes = false;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_RELEASEDATE_MONTH:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "releasemonth", len);
|
|
|
|
add_quotes = false;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_RELEASEDATE_YEAR:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "releaseyear", len);
|
|
|
|
add_quotes = false;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_QUERY_ENTRY_MAX_USERS:
|
2015-06-05 08:10:40 +00:00
|
|
|
strlcat(s, "users", len);
|
|
|
|
add_quotes = false;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-06-04 15:10:33 +00:00
|
|
|
RARCH_LOG("Unknown label: %s\n", label);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-05-24 17:36:28 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 16:20:34 +00:00
|
|
|
database_info_build_query_add_colon(s, len);
|
2015-06-12 16:26:39 +00:00
|
|
|
if (add_glob)
|
|
|
|
database_info_build_query_add_glob_open(s, len);
|
2015-05-24 17:36:28 +00:00
|
|
|
if (add_quotes)
|
2015-06-12 16:20:34 +00:00
|
|
|
database_info_build_query_add_quote(s, len);
|
2015-06-03 06:22:50 +00:00
|
|
|
strlcat(s, path, len);
|
2015-06-12 16:26:39 +00:00
|
|
|
if (add_glob)
|
|
|
|
database_info_build_query_add_glob_close(s, len);
|
2015-05-24 17:36:28 +00:00
|
|
|
if (add_quotes)
|
2015-06-12 16:20:34 +00:00
|
|
|
database_info_build_query_add_quote(s, len);
|
|
|
|
database_info_build_query_add_bracket_close(s, len);
|
2015-05-24 17:36:28 +00:00
|
|
|
|
2015-06-12 16:26:39 +00:00
|
|
|
#if 0
|
|
|
|
RARCH_LOG("query: %s\n", s);
|
|
|
|
#endif
|
|
|
|
|
2015-05-24 17:36:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-28 15:18:48 +00:00
|
|
|
/*
|
|
|
|
* NOTE: Allocates memory, it is the caller's responsibility to free the
|
|
|
|
* memory after it is no longer required.
|
|
|
|
*/
|
2015-09-23 13:11:35 +00:00
|
|
|
char *bin_to_hex_alloc(const uint8_t *data, size_t len)
|
2015-05-24 18:48:49 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
char *ret = (char*)malloc(len * 2 + 1);
|
|
|
|
|
|
|
|
if (len && !ret)
|
|
|
|
return NULL;
|
2016-09-25 04:13:33 +00:00
|
|
|
|
2015-05-24 18:48:49 +00:00
|
|
|
for (i = 0; i < len; i++)
|
2015-09-28 15:18:48 +00:00
|
|
|
snprintf(ret+i * 2, 3, "%02X", data[i]);
|
2015-05-24 18:48:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-03 06:48:20 +00:00
|
|
|
|
2015-05-25 03:24:47 +00:00
|
|
|
static int database_cursor_iterate(libretrodb_cursor_t *cur,
|
2015-05-24 18:48:49 +00:00
|
|
|
database_info_t *db_info)
|
2015-05-24 18:19:34 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
struct rmsgpack_dom_value item;
|
2015-06-12 15:04:25 +00:00
|
|
|
const char* str = NULL;
|
2015-05-24 18:19:34 +00:00
|
|
|
|
|
|
|
if (libretrodb_cursor_read_item(cur, &item) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (item.type != RDT_MAP)
|
2015-06-04 15:41:07 +00:00
|
|
|
{
|
|
|
|
rmsgpack_dom_value_free(&item);
|
2015-05-24 18:19:34 +00:00
|
|
|
return 1;
|
2015-06-04 15:41:07 +00:00
|
|
|
}
|
2015-05-24 18:19:34 +00:00
|
|
|
|
2015-05-24 18:48:49 +00:00
|
|
|
db_info->analog_supported = -1;
|
|
|
|
db_info->rumble_supported = -1;
|
2016-02-03 12:35:59 +00:00
|
|
|
db_info->coop_supported = -1;
|
2015-05-24 18:48:49 +00:00
|
|
|
|
2015-06-26 18:33:40 +00:00
|
|
|
for (i = 0; i < item.val.map.len; i++)
|
2015-05-24 18:19:34 +00:00
|
|
|
{
|
2015-06-03 06:22:50 +00:00
|
|
|
uint32_t value = 0;
|
2015-06-26 18:33:40 +00:00
|
|
|
struct rmsgpack_dom_value *key = &item.val.map.items[i].key;
|
|
|
|
struct rmsgpack_dom_value *val = &item.val.map.items[i].value;
|
2015-05-24 18:19:34 +00:00
|
|
|
|
|
|
|
if (!key || !val)
|
|
|
|
continue;
|
|
|
|
|
2015-06-26 18:33:40 +00:00
|
|
|
str = key->val.string.buff;
|
2015-07-01 22:56:51 +00:00
|
|
|
value = msg_hash_calculate(str);
|
2015-06-03 06:22:50 +00:00
|
|
|
|
|
|
|
switch (value)
|
2015-06-02 22:36:49 +00:00
|
|
|
{
|
2015-06-07 16:55:58 +00:00
|
|
|
case DB_CURSOR_SERIAL:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->serial = strdup(val->val.string.buff);
|
2015-06-07 16:55:58 +00:00
|
|
|
break;
|
|
|
|
case DB_CURSOR_ROM_NAME:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->rom_name = strdup(val->val.string.buff);
|
2015-06-07 16:55:58 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_NAME:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->name = strdup(val->val.string.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_DESCRIPTION:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->description = strdup(val->val.string.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2016-02-04 14:20:56 +00:00
|
|
|
case DB_CURSOR_GENRE:
|
|
|
|
db_info->genre = strdup(val->val.string.buff);
|
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_PUBLISHER:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->publisher = strdup(val->val.string.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_DEVELOPER:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->developer = string_split(val->val.string.buff, "|");
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_ORIGIN:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->origin = strdup(val->val.string.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_FRANCHISE:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->franchise = strdup(val->val.string.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_BBFC_RATING:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->bbfc_rating = strdup(val->val.string.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_ESRB_RATING:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->esrb_rating = strdup(val->val.string.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_ELSPA_RATING:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->elspa_rating = strdup(val->val.string.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_CERO_RATING:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->cero_rating = strdup(val->val.string.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_PEGI_RATING:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->pegi_rating = strdup(val->val.string.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_ENHANCEMENT_HW:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->enhancement_hw = strdup(val->val.string.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_EDGE_MAGAZINE_REVIEW:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->edge_magazine_review = strdup(val->val.string.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_EDGE_MAGAZINE_RATING:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->edge_magazine_rating = val->val.uint_;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_EDGE_MAGAZINE_ISSUE:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->edge_magazine_issue = val->val.uint_;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_FAMITSU_MAGAZINE_RATING:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->famitsu_magazine_rating = val->val.uint_;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2016-02-04 10:55:08 +00:00
|
|
|
case DB_CURSOR_TGDB_RATING:
|
|
|
|
db_info->tgdb_rating = val->val.uint_;
|
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_MAX_USERS:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->max_users = val->val.uint_;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_RELEASEDATE_MONTH:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->releasemonth = val->val.uint_;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_RELEASEDATE_YEAR:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->releaseyear = val->val.uint_;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_RUMBLE_SUPPORTED:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->rumble_supported = val->val.uint_;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2016-02-03 12:35:59 +00:00
|
|
|
case DB_CURSOR_COOP_SUPPORTED:
|
|
|
|
db_info->coop_supported = val->val.uint_;
|
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_ANALOG_SUPPORTED:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->analog_supported = val->val.uint_;
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-07 16:55:58 +00:00
|
|
|
case DB_CURSOR_SIZE:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->size = val->val.uint_;
|
2015-06-07 16:55:58 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_CHECKSUM_CRC32:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->crc32 = swap_if_little32(*(uint32_t*)val->val.binary.buff);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_CHECKSUM_SHA1:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->sha1 = bin_to_hex_alloc((uint8_t*)val->val.binary.buff, val->val.binary.len);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-03 06:48:20 +00:00
|
|
|
case DB_CURSOR_CHECKSUM_MD5:
|
2015-06-26 18:33:40 +00:00
|
|
|
db_info->md5 = bin_to_hex_alloc((uint8_t*)val->val.binary.buff, val->val.binary.len);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-06-05 20:39:20 +00:00
|
|
|
RARCH_LOG("Unknown key: %s\n", str);
|
2015-06-03 06:22:50 +00:00
|
|
|
break;
|
2015-06-02 22:36:49 +00:00
|
|
|
}
|
2015-05-24 18:19:34 +00:00
|
|
|
}
|
|
|
|
|
2015-05-28 00:23:06 +00:00
|
|
|
rmsgpack_dom_value_free(&item);
|
|
|
|
|
2015-05-24 18:48:49 +00:00
|
|
|
return 0;
|
2015-05-24 18:19:34 +00:00
|
|
|
}
|
|
|
|
|
2015-05-25 03:24:47 +00:00
|
|
|
static int database_cursor_open(libretrodb_t *db,
|
2015-05-25 03:09:18 +00:00
|
|
|
libretrodb_cursor_t *cur, const char *path, const char *query)
|
2015-01-27 17:09:19 +00:00
|
|
|
{
|
|
|
|
const char *error = NULL;
|
|
|
|
libretrodb_query_t *q = NULL;
|
|
|
|
|
2015-05-25 03:09:18 +00:00
|
|
|
if ((libretrodb_open(path, db)) != 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-09-25 04:13:33 +00:00
|
|
|
if (query)
|
2015-02-11 13:22:43 +00:00
|
|
|
q = (libretrodb_query_t*)libretrodb_query_compile(db, query,
|
2015-01-27 17:09:19 +00:00
|
|
|
strlen(query), &error);
|
2016-09-25 04:13:33 +00:00
|
|
|
|
2015-01-27 17:09:19 +00:00
|
|
|
if (error)
|
2015-05-28 00:22:50 +00:00
|
|
|
goto error;
|
2015-01-27 17:09:19 +00:00
|
|
|
if ((libretrodb_cursor_open(db, cur, q)) != 0)
|
2015-05-28 00:22:50 +00:00
|
|
|
goto error;
|
2015-01-27 17:09:19 +00:00
|
|
|
|
2015-05-28 00:24:51 +00:00
|
|
|
if (q)
|
|
|
|
libretrodb_query_free(q);
|
|
|
|
|
2015-01-27 17:09:19 +00:00
|
|
|
return 0;
|
2015-05-28 00:22:50 +00:00
|
|
|
|
|
|
|
error:
|
2015-05-28 00:24:51 +00:00
|
|
|
if (q)
|
2015-05-28 00:22:50 +00:00
|
|
|
libretrodb_query_free(q);
|
|
|
|
libretrodb_close(db);
|
|
|
|
|
|
|
|
return -1;
|
2015-01-27 17:09:19 +00:00
|
|
|
}
|
|
|
|
|
2015-05-25 03:24:47 +00:00
|
|
|
static int database_cursor_close(libretrodb_t *db, libretrodb_cursor_t *cur)
|
2015-05-24 23:56:33 +00:00
|
|
|
{
|
|
|
|
libretrodb_cursor_close(cur);
|
|
|
|
libretrodb_close(db);
|
2015-05-25 00:04:29 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-05-24 23:56:33 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 16:53:18 +00:00
|
|
|
database_info_handle_t *database_info_dir_init(const char *dir,
|
2015-06-03 06:22:50 +00:00
|
|
|
enum database_type type)
|
2015-02-05 15:25:29 +00:00
|
|
|
{
|
2015-06-03 06:22:50 +00:00
|
|
|
database_info_handle_t *db = (database_info_handle_t*)
|
|
|
|
calloc(1, sizeof(*db));
|
2016-09-30 06:23:24 +00:00
|
|
|
unsigned i = 0;
|
2015-02-16 06:25:40 +00:00
|
|
|
|
2015-04-14 07:27:55 +00:00
|
|
|
if (!db)
|
2015-02-16 06:25:40 +00:00
|
|
|
return NULL;
|
2015-02-05 15:25:29 +00:00
|
|
|
|
2016-08-21 04:59:41 +00:00
|
|
|
db->list = dir_list_new_special(dir, DIR_LIST_RECURSIVE, NULL);
|
2015-04-14 06:10:12 +00:00
|
|
|
|
2015-04-14 07:27:55 +00:00
|
|
|
if (!db->list)
|
2015-04-14 06:10:12 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-04-14 07:27:55 +00:00
|
|
|
db->list_ptr = 0;
|
2015-06-09 17:01:24 +00:00
|
|
|
db->status = DATABASE_STATUS_ITERATE;
|
|
|
|
db->type = type;
|
|
|
|
|
2016-09-25 04:13:33 +00:00
|
|
|
if (db->list->size > 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < db->list->size; i++)
|
|
|
|
{
|
|
|
|
const char *path = db->list->elems[i].data;
|
|
|
|
|
2016-11-28 23:19:54 +00:00
|
|
|
if (path_is_compressed_file(path) && !path_contains_compressed_file(path))
|
2016-09-25 04:13:33 +00:00
|
|
|
{
|
|
|
|
struct string_list *archive_list =
|
|
|
|
file_archive_get_file_list(path, NULL);
|
|
|
|
|
|
|
|
if (archive_list && archive_list->size > 0)
|
|
|
|
{
|
2016-09-30 06:23:24 +00:00
|
|
|
unsigned i;
|
2016-09-25 04:13:33 +00:00
|
|
|
|
|
|
|
for (i = 0; i < archive_list->size; i++)
|
|
|
|
{
|
2016-10-08 16:44:24 +00:00
|
|
|
char new_path[PATH_MAX_LENGTH];
|
2016-09-25 04:13:33 +00:00
|
|
|
size_t path_len = strlen(path);
|
|
|
|
|
2016-10-08 16:44:24 +00:00
|
|
|
new_path[0] = '\0';
|
|
|
|
|
2016-09-25 04:13:33 +00:00
|
|
|
strlcpy(new_path, path, sizeof(new_path));
|
|
|
|
|
|
|
|
if (path_len + strlen(archive_list->elems[i].data)
|
|
|
|
+ 1 < PATH_MAX_LENGTH)
|
|
|
|
{
|
|
|
|
new_path[path_len] = '#';
|
|
|
|
strlcpy(new_path + path_len + 1,
|
|
|
|
archive_list->elems[i].data,
|
|
|
|
sizeof(new_path) - path_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
string_list_append(db->list, new_path,
|
|
|
|
archive_list->elems[i].attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
string_list_free(archive_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 17:01:24 +00:00
|
|
|
return db;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (db)
|
|
|
|
free(db);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
database_info_handle_t *database_info_file_init(const char *path,
|
|
|
|
enum database_type type)
|
|
|
|
{
|
|
|
|
union string_list_elem_attr attr = {0};
|
|
|
|
database_info_handle_t *db = (database_info_handle_t*)
|
|
|
|
calloc(1, sizeof(*db));
|
|
|
|
|
|
|
|
if (!db)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
db->list = string_list_new();
|
|
|
|
|
|
|
|
if (!db->list)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
string_list_append(db->list, path, attr);
|
|
|
|
|
2016-09-25 04:13:33 +00:00
|
|
|
if (path_is_compressed_file(path))
|
|
|
|
{
|
|
|
|
struct string_list *archive_list =
|
|
|
|
file_archive_get_file_list(path, NULL);
|
|
|
|
|
|
|
|
if (archive_list && archive_list->size > 0)
|
|
|
|
{
|
2016-09-30 06:23:24 +00:00
|
|
|
unsigned i;
|
2016-09-25 04:13:33 +00:00
|
|
|
|
|
|
|
for (i = 0; i < archive_list->size; i++)
|
|
|
|
{
|
2016-10-08 16:44:24 +00:00
|
|
|
char new_path[PATH_MAX_LENGTH];
|
2016-09-25 04:13:33 +00:00
|
|
|
size_t path_len = strlen(path);
|
|
|
|
|
2016-10-08 16:44:24 +00:00
|
|
|
new_path[0] = '\0';
|
|
|
|
|
2016-09-25 04:13:33 +00:00
|
|
|
strlcpy(new_path, path, sizeof(new_path));
|
|
|
|
|
|
|
|
if (path_len + strlen(archive_list->elems[i].data)
|
|
|
|
+ 1 < PATH_MAX_LENGTH)
|
|
|
|
{
|
|
|
|
new_path[path_len] = '#';
|
|
|
|
strlcpy(new_path + path_len + 1,
|
|
|
|
archive_list->elems[i].data,
|
|
|
|
sizeof(new_path) - path_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
string_list_append(db->list, new_path,
|
|
|
|
archive_list->elems[i].attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
string_list_free(archive_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 17:01:24 +00:00
|
|
|
db->list_ptr = 0;
|
2015-04-14 07:27:55 +00:00
|
|
|
db->status = DATABASE_STATUS_ITERATE;
|
|
|
|
db->type = type;
|
2015-02-16 06:25:40 +00:00
|
|
|
|
2015-04-14 07:27:55 +00:00
|
|
|
return db;
|
2015-04-14 06:10:12 +00:00
|
|
|
|
|
|
|
error:
|
2015-04-14 07:27:55 +00:00
|
|
|
if (db)
|
|
|
|
free(db);
|
2015-04-14 06:10:12 +00:00
|
|
|
return NULL;
|
2015-02-16 06:25:40 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 07:27:55 +00:00
|
|
|
void database_info_free(database_info_handle_t *db)
|
2015-02-16 06:25:40 +00:00
|
|
|
{
|
2015-04-14 07:27:55 +00:00
|
|
|
if (!db)
|
2015-02-16 06:25:40 +00:00
|
|
|
return;
|
2015-03-14 19:22:45 +00:00
|
|
|
|
2015-04-14 07:27:55 +00:00
|
|
|
string_list_free(db->list);
|
2015-02-16 06:25:40 +00:00
|
|
|
}
|
2015-02-05 15:25:29 +00:00
|
|
|
|
2015-06-03 06:22:50 +00:00
|
|
|
database_info_list_t *database_info_list_new(
|
|
|
|
const char *rdb_path, const char *query)
|
2015-01-27 17:09:19 +00:00
|
|
|
{
|
2015-06-03 06:22:50 +00:00
|
|
|
int ret = 0;
|
2015-03-22 07:04:35 +00:00
|
|
|
unsigned k = 0;
|
|
|
|
database_info_t *database_info = NULL;
|
2015-01-27 17:09:19 +00:00
|
|
|
database_info_list_t *database_info_list = NULL;
|
2015-09-17 07:46:26 +00:00
|
|
|
libretrodb_t *db = libretrodb_new();
|
|
|
|
libretrodb_cursor_t *cur = libretrodb_cursor_new();
|
2015-01-27 17:09:19 +00:00
|
|
|
|
2015-09-17 07:46:26 +00:00
|
|
|
if (!db || !cur)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if ((database_cursor_open(db, cur, rdb_path, query) != 0))
|
|
|
|
goto end;
|
2015-01-27 17:09:19 +00:00
|
|
|
|
2015-06-03 06:22:50 +00:00
|
|
|
database_info_list = (database_info_list_t*)
|
|
|
|
calloc(1, sizeof(*database_info_list));
|
|
|
|
|
2015-01-27 17:09:19 +00:00
|
|
|
if (!database_info_list)
|
2015-05-24 18:54:08 +00:00
|
|
|
goto end;
|
2015-01-27 17:09:19 +00:00
|
|
|
|
2015-05-24 18:48:49 +00:00
|
|
|
while (ret != -1)
|
2015-01-27 17:09:19 +00:00
|
|
|
{
|
2015-05-24 18:48:49 +00:00
|
|
|
database_info_t db_info = {0};
|
2015-09-17 07:46:26 +00:00
|
|
|
ret = database_cursor_iterate(cur, &db_info);
|
2015-05-24 18:30:05 +00:00
|
|
|
|
2015-05-24 18:48:49 +00:00
|
|
|
if (ret == 0)
|
2015-01-27 17:09:19 +00:00
|
|
|
{
|
2015-09-28 14:57:07 +00:00
|
|
|
database_info_t *db_ptr = NULL;
|
|
|
|
database_info_t *new_ptr = (database_info_t*)
|
2015-06-03 06:22:50 +00:00
|
|
|
realloc(database_info, (k+1) * sizeof(database_info_t));
|
2015-01-27 18:20:39 +00:00
|
|
|
|
2015-09-28 14:57:07 +00:00
|
|
|
if (!new_ptr)
|
2015-05-24 18:54:08 +00:00
|
|
|
{
|
|
|
|
database_info_list_free(database_info_list);
|
2016-09-25 04:14:23 +00:00
|
|
|
free(database_info);
|
2016-09-25 03:55:55 +00:00
|
|
|
free(database_info_list);
|
2015-05-24 18:54:08 +00:00
|
|
|
database_info_list = NULL;
|
|
|
|
goto end;
|
|
|
|
}
|
2015-01-27 18:20:39 +00:00
|
|
|
|
2015-09-28 14:57:07 +00:00
|
|
|
database_info = new_ptr;
|
|
|
|
db_ptr = &database_info[k];
|
2015-01-27 18:20:39 +00:00
|
|
|
|
2015-05-24 18:48:49 +00:00
|
|
|
memcpy(db_ptr, &db_info, sizeof(*db_ptr));
|
2015-01-27 18:20:39 +00:00
|
|
|
|
2015-05-24 18:48:49 +00:00
|
|
|
k++;
|
2015-01-27 17:09:19 +00:00
|
|
|
}
|
2016-09-25 04:13:33 +00:00
|
|
|
}
|
2015-01-27 17:09:19 +00:00
|
|
|
|
|
|
|
database_info_list->list = database_info;
|
2015-02-10 21:39:42 +00:00
|
|
|
database_info_list->count = k;
|
2015-01-27 17:09:19 +00:00
|
|
|
|
2015-05-24 18:54:08 +00:00
|
|
|
end:
|
2015-09-17 07:46:26 +00:00
|
|
|
if (db)
|
2016-05-23 20:30:01 +00:00
|
|
|
{
|
|
|
|
database_cursor_close(db, cur);
|
2015-09-17 07:46:26 +00:00
|
|
|
libretrodb_free(db);
|
2016-05-23 20:30:01 +00:00
|
|
|
}
|
2015-09-17 07:46:26 +00:00
|
|
|
if (cur)
|
|
|
|
libretrodb_cursor_free(cur);
|
2015-05-24 18:54:08 +00:00
|
|
|
|
|
|
|
return database_info_list;
|
2015-01-27 17:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void database_info_list_free(database_info_list_t *database_info_list)
|
|
|
|
{
|
2015-01-27 22:36:20 +00:00
|
|
|
size_t i;
|
2015-01-27 17:09:19 +00:00
|
|
|
|
|
|
|
if (!database_info_list)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < database_info_list->count; i++)
|
|
|
|
{
|
2015-02-10 21:19:20 +00:00
|
|
|
database_info_t *info = &database_info_list->list[i];
|
2015-01-27 17:09:19 +00:00
|
|
|
|
2015-01-29 00:32:35 +00:00
|
|
|
if (info->name)
|
|
|
|
free(info->name);
|
2015-06-07 16:55:58 +00:00
|
|
|
if (info->rom_name)
|
|
|
|
free(info->rom_name);
|
|
|
|
if (info->serial)
|
|
|
|
free(info->serial);
|
2016-05-23 22:33:12 +00:00
|
|
|
if (info->genre)
|
|
|
|
free(info->genre);
|
2015-01-27 17:09:19 +00:00
|
|
|
if (info->description)
|
|
|
|
free(info->description);
|
|
|
|
if (info->publisher)
|
|
|
|
free(info->publisher);
|
|
|
|
if (info->developer)
|
2015-06-09 22:53:31 +00:00
|
|
|
string_list_free(info->developer);
|
|
|
|
info->developer = NULL;
|
2015-01-27 17:09:19 +00:00
|
|
|
if (info->origin)
|
|
|
|
free(info->origin);
|
|
|
|
if (info->franchise)
|
|
|
|
free(info->franchise);
|
2015-01-27 18:20:39 +00:00
|
|
|
if (info->edge_magazine_review)
|
|
|
|
free(info->edge_magazine_review);
|
|
|
|
|
|
|
|
if (info->cero_rating)
|
|
|
|
free(info->cero_rating);
|
|
|
|
if (info->pegi_rating)
|
|
|
|
free(info->pegi_rating);
|
2015-01-28 10:08:44 +00:00
|
|
|
if (info->enhancement_hw)
|
|
|
|
free(info->enhancement_hw);
|
2015-01-27 18:20:39 +00:00
|
|
|
if (info->elspa_rating)
|
|
|
|
free(info->elspa_rating);
|
|
|
|
if (info->esrb_rating)
|
|
|
|
free(info->esrb_rating);
|
|
|
|
if (info->bbfc_rating)
|
|
|
|
free(info->bbfc_rating);
|
2015-02-02 03:03:46 +00:00
|
|
|
if (info->sha1)
|
|
|
|
free(info->sha1);
|
|
|
|
if (info->md5)
|
|
|
|
free(info->md5);
|
2015-01-27 17:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(database_info_list->list);
|
|
|
|
}
|
2016-09-29 08:40:25 +00:00
|
|
|
|
2016-09-29 08:43:38 +00:00
|
|
|
void database_info_set_type(database_info_handle_t *handle, enum database_type type)
|
|
|
|
{
|
|
|
|
if (!handle)
|
|
|
|
return;
|
|
|
|
handle->type = type;
|
|
|
|
}
|
|
|
|
|
2016-09-29 08:40:25 +00:00
|
|
|
enum database_type database_info_get_type(database_info_handle_t *handle)
|
|
|
|
{
|
|
|
|
if (!handle)
|
|
|
|
return DATABASE_TYPE_NONE;
|
|
|
|
return handle->type;
|
|
|
|
}
|
2016-09-29 08:59:50 +00:00
|
|
|
|
2016-09-29 09:03:59 +00:00
|
|
|
const char *database_info_get_current_name(database_state_handle_t *handle)
|
|
|
|
{
|
|
|
|
if (!handle || !handle->list)
|
|
|
|
return NULL;
|
|
|
|
return handle->list->elems[handle->list_index].data;
|
|
|
|
}
|
|
|
|
|
2016-09-29 08:59:50 +00:00
|
|
|
const char *database_info_get_current_element_name(database_info_handle_t *handle)
|
|
|
|
{
|
|
|
|
if (!handle || !handle->list)
|
|
|
|
return NULL;
|
|
|
|
return handle->list->elems[handle->list_ptr].data;
|
|
|
|
}
|