Преглед на файлове

remove retroarch database

ZengGengSen преди 1 година
родител
ревизия
b949eb2e98

+ 1 - 1
app/src/main/cpp/CMakeLists.txt

@@ -100,7 +100,7 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
         # HAVE_XMB
         # HAVE_OZONE
         # HAVE_SHADERPIPELINE
-        HAVE_LIBRETRODB
+        # HAVE_LIBRETRODB
         # HAVE_STB_FONT
         HAVE_IMAGEVIEWER
         # HAVE_ONLINE_UPDATER

+ 0 - 1082
app/src/main/cpp/database_info.c

@@ -1,1082 +0,0 @@
-/*  RetroArch - A frontend for libretro.
- *  Copyright (C) 2010-2014 - Hans-Kristian Arntzen
- *  Copyright (C) 2011-2017 - Daniel De Matteis
- *  Copyright (C) 2016-2019 - Brad Parker
- *
- *  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 <stdio.h>
-#include <stdint.h>
-
-#include <compat/strl.h>
-#include <retro_endianness.h>
-#include <file/file_path.h>
-#include <lists/string_list.h>
-#include <lists/dir_list.h>
-#include <string/stdstring.h>
-
-#include "libretro-db/libretrodb.h"
-
-#include "core_info.h"
-#include "database_info.h"
-
-int database_info_build_query_enum(char *s, size_t len,
-      enum database_query_type type,
-      const char *path)
-{
-   size_t pos = 0;
-
-   switch (type)
-   {
-      case DATABASE_QUERY_ENTRY:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'n';
-         s[3]       = 'a';
-         s[4]       = 'm';
-         s[5]       = 'e';
-         s[6]       = '\'';
-         s[7]       = ':';
-         s[8]       = '"';
-         s[9]       = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '"';
-         s[pos+1]   = '}';
-         s[pos+2]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_PUBLISHER:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'p';
-         s[3]       = 'u';
-         s[4]       = 'b';
-         s[5]       = 'l';
-         s[6]       = 'i';
-         s[7]       = 's';
-         s[8]       = 'h';
-         s[9]       = 'e';
-         s[10]      = 'r';
-         s[11]      = '\'';
-         s[12]      = ':';
-         s[13]      = '"';
-         s[14]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '"';
-         s[pos+1]   = '}';
-         s[pos+2]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_DEVELOPER:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'd';
-         s[3]       = 'e';
-         s[4]       = 'v';
-         s[5]       = 'e';
-         s[6]       = 'l';
-         s[7]       = 'o';
-         s[8]       = 'p';
-         s[9]       = 'e';
-         s[10]      = 'r';
-         s[11]      = '\'';
-         s[12]      = ':';
-         s[13]      = 'g';
-         s[14]      = 'l';
-         s[15]      = 'o';
-         s[16]      = 'b';
-         s[17]      = '(';
-         s[18]      = '\'';
-         s[19]      = '*';
-         s[20]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '*';
-         s[pos+1]   = '\'';
-         s[pos+2]   = ')';
-         s[pos+3]   = '}';
-         s[pos+4]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_ORIGIN:
-         s[0]       = '{';
-	      s[1]       = '\'';
-         s[2]       = 'o';
-         s[3]       = 'r';
-         s[4]       = 'i';
-         s[5]       = 'g';
-         s[6]       = 'i';
-         s[7]       = 'n';
-         s[8]       = '\'';
-         s[9]       = ':';
-         s[10]      = '"';
-         s[11]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '"';
-         s[pos+1]   = '}';
-         s[pos+2]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_FRANCHISE:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'f';
-         s[3]       = 'r';
-         s[4]       = 'a';
-         s[5]       = 'n';
-         s[6]       = 'c';
-         s[7]       = 'h';
-         s[8]       = 'i';
-         s[9]       = 's';
-         s[10]      = 'e';
-         s[11]      = '\'';
-         s[12]      = ':';
-         s[13]      = '"';
-         s[14]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '"';
-         s[pos+1]   = '}';
-         s[pos+2]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_RATING:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'e';
-         s[3]       = 's';
-         s[4]       = 'r';
-         s[5]       = 'b';
-         s[6]       = '_';
-         s[7]       = 'r';
-         s[8]       = 'a';
-         s[9]       = 't';
-         s[10]      = 'i';
-         s[11]      = 'n';
-         s[12]      = 'g';
-         s[13]      = '\'';
-         s[14]      = ':';
-         s[15]      = '"';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '"';
-         s[pos+1]   = '}';
-         s[pos+2]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_BBFC_RATING:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'b';
-         s[3]       = 'b';
-         s[4]       = 'f';
-         s[5]       = 'c';
-         s[6]       = '_';
-         s[7]       = 'r';
-         s[8]       = 'a';
-         s[9]       = 't';
-         s[10]      = 'i';
-         s[11]      = 'n';
-         s[12]      = 'g';
-         s[13]      = '\'';
-         s[14]      = ':';
-         s[15]      = '"';
-         s[16]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '"';
-         s[pos+1]   = '}';
-         s[pos+2]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_ELSPA_RATING:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'e';
-         s[3]       = 'l';
-         s[4]       = 's';
-         s[5]       = 'p';
-         s[6]       = 'a';
-         s[7]       = '_';
-         s[8]       = 'r';
-         s[9]       = 'a';
-         s[10]      = 't';
-         s[11]      = 'i';
-         s[12]      = 'n';
-         s[13]      = 'g';
-         s[14]      = '\'';
-         s[15]      = ':';
-         s[16]      = '"';
-         s[17]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '"';
-         s[pos+1]   = '}';
-         s[pos+2]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_ESRB_RATING:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'e';
-         s[3]       = 's';
-         s[4]       = 'r';
-         s[5]       = 'b';
-         s[6]       = '_';
-         s[7]       = 'r';
-         s[8]       = 'a';
-         s[9 ]      = 't';
-         s[10]      = 'i';
-         s[11]      = 'n';
-         s[12]      = 'g';
-         s[13]      = '\'';
-         s[14]      = ':';
-         s[15]      = '"';
-         s[16]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '"';
-         s[pos+1]   = '}';
-         s[pos+2]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_PEGI_RATING:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'p';
-         s[3]       = 'e';
-         s[4]       = 'g';
-         s[5]       = 'i';
-         s[6]       = '_';
-         s[7]       = 'r';
-         s[8]       = 'a';
-         s[9]       = 't';
-         s[10]      = 'i';
-         s[11]      = 'n';
-         s[12]      = 'g';
-         s[13]      = '\'';
-         s[14]      = ':';
-         s[15]      = '"';
-         s[16]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '"';
-         s[pos+1]   = '}';
-         s[pos+2]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_CERO_RATING:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'c';
-         s[3]       = 'e';
-         s[4]       = 'r';
-         s[5]       = 'o';
-         s[6]       = '_';
-         s[7]       = 'r';
-         s[8]       = 'a';
-         s[9]       = 't';
-         s[10]      = 'i';
-         s[11]      = 'n';
-         s[12]      = 'g';
-         s[13]      = '\'';
-         s[14]      = ':';
-         s[15]      = '"';
-         s[16]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '"';
-         s[pos+1]   = '}';
-         s[pos+2]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_ENHANCEMENT_HW:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'e';
-         s[3]       = 'n';
-         s[4]       = 'h';
-         s[5]       = 'a';
-         s[6]       = 'n';
-         s[7]       = 'c';
-         s[8]       = 'e';
-         s[9]       = 'm';
-         s[10]      = 'e';
-         s[11]      = 'n';
-         s[12]      = 't';
-         s[13]      = '_';
-         s[14]      = 'h';
-         s[15]      = 'w';
-         s[16]      = '\'';
-         s[17]      = ':';
-         s[18]      = '"';
-         s[19]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '"';
-         s[pos+1]   = '}';
-         s[pos+2]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_EDGE_MAGAZINE_RATING:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'e';
-         s[3]       = 'd';
-         s[4]       = 'g';
-         s[5]       = 'e';
-         s[6]       = '_';
-         s[7]       = 'r';
-         s[8]       = 'a';
-         s[9]       = 't';
-         s[10]      = 'i';
-         s[11]      = 'n';
-         s[12]      = 'g';
-         s[13]      = '\'';
-         s[14]      = ':';
-         s[15]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '}';
-         s[pos+1]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_EDGE_MAGAZINE_ISSUE:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'e';
-         s[3]       = 'd';
-         s[4]       = 'g';
-         s[5]       = 'e';
-         s[6]       = '_';
-         s[7]       = 'i';
-         s[8]       = 's';
-         s[9]       = 's';
-         s[10]      = 'u';
-         s[11]      = 'e';
-         s[12]      = '\'';
-         s[13]      = ':';
-         s[14]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '}';
-         s[pos+1]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_FAMITSU_MAGAZINE_RATING:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'f';
-         s[3]       = 'a';
-         s[4]       = 'm';
-         s[5]       = 'i';
-         s[6]       = 't';
-         s[7]       = 's';
-         s[8]       = 'u';
-         s[9]       = '_';
-         s[10]      = 'r';
-         s[11]      = 'a';
-         s[12]      = 't';
-         s[13]      = 'i';
-         s[14]      = 'n';
-         s[15]      = 'g';
-         s[16]      = '\'';
-         s[17]      = ':';
-         s[18]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '}';
-         s[pos+1]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_RELEASEDATE_MONTH:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'r';
-         s[3]       = 'e';
-         s[4]       = 'l';
-         s[5]       = 'e';
-         s[6]       = 'a';
-         s[7]       = 's';
-         s[8]       = 'e';
-         s[9]       = 'm';
-         s[10]      = 'o';
-         s[11]      = 'n';
-         s[12]      = 't';
-         s[13]      = 'h';
-         s[14]      = '\'';
-         s[15]      = ':';
-         s[16]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '}';
-         s[pos+1]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_RELEASEDATE_YEAR:
-	 s[0]       = '{';
-	 s[1]       = '\'';
-         s[2]       = 'r';
-         s[3]       = 'e';
-         s[4]       = 'l';
-         s[5]       = 'e';
-         s[6]       = 'a';
-         s[7]       = 's';
-         s[8]       = 'e';
-         s[9]       = 'y';
-         s[10]      = 'e';
-         s[11]      = 'a';
-         s[12]      = 'r';
-         s[13]      = '\'';
-         s[14]      = ':';
-         s[15]      = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '}';
-         s[pos+1]   = '\0';
-         break;
-      case DATABASE_QUERY_ENTRY_MAX_USERS:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = 'u';
-         s[3]       = 's';
-         s[4]       = 'e';
-         s[5]       = 'r';
-         s[6]       = 's';
-         s[7]       = '\'';
-         s[8]       = ':';
-         s[9]       = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '}';
-         s[pos+1]   = '\0';
-         break;
-      case DATABASE_QUERY_NONE:
-         s[0]       = '{';
-         s[1]       = '\'';
-         s[2]       = '\'';
-         s[3]       = ':';
-         s[4]       = '\'';
-         s[5]       = ':';
-         s[6]       = '"';
-         s[7]       = '\0';
-         pos        = strlcat(s, path, len);
-         s[pos  ]   = '"';
-         s[pos+1]   = '}';
-         s[pos+2]   = '\0';
-         break;
-   }
-
-   return 0;
-}
-
-/*
- * NOTE: Allocates memory, it is the caller's responsibility to free the
- * memory after it is no longer required.
- */
-char *bin_to_hex_alloc(const uint8_t *data, size_t len)
-{
-   size_t i;
-   char *ret = (char*)malloc(len * 2 + 1);
-
-   if (len && !ret)
-      return NULL;
-
-   for (i = 0; i < len; i++)
-      snprintf(ret+i * 2, 3, "%02X", data[i]);
-   return ret;
-}
-
-static int database_cursor_iterate(libretrodb_cursor_t *cur,
-      database_info_t *db_info)
-{
-   unsigned i;
-   struct rmsgpack_dom_value item;
-   const char* str                = NULL;
-
-   if (libretrodb_cursor_read_item(cur, &item) != 0)
-      return -1;
-
-   if (item.type != RDT_MAP)
-   {
-      rmsgpack_dom_value_free(&item);
-      return 1;
-   }
-
-   db_info->analog_supported       = -1;
-   db_info->rumble_supported       = -1;
-   db_info->coop_supported         = -1;
-
-   for (i = 0; i < item.val.map.len; i++)
-   {
-      struct rmsgpack_dom_value *key = &item.val.map.items[i].key;
-      struct rmsgpack_dom_value *val = &item.val.map.items[i].value;
-      const char *val_string         = NULL;
-
-      if (!key || !val)
-         continue;
-
-      val_string                     = val->val.string.buff;
-      str                            = key->val.string.buff;
-
-      if (string_is_equal(str, "publisher"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->publisher = strdup(val_string);
-      }
-      else if (string_is_equal(str, "developer"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->developer = string_split(val_string, "|");
-      }
-      else if (string_is_equal(str, "serial"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->serial = strdup(val_string);
-      }
-      else if (string_is_equal(str, "rom_name"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->rom_name = strdup(val_string);
-      }
-      else if (string_is_equal(str, "name"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->name = strdup(val_string);
-      }
-      else if (string_is_equal(str, "description"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->description = strdup(val_string);
-      }
-      else if (string_is_equal(str, "genre"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->genre = strdup(val_string);
-      }
-      else if (string_is_equal(str, "category"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->category = strdup(val_string);
-      }
-      else if (string_is_equal(str, "language"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->language = strdup(val_string);
-      }
-      else if (string_is_equal(str, "region"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->region = strdup(val_string);
-      }
-      else if (string_is_equal(str, "score"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->score = strdup(val_string);
-      }
-      else if (string_is_equal(str, "media"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->media = strdup(val_string);
-      }
-      else if (string_is_equal(str, "controls"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->controls = strdup(val_string);
-      }
-      else if (string_is_equal(str, "artstyle"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->artstyle = strdup(val_string);
-      }
-      else if (string_is_equal(str, "gameplay"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->gameplay = strdup(val_string);
-      }
-      else if (string_is_equal(str, "narrative"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->narrative = strdup(val_string);
-      }
-      else if (string_is_equal(str, "pacing"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->pacing = strdup(val_string);
-      }
-      else if (string_is_equal(str, "perspective"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->perspective = strdup(val_string);
-      }
-      else if (string_is_equal(str, "setting"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->setting = strdup(val_string);
-      }
-      else if (string_is_equal(str, "visual"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->visual = strdup(val_string);
-      }
-      else if (string_is_equal(str, "vehicular"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->vehicular = strdup(val_string);
-      }
-      else if (string_is_equal(str, "origin"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->origin = strdup(val_string);
-      }
-      else if (string_is_equal(str, "franchise"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->franchise = strdup(val_string);
-      }
-      else if (string_ends_with_size(str, "_rating",
-               strlen(str), STRLEN_CONST("_rating")))
-      {
-         if (string_is_equal(str, "bbfc_rating"))
-         {
-            if (!string_is_empty(val_string))
-               db_info->bbfc_rating = strdup(val_string);
-         }
-         else if (string_is_equal(str, "esrb_rating"))
-         {
-            if (!string_is_empty(val_string))
-               db_info->esrb_rating = strdup(val_string);
-         }
-         else if (string_is_equal(str, "elspa_rating"))
-         {
-            if (!string_is_empty(val_string))
-               db_info->elspa_rating = strdup(val_string);
-         }
-         else if (string_is_equal(str, "cero_rating"))
-         {
-            if (!string_is_empty(val_string))
-               db_info->cero_rating          = strdup(val_string);
-         }
-         else if (string_is_equal(str, "pegi_rating"))
-         {
-            if (!string_is_empty(val_string))
-               db_info->pegi_rating          = strdup(val_string);
-         }
-         else if (string_is_equal(str, "edge_rating"))
-            db_info->edge_magazine_rating    = (unsigned)val->val.uint_;
-         else if (string_is_equal(str, "famitsu_rating"))
-            db_info->famitsu_magazine_rating = (unsigned)val->val.uint_;
-         else if (string_is_equal(str, "tgdb_rating"))
-            db_info->tgdb_rating             = (unsigned)val->val.uint_;
-      }
-      else if (string_is_equal(str, "enhancement_hw"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->enhancement_hw       = strdup(val_string);
-      }
-      else if (string_is_equal(str, "edge_review"))
-      {
-         if (!string_is_empty(val_string))
-            db_info->edge_magazine_review = strdup(val_string);
-      }
-      else if (string_is_equal(str, "edge_issue"))
-         db_info->edge_magazine_issue     = (unsigned)val->val.uint_;
-      else if (string_is_equal(str, "users"))
-         db_info->max_users               = (unsigned)val->val.uint_;
-      else if (string_is_equal(str, "releasemonth"))
-         db_info->releasemonth            = (unsigned)val->val.uint_;
-      else if (string_is_equal(str, "releaseyear"))
-         db_info->releaseyear             = (unsigned)val->val.uint_;
-      else if (string_is_equal(str, "rumble"))
-         db_info->rumble_supported        = (int)val->val.uint_;
-      else if (string_is_equal(str, "achievements"))
-         db_info->achievements            = (int)val->val.uint_;
-      else if (string_is_equal(str, "console_exclusive"))
-         db_info->console_exclusive       = (int)val->val.uint_;
-      else if (string_is_equal(str, "platform_exclusive"))
-         db_info->platform_exclusive      = (int)val->val.uint_;
-      else if (string_is_equal(str, "coop"))
-         db_info->coop_supported          = (int)val->val.uint_;
-      else if (string_is_equal(str, "analog"))
-         db_info->analog_supported        = (int)val->val.uint_;
-      else if (string_is_equal(str, "size"))
-         db_info->size                    = (unsigned)val->val.uint_;
-      else if (string_is_equal(str, "crc"))
-      {
-         switch (val->val.binary.len)
-         {
-            case 1:
-               db_info->crc32 = *(uint8_t*)val->val.binary.buff;
-               break;
-            case 2:
-               db_info->crc32 = swap_if_little16(*(uint16_t*)val->val.binary.buff);
-               break;
-            case 4:
-               db_info->crc32 = swap_if_little32(*(uint32_t*)val->val.binary.buff);
-               break;
-            default:
-               db_info->crc32 = 0;
-               break;
-         }
-      }
-      else if (string_is_equal(str, "sha1"))
-         db_info->sha1 = bin_to_hex_alloc(
-               (uint8_t*)val->val.binary.buff, val->val.binary.len);
-      else if (string_is_equal(str, "md5"))
-         db_info->md5 = bin_to_hex_alloc(
-               (uint8_t*)val->val.binary.buff, val->val.binary.len);
-   }
-
-   rmsgpack_dom_value_free(&item);
-
-   return 0;
-}
-
-static int database_cursor_open(libretrodb_t *db,
-      libretrodb_cursor_t *cur, const char *path, const char *query)
-{
-   const char *error     = NULL;
-   libretrodb_query_t *q = NULL;
-
-   if ((libretrodb_open(path, db)) != 0)
-      return -1;
-
-   if (query)
-      q = (libretrodb_query_t*)libretrodb_query_compile(db, query,
-      strlen(query), &error);
-
-   if (error)
-      goto error;
-   if ((libretrodb_cursor_open(db, cur, q)) != 0)
-      goto error;
-
-   if (q)
-      libretrodb_query_free(q);
-
-   return 0;
-
-error:
-   if (q)
-      libretrodb_query_free(q);
-   libretrodb_close(db);
-
-   return -1;
-}
-
-static bool type_is_prioritized(const char *path)
-{
-   const char *ext = path_get_extension(path);
-   if (string_is_equal_noncase(ext, "cue"))
-      return true;
-   if (string_is_equal_noncase(ext, "gdi"))
-      return true;
-   return false;
-}
-
-static int dir_entry_compare(const void *left, const void *right)
-{
-   const struct string_list_elem *le = (const struct string_list_elem*)left;
-   const struct string_list_elem *re = (const struct string_list_elem*)right;
-   bool                            l = type_is_prioritized(le->data);
-   bool                            r = type_is_prioritized(re->data);
-
-   return (int) r - (int) l;
-}
-
-database_info_handle_t *database_info_dir_init(const char *dir,
-      enum database_type type, retro_task_t *task,
-      bool show_hidden_files)
-{
-   core_info_list_t *core_info_list = NULL;
-   struct string_list       *list   = NULL;
-   database_info_handle_t     *db   = (database_info_handle_t*)
-      malloc(sizeof(*db));
-
-   if (!db)
-      return NULL;
-
-   core_info_get_list(&core_info_list);
-
-   if (!(list = dir_list_new(dir, core_info_list ? core_info_list->all_ext : NULL,
-         false, show_hidden_files,
-         false, true)))
-   {
-      free(db);
-      return NULL;
-   }
-
-   /* dir list prioritize */
-   qsort(list->elems, list->size, sizeof(*list->elems), dir_entry_compare);
-
-   db->status             = DATABASE_STATUS_ITERATE;
-   db->type               = type;
-   db->list_ptr           = 0;
-   db->list               = list;
-
-   return db;
-}
-
-database_info_handle_t *database_info_file_init(const char *path,
-      enum database_type type, retro_task_t *task)
-{
-   union string_list_elem_attr attr;
-   struct string_list        *list  = NULL;
-   database_info_handle_t      *db  = (database_info_handle_t*)
-      malloc(sizeof(*db));
-
-   if (!db)
-      return NULL;
-
-   if (!(list = string_list_new()))
-   {
-      free(db);
-      return NULL;
-   }
-
-   attr.i                 = 0;
-   string_list_append(list, path, attr);
-
-   db->status             = DATABASE_STATUS_ITERATE;
-   db->type               = type;
-   db->list_ptr           = 0;
-   db->list               = list;
-
-   return db;
-}
-
-void database_info_free(database_info_handle_t *db)
-{
-   if (db)
-      string_list_free(db->list);
-}
-
-database_info_list_t *database_info_list_new(
-      const char *rdb_path, const char *query)
-{
-   int ret                                  = 0;
-   unsigned k                               = 0;
-   database_info_t *database_info           = NULL;
-   database_info_list_t *database_info_list = NULL;
-   libretrodb_t *db                         = libretrodb_new();
-   libretrodb_cursor_t *cur                 = libretrodb_cursor_new();
-
-   if (!db || !cur)
-      goto end;
-
-   if ((database_cursor_open(db, cur, rdb_path, query) != 0))
-      goto end;
-
-   database_info_list = (database_info_list_t*)
-      malloc(sizeof(*database_info_list));
-
-   if (!database_info_list)
-      goto end;
-
-   database_info_list->count  = 0;
-   database_info_list->list   = NULL;
-
-   while (ret != -1)
-   {
-      database_info_t db_info = {0};
-      ret = database_cursor_iterate(cur, &db_info);
-
-      if (ret == 0)
-      {
-         database_info_t *db_ptr  = NULL;
-         database_info_t *new_ptr = (database_info_t*)
-            realloc(database_info, (k+1) * sizeof(database_info_t));
-
-         if (!new_ptr)
-         {
-            if (db_info.bbfc_rating)
-               free(db_info.bbfc_rating);
-            if (db_info.cero_rating)
-               free(db_info.cero_rating);
-            if (db_info.description)
-               free(db_info.description);
-            if (db_info.edge_magazine_review)
-               free(db_info.edge_magazine_review);
-            if (db_info.elspa_rating)
-               free(db_info.elspa_rating);
-            if (db_info.enhancement_hw)
-               free(db_info.enhancement_hw);
-            if (db_info.esrb_rating)
-               free(db_info.esrb_rating);
-            if (db_info.franchise)
-               free(db_info.franchise);
-            if (db_info.genre)
-               free(db_info.genre);
-            if (db_info.category)
-               free(db_info.category);
-            if (db_info.language)
-               free(db_info.language);
-            if (db_info.region)
-               free(db_info.region);
-            if (db_info.score)
-               free(db_info.score);
-            if (db_info.media)
-               free(db_info.media);
-            if (db_info.controls)
-               free(db_info.controls);
-            if (db_info.artstyle)
-               free(db_info.artstyle);
-            if (db_info.gameplay)
-               free(db_info.gameplay);
-            if (db_info.narrative)
-               free(db_info.narrative);
-            if (db_info.pacing)
-               free(db_info.pacing);
-            if (db_info.perspective)
-               free(db_info.perspective);
-            if (db_info.setting)
-               free(db_info.setting);
-            if (db_info.visual)
-               free(db_info.visual);
-            if (db_info.vehicular)
-               free(db_info.vehicular);
-            if (db_info.name)
-               free(db_info.name);
-            if (db_info.origin)
-               free(db_info.origin);
-            if (db_info.pegi_rating)
-               free(db_info.pegi_rating);
-            if (db_info.publisher)
-               free(db_info.publisher);
-            if (db_info.rom_name)
-               free(db_info.rom_name);
-            if (db_info.serial)
-               free(db_info.serial);
-            if (db_info.md5)
-               free(db_info.md5);
-            if (db_info.sha1)
-               free(db_info.sha1);
-
-            db_info.name                 = NULL;
-            db_info.rom_name             = NULL;
-            db_info.serial               = NULL;
-            db_info.genre                = NULL;
-            db_info.description          = NULL;
-            db_info.publisher            = NULL;
-            db_info.developer            = NULL;
-            db_info.origin               = NULL;
-            db_info.franchise            = NULL;
-            db_info.edge_magazine_review = NULL;
-            db_info.cero_rating          = NULL;
-            db_info.pegi_rating          = NULL;
-            db_info.enhancement_hw       = NULL;
-            db_info.elspa_rating         = NULL;
-            db_info.esrb_rating          = NULL;
-            db_info.bbfc_rating          = NULL; 
-            db_info.sha1                 = NULL;
-            db_info.md5                  = NULL;
-
-            database_info_list_free(database_info_list);
-            free(database_info);
-            free(database_info_list);
-            database_info_list = NULL;
-            goto end;
-         }
-
-         database_info = new_ptr;
-         db_ptr        = &database_info[k];
-
-         memcpy(db_ptr, &db_info, sizeof(*db_ptr));
-
-         k++;
-      }
-   }
-
-   database_info_list->list  = database_info;
-   database_info_list->count = k;
-
-end:
-   if (db)
-   {
-      libretrodb_cursor_close(cur);
-      libretrodb_close(db);
-      libretrodb_free(db);
-   }
-   if (cur)
-      libretrodb_cursor_free(cur);
-
-   return database_info_list;
-}
-
-void database_info_list_free(database_info_list_t *database_info_list)
-{
-   size_t i;
-
-   if (!database_info_list)
-      return;
-
-   for (i = 0; i < database_info_list->count; i++)
-   {
-      database_info_t *info = &database_info_list->list[i];
-
-      if (info->name)
-         free(info->name);
-      if (info->rom_name)
-         free(info->rom_name);
-      if (info->serial)
-         free(info->serial);
-      if (info->genre)
-         free(info->genre);
-      if (info->category)
-         free(info->category);
-      if (info->language)
-         free(info->language);
-      if (info->region)
-         free(info->region);
-      if (info->score)
-         free(info->score);
-      if (info->media)
-         free(info->media);
-      if (info->controls)
-         free(info->controls);
-      if (info->artstyle)
-         free(info->artstyle);
-      if (info->gameplay)
-         free(info->gameplay);
-      if (info->narrative)
-         free(info->narrative);
-      if (info->pacing)
-         free(info->pacing);
-      if (info->perspective)
-         free(info->perspective);
-      if (info->setting)
-         free(info->setting);
-      if (info->visual)
-         free(info->visual);
-      if (info->vehicular)
-         free(info->vehicular);
-      if (info->description)
-         free(info->description);
-      if (info->publisher)
-         free(info->publisher);
-      if (info->developer)
-         string_list_free(info->developer);
-      if (info->origin)
-         free(info->origin);
-      if (info->franchise)
-         free(info->franchise);
-      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);
-      if (info->enhancement_hw)
-         free(info->enhancement_hw);
-      if (info->elspa_rating)
-         free(info->elspa_rating);
-      if (info->esrb_rating)
-         free(info->esrb_rating);
-      if (info->bbfc_rating)
-         free(info->bbfc_rating);
-      if (info->sha1)
-         free(info->sha1);
-      if (info->md5)
-         free(info->md5);
-
-      info->name                 = NULL;
-      info->rom_name             = NULL;
-      info->serial               = NULL;
-      info->genre                = NULL;
-      info->description          = NULL;
-      info->publisher            = NULL;
-      info->developer            = NULL;
-      info->origin               = NULL;
-      info->franchise            = NULL;
-      info->edge_magazine_review = NULL;
-      info->cero_rating          = NULL;
-      info->pegi_rating          = NULL;
-      info->enhancement_hw       = NULL;
-      info->elspa_rating         = NULL;
-      info->esrb_rating          = NULL;
-      info->bbfc_rating          = NULL; 
-      info->sha1                 = NULL;
-      info->md5                  = NULL;
-   }
-
-   free(database_info_list->list);
-}

+ 0 - 162
app/src/main/cpp/database_info.h

@@ -1,162 +0,0 @@
-/*  RetroArch - A frontend for libretro.
- *  Copyright (C) 2010-2014 - Hans-Kristian Arntzen
- *  Copyright (C) 2011-2017 - Daniel De Matteis
- *  Copyright (C) 2016-2019 - Brad Parker
- *
- *  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 DATABASE_INFO_H_
-#define DATABASE_INFO_H_
-
-#include <stdint.h>
-#include <stddef.h>
-
-#include <file/archive_file.h>
-#include <retro_common_api.h>
-#include <queues/task_queue.h>
-
-RETRO_BEGIN_DECLS
-
-enum database_status
-{
-   DATABASE_STATUS_NONE = 0,
-   DATABASE_STATUS_ITERATE,
-   DATABASE_STATUS_ITERATE_BEGIN,
-   DATABASE_STATUS_ITERATE_START,
-   DATABASE_STATUS_ITERATE_NEXT,
-   DATABASE_STATUS_FREE
-};
-
-enum database_type
-{
-   DATABASE_TYPE_NONE = 0,
-   DATABASE_TYPE_ITERATE,
-   DATABASE_TYPE_ITERATE_ARCHIVE,
-   DATABASE_TYPE_ITERATE_LUTRO,
-   DATABASE_TYPE_SERIAL_LOOKUP,
-   DATABASE_TYPE_CRC_LOOKUP
-};
-
-enum database_query_type
-{
-   DATABASE_QUERY_NONE = 0,
-   DATABASE_QUERY_ENTRY,
-   DATABASE_QUERY_ENTRY_PUBLISHER,
-   DATABASE_QUERY_ENTRY_DEVELOPER,
-   DATABASE_QUERY_ENTRY_ORIGIN,
-   DATABASE_QUERY_ENTRY_FRANCHISE,
-   DATABASE_QUERY_ENTRY_RATING,
-   DATABASE_QUERY_ENTRY_BBFC_RATING,
-   DATABASE_QUERY_ENTRY_ELSPA_RATING,
-   DATABASE_QUERY_ENTRY_ESRB_RATING,
-   DATABASE_QUERY_ENTRY_PEGI_RATING,
-   DATABASE_QUERY_ENTRY_CERO_RATING,
-   DATABASE_QUERY_ENTRY_ENHANCEMENT_HW,
-   DATABASE_QUERY_ENTRY_EDGE_MAGAZINE_RATING,
-   DATABASE_QUERY_ENTRY_EDGE_MAGAZINE_ISSUE,
-   DATABASE_QUERY_ENTRY_FAMITSU_MAGAZINE_RATING,
-   DATABASE_QUERY_ENTRY_RELEASEDATE_MONTH,
-   DATABASE_QUERY_ENTRY_RELEASEDATE_YEAR,
-   DATABASE_QUERY_ENTRY_MAX_USERS
-};
-
-typedef struct
-{
-   struct string_list *list;
-   size_t list_ptr;
-   enum database_status status;
-   enum database_type type;
-} database_info_handle_t;
-
-typedef struct
-{
-   char *name;
-   char *rom_name;
-   char *serial;
-   char *description;
-   char *genre;
-   int  achievements;
-   char *category;
-   char *language;
-   char *region;
-   int  console_exclusive;
-   int  platform_exclusive;
-   char *score;
-   char *media;
-   char *controls;
-   char *artstyle;
-   char *gameplay;
-   char *narrative;
-   char *pacing;
-   char *perspective;
-   char *setting;
-   char *visual;
-   char *vehicular;
-   char *publisher;
-   struct string_list *developer;
-   char *origin;
-   char *franchise;
-   char *edge_magazine_review;
-   char *bbfc_rating;
-   char *elspa_rating;
-   char *esrb_rating;
-   char *pegi_rating;
-   char *cero_rating;
-   char *enhancement_hw;
-   char *sha1;
-   char *md5;
-   void *userdata;
-   int analog_supported;
-   int rumble_supported;
-   int coop_supported;
-   uint32_t crc32;
-   unsigned size;
-   unsigned famitsu_magazine_rating;
-   unsigned edge_magazine_rating;
-   unsigned edge_magazine_issue;
-   unsigned max_users;
-   unsigned releasemonth;
-   unsigned releaseyear;
-   unsigned tgdb_rating;
-} 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);
-
-database_info_handle_t *database_info_dir_init(const char *dir,
-      enum database_type type, retro_task_t *task,
-      bool show_hidden_files);
-
-database_info_handle_t *database_info_file_init(const char *path,
-      enum database_type type, retro_task_t *task);
-
-void database_info_free(database_info_handle_t *handle);
-
-int database_info_build_query_enum(
-      char *query, size_t len, enum database_query_type type, const char *path);
-
-/* NOTE: Allocates memory, it is the caller's responsibility to free the
- * memory after it is no longer required. */
-char *bin_to_hex_alloc(const uint8_t *data, size_t len);
-
-RETRO_END_DECLS
-
-#endif /* CORE_INFO_H_ */

+ 0 - 115
app/src/main/cpp/libretro-db/bintree.c

@@ -1,115 +0,0 @@
-/* Copyright  (C) 2010-2017 The RetroArch team
- *
- * ---------------------------------------------------------------------------------------
- * The following license statement only applies to this file (bintree.c).
- * ---------------------------------------------------------------------------------------
- *
- * Permission is hereby granted, free of charge,
- * to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <retro_inline.h>
-
-#include "bintree.h"
-
-static void * const NIL_NODE = (void*)&NIL_NODE;
-
-static struct bintree_node *bintree_new_nil_node(
-      struct bintree_node *parent)
-{
-   struct bintree_node *node = (struct bintree_node *)
-      malloc(sizeof(struct bintree_node));
-
-   if (!node)
-      return NULL;
-
-   node->value  = NIL_NODE;
-   node->parent = parent;
-   node->left   = NULL;
-   node->right  = NULL;
-
-   return node;
-}
-
-int bintree_insert(bintree_t *t, struct bintree_node *root, void *value)
-{
-   int cmp_res = 0;
-
-   if (!root || (root->value == NIL_NODE))
-   {
-      root->left  = bintree_new_nil_node(root);
-      root->right = bintree_new_nil_node(root);
-      root->value = value;
-
-      return 0;
-   }
-
-   cmp_res = t->cmp(root->value, value, t->ctx);
-
-   if (cmp_res > 0)
-      return bintree_insert(t, root->left, value);
-   else if (cmp_res < 0)
-      return bintree_insert(t, root->right, value);
-   return -1;
-}
-
-int bintree_iterate(struct bintree_node *n, bintree_iter_cb cb, void *ctx)
-{
-   int rv;
-
-   if (!n || (n->value == NIL_NODE))
-      return 0;
-
-   if ((rv = bintree_iterate(n->left, cb, ctx)) != 0)
-      return rv;
-   if ((rv = cb(n->value, ctx)) != 0)
-      return rv;
-   if ((rv = bintree_iterate(n->right, cb, ctx)) != 0)
-      return rv;
-
-   return 0;
-}
-
-void bintree_free(struct bintree_node *n)
-{
-   if (!n)
-      return;
-   if (n->value != NIL_NODE)
-   {
-	   n->value = NULL;
-	   if (n->left)
-		   bintree_free(n->left);
-	   if (n->right)
-		   bintree_free(n->right);
-   }
-   free(n);
-}
-
-bintree_t *bintree_new(bintree_cmp_func cmp, void *ctx)
-{
-   bintree_t *t = (bintree_t*)malloc(sizeof(*t));
-
-   if (!t)
-      return NULL;
-
-   t->root      = bintree_new_nil_node(NULL);
-   t->cmp       = cmp;
-   t->ctx       = ctx;
-
-   return t;
-}

+ 0 - 58
app/src/main/cpp/libretro-db/bintree.h

@@ -1,58 +0,0 @@
-/* Copyright  (C) 2010-2017 The RetroArch team
- *
- * ---------------------------------------------------------------------------------------
- * The following license statement only applies to this file (bintree.h).
- * ---------------------------------------------------------------------------------------
- *
- * Permission is hereby granted, free of charge,
- * to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef __LIBRETRODB_BINTREE_H__
-#define __LIBRETRODB_BINTREE_H__
-
-#include <retro_common_api.h>
-
-RETRO_BEGIN_DECLS
-
-typedef int (*bintree_cmp_func)(const void *a, const void *b, void *ctx);
-typedef int (*bintree_iter_cb) (void *value, void *ctx);
-
-typedef struct bintree_node
-{
-   void *value;
-   struct bintree_node *parent;
-   struct bintree_node *left;
-   struct bintree_node *right;
-} bintree_node_t;
-
-typedef struct bintree
-{
-   struct bintree_node *root;
-   void *ctx;
-   bintree_cmp_func cmp;
-} bintree_t;
-
-bintree_t *bintree_new(bintree_cmp_func cmp, void *ctx);
-
-int bintree_insert(bintree_t *t, struct bintree_node *root, void *value);
-
-int bintree_iterate(struct bintree_node *n, bintree_iter_cb cb, void *ctx);
-
-void bintree_free(struct bintree_node *n);
-
-RETRO_END_DECLS
-
-#endif

+ 0 - 580
app/src/main/cpp/libretro-db/libretrodb.c

@@ -1,580 +0,0 @@
-/* Copyright  (C) 2010-2017 The RetroArch team
- *
- * ---------------------------------------------------------------------------------------
- * The following license statement only applies to this file (libretrodb.c).
- * ---------------------------------------------------------------------------------------
- *
- * Permission is hereby granted, free of charge,
- * to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <sys/types.h>
-#ifdef _WIN32
-#include <direct.h>
-#else
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-
-#include <streams/file_stream.h>
-#include <retro_endianness.h>
-#include <string/stdstring.h>
-#include <compat/strl.h>
-
-#include "libretrodb.h"
-#include "rmsgpack_dom.h"
-#include "rmsgpack.h"
-#include "bintree.h"
-#include "query.h"
-#include "libretrodb.h"
-
-#define MAGIC_NUMBER "RARCHDB"
-
-struct node_iter_ctx
-{
-	libretrodb_t *db;
-	libretrodb_index_t *idx;
-};
-
-struct libretrodb
-{
-	RFILE *fd;
-   char *path;
-	uint64_t root;
-	uint64_t count;
-	uint64_t first_index_offset;
-};
-
-struct libretrodb_index
-{
-	char name[50];
-	uint64_t key_size;
-	uint64_t next;
-};
-
-typedef struct libretrodb_metadata
-{
-	uint64_t count;
-} libretrodb_metadata_t;
-
-typedef struct libretrodb_header
-{
-	char magic_number[sizeof(MAGIC_NUMBER)];
-	uint64_t metadata_offset;
-} libretrodb_header_t;
-
-struct libretrodb_cursor
-{
-   RFILE *fd;
-	libretrodb_query_t *query;
-	libretrodb_t *db;
-	int is_valid;
-	int eof;
-};
-
-static int libretrodb_validate_document(const struct rmsgpack_dom_value *doc)
-{
-   unsigned i;
-
-   if (doc->type != RDT_MAP)
-      return -1;
-
-   for (i = 0; i < doc->val.map.len; i++)
-   {
-      int rv                          = 0;
-      struct rmsgpack_dom_value key   = doc->val.map.items[i].key;
-      struct rmsgpack_dom_value value = doc->val.map.items[i].value;
-
-      if (key.type != RDT_STRING)
-         return -1;
-
-      if (key.val.string.len <= 0)
-         return -1;
-
-      if (key.val.string.buff[0] == '$')
-         return -1;
-
-      if (value.type != RDT_MAP)
-         continue;
-
-      if ((rv == libretrodb_validate_document(&value)) != 0)
-         return rv;
-   }
-
-   return 0;
-}
-
-int libretrodb_create(RFILE *fd, libretrodb_value_provider value_provider,
-      void *ctx)
-{
-   int rv;
-   libretrodb_metadata_t md;
-   static struct rmsgpack_dom_value sentinal;
-   struct rmsgpack_dom_value item;
-   uint64_t item_count        = 0;
-   libretrodb_header_t header = {{0}};
-   ssize_t root               = filestream_tell(fd);
-
-   memcpy(header.magic_number, MAGIC_NUMBER, sizeof(MAGIC_NUMBER)-1);
-
-   /* We write the header in the end because we need to know the size of
-    * the db first */
-
-   filestream_seek(fd, sizeof(libretrodb_header_t),
-         RETRO_VFS_SEEK_POSITION_CURRENT);
-
-   item.type = RDT_NULL;
-   while ((rv = value_provider(ctx, &item)) == 0)
-   {
-      if ((rv = libretrodb_validate_document(&item)) < 0)
-         goto clean;
-
-      if ((rv = rmsgpack_dom_write(fd, &item)) < 0)
-         goto clean;
-
-      rmsgpack_dom_value_free(&item);
-      item.type = RDT_NULL;
-      item_count++;
-   }
-
-   if (rv < 0)
-      goto clean;
-
-   if ((rv = rmsgpack_dom_write(fd, &sentinal)) < 0)
-      goto clean;
-
-   header.metadata_offset = swap_if_little64(filestream_tell(fd));
-   md.count               = item_count;
-   rmsgpack_write_map_header(fd, 1);
-   rmsgpack_write_string(fd, "count", STRLEN_CONST("count"));
-   rmsgpack_write_uint(fd, md.count);
-   filestream_seek(fd, root, RETRO_VFS_SEEK_POSITION_START);
-   filestream_write(fd, &header, sizeof(header));
-clean:
-   rmsgpack_dom_value_free(&item);
-   return rv;
-}
-
-void libretrodb_close(libretrodb_t *db)
-{
-   if (db->fd)
-      filestream_close(db->fd);
-   if (!string_is_empty(db->path))
-      free(db->path);
-   db->path = NULL;
-   db->fd   = NULL;
-}
-
-int libretrodb_open(const char *path, libretrodb_t *db)
-{
-   libretrodb_header_t header;
-   libretrodb_metadata_t md;
-   RFILE *fd = filestream_open(path,
-         RETRO_VFS_FILE_ACCESS_READ,
-         RETRO_VFS_FILE_ACCESS_HINT_NONE);
-
-   if (!fd)
-      return -1;
-
-   if (!string_is_empty(db->path))
-      free(db->path);
-
-   db->path  = strdup(path);
-   db->root  = filestream_tell(fd);
-
-   if ((int)filestream_read(fd, &header, sizeof(header)) == -1)
-      goto error;
-
-   if (strncmp(header.magic_number, MAGIC_NUMBER, sizeof(MAGIC_NUMBER)) != 0)
-      goto error;
-
-   header.metadata_offset = swap_if_little64(header.metadata_offset);
-   filestream_seek(fd, (ssize_t)header.metadata_offset,
-         RETRO_VFS_SEEK_POSITION_START);
-
-   if (rmsgpack_dom_read_into(fd, "count", &md.count, NULL) < 0)
-      goto error;
-
-   db->count              = md.count;
-   db->first_index_offset = filestream_tell(fd);
-   db->fd                 = fd;
-   return 0;
-
-error:
-   if (fd)
-      filestream_close(fd);
-   return -1;
-}
-
-static int libretrodb_find_index(libretrodb_t *db, const char *index_name,
-      libretrodb_index_t *idx)
-{
-   ssize_t eof    = filestream_get_size(db->fd);
-   ssize_t offset = filestream_seek(db->fd,
-         (ssize_t)db->first_index_offset,
-         RETRO_VFS_SEEK_POSITION_START);
-
-   /* TODO: this should use filestream_eof instead */
-   while (offset < eof)
-   {
-      uint64_t name_len = 50;
-      /* Read index header */
-      rmsgpack_dom_read_into(db->fd,
-            "name",     idx->name, &name_len,
-            "key_size", &idx->key_size,
-            "next",     &idx->next, NULL);
-
-      if (strncmp(index_name, idx->name, strlen(idx->name)) == 0)
-         return 0;
-
-      filestream_seek(db->fd, (ssize_t)idx->next,
-            RETRO_VFS_SEEK_POSITION_CURRENT);
-      offset = filestream_tell(db->fd);
-   }
-
-   return -1;
-}
-
-static int binsearch(const void *buff, const void *item,
-      uint64_t count, uint8_t field_size, uint64_t *offset)
-{
-   int mid            = (int)(count / 2);
-   int item_size      = field_size + sizeof(uint64_t);
-   uint64_t *current  = (uint64_t *)buff + (mid * item_size);
-   int rv             = memcmp(current, item, field_size);
-
-   if (rv == 0)
-   {
-      *offset         = *(uint64_t *)(current + field_size);
-      return 0;
-   }
-
-   if (count == 0)
-      return -1;
-
-   if (rv > 0)
-      return binsearch(buff, item, mid, field_size, offset);
-
-   return binsearch(current + item_size, item,
-         count - mid, field_size, offset);
-}
-
-int libretrodb_find_entry(libretrodb_t *db, const char *index_name,
-      const void *key, struct rmsgpack_dom_value *out)
-{
-   libretrodb_index_t idx;
-   int rv;
-   void *buff;
-   uint64_t offset;
-   ssize_t bufflen, nread = 0;
-
-   if (libretrodb_find_index(db, index_name, &idx) < 0)
-      return -1;
-
-   bufflen        = idx.next;
-
-   if (!(buff = malloc(bufflen)))
-      return -1;
-
-   while (nread < bufflen)
-   {
-      void *buff_ = (uint64_t *)buff + nread;
-      rv          = (int)filestream_read(db->fd, buff_, bufflen - nread);
-
-      if (rv <= 0)
-      {
-         free(buff);
-         return -1;
-      }
-      nread += rv;
-   }
-
-   rv = binsearch(buff, key, db->count, (ssize_t)idx.key_size, &offset);
-   free(buff);
-
-   if (rv == 0)
-      filestream_seek(db->fd, (ssize_t)offset,
-            RETRO_VFS_SEEK_POSITION_START);
-
-   return rmsgpack_dom_read(db->fd, out);
-}
-
-/**
- * libretrodb_cursor_reset:
- * @cursor              : Handle to database cursor.
- *
- * Resets cursor.
- *
- * Returns: ???.
- **/
-int libretrodb_cursor_reset(libretrodb_cursor_t *cursor)
-{
-   cursor->eof = 0;
-   return (int)filestream_seek(cursor->fd,
-         (ssize_t)(cursor->db->root + sizeof(libretrodb_header_t)),
-         RETRO_VFS_SEEK_POSITION_START);
-}
-
-int libretrodb_cursor_read_item(libretrodb_cursor_t *cursor,
-      struct rmsgpack_dom_value *out)
-{
-   int rv;
-
-   if (cursor->eof)
-      return EOF;
-
-retry:
-   if ((rv = rmsgpack_dom_read(cursor->fd, out)) < 0)
-      return rv;
-
-   if (out->type == RDT_NULL)
-   {
-      cursor->eof = 1;
-      return EOF;
-   }
-
-   if (cursor->query)
-   {
-      if (!libretrodb_query_filter(cursor->query, out))
-      {
-         rmsgpack_dom_value_free(out);
-         goto retry;
-      }
-   }
-
-   return 0;
-}
-
-/**
- * libretrodb_cursor_close:
- * @cursor              : Handle to database cursor.
- *
- * Closes cursor and frees up allocated memory.
- **/
-void libretrodb_cursor_close(libretrodb_cursor_t *cursor)
-{
-   if (!cursor)
-      return;
-
-   if (cursor->fd)
-      filestream_close(cursor->fd);
-
-   if (cursor->query)
-      libretrodb_query_free(cursor->query);
-
-   cursor->is_valid = 0;
-   cursor->eof      = 1;
-   cursor->fd       = NULL;
-   cursor->db       = NULL;
-   cursor->query    = NULL;
-}
-
-/**
- * libretrodb_cursor_open:
- * @db                  : Handle to database.
- * @cursor              : Handle to database cursor.
- * @q                   : Query to execute.
- *
- * Opens cursor to database based on query @q.
- *
- * Returns: 0 if successful, otherwise negative.
- **/
-int libretrodb_cursor_open(libretrodb_t *db,
-      libretrodb_cursor_t *cursor,
-      libretrodb_query_t *q)
-{
-   RFILE *fd = NULL;
-   if (!db || string_is_empty(db->path))
-      return -1;
-
-   if (!(fd = filestream_open(db->path,
-         RETRO_VFS_FILE_ACCESS_READ,
-         RETRO_VFS_FILE_ACCESS_HINT_NONE)))
-      return -1;
-
-   cursor->fd       = fd;
-   cursor->db       = db;
-   cursor->is_valid = 1;
-   libretrodb_cursor_reset(cursor);
-   cursor->query    = q;
-
-   if (q)
-      libretrodb_query_inc_ref(q);
-
-   return 0;
-}
-
-static int node_iter(void *value, void *ctx)
-{
-   struct node_iter_ctx *nictx = (struct node_iter_ctx*)ctx;
-
-   if (filestream_write(nictx->db->fd, value,
-            (ssize_t)(nictx->idx->key_size + sizeof(uint64_t))) > 0)
-      return 0;
-
-   return -1;
-}
-
-static int node_compare(const void *a, const void *b, void *ctx)
-{
-   return memcmp(a, b, *(uint8_t *)ctx);
-}
-
-int libretrodb_create_index(libretrodb_t *db,
-      const char *name, const char *field_name)
-{
-   struct node_iter_ctx nictx;
-   struct rmsgpack_dom_value key;
-   libretrodb_index_t idx;
-   struct rmsgpack_dom_value item;
-   libretrodb_cursor_t cur          = {0};
-   struct rmsgpack_dom_value *field = NULL;
-   void *buff                       = NULL;
-   uint64_t *buff_u64               = NULL;
-   uint8_t field_size               = 0;
-   uint64_t item_loc                = filestream_tell(db->fd);
-   bintree_t *tree                  = bintree_new(node_compare, &field_size);
-
-   item.type                        = RDT_NULL;
-
-   if (!tree || (libretrodb_cursor_open(db, &cur, NULL) != 0))
-      goto clean;
-
-   key.type                         = RDT_STRING;
-   key.val.string.len               = (uint32_t)strlen(field_name);
-   key.val.string.buff              = (char *)field_name;   /* We know we aren't going to change it */
-
-   while (libretrodb_cursor_read_item(&cur, &item) == 0)
-   {
-      /* Only map keys are supported */
-      if (item.type != RDT_MAP)
-         goto clean;
-
-      /* Field not found in item? */
-      if (!(field = rmsgpack_dom_value_map_value(&item, &key)))
-         goto clean;
-
-      /* Field is not binary? */
-      if (field->type != RDT_BINARY)
-         goto clean;
-
-      /* Field is empty? */
-      if (field->val.binary.len == 0)
-         goto clean;
-
-      if (field_size == 0)
-         field_size = field->val.binary.len;
-      /* Field is not of correct size */
-      else if (field->val.binary.len != field_size) 
-         goto clean;
-
-      if (!(buff = malloc(field_size + sizeof(uint64_t))))
-         goto clean;
-
-      memcpy(buff, field->val.binary.buff, field_size);
-
-      buff_u64 = (uint64_t *)buff + field_size;
-
-      memcpy(buff_u64, &item_loc, sizeof(uint64_t));
-
-      /* Value is not unique? */
-      if (bintree_insert(tree, tree->root, buff) != 0)
-      {
-         rmsgpack_dom_value_print(field);
-         goto clean;
-      }
-      buff     = NULL;
-      rmsgpack_dom_value_free(&item);
-      item_loc = filestream_tell(db->fd);
-   }
-
-   filestream_seek(db->fd, 0, RETRO_VFS_SEEK_POSITION_END);
-
-   strlcpy(idx.name, name, sizeof(idx.name));
-
-   idx.key_size = field_size;
-   idx.next     = db->count * (field_size + sizeof(uint64_t));
-
-   /* Write index header */
-   rmsgpack_write_map_header(db->fd, 3);
-   rmsgpack_write_string(db->fd, "name", STRLEN_CONST("name"));
-   rmsgpack_write_string(db->fd, idx.name, (uint32_t)strlen(idx.name));
-   rmsgpack_write_string(db->fd, "key_size", (uint32_t)STRLEN_CONST("key_size"));
-   rmsgpack_write_uint  (db->fd, idx.key_size);
-   rmsgpack_write_string(db->fd, "next", STRLEN_CONST("next"));
-   rmsgpack_write_uint  (db->fd, idx.next);
-
-   nictx.db     = db;
-   nictx.idx    = &idx;
-   bintree_iterate(tree->root, node_iter, &nictx);
-
-clean:
-   rmsgpack_dom_value_free(&item);
-   if (buff)
-      free(buff);
-   if (cur.is_valid)
-      libretrodb_cursor_close(&cur);
-   if (tree && tree->root)
-      bintree_free(tree->root);
-   free(tree);
-   return 0;
-}
-
-libretrodb_cursor_t *libretrodb_cursor_new(void)
-{
-   libretrodb_cursor_t *dbc = (libretrodb_cursor_t*)
-      malloc(sizeof(*dbc));
-
-   if (!dbc)
-      return NULL;
-
-   dbc->is_valid            = 0;
-   dbc->fd                  = NULL;
-   dbc->eof                 = 0;
-   dbc->query               = NULL;
-   dbc->db                  = NULL;
-
-   return dbc;
-}
-
-void libretrodb_cursor_free(libretrodb_cursor_t *dbc)
-{
-   if (dbc)
-      free(dbc);
-}
-
-libretrodb_t *libretrodb_new(void)
-{
-   libretrodb_t *db = (libretrodb_t*)malloc(sizeof(*db));
-
-   if (!db)
-      return NULL;
-
-   db->fd                 = NULL;
-   db->root               = 0;
-   db->count              = 0;
-   db->first_index_offset = 0;
-   db->path               = NULL;
-
-   return db;
-}
-
-void libretrodb_free(libretrodb_t *db)
-{
-   if (db)
-      free(db);
-}

+ 0 - 110
app/src/main/cpp/libretro-db/libretrodb.h

@@ -1,110 +0,0 @@
-/* Copyright  (C) 2010-2017 The RetroArch team
- *
- * ---------------------------------------------------------------------------------------
- * The following license statement only applies to this file (libretrodb.h).
- * ---------------------------------------------------------------------------------------
- *
- * Permission is hereby granted, free of charge,
- * to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef __LIBRETRODB_H__
-#define __LIBRETRODB_H__
-
-#include <stdint.h>
-#ifdef _WIN32
-#include <direct.h>
-#else
-#include <unistd.h>
-#endif
-
-#include <retro_common_api.h>
-
-#include "query.h"
-#include "rmsgpack_dom.h"
-
-RETRO_BEGIN_DECLS
-
-typedef struct libretrodb libretrodb_t;
-
-typedef struct libretrodb_cursor libretrodb_cursor_t;
-
-typedef struct libretrodb_index libretrodb_index_t;
-
-typedef int (*libretrodb_value_provider)(void *ctx, struct rmsgpack_dom_value *out);
-
-int libretrodb_create(RFILE *fd, libretrodb_value_provider value_provider, void *ctx);
-
-void libretrodb_close(libretrodb_t *db);
-
-int libretrodb_open(const char *path, libretrodb_t *db);
-
-int libretrodb_create_index(libretrodb_t *db, const char *name,
-      const char *field_name);
-
-int libretrodb_find_entry(libretrodb_t *db, const char *index_name,
-        const void *key, struct rmsgpack_dom_value *out);
-
-libretrodb_t *libretrodb_new(void);
-
-void libretrodb_free(libretrodb_t *db);
-
-libretrodb_cursor_t *libretrodb_cursor_new(void);
-
-void libretrodb_cursor_free(libretrodb_cursor_t *dbc);
-
-/**
- * libretrodb_cursor_open:
- * @db                  : Handle to database.
- * @cursor              : Handle to database cursor.
- * @q                   : Query to execute.
- *
- * Opens cursor to database based on query @q.
- *
- * Returns: 0 if successful, otherwise negative.
- **/
-int libretrodb_cursor_open(libretrodb_t *db,
-      libretrodb_cursor_t *cursor,
-      libretrodb_query_t *query);
-
-/**
- * libretrodb_cursor_reset:
- * @cursor              : Handle to database cursor.
- *
- * Resets cursor.
- *
- * Returns: ???.
- **/
-int libretrodb_cursor_reset(libretrodb_cursor_t *cursor);
-
-/**
- * libretrodb_cursor_close:
- * @cursor              : Handle to database cursor.
- *
- * Closes cursor and frees up allocated memory.
- **/
-void libretrodb_cursor_close(libretrodb_cursor_t *cursor);
-
-void *libretrodb_query_compile(libretrodb_t *db, const char *query,
-        size_t buff_len, const char **error);
-
-void libretrodb_query_free(void *q);
-
-int libretrodb_cursor_read_item(libretrodb_cursor_t *cursor,
-      struct rmsgpack_dom_value *out);
-
-RETRO_END_DECLS
-
-#endif

+ 0 - 993
app/src/main/cpp/libretro-db/query.c

@@ -1,993 +0,0 @@
-/* Copyright  (C) 2010-2017 The RetroArch team
- *
- * ---------------------------------------------------------------------------------------
- * The following license statement only applies to this file (query.c).
- * ---------------------------------------------------------------------------------------
- *
- * Permission is hereby granted, free of charge,
- * to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifdef _WIN32
-#include <direct.h>
-#else
-#include <unistd.h>
-#endif
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-
-#include <compat/fnmatch.h>
-#include <compat/strl.h>
-#include <string/stdstring.h>
-#include <retro_miscellaneous.h>
-
-#include "libretrodb.h"
-#include "query.h"
-#include "rmsgpack_dom.h"
-
-#define MAX_ERROR_LEN   256
-#define QUERY_MAX_ARGS  50
-
-struct buffer
-{
-   const char *data;
-   size_t len;
-   ssize_t offset;
-};
-
-enum argument_type
-{
-   AT_FUNCTION = 0,
-   AT_VALUE
-};
-
-struct argument;
-
-typedef struct rmsgpack_dom_value (*rarch_query_func)(
-      struct rmsgpack_dom_value input,
-      unsigned argc,
-      const struct argument *argv
-      );
-
-struct invocation
-{
-   struct argument *argv;
-   rarch_query_func func;
-   unsigned argc;
-};
-
-struct argument
-{
-   union
-   {
-      struct rmsgpack_dom_value value;
-      struct invocation invocation;
-   } a;
-   enum argument_type type;
-};
-
-struct query
-{
-   struct invocation root; /* ptr alignment */
-   unsigned ref_count;
-};
-
-struct registered_func
-{
-   const char *name;
-   rarch_query_func func;
-};
-
-/* Forward declarations */
-static struct buffer query_parse_method_call(char *s, size_t len,
-      struct buffer buff,
-      struct invocation *invocation, const char **error);
-static struct buffer query_parse_table(char *s,
-      size_t len, struct buffer buff,
-      struct invocation *invocation, const char **error);
-
-/* Errors */
-static struct rmsgpack_dom_value query_func_is_true(
-      struct rmsgpack_dom_value input,
-      unsigned argc, const struct argument *argv)
-{
-   struct rmsgpack_dom_value res;
-
-   res.type         = RDT_BOOL;
-   res.val.bool_    = 0;
-
-   if (!(argc > 0 || input.type != RDT_BOOL))
-      res.val.bool_ = input.val.bool_;
-
-   return res;
-}
-
-static struct rmsgpack_dom_value func_equals(
-      struct rmsgpack_dom_value input,
-      unsigned argc, const struct argument * argv)
-{
-   struct rmsgpack_dom_value res;
-
-   res.type                       = RDT_BOOL;
-   res.val.bool_                  = 0;
-
-   if (argc == 1)
-   {
-      struct argument arg         = argv[0];
-
-      if (arg.type == AT_VALUE)
-      {
-         if (     input.type       == RDT_UINT
-               && arg.a.value.type == RDT_INT)
-         {
-            arg.a.value.type      = RDT_UINT;
-            arg.a.value.val.uint_ = arg.a.value.val.int_;
-         }
-         res.val.bool_            = (rmsgpack_dom_value_cmp(&input, &arg.a.value) == 0);
-      }
-   }
-
-   return res;
-}
-
-static struct rmsgpack_dom_value query_func_operator_or(
-      struct rmsgpack_dom_value input,
-      unsigned argc, const struct argument * argv)
-{
-   size_t i;
-   struct rmsgpack_dom_value res;
-
-   res.type      = RDT_BOOL;
-   res.val.bool_ = 0;
-
-   for (i = 0; i < argc; i++)
-   {
-      if (argv[i].type == AT_VALUE)
-         res = func_equals(input, 1, &argv[i]);
-      else
-         res = query_func_is_true(
-                  argv[i].a.invocation.func(input,
-                  argv[i].a.invocation.argc,
-                  argv[i].a.invocation.argv
-                  ), 0, NULL);
-
-      if (res.val.bool_)
-         break;
-   }
-
-   return res;
-}
-
-static struct rmsgpack_dom_value query_func_operator_and(
-      struct rmsgpack_dom_value input,
-      unsigned argc, const struct argument * argv)
-{
-   size_t i;
-   struct rmsgpack_dom_value res;
-
-   res.type      = RDT_BOOL;
-   res.val.bool_ = 0;
-
-   for (i = 0; i < argc; i++)
-   {
-      if (argv[i].type == AT_VALUE)
-         res = func_equals(input, 1, &argv[i]);
-      else
-         res = query_func_is_true(
-               argv[i].a.invocation.func(input,
-                  argv[i].a.invocation.argc,
-                  argv[i].a.invocation.argv
-                  ),
-               0, NULL);
-
-      if (!res.val.bool_)
-         break;
-   }
-   return res;
-}
-
-static struct rmsgpack_dom_value query_func_between(
-      struct rmsgpack_dom_value input,
-      unsigned argc, const struct argument * argv)
-{
-   struct rmsgpack_dom_value res;
-
-   res.type                       = RDT_BOOL;
-   res.val.bool_                  = 0;
-
-   if (argc != 2)
-      return res;
-   if (     argv[0].type != AT_VALUE 
-         || argv[1].type != AT_VALUE)
-      return res;
-   if (     argv[0].a.value.type != RDT_INT 
-         || argv[1].a.value.type != RDT_INT)
-      return res;
-
-   switch (input.type)
-   {
-      case RDT_INT:
-         res.val.bool_ = (
-               (input.val.int_ >= argv[0].a.value.val.int_)
-               && (input.val.int_ <= argv[1].a.value.val.int_));
-         break;
-      case RDT_UINT:
-         res.val.bool_ = (
-               ((unsigned)input.val.int_ >= argv[0].a.value.val.uint_)
-               && (input.val.int_ <= argv[1].a.value.val.int_));
-         break;
-      default:
-         break;
-   }
-
-   return res;
-}
-
-static struct rmsgpack_dom_value query_func_glob(
-      struct rmsgpack_dom_value input,
-      unsigned argc, const struct argument * argv)
-{
-   struct rmsgpack_dom_value res;
-   res.type      = RDT_BOOL;
-   res.val.bool_ = 0;
-
-   if (argc != 1)
-      return res;
-   if (argv[0].type != AT_VALUE || argv[0].a.value.type != RDT_STRING)
-      return res;
-   if (input.type == RDT_STRING)
-      res.val.bool_ = rl_fnmatch(
-            argv[0].a.value.val.string.buff,
-            input.val.string.buff,
-            0
-            ) == 0;
-   return res;
-}
-
-struct registered_func registered_functions[100] = {
-   {"is_true", query_func_is_true},
-   {"or",      query_func_operator_or},
-   {"and",     query_func_operator_and},
-   {"between", query_func_between},
-   {"glob",    query_func_glob},
-   {NULL, NULL}
-};
-
-static void query_raise_unknown_function(
-      char *s, size_t _len,
-      ssize_t where, const char *name,
-      ssize_t len, const char **error)
-{
-   int n = snprintf(s, _len,
-         "%" PRIu64 "::Unknown function '",
-         (uint64_t)where
-         );
-
-   if (len < (_len - n - 3))
-      strncpy(s + n, name, len);
-
-   strcpy_literal(s + n + len, "'");
-   *error = s;
-}
-
-static void query_argument_free(struct argument *arg)
-{
-   size_t i;
-
-   if (arg->type != AT_FUNCTION)
-   {
-      rmsgpack_dom_value_free(&arg->a.value);
-      return;
-   }
-
-   for (i = 0; i < arg->a.invocation.argc; i++)
-      query_argument_free(&arg->a.invocation.argv[i]);
-
-   free((void*)arg->a.invocation.argv);
-}
-
-static struct buffer query_parse_integer(
-      char *s, size_t len, 
-      struct buffer buff,
-      struct rmsgpack_dom_value *value,
-      const char **error)
-{
-   value->type = RDT_INT;
-   if (sscanf(buff.data + buff.offset,
-            STRING_REP_INT64,
-            (int64_t*)&value->val.int_) == 0)
-   {
-      snprintf(s, len,
-            "%" PRIu64 "::Expected number",
-            (uint64_t)buff.offset);
-      *error = s;
-   }
-   else
-   {
-      while (ISDIGIT((int)buff.data[buff.offset]))
-         buff.offset++;
-   }
-
-   return buff;
-}
-
-static struct buffer query_chomp(struct buffer buff)
-{
-   for (; (unsigned)buff.offset < buff.len
-         && ISSPACE((int)buff.data[buff.offset]); buff.offset++);
-   return buff;
-}
-
-static struct buffer query_expect_eof(char *s, size_t len,
-      struct buffer buff, const char ** error)
-{
-   buff = query_chomp(buff);
-   if ((unsigned)buff.offset < buff.len)
-   {
-      snprintf(s, len,
-            "%" PRIu64 "::Expected EOF found '%c'",
-            (uint64_t)buff.offset,
-            buff.data[buff.offset]
-            );
-      *error = s;
-   }
-   return buff;
-}
-
-static int query_peek(struct buffer buff, const char * data,
-      size_t size_data)
-{
-   size_t remain    = buff.len - buff.offset;
-   if (remain < size_data)
-      return 0;
-   return (strncmp(buff.data + buff.offset,
-            data, size_data) == 0);
-}
-
-static struct buffer query_get_char(
-      char *s, size_t len,
-      struct buffer buff, char * c,
-      const char ** error)
-{
-   if ((unsigned)buff.offset >= buff.len)
-   {
-      snprintf(s, len,
-            "%" PRIu64 "::Unexpected EOF",
-            (uint64_t)buff.offset
-            );
-      *error = s;
-      return buff;
-   }
-
-   *c = buff.data[buff.offset];
-   buff.offset++;
-   return buff;
-}
-
-static struct buffer query_parse_string(
-      char *s, size_t len,
-      struct buffer buff,
-      struct rmsgpack_dom_value *value, const char **error)
-{
-   const char * str_start = NULL;
-   char terminator        = '\0';
-   char c                 = '\0';
-   int  is_binstr         = 0;
-   buff                   = query_get_char(s, len,buff, &terminator, error);
-
-   if (*error)
-      return buff;
-
-   if (terminator == 'b')
-   {
-      is_binstr           = 1;
-      buff                = query_get_char(s, len, buff, &terminator, error);
-   }
-
-   if (terminator != '"' && terminator != '\'')
-   {
-      buff.offset--;
-      snprintf(s, len,
-            "%" PRIu64 "::Expected string",
-            (uint64_t)buff.offset);
-      *error = s;
-   }
-
-   str_start = buff.data + buff.offset;
-   buff      = query_get_char(s, len, buff, &c, error);
-
-   while (!*error)
-   {
-      if (c == terminator)
-         break;
-      buff = query_get_char(s, len, buff, &c, error);
-   }
-
-   if (!*error)
-   {
-      size_t count;
-      value->type            = is_binstr ? RDT_BINARY : RDT_STRING;
-      value->val.string.len  = (uint32_t)((buff.data + buff.offset) - str_start - 1);
-
-      count                  = value->val.string.len + 1;
-      if (is_binstr)
-	      count         /= 2;
-      value->val.string.buff = (char*)calloc(count, sizeof(char));
-
-      if (!value->val.string.buff)
-      {
-         s[0]   = 'O';
-         s[1]   = 'O';
-         s[2]   = 'M';
-         s[3]   = '\0';
-         *error = s;
-      }
-      else if (is_binstr)
-      {
-         size_t i;
-         int j           = 0;
-         const char *tok = str_start;
-
-         for (i = 0; i < value->val.string.len; i += 2)
-         {
-            uint8_t hi, lo;
-            char hic = tok[i];
-            char loc = tok[i + 1];
-
-            if (hic <= '9')
-               hi = hic - '0';
-            else
-               hi = (hic - 'A') + 10;
-
-            if (loc <= '9')
-               lo = loc - '0';
-            else
-               lo = (loc - 'A') + 10;
-
-            value->val.string.buff[j++] = hi * 16 + lo;
-         }
-
-         value->val.string.len = j;
-      }
-      else
-         memcpy(value->val.string.buff, str_start, value->val.string.len);
-   }
-   return buff;
-}
-
-static struct buffer query_parse_value(
-      char *s, size_t len,
-      struct buffer buff,
-      struct rmsgpack_dom_value *value, const char **error)
-{
-   buff                 = query_chomp(buff);
-
-   if (query_peek(buff, "nil", STRLEN_CONST("nil")))
-   {
-      buff.offset      += STRLEN_CONST("nil");
-      value->type       = RDT_NULL;
-   }
-   else if (query_peek(buff, "true", STRLEN_CONST("true")))
-   {
-      buff.offset      += STRLEN_CONST("true");
-      value->type       = RDT_BOOL;
-      value->val.bool_  = 1;
-   }
-   else if (query_peek(buff, "false", STRLEN_CONST("false")))
-   {
-      buff.offset       += STRLEN_CONST("false");
-      value->type        = RDT_BOOL;
-      value->val.bool_   = 0;
-   }
-   else if (
-            query_peek(buff, "b",  STRLEN_CONST("b"))
-         || query_peek(buff, "\"", STRLEN_CONST("\"")) 
-         || query_peek(buff, "'",  STRLEN_CONST("'")))
-      buff = query_parse_string(s, len,
-             buff, value, error);
-   else if (ISDIGIT((int)buff.data[buff.offset]))
-      buff = query_parse_integer(s, len, buff, value, error);
-   return buff;
-}
-
-static void query_peek_char(char *s, size_t len,
-      struct buffer buff, char *c,
-      const char **error)
-{
-   if ((unsigned)buff.offset >= buff.len)
-   {
-      snprintf(s, len,
-            "%" PRIu64 "::Unexpected EOF",
-            (uint64_t)buff.offset
-            );
-      *error = s;
-      return;
-   }
-
-   *c = buff.data[buff.offset];
-}
-
-static struct buffer query_get_ident(
-      char *s, size_t _len,
-      struct buffer buff,
-      const char **ident,
-      size_t *len, const char **error)
-{
-   char c = '\0';
-
-   if ((unsigned)buff.offset >= buff.len)
-   {
-      snprintf(s, _len,
-            "%" PRIu64 "::Unexpected EOF",
-            (uint64_t)buff.offset
-            );
-      *error = s;
-      return buff;
-   }
-
-   *ident = buff.data + buff.offset;
-   *len   = 0;
-   query_peek_char(s, _len, buff, &c, error);
-
-   if (*error || !ISALPHA((int)c))
-      return buff;
-
-   buff.offset++;
-   *len = *len + 1;
-   query_peek_char(s, _len, buff, &c, error);
-
-   while (!*error)
-   {
-      if (!(ISALNUM((int)c) || c == '_'))
-         break;
-      buff.offset++;
-      *len = *len + 1;
-      query_peek_char(s, _len, buff, &c, error);
-   }
-
-   return buff;
-}
-
-static struct buffer query_expect_char(
-      char *s, size_t len,
-      struct buffer buff,
-      char c, const char ** error)
-{
-   if ((unsigned)buff.offset >= buff.len)
-   {
-      snprintf(s, len,
-            "%" PRIu64 "::Unexpected EOF",
-            (uint64_t)buff.offset
-            );
-      *error = s;
-   }
-   else if (buff.data[buff.offset] != c)
-   {
-      snprintf(s, len,
-            "%" PRIu64 "::Expected '%c' found '%c'",
-            (uint64_t)buff.offset, c, buff.data[buff.offset]);
-      *error = s;
-   }
-   else
-      buff.offset++;
-   return buff;
-}
-
-static struct buffer query_parse_argument(
-      char *s, size_t len,
-      struct buffer buff,
-      struct argument *arg, const char **error)
-{
-   buff = query_chomp(buff);
-
-   if (
-         ISALPHA((int)buff.data[buff.offset])
-         && !(
-               query_peek(buff, "nil",   STRLEN_CONST("nil"))
-            || query_peek(buff, "true",  STRLEN_CONST("true"))
-            || query_peek(buff, "false", STRLEN_CONST("false"))
-            || query_peek(buff, "b\"",   STRLEN_CONST("b\""))
-            || query_peek(buff, "b'",    STRLEN_CONST("b'"))
-            /* bin string prefix*/
-            )
-      )
-   {
-      arg->type = AT_FUNCTION;
-      buff      = query_parse_method_call(s, len, buff,
-            &arg->a.invocation, error);
-   }
-   else if (query_peek(buff, "{", STRLEN_CONST("{")))
-   {
-      arg->type = AT_FUNCTION;
-      buff      = query_parse_table(s, len,
-                  buff, &arg->a.invocation, error);
-   }
-   else
-   {
-      arg->type = AT_VALUE;
-      buff      = query_parse_value(s,
-                  len, buff, &arg->a.value, error);
-   }
-   return buff;
-}
-
-static struct buffer query_parse_method_call(
-      char *s, size_t len, struct buffer buff,
-      struct invocation *invocation, const char **error)
-{
-   size_t func_name_len;
-   unsigned i;
-   struct argument args[QUERY_MAX_ARGS];
-   unsigned argi              = 0;
-   const char *func_name      = NULL;
-   struct registered_func *rf = registered_functions;
-
-   invocation->func           = NULL;
-
-   buff                       = query_get_ident(s, len,
-         buff, &func_name, &func_name_len, error);
-   if (*error)
-      goto clean;
-
-   buff                       = query_chomp(buff);
-   buff                       = query_expect_char(s, len, buff, '(', error);
-   if (*error)
-      goto clean;
-
-   while (rf->name)
-   {
-      if (strncmp(rf->name, func_name, func_name_len) == 0)
-      {
-         invocation->func = rf->func;
-         break;
-      }
-      rf++;
-   }
-
-   if (!invocation->func)
-   {
-      query_raise_unknown_function(s, len,
-            buff.offset, func_name,
-            func_name_len, error);
-      goto clean;
-   }
-
-   buff = query_chomp(buff);
-   while (!query_peek(buff, ")", STRLEN_CONST(")")))
-   {
-      if (argi >= QUERY_MAX_ARGS)
-      {
-         strcpy_literal(s,
-               "Too many arguments in function call.");
-         *error = s;
-         goto clean;
-      }
-
-      buff = query_parse_argument(s, len, buff, &args[argi], error);
-
-      if (*error)
-         goto clean;
-
-      argi++;
-      buff = query_chomp(buff);
-      buff = query_expect_char(s, len, buff, ',', error);
-
-      if (*error)
-      {
-         *error = NULL;
-         break;
-      }
-      buff = query_chomp(buff);
-   }
-   buff = query_expect_char(s, len, buff, ')', error);
-
-   if (*error)
-      goto clean;
-
-   invocation->argc = argi;
-   invocation->argv = (argi > 0) ? (struct argument*)
-      malloc(sizeof(struct argument) * argi) : NULL;
-
-   if (!invocation->argv)
-   {
-      s[0]   = 'O';
-      s[1]   = 'O';
-      s[2]   = 'M';
-      s[3]   = '\0';
-      *error = s;
-      goto clean;
-   }
-   memcpy(invocation->argv, args,
-         sizeof(struct argument) * argi);
-
-   return buff;
-
-clean:
-   for (i = 0; i < argi; i++)
-      query_argument_free(&args[i]);
-   return buff;
-}
-
-static struct rmsgpack_dom_value query_func_all_map(
-      struct rmsgpack_dom_value input,
-      unsigned argc, const struct argument *argv)
-{
-   struct rmsgpack_dom_value res;
-   struct rmsgpack_dom_value nil_value;
-   struct rmsgpack_dom_value *value = NULL;
-
-   res.type       = RDT_BOOL;
-   res.val.bool_  = 1;
-
-   nil_value.type = RDT_NULL;
-
-   if (argc % 2 != 0)
-   {
-      res.val.bool_ = 0;
-      return res;
-   }
-
-   if (input.type == RDT_MAP)
-   {
-      unsigned i;
-      for (i = 0; i < argc; i += 2)
-      {
-         struct argument arg = argv[i];
-         if (arg.type != AT_VALUE)
-         {
-            res.val.bool_ = 0;
-            return res;
-         }
-         /* All missing fields are nil */
-         if (!(value = rmsgpack_dom_value_map_value(&input, &arg.a.value)))
-            value = &nil_value;
-         arg      = argv[i + 1];
-         if (arg.type == AT_VALUE)
-            res   = func_equals(*value, 1, &arg);
-         else
-         {
-            res   = query_func_is_true(arg.a.invocation.func(
-                     *value,
-                     arg.a.invocation.argc,
-                     arg.a.invocation.argv
-                     ), 0, NULL);
-            value = NULL;
-         }
-         if (!res.val.bool_)
-            break;
-      }
-   }
-   return res;
-}
-
-static struct buffer query_parse_table(
-      char *s, size_t len,
-      struct buffer buff,
-      struct invocation *invocation, const char **error)
-{
-   unsigned i;
-   size_t ident_len;
-   struct argument args[QUERY_MAX_ARGS];
-   const char *ident_name = NULL;
-   unsigned argi = 0;
-
-   buff = query_chomp(buff);
-   buff = query_expect_char(s, len, buff, '{', error);
-
-   if (*error)
-      goto clean;
-
-   buff = query_chomp(buff);
-
-   while (!query_peek(buff, "}", STRLEN_CONST("}")))
-   {
-      if (argi >= QUERY_MAX_ARGS)
-      {
-         strcpy_literal(s,
-               "Too many arguments in function call.");
-         *error = s;
-         goto clean;
-      }
-
-      if (ISALPHA((int)buff.data[buff.offset]))
-      {
-         buff = query_get_ident(s, len,
-               buff, &ident_name, &ident_len, error);
-
-         if (!*error)
-         {
-            args[argi].a.value.type            = RDT_STRING;
-            args[argi].a.value.val.string.len  = (uint32_t)ident_len;
-            args[argi].a.value.val.string.buff = (char*)calloc(
-                  ident_len + 1,
-                  sizeof(char)
-                  );
-
-            if (!args[argi].a.value.val.string.buff)
-               goto clean;
-
-            strncpy(
-                  args[argi].a.value.val.string.buff,
-                  ident_name,
-                  ident_len
-                  );
-         }
-      }
-      else
-         buff = query_parse_string(s, len,
-               buff, &args[argi].a.value, error);
-
-      if (*error)
-         goto clean;
-
-      args[argi].type = AT_VALUE;
-      buff            = query_chomp(buff);
-      argi++;
-      buff            = query_expect_char(s, len, buff, ':', error);
-
-      if (*error)
-         goto clean;
-
-      buff = query_chomp(buff);
-
-      if (argi >= QUERY_MAX_ARGS)
-      {
-         strcpy_literal(s,
-               "Too many arguments in function call.");
-         *error = s;
-         goto clean;
-      }
-
-      buff = query_parse_argument(s, len, buff, &args[argi], error);
-
-      if (*error)
-         goto clean;
-      argi++;
-      buff = query_chomp(buff);
-      buff = query_expect_char(s, len, buff, ',', error);
-
-      if (*error)
-      {
-         *error = NULL;
-         break;
-      }
-      buff = query_chomp(buff);
-   }
-
-   buff = query_expect_char(s, len, buff, '}', error);
-
-   if (*error)
-      goto clean;
-
-   invocation->func = query_func_all_map;
-   invocation->argc = argi;
-   invocation->argv = (struct argument*)
-      malloc(sizeof(struct argument) * argi);
-
-   if (!invocation->argv)
-   {
-      s[0]   = 'O';
-      s[1]   = 'O';
-      s[2]   = 'M';
-      s[3]   = '\0';
-      *error = s;
-      goto clean;
-   }
-   memcpy(invocation->argv, args,
-         sizeof(struct argument) * argi);
-
-   return buff;
-
-clean:
-   for (i = 0; i < argi; i++)
-      query_argument_free(&args[i]);
-   return buff;
-}
-
-void libretrodb_query_free(void *q)
-{
-   unsigned i;
-   struct query *real_q = (struct query*)q;
-
-   real_q->ref_count--;
-   if (real_q->ref_count > 0)
-      return;
-
-   for (i = 0; i < real_q->root.argc; i++)
-      query_argument_free(&real_q->root.argv[i]);
-
-   free(real_q->root.argv);
-   real_q->root.argv = NULL;
-   real_q->root.argc = 0;
-   free(real_q);
-}
-
-void *libretrodb_query_compile(libretrodb_t *db,
-      const char *query, size_t buff_len, const char **error_string)
-{
-   struct buffer buff;
-   /* TODO/FIXME - static local variable */
-   static char tmp_error_buff [MAX_ERROR_LEN] = {0};
-   struct query *q       = (struct query*)malloc(sizeof(*q));
-   size_t error_buff_len = sizeof(tmp_error_buff);
-
-   if (!q)
-      return NULL;
-
-   q->ref_count          = 1;
-   q->root.argc          = 0;
-   q->root.func          = NULL;
-   q->root.argv          = NULL;
-
-   buff.data             = query;
-   buff.len              = buff_len;
-   buff.offset           = 0;
-   *error_string         = NULL;
-
-   buff                  = query_chomp(buff);
-
-   if (query_peek(buff, "{", STRLEN_CONST("{")))
-   {
-      buff = query_parse_table(tmp_error_buff,
-            error_buff_len, buff, &q->root, error_string);
-      if (*error_string)
-         goto error;
-   }
-   else if (ISALPHA((int)buff.data[buff.offset]))
-      buff = query_parse_method_call(tmp_error_buff,
-            error_buff_len,
-            buff, &q->root, error_string);
-
-   buff = query_expect_eof(tmp_error_buff,
-            error_buff_len,
-            buff, error_string);
-
-   if (*error_string)
-      goto error;
-
-   if (!q->root.func)
-   {
-      snprintf(tmp_error_buff, error_buff_len,
-            "%" PRIu64 "::Unexpected EOF",
-            (uint64_t)buff.offset
-            );
-      *error_string = tmp_error_buff;
-      goto error;
-   }
-
-   return q;
-
-error:
-   if (q)
-      libretrodb_query_free(q);
-   return NULL;
-}
-
-void libretrodb_query_inc_ref(libretrodb_query_t *q)
-{
-   struct query *rq = (struct query*)q;
-   if (rq)
-      rq->ref_count += 1;
-}
-
-int libretrodb_query_filter(libretrodb_query_t *q,
-      struct rmsgpack_dom_value *v)
-{
-   struct invocation inv         = ((struct query *)q)->root;
-   struct rmsgpack_dom_value res = inv.func(*v, inv.argc, inv.argv);
-   return (res.type == RDT_BOOL && res.val.bool_);
-}

+ 0 - 43
app/src/main/cpp/libretro-db/query.h

@@ -1,43 +0,0 @@
-/* Copyright  (C) 2010-2017 The RetroArch team
- *
- * ---------------------------------------------------------------------------------------
- * The following license statement only applies to this file (query.h).
- * ---------------------------------------------------------------------------------------
- *
- * Permission is hereby granted, free of charge,
- * to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef __LIBRETRODB_QUERY_H__
-#define __LIBRETRODB_QUERY_H__
-
-#include <retro_common_api.h>
-
-#include "libretrodb.h"
-#include "rmsgpack_dom.h"
-
-RETRO_BEGIN_DECLS
-
-typedef struct libretrodb_query libretrodb_query_t;
-
-void libretrodb_query_inc_ref(libretrodb_query_t *q);
-
-void libretrodb_query_dec_ref(libretrodb_query_t *q);
-
-int libretrodb_query_filter(libretrodb_query_t *q, struct rmsgpack_dom_value *v);
-
-RETRO_END_DECLS
-
-#endif

+ 0 - 595
app/src/main/cpp/libretro-db/rmsgpack.c

@@ -1,595 +0,0 @@
-/* Copyright  (C) 2010-2017 The RetroArch team
- *
- * ---------------------------------------------------------------------------------------
- * The following license statement only applies to this file (rmsgpack.c).
- * ---------------------------------------------------------------------------------------
- *
- * Permission is hereby granted, free of charge,
- * to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <stdlib.h>
-#ifdef _WIN32
-#include <direct.h>
-#else
-#include <unistd.h>
-#endif
-#include <stdint.h>
-#include <string.h>
-
-#include <retro_endianness.h>
-
-#include "rmsgpack.h"
-
-#define _MPF_FIXMAP     0x80
-#define _MPF_MAP16      0xde
-#define _MPF_MAP32      0xdf
-
-#define _MPF_FIXARRAY   0x90
-#define _MPF_ARRAY16    0xdc
-#define _MPF_ARRAY32    0xdd
-
-#define _MPF_FIXSTR     0xa0
-#define _MPF_STR8       0xd9
-#define _MPF_STR16      0xda
-#define _MPF_STR32      0xdb
-
-#define _MPF_BIN8       0xc4
-#define _MPF_BIN16      0xc5
-#define _MPF_BIN32      0xc6
-
-#define _MPF_FALSE      0xc2
-#define _MPF_TRUE       0xc3
-
-#define _MPF_INT8       0xd0
-#define _MPF_INT16      0xd1
-#define _MPF_INT32      0xd2
-#define _MPF_INT64      0xd3
-
-#define _MPF_UINT8      0xcc
-#define _MPF_UINT16     0xcd
-#define _MPF_UINT32     0xce
-#define _MPF_UINT64     0xcf
-
-#define _MPF_NIL        0xc0
-
-static const uint8_t MPF_FIXMAP   = _MPF_FIXMAP;
-static const uint8_t MPF_MAP32    = _MPF_MAP32;
-
-static const uint8_t MPF_FIXARRAY = _MPF_FIXARRAY;
-
-static const uint8_t MPF_FIXSTR   = _MPF_FIXSTR;
-
-static const uint8_t MPF_NIL      = _MPF_NIL;
-
-int rmsgpack_write_array_header(RFILE *fd, uint32_t size)
-{
-   if (size < 16)
-   {
-      size = (size | MPF_FIXARRAY);
-      if (filestream_write(fd, &size, sizeof(int8_t)) != -1)
-         return sizeof(int8_t);
-   }
-   else if (size == (uint16_t)size)
-   {
-      static const uint8_t MPF_ARRAY16  = _MPF_ARRAY16;
-      if (filestream_write(fd, &MPF_ARRAY16, sizeof(MPF_ARRAY16)) != -1)
-      {
-         uint16_t tmp_i16 = swap_if_little16(size);
-         if (filestream_write(fd, (void *)(&tmp_i16), sizeof(uint16_t)) != -1)
-            return sizeof(int8_t) + sizeof(uint16_t);
-      }
-   }
-   else
-   {
-      static const uint8_t MPF_ARRAY32  = _MPF_ARRAY32;
-      if (filestream_write(fd, &MPF_ARRAY32, sizeof(MPF_ARRAY32)) != -1)
-      {
-         uint32_t tmp_i32 = swap_if_little32(size);
-         if (filestream_write(fd, (void *)(&tmp_i32), sizeof(uint32_t)) != -1)
-            return sizeof(int8_t) + sizeof(uint32_t);
-      }
-   }
-   return -1;
-}
-
-int rmsgpack_write_map_header(RFILE *fd, uint32_t size)
-{
-   if (size < 16)
-   {
-      size = (size | MPF_FIXMAP);
-      if (filestream_write(fd, &size, sizeof(int8_t)) != -1)
-         return sizeof(int8_t);
-   }
-   else if (size == (uint16_t)size)
-   {
-      static const uint8_t MPF_MAP16    = _MPF_MAP16;
-      if (filestream_write(fd, &MPF_MAP16, sizeof(MPF_MAP16)) != -1)
-      {
-         uint16_t tmp_i16 = swap_if_little16(size);
-         if (filestream_write(fd, (void *)(&tmp_i16), sizeof(uint16_t)) != -1)
-            return sizeof(uint8_t) + sizeof(uint16_t);
-      }
-   }
-   else
-   {
-      if (filestream_write(fd, &MPF_MAP32, sizeof(MPF_MAP32)) != -1)
-      {
-         uint32_t tmp_i32 = swap_if_little32(size);
-         if (filestream_write(fd, (void *)(&tmp_i32), sizeof(uint32_t)) != -1)
-            return sizeof(int8_t) + sizeof(uint32_t);
-      }
-   }
-   return -1;
-}
-
-int rmsgpack_write_string(RFILE *fd, const char *s, uint32_t len)
-{
-   if (len < 32)
-   {
-      uint8_t tmp_i8 = len | MPF_FIXSTR;
-      if (filestream_write(fd, &tmp_i8, sizeof(uint8_t)) != -1)
-         if (filestream_write(fd, s, len) != -1)
-            return (sizeof(uint8_t) + len);
-   }
-   else if (len == (uint8_t)len)
-   {
-      static const uint8_t MPF_STR8     = _MPF_STR8;
-      if (filestream_write(fd, &MPF_STR8, sizeof(MPF_STR8)) != -1)
-      {
-         uint8_t tmp_i8 = (uint8_t)len;
-         if (filestream_write(fd, &tmp_i8, sizeof(uint8_t)) != -1)
-         {
-            int written = sizeof(uint8_t) + sizeof(uint8_t);
-            if (filestream_write(fd, s, len) != -1)
-               return written + len;
-         }
-      }
-   }
-   else if (len == (uint16_t)len)
-   {
-      static const uint8_t MPF_STR16    = _MPF_STR16;
-      if (filestream_write(fd, &MPF_STR16, sizeof(MPF_STR16)) != -1)
-      {
-         uint16_t tmp_i16 = swap_if_little16(len);
-         if (filestream_write(fd, &tmp_i16, sizeof(uint16_t)) != -1)
-         {
-            int written = sizeof(uint8_t) + sizeof(uint16_t);
-            if (filestream_write(fd, s, len) != -1)
-               return written + len;
-         }
-      }
-   }
-   else
-   {
-      static const uint8_t MPF_STR32    = _MPF_STR32;
-      if (filestream_write(fd, &MPF_STR32, sizeof(MPF_STR32)) != -1)
-      {
-         uint32_t tmp_i32 = swap_if_little32(len);
-         if (filestream_write(fd, &tmp_i32, sizeof(uint32_t)) != -1)
-         {
-            int written = sizeof(uint8_t) + sizeof(uint32_t);
-            if (filestream_write(fd, s, len) != -1)
-               return written + len;
-         }
-      }
-   }
-   return -1;
-}
-
-int rmsgpack_write_bin(RFILE *fd, const void *s, uint32_t len)
-{
-   if (len == (uint8_t)len)
-   {
-      static const uint8_t MPF_BIN8     = _MPF_BIN8;
-      if (filestream_write(fd, &MPF_BIN8, sizeof(MPF_BIN8)) != -1)
-      {
-         uint8_t tmp_i8 = (uint8_t)len;
-         if (filestream_write(fd, &tmp_i8, sizeof(uint8_t)) != -1)
-            if (filestream_write(fd, s, len) != -1)
-               return 0;
-      }
-   }
-   else if (len == (uint16_t)len)
-   {
-      static const uint8_t MPF_BIN16    = _MPF_BIN16;
-      if (filestream_write(fd, &MPF_BIN16, sizeof(MPF_BIN16)) != -1)
-      {
-         uint16_t tmp_i16 = swap_if_little16(len);
-         if (filestream_write(fd, &tmp_i16, sizeof(uint16_t)) != -1)
-            if (filestream_write(fd, s, len) != -1)
-               return 0;
-      }
-   }
-   else
-   {
-      static const uint8_t MPF_BIN32    = _MPF_BIN32;
-      if (filestream_write(fd, &MPF_BIN32, sizeof(MPF_BIN32)) != -1)
-      {
-         uint32_t tmp_i32 = swap_if_little32(len);
-         if (filestream_write(fd, &tmp_i32, sizeof(uint32_t)) != -1)
-            if (filestream_write(fd, s, len) != -1)
-               return 0;
-      }
-   }
-   return -1;
-}
-
-int rmsgpack_write_nil(RFILE *fd)
-{
-   if (filestream_write(fd, &MPF_NIL, sizeof(MPF_NIL)) == -1)
-      return -1;
-   return sizeof(uint8_t);
-}
-
-int rmsgpack_write_bool(RFILE *fd, int value)
-{
-   static const uint8_t MPF_FALSE    = _MPF_FALSE;
-   if (value)
-   {
-      static const uint8_t MPF_TRUE  = _MPF_TRUE;
-      if (filestream_write(fd, &MPF_TRUE, sizeof(MPF_TRUE)) == -1)
-         return -1;
-   }
-
-   if (filestream_write(fd, &MPF_FALSE, sizeof(MPF_FALSE)) == -1)
-      return -1;
-
-   return sizeof(uint8_t);
-}
-
-int rmsgpack_write_int(RFILE *fd, int64_t value)
-{
-   if (value >= 0 && value < 128)
-   {
-      uint8_t tmpval = (uint8_t)value;
-      if (filestream_write(fd, &tmpval, sizeof(uint8_t)) != -1)
-         return sizeof(uint8_t);
-   }
-   else if (value >= -32 && value < 0)
-   {
-      uint8_t tmpval = (uint8_t)(value + 256); /* -32..-1 => 0xE0 .. 0xFF */
-      if (filestream_write(fd, &tmpval, sizeof(uint8_t)) != -1)
-         return sizeof(uint8_t);
-   }
-   else if (value == (int8_t)value)
-   {
-      static const uint8_t MPF_INT8     = _MPF_INT8;
-      if (filestream_write(fd, &MPF_INT8, sizeof(MPF_INT8)) != -1)
-      {
-         int8_t tmp_i8 = (int8_t)value;
-         if (filestream_write(fd, &tmp_i8, sizeof(int8_t)) != -1)
-            return (sizeof(uint8_t) + sizeof(int8_t));
-      }
-   }
-   else if (value == (int16_t)value)
-   {
-      static const uint8_t MPF_INT16    = _MPF_INT16;
-      if (filestream_write(fd, &MPF_INT16, sizeof(MPF_INT16)) != -1)
-      {
-         int16_t tmp_i16 = swap_if_little16((uint16_t)value);
-         if (filestream_write(fd, &tmp_i16, sizeof(int16_t)) != -1)
-            return (sizeof(uint8_t) + sizeof(int16_t));
-      }
-   }
-   else if (value == (int32_t)value)
-   {
-      static const uint8_t MPF_INT32    = _MPF_INT32;
-      if (filestream_write(fd, &MPF_INT32, sizeof(MPF_INT32)) != -1)
-      {
-         int32_t tmp_i32 = swap_if_little32((uint32_t)value);
-         if (filestream_write(fd, &tmp_i32, sizeof(int32_t)) != -1)
-            return (sizeof(uint8_t) + sizeof(int32_t));
-      }
-   }
-   else
-   {
-      static const uint8_t MPF_INT64    = _MPF_INT64;
-      if (filestream_write(fd, &MPF_INT64, sizeof(MPF_INT64)) != -1)
-      {
-         value = swap_if_little64(value);
-         if (filestream_write(fd, &value, sizeof(int64_t)) != -1)
-            return (sizeof(uint8_t) + sizeof(int64_t));
-      }
-   }
-
-   return -1;
-}
-
-int rmsgpack_write_uint(RFILE *fd, uint64_t value)
-{
-   if (value == (uint8_t)value)
-   {
-      static const uint8_t MPF_UINT8    = _MPF_UINT8;
-      if (filestream_write(fd, &MPF_UINT8, sizeof(MPF_UINT8)) != -1)
-      {
-         uint8_t tmp_i8 = (uint8_t)value;
-         if (filestream_write(fd, &tmp_i8, sizeof(uint8_t)) != -1)
-            return (sizeof(uint8_t) + sizeof(uint8_t));
-      }
-   }
-   else if (value == (uint16_t)value)
-   {
-      static const uint8_t MPF_UINT16   = _MPF_UINT16;
-      if (filestream_write(fd, &MPF_UINT16, sizeof(MPF_UINT16)) != -1)
-      {
-         uint16_t tmp_i16 = swap_if_little16((uint16_t)value);
-         if (filestream_write(fd, &tmp_i16, sizeof(uint16_t)) != -1)
-            return (sizeof(uint8_t) + sizeof(uint16_t));
-      }
-   }
-   else if (value == (uint32_t)value)
-   {
-      static const uint8_t MPF_UINT32   = _MPF_UINT32;
-      if (filestream_write(fd, &MPF_UINT32, sizeof(MPF_UINT32)) != -1)
-      {
-         uint32_t tmp_i32 = swap_if_little32((uint32_t)value);
-         if (filestream_write(fd, &tmp_i32, sizeof(uint32_t)) != -1)
-            return (sizeof(uint8_t) + sizeof(uint32_t));
-      }
-   }
-   else
-   {
-      static const uint8_t MPF_UINT64   = _MPF_UINT64;
-      if (filestream_write(fd, &MPF_UINT64, sizeof(MPF_UINT64)) != -1)
-      {
-         value = swap_if_little64(value);
-         if (filestream_write(fd, &value, sizeof(uint64_t)) != -1)
-            return (sizeof(uint8_t) + sizeof(uint64_t));
-      }
-   }
-   return -1;
-}
-
-static int rmsgpack_read_uint(RFILE *fd, uint64_t *out, size_t size)
-{
-   union { uint64_t u64; uint32_t u32; uint16_t u16; uint8_t u8; } tmp;
-
-   if (filestream_read(fd, &tmp, size) == -1)
-      return -1;
-
-   switch (size)
-   {
-      case 1:
-         *out = tmp.u8;
-         break;
-      case 2:
-         *out = swap_if_little16(tmp.u16);
-         break;
-      case 4:
-         *out = swap_if_little32(tmp.u32);
-         break;
-      case 8:
-         *out = swap_if_little64(tmp.u64);
-         break;
-   }
-   return 0;
-}
-
-static int rmsgpack_read_int(RFILE *fd, int64_t *out, size_t size)
-{
-   union { uint64_t u64; uint32_t u32; uint16_t u16; uint8_t u8; } tmp;
-
-   if (filestream_read(fd, &tmp, size) == -1)
-      return -1;
-
-   switch (size)
-   {
-      case 1:
-         *out = (int8_t)tmp.u8;
-         break;
-      case 2:
-         *out = (int16_t)swap_if_little16(tmp.u16);
-         break;
-      case 4:
-         *out = (int32_t)swap_if_little32(tmp.u32);
-         break;
-      case 8:
-         *out = (int64_t)swap_if_little64(tmp.u64);
-         break;
-   }
-   return 0;
-}
-
-static int rmsgpack_read_buff(RFILE *fd, size_t size, char **pbuff, uint64_t *len)
-{
-   ssize_t read_len;
-   uint64_t tmp_len   = 0;
-
-   if (rmsgpack_read_uint(fd, &tmp_len, size) == -1)
-      return -1;
-
-   *pbuff             = (char *)malloc((size_t)(tmp_len + 1) * sizeof(char));
-
-   if ((read_len      = filestream_read(fd, *pbuff, (size_t)tmp_len)) == -1)
-   {
-      free(*pbuff);
-      *pbuff = NULL;
-      return -1;
-   }
-
-   *len               = read_len;
-   (*pbuff)[read_len] = 0;
-
-   /* Throw warning on read_len != tmp_len ? */
-   return 0;
-}
-
-static int rmsgpack_read_map(RFILE *fd, uint32_t len,
-        struct rmsgpack_read_callbacks *callbacks, void *data)
-{
-   int rv;
-   unsigned i;
-
-   if (     (     callbacks->read_map_start)
-         && (rv = callbacks->read_map_start(len, data)) < 0)
-      return rv;
-
-   for (i = 0; i < len; i++)
-   {
-      if ((rv = rmsgpack_read(fd, callbacks, data)) < 0)
-         return rv;
-      if ((rv = rmsgpack_read(fd, callbacks, data)) < 0)
-         return rv;
-   }
-
-   return 0;
-}
-
-static int rmsgpack_read_array(RFILE *fd, uint32_t len,
-      struct rmsgpack_read_callbacks *callbacks, void *data)
-{
-   int rv;
-   unsigned i;
-
-   if (     (     callbacks->read_array_start)
-         && (rv = callbacks->read_array_start(len, data)) < 0)
-      return rv;
-
-   for (i = 0; i < len; i++)
-   {
-      if ((rv = rmsgpack_read(fd, callbacks, data)) < 0)
-         return rv;
-   }
-
-   return 0;
-}
-
-int rmsgpack_read(RFILE *fd,
-      struct rmsgpack_read_callbacks *callbacks, void *data)
-{
-   int rv;
-   uint64_t tmp_len  = 0;
-   uint64_t tmp_uint = 0;
-   int64_t tmp_int   = 0;
-   uint8_t type      = 0;
-   char *buff        = NULL;
-
-   if (filestream_read(fd, &type, sizeof(uint8_t)) == -1)
-      return -1;
-
-   if (type < MPF_FIXMAP)
-   {
-      if (callbacks->read_int)
-         return callbacks->read_int(type, data);
-      return 0;
-   }
-   else if (type < MPF_FIXARRAY)
-   {
-      tmp_len = type - MPF_FIXMAP;
-      return rmsgpack_read_map(fd, (uint32_t)tmp_len, callbacks, data);
-   }
-   else if (type < MPF_FIXSTR)
-   {
-      tmp_len = type - MPF_FIXARRAY;
-      return rmsgpack_read_array(fd, (uint32_t)tmp_len, callbacks, data);
-   }
-   else if (type < MPF_NIL)
-   {
-      ssize_t read_len = 0;
-      tmp_len          = type - MPF_FIXSTR;
-      if (!(buff = (char *)malloc((size_t)(tmp_len + 1) * sizeof(char))))
-         return -1;
-      if ((read_len = filestream_read(fd, buff, (ssize_t)tmp_len)) == -1)
-      {
-         free(buff);
-         return -1;
-      }
-      buff[read_len] = '\0';
-      if (callbacks->read_string)
-         return callbacks->read_string(buff, (uint32_t)read_len, data);
-      goto end;
-   }
-   else if (type > MPF_MAP32)
-   {
-      if (callbacks->read_int)
-         return callbacks->read_int(type - 0xff - 1, data);
-      return 0;
-   }
-
-   switch (type)
-   {
-      case _MPF_NIL:
-         if (callbacks->read_nil)
-            return callbacks->read_nil(data);
-         break;
-      case _MPF_FALSE:
-         if (callbacks->read_bool)
-            return callbacks->read_bool(0, data);
-         break;
-      case _MPF_TRUE:
-         if (callbacks->read_bool)
-            return callbacks->read_bool(1, data);
-         break;
-      case _MPF_BIN8:
-      case _MPF_BIN16:
-      case _MPF_BIN32:
-         if ((rv = rmsgpack_read_buff(fd, (size_t)(1 << (type - _MPF_BIN8)),
-                     &buff, &tmp_len)) < 0)
-            return rv;
-
-         if (callbacks->read_bin)
-            return callbacks->read_bin(buff, (uint32_t)tmp_len, data);
-         break;
-      case _MPF_UINT8:
-      case _MPF_UINT16:
-      case _MPF_UINT32:
-      case _MPF_UINT64:
-         tmp_len  = UINT64_C(1) << (type - _MPF_UINT8);
-         tmp_uint = 0;
-         if (rmsgpack_read_uint(fd, &tmp_uint, (size_t)tmp_len) == -1)
-            return -1;
-
-         if (callbacks->read_uint)
-            return callbacks->read_uint(tmp_uint, data);
-         break;
-      case _MPF_INT8:
-      case _MPF_INT16:
-      case _MPF_INT32:
-      case _MPF_INT64:
-         tmp_len = UINT64_C(1) << (type - _MPF_INT8);
-         tmp_int = 0;
-         if (rmsgpack_read_int(fd, &tmp_int, (size_t)tmp_len) == -1)
-            return -1;
-
-         if (callbacks->read_int)
-            return callbacks->read_int(tmp_int, data);
-         break;
-      case _MPF_STR8:
-      case _MPF_STR16:
-      case _MPF_STR32:
-         if ((rv = rmsgpack_read_buff(fd, (size_t)(1 << (type - _MPF_STR8)), &buff, &tmp_len)) < 0)
-            return rv;
-
-         if (callbacks->read_string)
-            return callbacks->read_string(buff, (uint32_t)tmp_len, data);
-         break;
-      case _MPF_ARRAY16:
-      case _MPF_ARRAY32:
-         if (rmsgpack_read_uint(fd, &tmp_len, 2<<(type - _MPF_ARRAY16)) != -1)
-            return rmsgpack_read_array(fd, (uint32_t)tmp_len, callbacks, data);
-         return -1;
-      case _MPF_MAP16:
-      case _MPF_MAP32:
-         if (rmsgpack_read_uint(fd, &tmp_len, 2<<(type - _MPF_MAP16)) != -1)
-            return rmsgpack_read_map(fd, (uint32_t)tmp_len, callbacks, data);
-         return -1;
-   }
-
-end:
-   if (buff)
-      free(buff);
-   return 0;
-}

+ 0 - 60
app/src/main/cpp/libretro-db/rmsgpack.h

@@ -1,60 +0,0 @@
-/* Copyright  (C) 2010-2017 The RetroArch team
- *
- * ---------------------------------------------------------------------------------------
- * The following license statement only applies to this file (rmsgpack.h).
- * ---------------------------------------------------------------------------------------
- *
- * Permission is hereby granted, free of charge,
- * to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef __LIBRETRODB_MSGPACK_H__
-#define __LIBRETRODB_MSGPACK_H__
-
-#include <stdint.h>
-
-#include <streams/file_stream.h>
-
-struct rmsgpack_read_callbacks
-{
-   int (*read_nil        )(void *);
-   int (*read_bool       )(int, void *);
-   int (*read_int        )(int64_t, void *);
-   int (*read_uint       )(uint64_t, void *);
-   int (*read_string     )(char *, uint32_t, void *);
-   int (*read_bin        )(void *, uint32_t, void *);
-   int (*read_map_start  )(uint32_t, void *);
-   int (*read_array_start)(uint32_t, void *);
-};
-
-int rmsgpack_write_array_header(RFILE *fd, uint32_t size);
-
-int rmsgpack_write_map_header(RFILE *fd, uint32_t size);
-
-int rmsgpack_write_string(RFILE *fd, const char *s, uint32_t len);
-
-int rmsgpack_write_bin(RFILE *fd, const void *s, uint32_t len);
-
-int rmsgpack_write_nil(RFILE *fd);
-
-int rmsgpack_write_bool(RFILE *fd, int value);
-
-int rmsgpack_write_int(RFILE *fd, int64_t value);
-
-int rmsgpack_write_uint(RFILE *fd, uint64_t value );
-
-int rmsgpack_read(RFILE *fd, struct rmsgpack_read_callbacks *callbacks, void *data);
-
-#endif

+ 0 - 498
app/src/main/cpp/libretro-db/rmsgpack_dom.c

@@ -1,498 +0,0 @@
-/* Copyright  (C) 2010-2017 The RetroArch team
- *
- * ---------------------------------------------------------------------------------------
- * The following license statement only applies to this file (rmsgpack_dom.c).
- * ---------------------------------------------------------------------------------------
- *
- * Permission is hereby granted, free of charge,
- * to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "rmsgpack_dom.h"
-
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-
-#include "rmsgpack.h"
-
-#define MAX_DEPTH 128
-
-struct dom_reader_state
-{
-   int i;
-   struct rmsgpack_dom_value *stack[MAX_DEPTH];
-};
-
-static struct rmsgpack_dom_value *dom_reader_state_pop(
-      struct dom_reader_state *s)
-{
-   struct rmsgpack_dom_value *v = s->stack[s->i];
-   s->i--;
-   return v;
-}
-
-static int dom_reader_state_push(
-      struct dom_reader_state *s, struct rmsgpack_dom_value *v)
-{
-   if ((s->i + 1) == MAX_DEPTH)
-      return -1;
-   s->i++;
-   s->stack[s->i] = v;
-   return 0;
-}
-
-static int dom_read_nil(void *data)
-{
-   struct dom_reader_state *dom_state = (struct dom_reader_state *)data;
-   struct rmsgpack_dom_value *v       =
-      (struct rmsgpack_dom_value*)dom_reader_state_pop(dom_state);
-   v->type                            = RDT_NULL;
-   return 0;
-}
-
-static int dom_read_bool(int value, void *data)
-{
-   struct dom_reader_state *dom_state = (struct dom_reader_state *)data;
-   struct rmsgpack_dom_value *v       =
-      (struct rmsgpack_dom_value*)dom_reader_state_pop(dom_state);
-   v->type                            = RDT_BOOL;
-   v->val.bool_                       = value;
-   return 0;
-}
-
-static int dom_read_int(int64_t value, void *data)
-{
-   struct dom_reader_state *dom_state = (struct dom_reader_state *)data;
-   struct rmsgpack_dom_value *v       =
-      (struct rmsgpack_dom_value*)dom_reader_state_pop(dom_state);
-   v->type                            = RDT_INT;
-   v->val.int_                        = value;
-   return 0;
-}
-
-static int dom_read_uint(uint64_t value, void *data)
-{
-   struct dom_reader_state *dom_state = (struct dom_reader_state *)data;
-   struct rmsgpack_dom_value *v       =
-      (struct rmsgpack_dom_value*)dom_reader_state_pop(dom_state);
-   v->type                            = RDT_UINT;
-   v->val.uint_                       = value;
-   return 0;
-}
-
-static int dom_read_string(char *value, uint32_t len, void *data)
-{
-   struct dom_reader_state *dom_state = (struct dom_reader_state *)data;
-   struct rmsgpack_dom_value *v       =
-      (struct rmsgpack_dom_value*)dom_reader_state_pop(dom_state);
-
-   v->type                            = RDT_STRING;
-   v->val.string.len                  = len;
-   v->val.string.buff                 = value;
-   return 0;
-}
-
-static int dom_read_bin(void *value, uint32_t len, void *data)
-{
-   struct dom_reader_state *dom_state = (struct dom_reader_state *)data;
-   struct rmsgpack_dom_value *v       = (struct rmsgpack_dom_value*)
-      dom_reader_state_pop(dom_state);
-   v->type                            = RDT_BINARY;
-   v->val.binary.len                  = len;
-   v->val.binary.buff                 = (char *)value;
-   return 0;
-}
-
-static int dom_read_map_start(uint32_t len, void *data)
-{
-   unsigned i;
-   struct rmsgpack_dom_pair    *items = NULL;
-   struct dom_reader_state *dom_state = (struct dom_reader_state *)data;
-   struct rmsgpack_dom_value       *v = dom_reader_state_pop(dom_state);
-
-   v->type                            = RDT_MAP;
-   v->val.map.len                     = len;
-   v->val.map.items                   = NULL;
-
-   if (!(items = (struct rmsgpack_dom_pair *)
-      calloc(len, sizeof(struct rmsgpack_dom_pair))))
-      return -1;
-
-   v->val.map.items                   = items;
-
-   for (i = 0; i < len; i++)
-   {
-      if (dom_reader_state_push(dom_state, &items[i].value) < 0)
-         return -1;
-      if (dom_reader_state_push(dom_state, &items[i].key) < 0)
-         return -1;
-   }
-
-   return 0;
-}
-
-static int dom_read_array_start(uint32_t len, void *data)
-{
-   size_t i;
-   struct dom_reader_state *dom_state = (struct dom_reader_state *)data;
-   struct rmsgpack_dom_value *v       = dom_reader_state_pop(dom_state);
-   struct rmsgpack_dom_value *items   = NULL;
-
-   v->type                            = RDT_ARRAY;
-   v->val.array.len                   = len;
-   v->val.array.items                 = NULL;
-
-   if (!(items = (struct rmsgpack_dom_value *)
-            calloc(len, sizeof(*items))))
-      return -1;
-
-   v->val.array.items                 = items;
-
-   for (i = 0; i < len; i++)
-   {
-      if (dom_reader_state_push(dom_state, &items[i]) < 0)
-         return -1;
-   }
-
-   return 0;
-}
-
-void rmsgpack_dom_value_free(struct rmsgpack_dom_value *v)
-{
-   size_t i;
-   switch (v->type)
-   {
-      case RDT_STRING:
-         free(v->val.string.buff);
-         break;
-      case RDT_BINARY:
-         free(v->val.binary.buff);
-         break;
-      case RDT_MAP:
-         for (i = 0; i < v->val.map.len; i++)
-         {
-            rmsgpack_dom_value_free(&v->val.map.items[i].key);
-            rmsgpack_dom_value_free(&v->val.map.items[i].value);
-         }
-         free(v->val.map.items);
-         break;
-      case RDT_ARRAY:
-         for (i = 0; i < v->val.array.len; i++)
-            rmsgpack_dom_value_free(&v->val.array.items[i]);
-         free(v->val.array.items);
-         break;
-      case RDT_NULL:
-      case RDT_INT:
-      case RDT_BOOL:
-      case RDT_UINT:
-         /* Do nothing */
-         break;
-   }
-}
-
-struct rmsgpack_dom_value *rmsgpack_dom_value_map_value(
-      const struct rmsgpack_dom_value *map,
-      const struct rmsgpack_dom_value *key)
-{
-   if (map->type == RDT_MAP)
-   {
-      unsigned i;
-      for (i = 0; i < map->val.map.len; i++)
-      {
-         if (rmsgpack_dom_value_cmp(key, &map->val.map.items[i].key) == 0)
-            return &map->val.map.items[i].value;
-      }
-   }
-   return NULL;
-}
-
-int rmsgpack_dom_value_cmp(
-      const struct rmsgpack_dom_value *a,
-      const struct rmsgpack_dom_value *b)
-{
-   if ((a != b) && (a->type == b->type))
-   {
-      switch (a->type)
-      {
-         case RDT_NULL:
-            return 0;
-         case RDT_BOOL:
-            if (a->val.bool_ == b->val.bool_)
-               return 0;
-            break;
-         case RDT_INT:
-            if (a->val.int_ == b->val.int_)
-               return 0;
-            break;
-         case RDT_UINT:
-            if (a->val.uint_ == b->val.uint_)
-               return 0;
-            break;
-         case RDT_STRING:
-            if (a->val.string.len == b->val.string.len)
-               return strncmp(a->val.string.buff,
-                     b->val.string.buff, a->val.string.len);
-            break;
-         case RDT_BINARY:
-            if (a->val.binary.len == b->val.binary.len)
-               return memcmp(a->val.binary.buff,
-                     b->val.binary.buff, a->val.binary.len);
-            break;
-         case RDT_MAP:
-            if (a->val.map.len == b->val.map.len)
-            {
-               unsigned i;
-               for (i = 0; i < a->val.map.len; i++)
-               {
-                  int rv;
-                  if ((rv = rmsgpack_dom_value_cmp(&a->val.map.items[i].key,
-                              &b->val.map.items[i].key)) != 0)
-                     return rv;
-                  if ((rv = rmsgpack_dom_value_cmp(&a->val.map.items[i].value,
-                              &b->val.map.items[i].value)) != 0)
-                     return rv;
-               }
-            }
-            break;
-         case RDT_ARRAY:
-            if (a->val.array.len == b->val.array.len)
-            {
-               unsigned i;
-               for (i = 0; i < a->val.array.len; i++)
-               {
-                  int rv;
-                  if ((rv = rmsgpack_dom_value_cmp(&a->val.array.items[i],
-                              &b->val.array.items[i])) != 0)
-                     return rv;
-               }
-            }
-            break;
-      }
-   }
-
-   return 1;
-}
-
-void rmsgpack_dom_value_print(struct rmsgpack_dom_value *obj)
-{
-   unsigned i;
-
-   switch (obj->type)
-   {
-      case RDT_NULL:
-         printf("nil");
-         break;
-      case RDT_BOOL:
-         if (obj->val.bool_)
-            printf("true");
-         else
-            printf("false");
-         break;
-      case RDT_INT:
-         printf("%" PRId64, (int64_t)obj->val.int_);
-         break;
-      case RDT_UINT:
-         printf("%" PRIu64, (uint64_t)obj->val.uint_);
-         break;
-      case RDT_STRING:
-         printf("\"%s\"", obj->val.string.buff);
-         break;
-      case RDT_BINARY:
-         printf("\"");
-         for (i = 0; i < obj->val.binary.len; i++)
-            printf("%02X", (unsigned char) obj->val.binary.buff[i]);
-         printf("\"");
-         break;
-      case RDT_MAP:
-         printf("{");
-         for (i = 0; i < obj->val.map.len; i++)
-         {
-            rmsgpack_dom_value_print(&obj->val.map.items[i].key);
-            printf(": ");
-            rmsgpack_dom_value_print(&obj->val.map.items[i].value);
-            if (i < (obj->val.map.len - 1))
-               printf(", ");
-         }
-         printf("}");
-         break;
-      case RDT_ARRAY:
-         printf("[");
-         for (i = 0; i < obj->val.array.len; i++)
-         {
-            rmsgpack_dom_value_print(&obj->val.array.items[i]);
-            if (i < (obj->val.array.len - 1))
-               printf(", ");
-         }
-         printf("]");
-   }
-}
-
-int rmsgpack_dom_write(RFILE *fd, const struct rmsgpack_dom_value *obj)
-{
-   unsigned i;
-   int rv = 0;
-   int written = 0;
-
-   switch (obj->type)
-   {
-      case RDT_NULL:
-         return rmsgpack_write_nil(fd);
-      case RDT_BOOL:
-         return rmsgpack_write_bool(fd, obj->val.bool_);
-      case RDT_INT:
-         return rmsgpack_write_int(fd, obj->val.int_);
-      case RDT_UINT:
-         return rmsgpack_write_uint(fd, obj->val.uint_);
-      case RDT_STRING:
-         return rmsgpack_write_string(fd, obj->val.string.buff, obj->val.string.len);
-      case RDT_BINARY:
-         return rmsgpack_write_bin(fd, obj->val.binary.buff, obj->val.binary.len);
-      case RDT_MAP:
-         if ((rv = rmsgpack_write_map_header(fd, obj->val.map.len)) < 0)
-            return rv;
-         written += rv;
-
-         for (i = 0; i < obj->val.map.len; i++)
-         {
-            if ((rv = rmsgpack_dom_write(fd, &obj->val.map.items[i].key)) < 0)
-               return rv;
-            written += rv;
-            if ((rv = rmsgpack_dom_write(fd, &obj->val.map.items[i].value)) < 0)
-               return rv;
-            written += rv;
-         }
-         break;
-      case RDT_ARRAY:
-         if ((rv = rmsgpack_write_array_header(fd, obj->val.array.len)) < 0)
-            return rv;
-         written += rv;
-
-         for (i = 0; i < obj->val.array.len; i++)
-         {
-            if ((rv = rmsgpack_dom_write(fd, &obj->val.array.items[i])) < 0)
-               return rv;
-            written += rv;
-         }
-   }
-   return written;
-}
-
-static struct rmsgpack_read_callbacks dom_reader_callbacks = {
-	dom_read_nil,
-	dom_read_bool,
-	dom_read_int,
-	dom_read_uint,
-	dom_read_string,
-	dom_read_bin,
-	dom_read_map_start,
-	dom_read_array_start
-};
-
-int rmsgpack_dom_read(RFILE *fd, struct rmsgpack_dom_value *out)
-{
-   int rv;
-   struct dom_reader_state s;
-
-   s.i        = 0;
-   s.stack[0] = out;
-
-   if ((rv = rmsgpack_read(fd, &dom_reader_callbacks, &s)) < 0)
-      rmsgpack_dom_value_free(out);
-
-   return rv;
-}
-
-int rmsgpack_dom_read_into(RFILE *fd, ...)
-{
-   int rv;
-   va_list ap;
-   struct rmsgpack_dom_value map;
-   struct rmsgpack_dom_value key;
-   int64_t *int_value;
-   uint64_t *uint_value;
-   int *bool_value;
-   char *buff_value;
-   uint64_t min_len;
-
-   va_start(ap, fd);
-
-   if ((rv = rmsgpack_dom_read(fd, &map)) < 0)
-   {
-      va_end(ap);
-      return rv;
-   }
-
-   if (map.type == RDT_MAP)
-   {
-      for (;;)
-      {
-         struct rmsgpack_dom_value *value;
-         const char *key_name = va_arg(ap, const char *);
-
-         if (!key_name)
-            goto clean;
-
-         key.type             = RDT_STRING;
-         key.val.string.len   = (uint32_t)strlen(key_name);
-         key.val.string.buff  = (char *)key_name;
-
-         value                = rmsgpack_dom_value_map_value(&map, &key);
-
-         switch (value->type)
-         {
-            case RDT_INT:
-               int_value      = va_arg(ap, int64_t *);
-               *int_value     = value->val.int_;
-               break;
-            case RDT_BOOL:
-               bool_value     = va_arg(ap, int *);
-               *bool_value    = value->val.bool_;
-               break;
-            case RDT_UINT:
-               uint_value     = va_arg(ap, uint64_t *);
-               *uint_value    = value->val.uint_;
-               break;
-            case RDT_BINARY:
-               buff_value     = va_arg(ap, char *);
-               uint_value     = va_arg(ap, uint64_t *);
-               *uint_value    = value->val.binary.len;
-               min_len        = (value->val.binary.len > *uint_value) ?
-                  *uint_value : value->val.binary.len;
-
-               memcpy(buff_value, value->val.binary.buff, (size_t)min_len);
-               break;
-            case RDT_STRING:
-               buff_value     = va_arg(ap, char *);
-               uint_value     = va_arg(ap, uint64_t *);
-               min_len        = (value->val.string.len + 1 > *uint_value) ?
-                  *uint_value : value->val.string.len + 1;
-               *uint_value    = min_len;
-
-               memcpy(buff_value, value->val.string.buff, (size_t)min_len);
-               break;
-            default:
-               goto clean;
-         }
-      }
-   }
-
-clean:
-   va_end(ap);
-   rmsgpack_dom_value_free(&map);
-   return 0;
-}

+ 0 - 100
app/src/main/cpp/libretro-db/rmsgpack_dom.h

@@ -1,100 +0,0 @@
-/* Copyright  (C) 2010-2017 The RetroArch team
- *
- * ---------------------------------------------------------------------------------------
- * The following license statement only applies to this file (rmsgpack_dom.h).
- * ---------------------------------------------------------------------------------------
- *
- * Permission is hereby granted, free of charge,
- * to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef __LIBRETRODB_MSGPACK_DOM_H__
-#define __LIBRETRODB_MSGPACK_DOM_H__
-
-#include <stdint.h>
-
-#include <retro_common_api.h>
-#include <streams/file_stream.h>
-
-RETRO_BEGIN_DECLS
-
-enum rmsgpack_dom_type
-{
-	RDT_NULL = 0,
-	RDT_BOOL,
-	RDT_UINT,
-	RDT_INT,
-	RDT_STRING,
-	RDT_BINARY,
-	RDT_MAP,
-	RDT_ARRAY
-};
-
-struct rmsgpack_dom_value
-{
-   union
-   {
-      uint64_t uint_;
-      int64_t int_;
-      struct
-      {
-         uint32_t len;
-         char *buff;
-      } string;
-      struct
-      {
-         uint32_t len;
-         char *buff;
-      } binary;
-      int bool_;
-      struct
-      {
-         uint32_t len;
-         struct rmsgpack_dom_pair *items;
-      } map;
-      struct
-      {
-         uint32_t len;
-         struct rmsgpack_dom_value *items;
-      } array;
-   } val;
-   enum rmsgpack_dom_type type;
-};
-
-struct rmsgpack_dom_pair
-{
-	struct rmsgpack_dom_value key;   /* uint64_t alignment */
-	struct rmsgpack_dom_value value; /* uint64_t alignment */
-};
-
-void rmsgpack_dom_value_print(struct rmsgpack_dom_value *obj);
-void rmsgpack_dom_value_free(struct rmsgpack_dom_value *v);
-
-int rmsgpack_dom_value_cmp(
-      const struct rmsgpack_dom_value *a, const struct rmsgpack_dom_value *b);
-
-struct rmsgpack_dom_value *rmsgpack_dom_value_map_value(
-        const struct rmsgpack_dom_value *map,
-        const struct rmsgpack_dom_value *key);
-
-int rmsgpack_dom_read(RFILE *fd, struct rmsgpack_dom_value *out);
-
-int rmsgpack_dom_write(RFILE *fd, const struct rmsgpack_dom_value *obj);
-
-int rmsgpack_dom_read_into(RFILE *fd, ...);
-
-RETRO_END_DECLS
-
-#endif

+ 0 - 1397
app/src/main/cpp/tasks/task_database.c

@@ -1,1397 +0,0 @@
-/*  RetroArch - A frontend for libretro.
- *  Copyright (C) 2011-2017 - Daniel De Matteis
- *  Copyright (C) 2014-2017 - Jean-André Santoni
- *  Copyright (C) 2016-2019 - Brad Parker
- *
- *  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 <math.h>
-#include <compat/strcasestr.h>
-#include <compat/strl.h>
-#include <retro_miscellaneous.h>
-#include <retro_endianness.h>
-#include <string/stdstring.h>
-#include <lists/dir_list.h>
-#include <file/file_path.h>
-#include <encodings/crc32.h>
-#include <streams/file_stream.h>
-#include <streams/chd_stream.h>
-#include <streams/interface_stream.h>
-#include "tasks_internal.h"
-
-#include "../core_info.h"
-#include "../database_info.h"
-
-#include "../file_path_special.h"
-#include "../msg_hash.h"
-#ifdef HAVE_PLAYLIST
-#include "../playlist.h"
-#endif
-#ifdef RARCH_INTERNAL
-#include "../configuration.h"
-#include "../ui/ui_companion_driver.h"
-#include "../gfx/video_display_server.h"
-#endif
-#include "../retroarch.h"
-#include "../verbosity.h"
-#include "task_database_cue.h"
-
-typedef struct database_state_handle
-{
-   database_info_list_t *info;
-   struct string_list *list;
-   uint8_t *buf;
-   size_t list_index;
-   size_t entry_index;
-   uint32_t crc;
-   uint32_t archive_crc;
-   char archive_name[511];
-   char serial[4096];
-} database_state_handle_t;
-
-enum db_flags_enum
-{
-   DB_HANDLE_FLAG_IS_DIRECTORY            = (1 << 0),
-   DB_HANDLE_FLAG_SCAN_STARTED            = (1 << 1),
-   DB_HANDLE_FLAG_SCAN_WITHOUT_CORE_MATCH = (1 << 2),
-   DB_HANDLE_FLAG_SHOW_HIDDEN_FILES       = (1 << 3)
-};
-
-typedef struct db_handle
-{
-   char *playlist_directory;
-   char *content_database_path;
-   char *fullpath;
-   database_info_handle_t *handle;
-   database_state_handle_t state;
-#ifdef HAVE_PLAYLIST
-   playlist_config_t playlist_config; /* size_t alignment */
-#endif
-   unsigned status;
-   uint8_t flags;
-} db_handle_t;
-
-static 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;
-}
-
-static const char *database_info_get_current_element_name(
-      database_info_handle_t *handle)
-{
-   if (!handle || !handle->list)
-      return NULL;
-#if 1
-   /* Don't skip pruned entries, otherwise iteration
-    * ends prematurely */
-   if (!handle->list->elems[handle->list_ptr].data)
-      return "";
-#else
-   /* Skip pruned entries */
-   while (!handle->list->elems[handle->list_ptr].data)
-   {
-      if (++handle->list_ptr >= handle->list->size)
-         return NULL;
-   }
-#endif
-   return handle->list->elems[handle->list_ptr].data;
-}
-
-static int task_database_iterate_start(retro_task_t *task,
-      database_info_handle_t *db,
-      const char *name)
-{
-   char msg[256];
-   const char *basename_path = !string_is_empty(name)
-         ? path_basename_nocompression(name) : "";
-
-   msg[0] = '\0';
-
-   if (!string_is_empty(basename_path))
-      snprintf(msg, sizeof(msg),
-         STRING_REP_USIZE "/" STRING_REP_USIZE ": %s..\n",
-         db->list_ptr + 1,
-         (size_t)db->list->size,
-         basename_path);
-
-   if (!string_is_empty(msg))
-   {
-#ifdef RARCH_INTERNAL
-      task_free_title(task);
-      task_set_title(task, strdup(msg));
-      if (db->list->size != 0)
-         task_set_progress(task,
-               roundf((float)db->list_ptr /
-                  ((float)db->list->size / 100.0f)));
-      RARCH_LOG("[Scanner]: %s", msg);
-      if (retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_DATABASE_SCAN, NULL))
-         printf("%s", msg);
-#else
-      fprintf(stderr, "msg: %s\n", msg);
-#endif
-   }
-
-   db->status = DATABASE_STATUS_ITERATE;
-
-   return 0;
-}
-
-static int intfstream_get_serial(intfstream_t *fd, char *serial, size_t serial_len, const char *filename)
-{
-   const char *system_name = NULL;
-   if (detect_system(fd, &system_name, filename) >= 1)
-   {
-      if (string_is_equal(system_name, "Sony - PlayStation Portable"))
-      {
-         if (detect_psp_game(fd, serial, serial_len, filename) != 0)
-            return 1;
-      }
-      else if (string_is_equal(system_name, "Sony - PlayStation"))
-      {
-         if (detect_ps1_game(fd, serial, serial_len, filename) != 0)
-            return 1;
-      }
-      else if (string_is_equal(system_name, "Sony - PlayStation 2"))
-      {
-         if (detect_ps2_game(fd, serial, serial_len, filename) != 0)
-            return 1;
-      }
-      else if (string_is_equal(system_name, "Nintendo - GameCube"))
-      {
-         if (detect_gc_game(fd, serial, serial_len, filename) != 0)
-            return 1;
-      }
-      else if (string_is_equal(system_name, "Sega - Mega-CD - Sega CD"))
-      {
-         if (detect_scd_game(fd, serial, serial_len, filename) != 0)
-            return 1;
-      }
-      else if (string_is_equal(system_name, "Sega - Saturn"))
-      {
-         if (detect_sat_game(fd, serial, serial_len, filename) != 0)
-            return 1;
-      }
-      else if (string_is_equal(system_name, "Sega - Dreamcast"))
-      {
-         if (detect_dc_game(fd, serial, serial_len, filename) != 0)
-            return 1;
-      }
-      else if (string_is_equal(system_name, "Nintendo - Wii"))
-      {
-         if (detect_wii_game(fd, serial, serial_len, filename) != 0)
-            return 1;
-      }
-   }
-   return 0;
-}
-
-static bool intfstream_file_get_serial(const char *name,
-      uint64_t offset, uint64_t size, char *serial, size_t serial_len)
-{
-   int rv;
-   uint8_t *data     = NULL;
-   int64_t file_size = -1;
-   intfstream_t *fd  = intfstream_open_file(name,
-         RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
-
-   if (!fd)
-      return 0;
-
-   if (intfstream_seek(fd, 0, SEEK_END) == -1)
-      goto error;
-
-   file_size = intfstream_tell(fd);
-
-   if (intfstream_seek(fd, 0, SEEK_SET) == -1)
-      goto error;
-
-   if (file_size < 0)
-      goto error;
-
-   if (offset != 0 || size < (uint64_t) file_size)
-   {
-      if (intfstream_seek(fd, (int64_t)offset, SEEK_SET) == -1)
-         goto error;
-
-      data = (uint8_t*)malloc((size_t)size);
-
-      if (intfstream_read(fd, data, size) != (int64_t) size)
-      {
-         free(data);
-         goto error;
-      }
-
-      intfstream_close(fd);
-      free(fd);
-      if (!(fd = intfstream_open_memory(data, RETRO_VFS_FILE_ACCESS_READ,
-            RETRO_VFS_FILE_ACCESS_HINT_NONE,
-            size)))
-      {
-         free(data);
-         return 0;
-      }
-   }
-
-   rv = intfstream_get_serial(fd, serial, serial_len, name);
-   intfstream_close(fd);
-   free(fd);
-   free(data);
-   return rv;
-
-error:
-   intfstream_close(fd);
-   free(fd);
-   return 0;
-}
-
-static int task_database_cue_get_serial(const char *name, char* serial, size_t serial_len)
-{
-   char track_path[PATH_MAX_LENGTH];
-   uint64_t offset                  = 0;
-   uint64_t size                    = 0;
-
-   track_path[0]                    = '\0';
-
-   if (cue_find_track(name, true, &offset, &size, track_path,
-            sizeof(track_path)) < 0)
-   {
-#ifdef DEBUG
-      RARCH_LOG("%s\n",
-            msg_hash_to_str(MSG_COULD_NOT_FIND_VALID_DATA_TRACK));
-#endif
-      return 0;
-   }
-
-   return intfstream_file_get_serial(track_path, offset, size, serial, serial_len);
-}
-
-static int task_database_gdi_get_serial(const char *name, char* serial, size_t serial_len)
-{
-   char track_path[PATH_MAX_LENGTH];
-
-   track_path[0]                    = '\0';
-
-   if (gdi_find_track(name, true,
-               track_path, sizeof(track_path)) < 0)
-   {
-#ifdef DEBUG
-      RARCH_LOG("%s\n",
-            msg_hash_to_str(MSG_COULD_NOT_FIND_VALID_DATA_TRACK));
-#endif
-      return 0;
-   }
-
-   return intfstream_file_get_serial(track_path, 0, SIZE_MAX, serial, serial_len);
-}
-
-static int task_database_chd_get_serial(const char *name, char* serial, size_t serial_len)
-{
-   int result;
-   intfstream_t *fd = intfstream_open_chd_track(
-         name,
-         RETRO_VFS_FILE_ACCESS_READ,
-         RETRO_VFS_FILE_ACCESS_HINT_NONE,
-         CHDSTREAM_TRACK_FIRST_DATA);
-   if (!fd)
-      return 0;
-
-   result = intfstream_get_serial(fd, serial, serial_len, name);
-   intfstream_close(fd);
-   free(fd);
-   return result;
-}
-
-static bool intfstream_file_get_crc(const char *name,
-      uint64_t offset, size_t size, uint32_t *crc)
-{
-   bool rv;
-   intfstream_t *fd  = intfstream_open_file(name,
-         RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
-   uint8_t *data     = NULL;
-   int64_t file_size = -1;
-
-   if (!fd)
-      return 0;
-
-   if (intfstream_seek(fd, 0, SEEK_END) == -1)
-      goto error;
-
-   file_size = intfstream_tell(fd);
-
-   if (intfstream_seek(fd, 0, SEEK_SET) == -1)
-      goto error;
-
-   if (file_size < 0)
-      goto error;
-
-   if (offset != 0 || size < (uint64_t) file_size)
-   {
-      if (intfstream_seek(fd, (int64_t)offset, SEEK_SET) == -1)
-         goto error;
-
-      data = (uint8_t*)malloc(size);
-
-      if (intfstream_read(fd, data, size) != (int64_t) size)
-         goto error;
-
-      intfstream_close(fd);
-      free(fd);
-      fd = intfstream_open_memory(data, RETRO_VFS_FILE_ACCESS_READ,
-            RETRO_VFS_FILE_ACCESS_HINT_NONE, size);
-
-      if (!fd)
-         goto error;
-   }
-
-   rv = intfstream_get_crc(fd, crc);
-   intfstream_close(fd);
-   free(fd);
-   free(data);
-   return rv;
-
-error:
-   if (fd)
-   {
-      intfstream_close(fd);
-      free(fd);
-   }
-   if (data)
-      free(data);
-   return 0;
-}
-
-static int task_database_cue_get_crc(const char *name, uint32_t *crc)
-{
-   char track_path[PATH_MAX_LENGTH];
-   uint64_t offset  = 0;
-   uint64_t size    = 0;
-
-   track_path[0]    = '\0';
-
-   if (cue_find_track(name, false, &offset, &size,
-         track_path, sizeof(track_path)) < 0)
-   {
-#ifdef DEBUG
-      RARCH_LOG("%s\n",
-            msg_hash_to_str(MSG_COULD_NOT_FIND_VALID_DATA_TRACK));
-#endif
-      return 0;
-   }
-
-   return intfstream_file_get_crc(track_path, offset, (size_t)size, crc);
-}
-
-static int task_database_gdi_get_crc(const char *name, uint32_t *crc)
-{
-   char track_path[PATH_MAX_LENGTH];
-
-   track_path[0] = '\0';
-
-   if (gdi_find_track(name, true,
-               track_path, sizeof(track_path)) < 0)
-   {
-#ifdef DEBUG
-      RARCH_LOG("%s\n",
-            msg_hash_to_str(MSG_COULD_NOT_FIND_VALID_DATA_TRACK));
-#endif
-      return 0;
-   }
-
-   return intfstream_file_get_crc(track_path, 0, SIZE_MAX, crc);
-}
-
-static bool task_database_chd_get_crc(const char *name, uint32_t *crc)
-{
-   bool found_crc   = false;
-   intfstream_t *fd = intfstream_open_chd_track(
-         name,
-         RETRO_VFS_FILE_ACCESS_READ,
-         RETRO_VFS_FILE_ACCESS_HINT_NONE,
-         CHDSTREAM_TRACK_PRIMARY);
-   if (!fd)
-      return 0;
-
-   found_crc = intfstream_get_crc(fd, crc);
-   if (fd)
-   {
-      intfstream_close(fd);
-      free(fd);
-   }
-   return found_crc;
-}
-
-static void task_database_cue_prune(database_info_handle_t *db,
-      const char *name)
-{
-   size_t i;
-   char path[PATH_MAX_LENGTH];
-   intfstream_t *fd = intfstream_open_file(name,
-         RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
-
-   if (!fd)
-      return;
-
-   path[0] = '\0';
-
-   while (cue_next_file(fd, name, path, sizeof(path)))
-   {
-      for (i = db->list_ptr; i < db->list->size; ++i)
-      {
-         if (db->list->elems[i].data
-               && string_is_equal(path, db->list->elems[i].data))
-         {
-#ifdef DEBUG
-            RARCH_LOG("Pruning file referenced by cue: %s\n", path);
-#endif
-            free(db->list->elems[i].data);
-            db->list->elems[i].data = NULL;
-         }
-      }
-   }
-
-   intfstream_close(fd);
-   free(fd);
-}
-
-static void gdi_prune(database_info_handle_t *db, const char *name)
-{
-   size_t i;
-   char path[PATH_MAX_LENGTH];
-   intfstream_t *fd = intfstream_open_file(name,
-         RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
-
-   if (!fd)
-      return;
-
-   path[0] = '\0';
-
-   while (gdi_next_file(fd, name, path, sizeof(path)))
-   {
-      for (i = db->list_ptr; i < db->list->size; ++i)
-      {
-         if (db->list->elems[i].data
-               && string_is_equal(path, db->list->elems[i].data))
-         {
-            RARCH_LOG("Pruning file referenced by gdi: %s\n", path);
-            free(db->list->elems[i].data);
-            db->list->elems[i].data = NULL;
-         }
-      }
-   }
-
-   free(fd);
-}
-
-static enum msg_file_type extension_to_file_type(const char *ext)
-{
-   char ext_lower[6];
-   /* Copy and convert to lower case */
-   strlcpy(ext_lower, ext, sizeof(ext_lower));
-   string_to_lower(ext_lower);
-
-   if (
-         string_is_equal(ext_lower, "7z")  ||
-         string_is_equal(ext_lower, "zip") ||
-         string_is_equal(ext_lower, "apk")
-      )
-      return FILE_TYPE_COMPRESSED;
-   if (
-         string_is_equal(ext_lower, "cue")
-      )
-      return FILE_TYPE_CUE;
-   if (
-         string_is_equal(ext_lower, "gdi")
-      )
-      return FILE_TYPE_GDI;
-   if (
-         string_is_equal(ext_lower, "iso")
-      )
-      return FILE_TYPE_ISO;
-   if (
-         string_is_equal(ext_lower, "chd")
-      )
-      return FILE_TYPE_CHD;
-   if (
-         string_is_equal(ext_lower, "wbfs")
-      )
-      return FILE_TYPE_WBFS;
-   if (
-         string_is_equal(ext_lower, "rvz")
-      )
-      return FILE_TYPE_RVZ;
-   if (
-         string_is_equal(ext_lower, "wia")
-      )
-      return FILE_TYPE_WIA;
-   if (
-         string_is_equal(ext_lower, "lutro")
-      )
-      return FILE_TYPE_LUTRO;
-   return FILE_TYPE_NONE;
-}
-
-static int task_database_iterate_playlist(
-      database_state_handle_t *db_state,
-      database_info_handle_t *db, const char *name)
-{
-   switch (extension_to_file_type(path_get_extension(name)))
-   {
-      case FILE_TYPE_COMPRESSED:
-#ifdef HAVE_COMPRESSION
-         db->type = DATABASE_TYPE_CRC_LOOKUP;
-         /* first check crc of archive itself */
-         return intfstream_file_get_crc(name,
-               0, SIZE_MAX, &db_state->archive_crc);
-#else
-         break;
-#endif
-      case FILE_TYPE_CUE:
-         task_database_cue_prune(db, name);
-         db_state->serial[0] = '\0';
-         if (task_database_cue_get_serial(name, db_state->serial, sizeof(db_state->serial)))
-            db->type = DATABASE_TYPE_SERIAL_LOOKUP;
-         else
-         {
-            db->type = DATABASE_TYPE_CRC_LOOKUP;
-            return task_database_cue_get_crc(name, &db_state->crc);
-         }
-         break;
-      case FILE_TYPE_GDI:
-         gdi_prune(db, name);
-         db_state->serial[0] = '\0';
-         /* There are no serial databases, so don't bother with
-            serials at the moment */
-         if (0 && task_database_gdi_get_serial(name, db_state->serial, sizeof(db_state->serial)))
-            db->type = DATABASE_TYPE_SERIAL_LOOKUP;
-         else
-         {
-            db->type = DATABASE_TYPE_CRC_LOOKUP;
-            return task_database_gdi_get_crc(name, &db_state->crc);
-         }
-         break;
-      /* Consider WBFS, RVZ and WIA files similar to ISO files. */
-      case FILE_TYPE_WBFS:
-      case FILE_TYPE_RVZ:
-      case FILE_TYPE_WIA:
-      case FILE_TYPE_ISO:
-         db_state->serial[0] = '\0';
-         intfstream_file_get_serial(name, 0, SIZE_MAX, db_state->serial, sizeof(db_state->serial));
-         db->type            =  DATABASE_TYPE_SERIAL_LOOKUP;
-         break;
-      case FILE_TYPE_CHD:
-         db_state->serial[0] = '\0';
-         if (task_database_chd_get_serial(name, db_state->serial, sizeof(db_state->serial)))
-            db->type         = DATABASE_TYPE_SERIAL_LOOKUP;
-         else
-         {
-            db->type         = DATABASE_TYPE_CRC_LOOKUP;
-            return task_database_chd_get_crc(name, &db_state->crc);
-         }
-         break;
-      case FILE_TYPE_LUTRO:
-         db->type            = DATABASE_TYPE_ITERATE_LUTRO;
-         break;
-      default:
-         db_state->serial[0] = '\0';
-         db->type            = DATABASE_TYPE_CRC_LOOKUP;
-         return intfstream_file_get_crc(name, 0, SIZE_MAX, &db_state->crc);
-   }
-
-   return 1;
-}
-
-static int database_info_list_iterate_end_no_match(
-      database_info_handle_t *db,
-      database_state_handle_t *db_state,
-      const char *path,
-      bool path_contains_compressed_file)
-{
-   /* Reached end of database list,
-    * CRC match probably didn't succeed. */
-
-   /* If this was a compressed file and no match in the database
-    * list was found then expand the search list to include the
-    * archive's contents. */
-   if (!path_contains_compressed_file && path_is_compressed_file(path))
-   {
-      struct string_list *archive_list =
-         file_archive_get_file_list(path, NULL);
-
-      if (archive_list && archive_list->size > 0)
-      {
-         unsigned i;
-         size_t path_len  = strlen(path);
-
-         for (i = 0; i < archive_list->size; i++)
-         {
-            if (path_len + strlen(archive_list->elems[i].data)
-                     + 1 < PATH_MAX_LENGTH)
-            {
-               char new_path[PATH_MAX_LENGTH];
-               strlcpy(new_path, path, sizeof(new_path));
-               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);
-            }
-            else
-               string_list_append(db->list, path,
-                     archive_list->elems[i].attr);
-         }
-
-         string_list_free(archive_list);
-      }
-   }
-
-   db_state->list_index  = 0;
-   db_state->entry_index = 0;
-
-   if (db_state->crc != 0)
-      db_state->crc = 0;
-
-   if (db_state->archive_crc != 0)
-      db_state->archive_crc = 0;
-
-   return 0;
-}
-
-static int database_info_list_iterate_new(database_state_handle_t *db_state,
-      const char *query)
-{
-   const char *new_database = database_info_get_current_name(db_state);
-
-#ifndef RARCH_INTERNAL
-   fprintf(stderr, "Check database [%d/%d] : %s\n",
-         (unsigned)db_state->list_index,
-         (unsigned)db_state->list->size, new_database);
-#endif
-   if (db_state->info)
-   {
-      database_info_list_free(db_state->info);
-      free(db_state->info);
-   }
-   db_state->info = database_info_list_new(new_database, query);
-   return 0;
-}
-
-static int database_info_list_iterate_found_match(
-      db_handle_t *_db,
-      database_state_handle_t *db_state,
-      database_info_handle_t *db,
-      const char *archive_name
-      )
-{
-   /* TODO/FIXME - heap allocations are done here to avoid
-    * running out of stack space on systems with a limited stack size.
-    * We should use less fullsize paths in the future so that we don't
-    * need to have all these big char arrays here */
-   size_t str_len                 = PATH_MAX_LENGTH * sizeof(char);
-   char* db_crc                   = (char*)malloc(str_len);
-   char* db_playlist_base_str     = (char*)malloc(str_len);
-   char* db_playlist_path         = (char*)malloc(str_len);
-   char* entry_path_str           = (char*)malloc(str_len);
-   char* entry_label              = (char*)malloc(str_len);
-   char *hash                     = NULL;
-#ifdef HAVE_PLAYLIST
-   playlist_t   *playlist         = NULL;
-#endif
-   const char         *db_path    =
-      database_info_get_current_name(db_state);
-   const char         *entry_path =
-      database_info_get_current_element_name(db);
-   database_info_t *db_info_entry =
-      &db_state->info->list[db_state->entry_index];
-
-   db_crc[0]                      = '\0';
-   db_playlist_path[0]            = '\0';
-   entry_path_str[0]              = '\0';
-
-   fill_pathname(db_playlist_base_str,
-         path_basename_nocompression(db_path), "", str_len);
-   path_remove_extension(db_playlist_base_str);
-
-   strlcat(db_playlist_base_str, ".lpl", str_len);
-
-   if (!string_is_empty(_db->playlist_directory))
-      fill_pathname_join_special(db_playlist_path, _db->playlist_directory,
-            db_playlist_base_str, str_len);
-
-#ifdef HAVE_PLAYLIST
-   playlist_config_set_path(&_db->playlist_config, db_playlist_path);
-   playlist = playlist_init(&_db->playlist_config);
-#endif
-
-   if (!string_is_empty(db_state->serial))
-   {
-      if (snprintf(db_crc, str_len, "%s|serial", db_state->serial) < 0)
-         RARCH_ERR("Serial string encoding error\n");
-   }
-   else
-      snprintf(db_crc, str_len, "%08lX|crc", (unsigned long)db_info_entry->crc32);
-
-   if (entry_path)
-      strlcpy(entry_path_str, entry_path, str_len);
-
-   /* Use database name for label if found,
-    * otherwise use filename without extension */
-   if (!string_is_empty(db_info_entry->name))
-      strlcpy(entry_label, db_info_entry->name, str_len);
-   else if (!string_is_empty(entry_path))
-   {
-      char *delim = (char*)strchr(entry_path, '#');
-
-      if (delim)
-         *delim = '\0';
-      fill_pathname(entry_label,
-            path_basename_nocompression(entry_path), "", str_len);
-      path_remove_extension(entry_label);
-
-      RARCH_LOG("[Scanner]: No match for: \"%s\", CRC: 0x%08X\n", entry_path_str, db_state->crc);
-   }
-
-   if (!string_is_empty(archive_name))
-      fill_pathname_join_delim(entry_path_str,
-            entry_path_str, archive_name, '#', str_len);
-
-   if (core_info_database_match_archive_member(
-         db_state->list->elems[db_state->list_index].data) &&
-       (hash = strchr(entry_path_str, '#')))
-       *hash = '\0';
-
-#if !defined(RARCH_INTERNAL)
-   fprintf(stderr, "Found match in database !\n");
-
-   fprintf(stderr, "Path: %s\n", db_path);
-   fprintf(stderr, "CRC : %s\n", db_crc);
-   fprintf(stderr, "Playlist Path: %s\n", db_playlist_path);
-   fprintf(stderr, "Entry Path: %s\n", entry_path);
-   fprintf(stderr, "Playlist not NULL: %d\n", playlist != NULL);
-   fprintf(stderr, "ZIP entry: %s\n", archive_name);
-   fprintf(stderr, "entry path str: %s\n", entry_path_str);
-#endif
-
-#ifdef HAVE_PLAYLIST
-   if (!playlist_entry_exists(playlist, entry_path_str))
-   {
-      struct playlist_entry entry;
-
-      /* the push function reads our entry as const,
-       * so these casts are safe */
-      entry.path              = entry_path_str;
-      entry.label             = entry_label;
-      entry.core_path         = (char*)"DETECT";
-      entry.core_name         = (char*)"DETECT";
-      entry.db_name           = db_playlist_base_str;
-      entry.crc32             = db_crc;
-      entry.subsystem_ident   = NULL;
-      entry.subsystem_name    = NULL;
-      entry.subsystem_roms    = NULL;
-      entry.entry_slot        = 0;
-      entry.runtime_hours     = 0;
-      entry.runtime_minutes   = 0;
-      entry.runtime_seconds   = 0;
-      entry.last_played_year  = 0;
-      entry.last_played_month = 0;
-      entry.last_played_day   = 0;
-      entry.last_played_hour  = 0;
-      entry.last_played_minute= 0;
-      entry.last_played_second= 0;
-
-      playlist_push(playlist, &entry);
-      RARCH_LOG("[Scanner]: Add \"%s\"\n", entry_label);
-      if (retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_DATABASE_SCAN, NULL))
-         printf("Add \"%s\"\n", entry.label);
-   }
-
-   playlist_write_file(playlist);
-   playlist_free(playlist);
-#endif
-
-   database_info_list_free(db_state->info);
-   free(db_state->info);
-
-   db_state->info        = NULL;
-   db_state->crc         = 0;
-   db_state->archive_crc = 0;
-
-   /* Move database to start since we are likely to match against it
-      again */
-   if (db_state->list_index != 0)
-   {
-      struct string_list_elem entry =
-         db_state->list->elems[db_state->list_index];
-      memmove(&db_state->list->elems[1],
-              &db_state->list->elems[0],
-              sizeof(entry) * db_state->list_index);
-      db_state->list->elems[0] = entry;
-   }
-
-   free(db_crc);
-   free(db_playlist_base_str);
-   free(db_playlist_path);
-   free(entry_path_str);
-   free(entry_label);
-   return 0;
-}
-
-/* End of entries in database info list and didn't find a
- * match, go to the next database. */
-static int database_info_list_iterate_next(
-      database_state_handle_t *db_state)
-{
-   db_state->list_index++;
-   db_state->entry_index = 0;
-
-   database_info_list_free(db_state->info);
-   free(db_state->info);
-   db_state->info        = NULL;
-
-   return 1;
-}
-
-static int task_database_iterate_crc_lookup(
-      db_handle_t *_db,
-      database_state_handle_t *db_state,
-      database_info_handle_t *db,
-      const char *name,
-      const char *archive_entry,
-      bool path_contains_compressed_file)
-{
-   if (!db_state->list ||
-         (unsigned)db_state->list_index == (unsigned)db_state->list->size)
-      return database_info_list_iterate_end_no_match(db, db_state, name,
-            path_contains_compressed_file);
-
-   /* Archive did not contain a CRC for this entry,
-    * or the file is empty. */
-   if (!db_state->crc)
-   {
-      db_state->crc = file_archive_get_file_crc32(name);
-
-      if (!db_state->crc)
-         return database_info_list_iterate_next(db_state);
-   }
-
-   if (db_state->entry_index == 0)
-   {
-      char query[50];
-
-      query[0] = '\0';
-
-      if (!(_db->flags & DB_HANDLE_FLAG_SCAN_WITHOUT_CORE_MATCH))
-      {
-         /* don't scan files that can't be in this database.
-          *
-          * Could be because of:
-          * - A matching core missing
-          * - Incompatible file extension */
-         if (!core_info_database_supports_content_path(
-               db_state->list->elems[db_state->list_index].data, name))
-            return database_info_list_iterate_next(db_state);
-
-         if (!path_contains_compressed_file)
-         {
-            if (core_info_database_match_archive_member(
-                  db_state->list->elems[db_state->list_index].data))
-               return database_info_list_iterate_next(db_state);
-         }
-      }
-
-      snprintf(query, sizeof(query),
-            "{crc:or(b\"%08lX\",b\"%08lX\")}",
-            (unsigned long)db_state->crc, (unsigned long)db_state->archive_crc);
-
-      database_info_list_iterate_new(db_state, query);
-   }
-
-   if (db_state->info)
-   {
-      database_info_t *db_info_entry =
-         &db_state->info->list[db_state->entry_index];
-
-      if (db_info_entry && db_info_entry->crc32)
-      {
-         if (db_state->archive_crc == db_info_entry->crc32)
-            return database_info_list_iterate_found_match(
-                  _db,
-                  db_state, db, NULL);
-         if (db_state->crc == db_info_entry->crc32)
-            return database_info_list_iterate_found_match(
-                  _db,
-                  db_state, db, archive_entry);
-      }
-   }
-
-   db_state->entry_index++;
-
-   if (db_state->info)
-   {
-      if (db_state->entry_index >= db_state->info->count)
-         return database_info_list_iterate_next(db_state);
-   }
-
-   /* If we haven't reached the end of the database list yet,
-    * continue iterating. */
-   if (db_state->list_index < db_state->list->size)
-      return 1;
-
-   database_info_list_free(db_state->info);
-
-   if (db_state->info)
-      free(db_state->info);
-
-   return 0;
-}
-
-static int task_database_iterate_playlist_lutro(
-      db_handle_t *_db,
-      database_state_handle_t *db_state,
-      database_info_handle_t *db,
-      const char *path)
-{
-   char db_playlist_path[PATH_MAX_LENGTH];
-#ifdef HAVE_PLAYLIST
-   playlist_t   *playlist  = NULL;
-#endif
-   db_playlist_path[0]     = '\0';
-
-   if (!string_is_empty(_db->playlist_directory))
-      fill_pathname_join_special(db_playlist_path,
-            _db->playlist_directory,
-            "Lutro.lpl", sizeof(db_playlist_path));
-
-#ifdef HAVE_PLAYLIST
-   playlist_config_set_path(&_db->playlist_config, db_playlist_path);
-   playlist = playlist_init(&_db->playlist_config);
-
-   if (!playlist_entry_exists(playlist, path))
-   {
-      struct playlist_entry entry;
-      char game_title[PATH_MAX_LENGTH];
-      fill_pathname(game_title,
-            path_basename(path), "", sizeof(game_title));
-      path_remove_extension(game_title);
-
-      /* the push function reads our entry as const,
-       * so these casts are safe */
-      entry.path                  = (char*)path;
-      entry.label                 = game_title;
-      entry.core_path             = (char*)"DETECT";
-      entry.core_name             = (char*)"DETECT";
-      entry.db_name               = (char*)"Lutro.lpl";
-      entry.crc32                 = (char*)"DETECT";
-      entry.subsystem_ident       = NULL;
-      entry.subsystem_name        = NULL;
-      entry.subsystem_roms        = NULL;
-      entry.entry_slot            = 0;
-      entry.runtime_hours         = 0;
-      entry.runtime_minutes       = 0;
-      entry.runtime_seconds       = 0;
-      entry.last_played_year      = 0;
-      entry.last_played_month     = 0;
-      entry.last_played_day       = 0;
-      entry.last_played_hour      = 0;
-      entry.last_played_minute    = 0;
-      entry.last_played_second    = 0;
-
-      playlist_push(playlist, &entry);
-   }
-
-   playlist_write_file(playlist);
-   playlist_free(playlist);
-#endif
-   return 0;
-}
-
-static int task_database_iterate_serial_lookup(
-      db_handle_t *_db,
-      database_state_handle_t *db_state,
-      database_info_handle_t *db, const char *name,
-      bool path_contains_compressed_file)
-{
-   if (
-         !db_state->list ||
-         (unsigned)db_state->list_index == (unsigned)db_state->list->size
-      )
-      return database_info_list_iterate_end_no_match(db, db_state, name,
-            path_contains_compressed_file);
-
-   if (db_state->entry_index == 0)
-   {
-      size_t _len;
-      char query[50];
-      char *serial_buf = bin_to_hex_alloc(
-            (uint8_t*)db_state->serial,
-            strlen(db_state->serial) * sizeof(uint8_t));
-
-      if (!serial_buf)
-         return 1;
-
-      strlcpy(query, "{'serial': b'", sizeof(query));
-      _len          = strlcat(query, serial_buf, sizeof(query));
-      query[_len  ] = '\'';
-      query[_len+1] = '}';
-      query[_len+2] = '\0';
-      database_info_list_iterate_new(db_state, query);
-
-      free(serial_buf);
-   }
-
-   if (db_state->info)
-   {
-      database_info_t *db_info_entry = &db_state->info->list[
-         db_state->entry_index];
-
-      if (db_info_entry && db_info_entry->serial)
-      {
-         if (string_is_equal(db_state->serial, db_info_entry->serial))
-            return database_info_list_iterate_found_match(_db,
-                  db_state, db, NULL);
-      }
-   }
-
-   db_state->entry_index++;
-
-   if (db_state->info)
-   {
-      if (db_state->entry_index >= db_state->info->count)
-         return database_info_list_iterate_next(db_state);
-   }
-
-   /* If we haven't reached the end of the database list yet,
-    * continue iterating. */
-   if (db_state->list_index < db_state->list->size)
-      return 1;
-
-   database_info_list_free(db_state->info);
-   free(db_state->info);
-   return 0;
-}
-
-static int task_database_iterate(
-      db_handle_t *_db,
-      const char *name,
-      database_state_handle_t *db_state,
-      database_info_handle_t *db,
-      bool path_contains_compressed_file)
-{
-   switch (db->type)
-   {
-      case DATABASE_TYPE_ITERATE:
-         return task_database_iterate_playlist(db_state, db, name);
-      case DATABASE_TYPE_ITERATE_ARCHIVE:
-#ifdef HAVE_COMPRESSION
-         return task_database_iterate_crc_lookup(
-               _db, db_state, db, name, db_state->archive_name,
-               path_contains_compressed_file);
-#else
-         return 1;
-#endif
-      case DATABASE_TYPE_ITERATE_LUTRO:
-         return task_database_iterate_playlist_lutro(_db, db_state, db, name);
-      case DATABASE_TYPE_SERIAL_LOOKUP:
-         return task_database_iterate_serial_lookup(_db, db_state, db, name,
-               path_contains_compressed_file);
-      case DATABASE_TYPE_CRC_LOOKUP:
-         return task_database_iterate_crc_lookup(_db, db_state, db, name, NULL,
-               path_contains_compressed_file);
-      case DATABASE_TYPE_NONE:
-      default:
-         break;
-   }
-
-   return 0;
-}
-
-static void task_database_cleanup_state(
-      database_state_handle_t *db_state)
-{
-   if (!db_state)
-      return;
-
-   if (db_state->buf)
-      free(db_state->buf);
-   db_state->buf = NULL;
-}
-
-static void task_database_handler(retro_task_t *task)
-{
-   const char *name                 = NULL;
-   database_info_handle_t  *dbinfo  = NULL;
-   database_state_handle_t *dbstate = NULL;
-   db_handle_t *db                  = NULL;
-
-   if (!task)
-      goto task_finished;
-
-   db      = (db_handle_t*)task->state;
-
-   if (!db)
-      goto task_finished;
-
-   if (!(db->flags & DB_HANDLE_FLAG_SCAN_STARTED))
-   {
-      db->flags       |= DB_HANDLE_FLAG_SCAN_STARTED;
-
-      if (!string_is_empty(db->fullpath))
-      {
-         if (db->flags & DB_HANDLE_FLAG_IS_DIRECTORY)
-            db->handle = database_info_dir_init(
-                  db->fullpath, DATABASE_TYPE_ITERATE,
-                  task, db->flags & DB_HANDLE_FLAG_SHOW_HIDDEN_FILES);
-         else
-            db->handle = database_info_file_init(
-                  db->fullpath, DATABASE_TYPE_ITERATE,
-                  task);
-      }
-
-      if (db->handle)
-         db->handle->status = DATABASE_STATUS_ITERATE_BEGIN;
-   }
-
-   dbinfo  = db->handle;
-   dbstate = &db->state;
-
-   if (!dbinfo || task_get_cancelled(task))
-      goto task_finished;
-
-   switch (dbinfo->status)
-   {
-      case DATABASE_STATUS_ITERATE_BEGIN:
-         if (dbstate && !dbstate->list)
-         {
-            if (!string_is_empty(db->content_database_path))
-               dbstate->list        = dir_list_new(
-                     db->content_database_path,
-                     "rdb", false,
-                     db->flags & DB_HANDLE_FLAG_SHOW_HIDDEN_FILES,
-                     false, false);
-
-            RARCH_LOG("[Scanner]: %s\"%s\"..\n", msg_hash_to_str(MSG_MANUAL_CONTENT_SCAN_START), db->fullpath);
-            if (retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_DATABASE_SCAN, NULL))
-               printf("%s\"%s\"..\n", msg_hash_to_str(MSG_MANUAL_CONTENT_SCAN_START), db->fullpath);
-
-            /* If the scan path matches a database path exactly then
-             * save time by only processing that database. */
-            if (dbstate->list && (db->flags & DB_HANDLE_FLAG_IS_DIRECTORY))
-            {
-               size_t i;
-               char *dirname = NULL;
-
-               if (!string_is_empty(db->fullpath))
-                  dirname    = find_last_slash(db->fullpath) + 1;
-
-               if (!string_is_empty(dirname))
-               {
-                  for (i = 0; i < dbstate->list->size; i++)
-                  {
-                     const char *data = dbstate->list->elems[i].data;
-                     char *dbname     = NULL;
-                     bool strmatch    = false;
-                     char *dbpath     = strdup(data);
-
-                     path_remove_extension(dbpath);
-
-                     dbname           = find_last_slash(dbpath) + 1;
-                     strmatch         = strcasecmp(dbname, dirname) == 0;
-
-                     free(dbpath);
-
-                     if (strmatch)
-                     {
-                        struct string_list *single_list = string_list_new();
-                        string_list_append(single_list,
-                              data,
-                              dbstate->list->elems[i].attr);
-                        dir_list_free(dbstate->list);
-                        dbstate->list = single_list;
-                        break;
-                     }
-                  }
-               }
-            }
-         }
-         dbinfo->status = DATABASE_STATUS_ITERATE_START;
-         break;
-      case DATABASE_STATUS_ITERATE_START:
-         name                 = database_info_get_current_element_name(dbinfo);
-         task_database_cleanup_state(dbstate);
-         dbstate->list_index  = 0;
-         dbstate->entry_index = 0;
-         task_database_iterate_start(task, dbinfo, name);
-         break;
-      case DATABASE_STATUS_ITERATE:
-         {
-            bool path_contains_compressed_file = false;
-            const char *name                   =
-               database_info_get_current_element_name(dbinfo);
-            if (!name)
-               goto task_finished;
-
-            path_contains_compressed_file      = path_contains_compressed_file(name);
-            if (path_contains_compressed_file)
-               if (dbinfo->type == DATABASE_TYPE_ITERATE)
-                  dbinfo->type   = DATABASE_TYPE_ITERATE_ARCHIVE;
-
-            if (task_database_iterate(db, name, dbstate, dbinfo,
-                     path_contains_compressed_file) == 0)
-            {
-               dbinfo->status    = DATABASE_STATUS_ITERATE_NEXT;
-               dbinfo->type      = DATABASE_TYPE_ITERATE;
-            }
-         }
-         break;
-      case DATABASE_STATUS_ITERATE_NEXT:
-         dbinfo->list_ptr++;
-
-         if (dbinfo->list_ptr < dbinfo->list->size)
-         {
-            dbinfo->status = DATABASE_STATUS_ITERATE_START;
-            dbinfo->type   = DATABASE_TYPE_ITERATE;
-         }
-         else
-         {
-            const char *msg = NULL;
-            if (db->flags & DB_HANDLE_FLAG_IS_DIRECTORY)
-               msg = msg_hash_to_str(MSG_SCANNING_OF_DIRECTORY_FINISHED);
-            else
-               msg = msg_hash_to_str(MSG_SCANNING_OF_FILE_FINISHED);
-#ifdef RARCH_INTERNAL
-            task_free_title(task);
-            task_set_title(task, strdup(msg));
-            task_set_progress(task, 100);
-            ui_companion_driver_notify_refresh();
-            RARCH_LOG("[Scanner]: %s\n", msg);
-            if (retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_DATABASE_SCAN, NULL))
-               printf("%s\n", msg);
-#else
-            fprintf(stderr, "msg: %s\n", msg);
-#endif
-            goto task_finished;
-         }
-         break;
-      default:
-      case DATABASE_STATUS_FREE:
-      case DATABASE_STATUS_NONE:
-         goto task_finished;
-   }
-
-   return;
-
-task_finished:
-   if (task)
-      task_set_finished(task, true);
-
-   if (dbstate)
-   {
-      if (dbstate->list)
-         dir_list_free(dbstate->list);
-   }
-
-   if (db)
-   {
-      if (!string_is_empty(db->playlist_directory))
-         free(db->playlist_directory);
-      if (!string_is_empty(db->content_database_path))
-         free(db->content_database_path);
-      if (!string_is_empty(db->fullpath))
-         free(db->fullpath);
-      if (db->state.buf)
-         free(db->state.buf);
-
-      if (db->handle)
-         database_info_free(db->handle);
-      free(db);
-   }
-
-   if (dbinfo)
-      free(dbinfo);
-}
-
-#ifdef RARCH_INTERNAL
-static void task_database_progress_cb(retro_task_t *task)
-{
-   if (task)
-      video_display_server_set_window_progress(task->progress,
-            task->finished);
-}
-#endif
-
-bool task_push_dbscan(
-      const char *playlist_directory,
-      const char *content_database,
-      const char *fullpath,
-      bool directory,
-      bool db_dir_show_hidden_files,
-      retro_task_callback_t cb)
-{
-   retro_task_t *t                         = task_init();
-#ifdef RARCH_INTERNAL
-   settings_t *settings                    = config_get_ptr();
-#endif
-   db_handle_t *db                         = (db_handle_t*)calloc(1, sizeof(db_handle_t));
-
-   if (!t || !db)
-      goto error;
-
-   t->handler                              = task_database_handler;
-   t->state                                = db;
-   t->callback                             = cb;
-   t->title                                = strdup(msg_hash_to_str(
-            MSG_PREPARING_FOR_CONTENT_SCAN));
-   t->alternative_look                     = true;
-
-#ifdef RARCH_INTERNAL
-   t->progress_cb                          = task_database_progress_cb;
-   if (settings->bools.scan_without_core_match)
-      db->flags |= DB_HANDLE_FLAG_SCAN_WITHOUT_CORE_MATCH;
-#ifdef HAVE_PLAYLIST
-   db->playlist_config.capacity            = COLLECTION_SIZE;
-   db->playlist_config.old_format          = settings->bools.playlist_use_old_format;
-   db->playlist_config.compress            = settings->bools.playlist_compression;
-   db->playlist_config.fuzzy_archive_match = settings->bools.playlist_fuzzy_archive_match;
-   playlist_config_set_base_content_directory(&db->playlist_config, settings->bools.playlist_portable_paths ? settings->paths.directory_menu_content : NULL);
-#endif
-#else
-#ifdef HAVE_PLAYLIST
-   db->playlist_config.capacity            = COLLECTION_SIZE;
-   db->playlist_config.old_format          = false;
-   db->playlist_config.compress            = false;
-   db->playlist_config.fuzzy_archive_match = false;
-   playlist_config_set_base_content_directory(&db->playlist_config, NULL);
-#endif
-#endif
-   if (db_dir_show_hidden_files)
-      db->flags |= DB_HANDLE_FLAG_SHOW_HIDDEN_FILES;
-   if (directory)
-      db->flags |= DB_HANDLE_FLAG_IS_DIRECTORY;
-   db->fullpath                            = strdup(fullpath);
-   db->playlist_directory                  = strdup(playlist_directory);
-   db->content_database_path               = strdup(content_database);
-
-   task_queue_push(t);
-
-   return true;
-
-error:
-   if (t)
-      free(t);
-   if (db)
-      free(db);
-   return false;
-}

+ 0 - 1449
app/src/main/cpp/tasks/task_database_cue.c

@@ -1,1449 +0,0 @@
-/*  RetroArch - A frontend for libretro.
- *  Copyright (C) 2011-2017 - Daniel De Matteis
- *  Copyright (C) 2014-2017 - Jean-André Santoni
- *  Copyright (C) 2016-2019 - Brad Parker
- *
- *  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 <ctype.h>
-#include <string.h>
-
-#include <retro_miscellaneous.h>
-#include <retro_endianness.h>
-#include <compat/strcasestr.h>
-#include <compat/strl.h>
-#include <file/file_path.h>
-#include <retro_endianness.h>
-#include <streams/file_stream.h>
-#include <streams/interface_stream.h>
-#include <string/stdstring.h>
-#include "task_database_cue.h"
-
-#ifdef HAVE_CONFIG_H
-#include "../config.h"
-#endif
-
-#include "../database_info.h"
-
-#include "tasks_internal.h"
-
-#include "../msg_hash.h"
-#include "../verbosity.h"
-
-#define MAX_TOKEN_LEN   255
-
-#ifdef MSB_FIRST
-#define MODETEST_VAL    0x00ffffff
-#else
-#define MODETEST_VAL    0xffffff00
-#endif
-
-static struct magic_entry MAGIC_NUMBERS[] = {
-   { "Nintendo - GameCube",         "\xc2\x33\x9f\x3d", 0x00001c},
-   { "Nintendo - GameCube",         "\xc2\x33\x9f\x3d", 0x000074}, /* RVZ, WIA */
-   { "Nintendo - Wii",              "\x5d\x1c\x9e\xa3", 0x000018},
-   { "Nintendo - Wii",              "\x5d\x1c\x9e\xa3", 0x000218}, /* WBFS */
-   { "Nintendo - Wii",              "\x5d\x1c\x9e\xa3", 0x000070}, /* RVZ, WIA */
-   { "Sega - Dreamcast",            "SEGA SEGAKATANA",  0x000010},
-   { "Sega - Mega-CD - Sega CD",    "SEGADISCSYSTEM",   0x000010},
-   { "Sega - Saturn",               "SEGA SEGASATURN",  0x000010},
-   { "Sony - PlayStation",          "Sony Computer ",   0x0024f8}, /* PS1 CD license string, PS2 CD doesnt have this string */
-   { "Sony - PlayStation 2",        "PLAYSTATION",      0x009320}, /* PS1 CD and PS2 CD */
-   { "Sony - PlayStation 2",        "PLAYSTATION",      0x008008}, /* PS2 DVD */
-   { "Sony - PlayStation Portable", "PSP GAME",         0x008008},
-   { NULL,                          NULL,               0}
-};
-
-/**
- * Given a filename and position, find the associated disc number.
- */
-static int cue_find_disc_number(const char* str1, char disc)
-{
-   switch (disc)
-   {
-      case 'a':
-      case 'A':
-         return 1;
-      case 'b':
-      case 'B':
-         return 2;
-      case 'c':
-      case 'C':
-         return 3;
-      case 'd':
-      case 'D':
-         return 4;
-      case 'e':
-      case 'E':
-         return 5;
-      case 'f':
-      case 'F':
-         return 6;
-      case 'g':
-      case 'G':
-         return 7;
-      case 'h':
-      case 'H':
-         return 8;
-      case 'i':
-      case 'I':
-         return 9;
-      default:
-         if ((disc - '0') >= 1)
-            return (disc - '0');
-         break;
-   }
-
-   return 0;
-}
-
-/**
- * Given a title and filename, append the appropriate disc number to it.
- */
-static void cue_append_multi_disc_suffix(char * str1, const char *filename)
-{
-   /* Check multi-disc and insert suffix */
-   int result = string_find_index_substring_string(filename, "(Disc ");
-   if (result < 0)
-      result = string_find_index_substring_string(filename, "(disc ");
-   if (result < 0)
-      result = string_find_index_substring_string(filename, "(Disk ");
-   if (result < 0)
-      result = string_find_index_substring_string(filename, "(disk ");
-   if (result >= 0)
-   {
-      int disc_number = cue_find_disc_number(filename, filename[result + 6]);
-      if (disc_number > 0)
-      {
-         char *dest = str1;
-         sprintf(dest + strlen(dest), "-%i", disc_number - 1);
-      }
-   }
-}
-
-static int64_t task_database_cue_get_token(intfstream_t *fd, char *token, uint64_t max_len)
-{
-   char *c       = token;
-   int64_t len   = 0;
-   int in_string = 0;
-
-   for (;;)
-   {
-      int64_t rv = (int64_t)intfstream_read(fd, c, 1);
-      if (rv == 0)
-         return 0;
-      else if (rv < 0)
-         return -1;
-
-      switch (*c)
-      {
-         case ' ':
-         case '\t':
-         case '\r':
-         case '\n':
-            if (c == token)
-               continue;
-
-            if (!in_string)
-            {
-               *c = '\0';
-               return len;
-            }
-            break;
-         case '\"':
-            if (c == token)
-            {
-               in_string = 1;
-               continue;
-            }
-
-            *c = '\0';
-            return len;
-      }
-
-      len++;
-      c++;
-      if (len == (int64_t)max_len)
-      {
-         *c = '\0';
-         return len;
-      }
-   }
-}
-
-int detect_ps1_game(intfstream_t *fd, char *s, size_t len, const char *filename)
-{
-   #define DISC_DATA_SIZE_PS1 60000
-   int pos;
-   char raw_game_id[50];
-   char disc_data[DISC_DATA_SIZE_PS1];
-
-   /* Load data into buffer and use pointers */
-   if (intfstream_seek(fd, 0, SEEK_SET) < 0)
-      return false;
-
-   if (intfstream_read(fd, disc_data, DISC_DATA_SIZE_PS1) <= 0)
-      return false;
-
-   disc_data[DISC_DATA_SIZE_PS1 - 1] = '\0';
-
-   for (pos = 0; pos < DISC_DATA_SIZE_PS1; pos++)
-   {
-      strncpy(raw_game_id, &disc_data[pos], 12);
-      raw_game_id[12] = '\0';
-      if (     string_is_equal_fast(raw_game_id, "S", STRLEN_CONST("S"))
-            || string_is_equal_fast(raw_game_id, "E", STRLEN_CONST("E")))
-      {
-         if (  string_is_equal_fast(raw_game_id, "SCUS_", STRLEN_CONST("SCUS_"))
-            || string_is_equal_fast(raw_game_id, "SLUS_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SLES_", STRLEN_CONST("SLES_"))
-            || string_is_equal_fast(raw_game_id, "SCED_", STRLEN_CONST("SCED_"))
-            || string_is_equal_fast(raw_game_id, "SLPS_", STRLEN_CONST("SLPS_"))
-            || string_is_equal_fast(raw_game_id, "SLPM_", STRLEN_CONST("SLPM_"))
-            || string_is_equal_fast(raw_game_id, "SCPS_", STRLEN_CONST("SCPS_"))
-            || string_is_equal_fast(raw_game_id, "SLED_", STRLEN_CONST("SLED_"))
-            || string_is_equal_fast(raw_game_id, "SIPS_", STRLEN_CONST("SIPS_"))
-            || string_is_equal_fast(raw_game_id, "ESPM_", STRLEN_CONST("ESPM_"))
-            || string_is_equal_fast(raw_game_id, "SCES_", STRLEN_CONST("SCES_"))
-            || string_is_equal_fast(raw_game_id, "SLKA_", STRLEN_CONST("SLKA_"))
-            || string_is_equal_fast(raw_game_id, "SCAJ_", STRLEN_CONST("SCAJ_"))
-            )
-         {
-            raw_game_id[4] = '-';
-            if (string_is_equal_fast(&raw_game_id[8], ".", STRLEN_CONST(".")))
-            {
-               raw_game_id[8] = raw_game_id[9];
-               raw_game_id[9] = raw_game_id[10];
-            }
-            /* A few games have their serial in the form of xx.xxx */
-            /* Tanaka Torahiko no Ultra-ryuu Shougi - Ibisha Anaguma-hen (Japan) -> SLPS_02.261 */
-            else if (string_is_equal_fast(&raw_game_id[7], ".", STRLEN_CONST(".")))
-            {
-               raw_game_id[7] = raw_game_id[8];
-               raw_game_id[8] = raw_game_id[9];
-               raw_game_id[9] = raw_game_id[10];
-            }
-            raw_game_id[10] = '\0';
-
-            string_remove_all_whitespace(s, raw_game_id);
-            cue_append_multi_disc_suffix(s, filename);
-            return true;
-         }
-      }
-      else if (string_is_equal_fast(raw_game_id, "LSP-", STRLEN_CONST("LSP-")))
-      {
-         raw_game_id[10] = '\0';
-
-         string_remove_all_whitespace(s, raw_game_id);
-         cue_append_multi_disc_suffix(s, filename);
-         return true;
-      }
-      else if (string_is_equal_fast(raw_game_id, "PSX.EXE", STRLEN_CONST("PSX.EXE")))
-      {
-         raw_game_id[7] = '\0';
-
-         string_remove_all_whitespace(s, raw_game_id);
-         cue_append_multi_disc_suffix(s, filename);
-         return false;
-      }
-   }
-
-   s[0 ] = 'X';
-   s[1 ] = 'X';
-   s[2 ] = 'X';
-   s[3 ] = 'X';
-   s[4 ] = 'X';
-   s[5 ] = 'X';
-   s[6 ] = 'X';
-   s[7 ] = 'X';
-   s[8 ] = 'X';
-   s[9 ] = 'X';
-   s[10] = '\0';
-   cue_append_multi_disc_suffix(s, filename);
-   return false;
-}
-
-int detect_ps2_game(intfstream_t *fd, char *s, size_t len, const char *filename)
-{
-   #define DISC_DATA_SIZE_PS2 0x84000
-   int pos;
-   char raw_game_id[50];
-   char disc_data[DISC_DATA_SIZE_PS2];
-
-   /* Load data into buffer and use pointers */
-   if (intfstream_seek(fd, 0, SEEK_SET) < 0)
-      return false;
-
-   if (intfstream_read(fd, disc_data, DISC_DATA_SIZE_PS2) <= 0)
-      return false;
-
-   disc_data[DISC_DATA_SIZE_PS2 - 1] = '\0';
-
-   for (pos = 0; pos < DISC_DATA_SIZE_PS2; pos++)
-   {
-      strncpy(raw_game_id, &disc_data[pos], 12);
-      raw_game_id[12] = '\0';
-      if (     string_is_equal_fast(raw_game_id, "S", STRLEN_CONST("S"))
-            || string_is_equal_fast(raw_game_id, "P", STRLEN_CONST("P"))
-            || string_is_equal_fast(raw_game_id, "T", STRLEN_CONST("T"))
-            || string_is_equal_fast(raw_game_id, "C", STRLEN_CONST("C"))
-            || string_is_equal_fast(raw_game_id, "H", STRLEN_CONST("H"))
-            || string_is_equal_fast(raw_game_id, "A", STRLEN_CONST("A"))
-            || string_is_equal_fast(raw_game_id, "V", STRLEN_CONST("A"))
-            || string_is_equal_fast(raw_game_id, "L", STRLEN_CONST("A"))
-            || string_is_equal_fast(raw_game_id, "M", STRLEN_CONST("A"))
-            || string_is_equal_fast(raw_game_id, "N", STRLEN_CONST("A"))
-            || string_is_equal_fast(raw_game_id, "U", STRLEN_CONST("A"))
-            || string_is_equal_fast(raw_game_id, "W", STRLEN_CONST("A"))
-            || string_is_equal_fast(raw_game_id, "G", STRLEN_CONST("A"))
-            || string_is_equal_fast(raw_game_id, "K", STRLEN_CONST("A"))
-            || string_is_equal_fast(raw_game_id, "R", STRLEN_CONST("A"))
-         )
-      {
-         if (  string_is_equal_fast(raw_game_id, "SLPM_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SLES_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SCES_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SLUS_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SLPS_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SCED_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SCUS_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SCPS_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SCAJ_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SLKA_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SCKA_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SLAJ_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "TCPS_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "KOEI_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "PBPX_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "PCPX_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "PAPX_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SCCS_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "ALCH_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "TCES_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "CPCS_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SLED_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "TLES_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "GUST_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "CF00_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SCPN_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SCPM_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "PSXC_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SLPN_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "ULKS_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "LDTL_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "PKP2_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "WLFD_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "CZP2_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "HAKU_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "SRPM_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "MTP2_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "NMP2_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "ARZE_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "VUGJ_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "ARP2_", STRLEN_CONST("SLUS_"))
-            || string_is_equal_fast(raw_game_id, "ROSE_", STRLEN_CONST("SLUS_"))
-            )
-         {
-            raw_game_id[4] = '-';
-            if (string_is_equal_fast(&raw_game_id[8], ".", STRLEN_CONST(".")))
-            {
-               raw_game_id[8] = raw_game_id[9];
-               raw_game_id[9] = raw_game_id[10];
-            }
-            /* A few games have their serial in the form of xx.xxx */
-            /* Tanaka Torahiko no Ultra-ryuu Shougi - Ibisha Anaguma-hen (Japan) -> SLPS_02.261 */
-            else if (string_is_equal_fast(&raw_game_id[7], ".", STRLEN_CONST(".")))
-            {
-               raw_game_id[7] = raw_game_id[8];
-               raw_game_id[8] = raw_game_id[9];
-               raw_game_id[9] = raw_game_id[10];
-            }
-            raw_game_id[10] = '\0';
-
-            string_remove_all_whitespace(s, raw_game_id);
-            cue_append_multi_disc_suffix(s, filename);
-            return true;
-         }
-      }
-   }
-
-   s[0 ] = 'X';
-   s[1 ] = 'X';
-   s[2 ] = 'X';
-   s[3 ] = 'X';
-   s[4 ] = 'X';
-   s[5 ] = 'X';
-   s[6 ] = 'X';
-   s[7 ] = 'X';
-   s[8 ] = 'X';
-   s[9 ] = 'X';
-   s[10] = '\0';
-   cue_append_multi_disc_suffix(s, filename);
-   return false;
-}
-
-int detect_psp_game(intfstream_t *fd, char *s, size_t len, const char *filename)
-{
-   #define DISC_DATA_SIZE_PSP 40000
-   int pos;
-   char disc_data[DISC_DATA_SIZE_PSP];
-
-   /* Load data into buffer and use pointers */
-   if (intfstream_seek(fd, 0, SEEK_SET) < 0)
-      return false;
-
-   if (intfstream_read(fd, disc_data, DISC_DATA_SIZE_PSP) <= 0)
-      return false;
-
-   disc_data[DISC_DATA_SIZE_PSP - 1] = '\0';
-
-   for (pos = 0; pos < DISC_DATA_SIZE_PSP; pos++)
-   {
-      strncpy(s, &disc_data[pos], 10);
-      s[10] = '\0';
-      if (     string_is_equal_fast(s, "U", STRLEN_CONST("U"))
-            || string_is_equal_fast(s, "N", STRLEN_CONST("N")))
-      {
-         if (
-            (   string_is_equal_fast(s, "ULES-", STRLEN_CONST("ULES-")))
-            || (string_is_equal_fast(s, "ULUS-", STRLEN_CONST("ULUS-")))
-            || (string_is_equal_fast(s, "ULJS-", STRLEN_CONST("ULJS-")))
-
-            || (string_is_equal_fast(s, "ULEM-", STRLEN_CONST("ULEM-")))
-            || (string_is_equal_fast(s, "ULUM-", STRLEN_CONST("ULUM-")))
-            || (string_is_equal_fast(s, "ULJM-", STRLEN_CONST("ULJM-")))
-
-            || (string_is_equal_fast(s, "UCES-", STRLEN_CONST("UCES-")))
-            || (string_is_equal_fast(s, "UCUS-", STRLEN_CONST("UCUS-")))
-            || (string_is_equal_fast(s, "UCJS-", STRLEN_CONST("UCJS-")))
-            || (string_is_equal_fast(s, "UCAS-", STRLEN_CONST("UCAS-")))
-            || (string_is_equal_fast(s, "UCKS-", STRLEN_CONST("UCKS-")))
-
-            || (string_is_equal_fast(s, "ULKS-", STRLEN_CONST("ULKS-")))
-            || (string_is_equal_fast(s, "ULAS-", STRLEN_CONST("ULAS-")))
-            || (string_is_equal_fast(s, "NPEH-", STRLEN_CONST("NPEH-")))
-            || (string_is_equal_fast(s, "NPUH-", STRLEN_CONST("NPUH-")))
-            || (string_is_equal_fast(s, "NPJH-", STRLEN_CONST("NPJH-")))
-            || (string_is_equal_fast(s, "NPHH-", STRLEN_CONST("NPHH-")))
-
-            || (string_is_equal_fast(s, "NPEG-", STRLEN_CONST("NPEG-")))
-            || (string_is_equal_fast(s, "NPUG-", STRLEN_CONST("NPUG-")))
-            || (string_is_equal_fast(s, "NPJG-", STRLEN_CONST("NPJG-")))
-            || (string_is_equal_fast(s, "NPHG-", STRLEN_CONST("NPHG-")))
-
-            || (string_is_equal_fast(s, "NPEZ-", STRLEN_CONST("NPEZ-")))
-            || (string_is_equal_fast(s, "NPUZ-", STRLEN_CONST("NPUZ-")))
-            || (string_is_equal_fast(s, "NPJZ-", STRLEN_CONST("NPJZ-")))
-            )
-         {
-            cue_append_multi_disc_suffix(s, filename);
-            return true;
-         }
-      }
-   }
-
-   return false;
-}
-
-int detect_gc_game(intfstream_t *fd, char *s, size_t len, const char *filename)
-{
-   size_t _len;
-   char region_id;
-   char pre_game_id[20];
-   char raw_game_id[20];
-
-   /* Load raw serial or quit */
-   if (intfstream_seek(fd, 0, SEEK_SET) < 0)
-      return false;
-
-   if (intfstream_read(fd, raw_game_id, 4) <= 0)
-      return false;
-
-   if (string_is_equal_fast(raw_game_id, "RVZ", STRLEN_CONST("RVZ"))
-         || string_is_equal_fast(raw_game_id, "WIA", STRLEN_CONST("WIA")))
-   {
-      if (intfstream_seek(fd, 0x0058, SEEK_SET) < 0)
-         return false;
-      if (intfstream_read(fd, raw_game_id, 4) <= 0)
-         return false;
-   }
-
-   raw_game_id[4] = '\0';
-
-   /** Scrub files with bad data and log **/
-   if (raw_game_id[0] == '\0' || raw_game_id[0] == ' ')
-   {
-#ifdef DEBUG
-      RARCH_LOG("[Scanner]: Scrubbing: %s\n", filename);
-#endif
-      return false;
-   }
-
-   /** convert raw gamecube serial to redump serial.
-   not enough is known about the disc data to properly
-   convert every raw serial to redump serial.  it will
-   only fail with the following excpetions: the
-   subregions of europe P-UKV, P-AUS, X-UKV, X-EUU
-   will not match redump.**/
-
-   /** insert prefix **/
-   pre_game_id[0  ] = 'D';
-   pre_game_id[1  ] = 'L';
-   pre_game_id[2  ] = '-';
-   pre_game_id[3  ] = 'D';
-   pre_game_id[4  ] = 'O';
-   pre_game_id[5  ] = 'L';
-   pre_game_id[6  ] = '-';
-   pre_game_id[7  ] = '\0';
-
-   /** add raw serial **/
-   strlcat(pre_game_id, raw_game_id, sizeof(pre_game_id));
-
-   /** check region **/
-   region_id = pre_game_id[10];
-
-   /** check multi-disc and insert suffix **/
-   cue_append_multi_disc_suffix(pre_game_id, filename);
-   _len = strlcpy(s, pre_game_id, len);
-
-   switch (region_id)
-   {
-      case 'E':
-         s[_len  ] = '-';
-         s[_len+1] = 'U';
-         s[_len+2] = 'S';
-         s[_len+3] = 'A';
-         s[_len+4] = '\0';
-         return true;
-      case 'J':
-         s[_len  ] = '-';
-         s[_len+1] = 'J';
-         s[_len+2] = 'P';
-         s[_len+3] = 'N';
-         s[_len+4] = '\0';
-         return true;
-      case 'P': /** NYI: P can also be P-UKV, P-AUS **/
-      case 'X': /** NYI: X can also be X-UKV, X-EUU **/
-         s[_len  ] = '-';
-         s[_len+1] = 'E';
-         s[_len+2] = 'U';
-         s[_len+3] = 'R';
-         s[_len+4] = '\0';
-         return true;
-      case 'Y':
-         s[_len  ] = '-';
-         s[_len+1] = 'F';
-         s[_len+2] = 'A';
-         s[_len+3] = 'H';
-         s[_len+4] = '\0';
-         return true;
-      case 'D':
-         s[_len  ] = '-';
-         s[_len+1] = 'N';
-         s[_len+2] = 'O';
-         s[_len+3] = 'E';
-         s[_len+4] = '\0';
-         return true;
-      case 'S':
-         s[_len  ] = '-';
-         s[_len+1] = 'E';
-         s[_len+2] = 'S';
-         s[_len+3] = 'P';
-         s[_len+4] = '\0';
-         return true;
-      case 'F':
-         s[_len  ] = '-';
-         s[_len+1] = 'F';
-         s[_len+2] = 'R';
-         s[_len+3] = 'A';
-         s[_len+4] = '\0';
-         return true;
-      case 'I':
-         s[_len  ] = '-';
-         s[_len+1] = 'I';
-         s[_len+2] = 'T';
-         s[_len+3] = 'A';
-         s[_len+4] = '\0';
-         return true;
-      case 'H':
-         s[_len  ] = '-';
-         s[_len+1] = 'H';
-         s[_len+2] = 'O';
-         s[_len+3] = 'L';
-         s[_len+4] = '\0';
-         return true;
-      default:
-    break;
-   }
-
-   return false;
-}
-
-int detect_scd_game(intfstream_t *fd, char *s, size_t len, const char *filename)
-{
-   #define SCD_SERIAL_OFFSET 0x0193
-   #define SCD_SERIAL_LEN    11
-   #define SCD_REGION_OFFSET 0x0200
-   size_t _len;
-   char pre_game_id[SCD_SERIAL_LEN+1];
-   char raw_game_id[SCD_SERIAL_LEN+1];
-   char check_suffix_50[10];
-   char region_id;
-   size_t length;
-   size_t lengthref;
-   int index;
-   char lgame_id[10];
-
-   /* Load raw serial or quit */
-   if (intfstream_seek(fd, SCD_SERIAL_OFFSET, SEEK_SET) < 0)
-      return false;
-
-   if (intfstream_read(fd, raw_game_id, SCD_SERIAL_LEN) <= 0)
-      return false;
-
-   raw_game_id[SCD_SERIAL_LEN] = '\0';
-
-   /* Load raw region id or quit */
-   if (intfstream_seek(fd, SCD_REGION_OFFSET, SEEK_SET) < 0)
-      return false;
-
-   if (intfstream_read(fd, &region_id, 1) <= 0)
-      return false;
-
-#ifdef DEBUG
-   /** Scrub files with bad data and log **/
-   if (raw_game_id[0] == '\0' || raw_game_id[0] == ' ' || raw_game_id[0] == '0')
-      RARCH_LOG("[Scanner]: Scrubbing: %s\n", filename);
-#endif
-
-   /** convert raw Sega - Mega-CD - Sega CD serial to redump serial. **/
-   /** process raw serial to a pre serial without spaces **/
-   string_remove_all_whitespace(pre_game_id, raw_game_id);  /** rule: remove all spaces from the raw serial globally **/
-
-   /** Dissect this pre serial into parts **/
-   length             = strlen(pre_game_id);
-   lengthref          = length - 2;
-   strncpy(check_suffix_50, &pre_game_id[lengthref], length - 2 + 1);
-   check_suffix_50[2] = '\0';
-
-   /** redump serials are built differently for each prefix **/
-   if (pre_game_id[0] == 'T' && pre_game_id[1] == '-')
-   {
-      if (region_id == 'U' || region_id == 'J')
-      {
-         if ((index = string_index_last_occurance(pre_game_id, '-')) == -1)
-            return false;
-         strncpy(s, pre_game_id, index);
-         s[index] = '\0';
-         cue_append_multi_disc_suffix(s, filename);
-         return true;
-      }
-      if ((index = string_index_last_occurance(pre_game_id, '-')) == -1)
-         return false;
-      strncpy(lgame_id, pre_game_id, index);
-      lgame_id[index] = '\0';
-      _len            = strlcat(s, lgame_id, len);
-      s[_len  ]       = '-';
-      s[_len+1]       = '5';
-      s[_len+2]       = '0';
-      s[_len+3]       = '\0';
-      cue_append_multi_disc_suffix(s, filename);
-      return true;
-   }
-   else if (pre_game_id[0] == 'G' && pre_game_id[1] == '-')
-   {
-      if ((index = string_index_last_occurance(pre_game_id, '-')) == -1)
-         return false;
-      strncpy(s, pre_game_id, index);
-      s[index] = '\0';
-      cue_append_multi_disc_suffix(s, filename);
-      return true;
-   }
-   else if (pre_game_id[0] == 'M'
-         && pre_game_id[1] == 'K'
-         && pre_game_id[2] == '-')
-   {
-      if (     check_suffix_50[0] == '5'
-            && check_suffix_50[1] == '0')
-      {
-         strncpy(lgame_id, &pre_game_id[3], 4);
-         lgame_id[4]     = '\0';
-         _len            = strlcat(s, lgame_id, len);
-         s[_len  ]       = '-';
-         s[_len+1]       = '5';
-         s[_len+2]       = '0';
-         s[_len+3]       = '\0';
-         cue_append_multi_disc_suffix(s, filename);
-         return true;
-      }
-      strncpy(s, &pre_game_id[3], 4);
-      s[4] = '\0';
-      cue_append_multi_disc_suffix(s, filename);
-      return true;
-   }
-   else
-   {
-      string_trim_whitespace(raw_game_id);
-      strlcpy(s, raw_game_id, len);
-      return true;
-   }
-   return false;
-}
-
-int detect_sat_game(intfstream_t *fd, char *s, size_t len, const char *filename)
-{
-   #define SAT_SERIAL_OFFSET 0x0030
-   #define SAT_SERIAL_LEN    9
-   #define SAT_REGION_OFFSET 0x0050
-   size_t _len, length;
-   char raw_game_id[SAT_SERIAL_LEN+1];
-   char region_id;
-   char check_suffix_5[10];
-   char check_suffix_50[10];
-   char lgame_id[10];
-   char rgame_id[10];
-
-   /* Load raw serial or quit */
-   if (intfstream_seek(fd, SAT_SERIAL_OFFSET, SEEK_SET) < 0)
-      return false;
-
-   if (intfstream_read(fd, raw_game_id, SAT_SERIAL_LEN) <= 0)
-      return false;
-
-   raw_game_id[SAT_SERIAL_LEN] = '\0';
-
-   /* Load raw region id or quit */
-   if (intfstream_seek(fd, SAT_REGION_OFFSET, SEEK_SET) < 0)
-      return false;
-
-   if (intfstream_read(fd, &region_id, 1) <= 0)
-      return false;
-
-   /** Scrub files with bad data and log **/
-   if (raw_game_id[0] == '\0' || raw_game_id[0] == ' ')
-   {
-#ifdef DEBUG
-      RARCH_LOG("[Scanner]: Scrubbing: %s\n", filename);
-#endif
-      return false;
-   }
-
-   string_trim_whitespace(raw_game_id);
-
-   /** Dissect this raw serial into parts **/
-   length             = strlen(raw_game_id);
-   strncpy(check_suffix_5,  &raw_game_id[length - 2], 2);
-   check_suffix_5[2]  = '\0';
-   strncpy(check_suffix_50, &raw_game_id[length - 2], 2);
-   check_suffix_50[2] = '\0';
-
-   /** redump serials are built differently for each region **/
-   switch (region_id)
-   {
-      case 'U':
-         if (     raw_game_id[0] == 'M'
-               && raw_game_id[1] == 'K'
-               && raw_game_id[2] == '-')
-         {
-            strncpy(s, &raw_game_id[3], length - 3);
-            s[length - 3] = '\0';
-            cue_append_multi_disc_suffix(s, filename);
-         }
-         else
-         {
-            strlcpy(s, raw_game_id, len);
-            cue_append_multi_disc_suffix(s, filename);
-         }
-         return true;
-      case 'E':
-         strncpy(lgame_id, &raw_game_id[0], 2);
-         lgame_id[2] = '\0';
-         if (     !strcmp(check_suffix_5, "-5")
-               || !strcmp(check_suffix_50, "50"))
-         {
-            strncpy(rgame_id, &raw_game_id[2], length - 4);
-            rgame_id[length - 4] = '\0';
-         }
-         else
-         {
-            strncpy(rgame_id, &raw_game_id[2], length - 1);
-            rgame_id[length - 1] = '\0';
-         }
-         strlcat(s, lgame_id, len);
-         _len      = strlcat(s, rgame_id, len);
-         s[_len  ] = '-';
-         s[_len+1] = '5';
-         s[_len+2] = '0';
-         s[_len+3] = '\0';
-         cue_append_multi_disc_suffix(s, filename);
-         return true;
-      case 'J':
-         strlcpy(s, raw_game_id, len);
-         cue_append_multi_disc_suffix(s, filename);
-         return true;
-      default:
-         strlcpy(s, raw_game_id, len);
-         return true;
-   }
-   return false;
-}
-
-int detect_dc_game(intfstream_t *fd, char *s, size_t len, const char *filename)
-{
-   size_t _len;
-   int total_hyphens;
-   int total_hyphens_recalc;
-   char pre_game_id[50];
-   char raw_game_id[50];
-   size_t length;
-   size_t length_recalc;
-   int index;
-   size_t size_t_var;
-   char lgame_id[20];
-   char rgame_id[20];
-
-   /* Load raw serial or quit */
-   if (intfstream_seek(fd, 0x0050, SEEK_SET) < 0)
-      return false;
-
-   if (intfstream_read(fd, raw_game_id, 10) <= 0)
-      return false;
-
-   raw_game_id[10] = '\0';
-
-   /** Scrub files with bad data and log **/
-   if (raw_game_id[0] == '\0' || raw_game_id[0] == ' ')
-   {
-#ifdef DEBUG
-      RARCH_LOG("[Scanner]: Scrubbing: %s\n", filename);
-#endif
-      return false;
-   }
-
-   string_trim_whitespace(raw_game_id);
-   string_replace_multi_space_with_single_space(raw_game_id);
-   string_replace_whitespace_with_single_character(raw_game_id, '-');
-   length        = strlen(raw_game_id);
-   total_hyphens = string_count_occurrences_single_character(raw_game_id, '-');
-
-   /** redump serials are built differently for each prefix **/
-   if (     raw_game_id[0] == 'T'
-         && raw_game_id[1] == '-')
-   {
-      if (total_hyphens >= 2)
-      {
-         index                = string_index_last_occurance(raw_game_id, '-');
-         if (index < 0)
-            return false;
-         size_t_var           = (size_t)index;
-         strncpy(lgame_id, &raw_game_id[0], size_t_var);
-         lgame_id[index]      = '\0';
-         strncpy(rgame_id, &raw_game_id[index + 1], length - 1);
-         rgame_id[length - 1] = '\0';
-         _len                 = strlcat(s, lgame_id, len);
-         s[_len  ]            = '-';
-         s[_len+1]            = '\0';
-         strlcat(s, rgame_id, len);
-         cue_append_multi_disc_suffix(s, filename);
-         return true;
-      }
-      if (length <= 7)
-      {
-         strncpy(s, raw_game_id, 7);
-         s[7] = '\0';
-         cue_append_multi_disc_suffix(s, filename);
-         return true;
-      }
-      strncpy(lgame_id, raw_game_id, 7);
-      lgame_id[7]          = '\0';
-      strncpy(rgame_id, &raw_game_id[length - 2], length - 1);
-      rgame_id[length - 1] = '\0';
-      _len                 = strlcat(s, lgame_id, len);
-      s[_len  ]            = '-';
-      s[_len+1]            = '\0';
-      strlcat(s, rgame_id, len);
-      cue_append_multi_disc_suffix(s, filename);
-      return true;
-   }
-   else if (raw_game_id[0] == 'T')
-   {
-      strncpy(lgame_id, raw_game_id, 1);
-      lgame_id[1]          = '\0';
-      strncpy(rgame_id, &raw_game_id[1], length - 1);
-      rgame_id[length - 1] = '\0';
-      _len                 = strlcpy(pre_game_id, lgame_id, sizeof(pre_game_id));
-      pre_game_id[_len  ]  = '-';
-      pre_game_id[_len+1]  = '\0';
-      strlcat(pre_game_id, rgame_id, sizeof(pre_game_id));
-      total_hyphens_recalc = string_count_occurrences_single_character(pre_game_id, '-');
-
-      if (total_hyphens_recalc >= 2)
-      {
-         index                       = string_index_last_occurance(pre_game_id, '-');
-         if (index < 0)
-            return false;
-         size_t_var                  = (size_t)index;
-         strncpy(lgame_id, pre_game_id, size_t_var);
-         lgame_id[index]             = '\0';
-         length_recalc               = strlen(pre_game_id);
-         strncpy(rgame_id, &pre_game_id[length_recalc - 2], length_recalc - 1);
-         rgame_id[length_recalc - 1] = '\0';
-         _len                        = strlcat(s, lgame_id, len);
-         s[_len  ]                   = '-';
-         s[_len+1]                   = '\0';
-         strlcat(s, rgame_id, len);
-         cue_append_multi_disc_suffix(s, filename);
-      }
-      else
-      {
-         length_recalc = strlen(pre_game_id) - 1;
-         if (length_recalc <= 8)
-         {
-            strncpy(s, pre_game_id, 8);
-            s[8] = '\0';
-            cue_append_multi_disc_suffix(s, filename);
-            return true;
-         }
-         strncpy(lgame_id, pre_game_id, 7);
-         lgame_id[7] = '\0';
-         strncpy(rgame_id, &pre_game_id[length_recalc - 2], length_recalc - 1);
-         rgame_id[length_recalc - 1] = '\0';
-         _len                        = strlcat(s, lgame_id, len);
-         s[_len  ]                   = '-';
-         s[_len+1]                   = '\0';
-         strlcat(s, rgame_id ,len);
-         cue_append_multi_disc_suffix(s, filename);
-      }
-      return true;
-   }
-   else if (raw_game_id[0] == 'H'
-         && raw_game_id[1] == 'D'
-         && raw_game_id[2] == 'R'
-         && raw_game_id[3] == '-')
-   {
-      if (total_hyphens >= 2)
-      {
-         index = string_index_last_occurance(raw_game_id, '-');
-         if (index < 0)
-            return false;
-         strncpy(lgame_id, raw_game_id, index - 1);
-         lgame_id[index - 1]  = '\0';
-         strncpy(rgame_id, &raw_game_id[length - 4], length - 3);
-         rgame_id[length - 3] = '\0';
-         _len                 = strlcat(s, lgame_id, len);
-         s[_len  ]            = '-';
-         s[_len+1]            = '\0';
-         strlcat(s, rgame_id, len);
-         cue_append_multi_disc_suffix(s, filename);
-         return true;
-      }
-      strlcpy(s, raw_game_id, len);
-      cue_append_multi_disc_suffix(s, filename);
-      return true;
-   }
-   else if (raw_game_id[0] == 'M'
-         && raw_game_id[1] == 'K'
-         && raw_game_id[2] == '-')
-   {
-      if (length <= 8)
-      {
-         /* For 8 chars serials in 'MK-xxxxx' format, we need to remove 'MK-' to match Redump database
-          * Sega GT being the only exception (MK-51053), we have to check if it's not that game first */
-         if (string_is_not_equal_fast(raw_game_id, "MK-51053", STRLEN_CONST("MK-51053")))
-         {
-            strncpy(s, raw_game_id + 3, 5);
-            s[5] = '\0';
-            cue_append_multi_disc_suffix(s, filename);
-            return true;
-         }
-         strncpy(s, raw_game_id, 8);
-         s[8] = '\0';
-         cue_append_multi_disc_suffix(s, filename);
-         return true;
-      }
-      strncpy(lgame_id, raw_game_id, 8);
-      lgame_id[8]          = '\0';
-      strncpy(rgame_id, &raw_game_id[length - 2], length - 1);
-      rgame_id[length - 1] = '\0';
-      _len                 = strlcat(s, lgame_id, len);
-      s[_len  ]            = '-';
-      s[_len+1]            = '\0';
-      strlcat(s, rgame_id, len);
-      cue_append_multi_disc_suffix(s, filename);
-      return true;
-   }
-   else
-   {
-      strlcpy(s, raw_game_id, len);
-      return true;
-   }
-
-   return false;
-}
-
-int detect_wii_game(intfstream_t *fd, char *s, size_t len, const char *filename)
-{
-   char raw_game_id[15];
-
-   /* Load raw serial or quit */
-   if (intfstream_seek(fd, 0x0000, SEEK_SET) < 0)
-      return false;
-
-   if (intfstream_read(fd, raw_game_id, 6) <= 0)
-      return false;
-
-   if (string_is_equal_fast(raw_game_id, "WBFS", STRLEN_CONST("WBFS")))
-   {
-      if (intfstream_seek(fd, 0x0200, SEEK_SET) < 0)
-         return false;
-      if (intfstream_read(fd, raw_game_id, 6) <= 0)
-         return false;
-   }
-
-   if (string_is_equal_fast(raw_game_id, "RVZ", STRLEN_CONST("RVZ"))
-         || string_is_equal_fast(raw_game_id, "WIA", STRLEN_CONST("WIA")))
-   {
-      if (intfstream_seek(fd, 0x0058, SEEK_SET) < 0)
-         return false;
-      if (intfstream_read(fd, raw_game_id, 6) <= 0)
-         return false;
-   }
-   raw_game_id[6] = '\0';
-
-   /** Scrub files with bad data and log **/
-   if (raw_game_id[0] == '\0' || raw_game_id[0] == ' ')
-   {
-#ifdef DEBUG
-      RARCH_LOG("[Scanner]: Scrubbing: %s\n", filename);
-#endif
-      return false;
-   }
-
-   cue_append_multi_disc_suffix(s, filename);
-   strlcpy(s, raw_game_id, len);
-   return true;
-}
-
-#if 0
-/**
- * Check for an ASCII serial in the first few bits of the ISO (Wii).
- * TODO/FIXME - unused for now
- */
-static int detect_serial_ascii_game(intfstream_t *fd, char *s, size_t len)
-{
-   unsigned pos;
-   int number_of_ascii = 0;
-   bool rv             = false;
-
-   for (pos = 0; pos < 10000; pos++)
-   {
-      intfstream_seek(fd, pos, SEEK_SET);
-      if (intfstream_read(fd, s, 15) > 0)
-      {
-         unsigned i;
-         s[15]           = '\0';
-         number_of_ascii = 0;
-
-         /* When scanning WBFS files, "WBFS" is discovered as the first serial. Ignore it. */
-         if (string_is_equal(s, "WBFS"))
-            continue;
-
-         /* Loop through until we run out of ASCII characters. */
-         for (i = 0; i < 15; i++)
-         {
-            /* Is the given character ASCII? A-Z, 0-9, - */
-            if (  (s[i] == 45) ||
-                  (s[i] >= 48 && s[i] <= 57) ||
-                  (s[i] >= 65 && s[i] <= 90))
-               number_of_ascii++;
-            else
-               break;
-         }
-
-         /* If the length of the text is between 3 and 9 characters,
-          * it could be a serial. */
-         if (number_of_ascii > 3 && number_of_ascii < 9)
-         {
-            /* Cut the string off, and return it as a valid serial. */
-            s[number_of_ascii]       = '\0';
-            rv                       = true;
-            break;
-         }
-      }
-   }
-
-   return rv;
-}
-#endif
-
-int detect_system(intfstream_t *fd, const char **system_name, const char * filename)
-{
-   int i;
-   char magic[50];
-#ifdef DEBUG
-   RARCH_LOG("[Scanner]: %s\n", msg_hash_to_str(MSG_COMPARING_WITH_KNOWN_MAGIC_NUMBERS));
-#endif
-   for (i = 0; MAGIC_NUMBERS[i].system_name != NULL; i++)
-   {
-      if (intfstream_seek(fd, MAGIC_NUMBERS[i].offset, SEEK_SET) >= 0)
-      {
-         size_t magic_len = strlen(MAGIC_NUMBERS[i].magic);
-         if (intfstream_read(fd, magic, magic_len) > 0)
-         {
-            magic[magic_len] = '\0';
-            if (memcmp(MAGIC_NUMBERS[i].magic, magic, magic_len) == 0)
-            {
-               *system_name = MAGIC_NUMBERS[i].system_name;
-#ifdef DEBUG
-               RARCH_LOG("[Scanner]: Name: %s\n", filename);
-               RARCH_LOG("[Scanner]: System: %s\n", MAGIC_NUMBERS[i].system_name);
-#endif
-               return true;
-            }
-         }
-      }
-   }
-
-#ifdef DEBUG
-   RARCH_LOG("[Scanner]: Name: %s\n", filename);
-   RARCH_LOG("[Scanner]: System: Unknown\n");
-#endif
-   return false;
-}
-
-static int64_t intfstream_get_file_size(const char *path)
-{
-   int64_t rv;
-   intfstream_t *fd = intfstream_open_file(path,
-         RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
-   if (!fd)
-      return -1;
-   rv = intfstream_get_size(fd);
-   intfstream_close(fd);
-   free(fd);
-   return rv;
-}
-
-static bool update_cand(int64_t *cand_index, int64_t *last_index,
-      uint64_t *largest, char *last_file, uint64_t *offset,
-      uint64_t *size, char *track_path, uint64_t max_len)
-{
-   if (*cand_index != -1)
-   {
-      if ((uint64_t)(*last_index - *cand_index) > *largest)
-      {
-         *largest    = *last_index - *cand_index;
-         strlcpy(track_path, last_file, (size_t)max_len);
-         *offset     = *cand_index;
-         *size       = *largest;
-         *cand_index = -1;
-         return true;
-      }
-      *cand_index    = -1;
-   }
-   return false;
-}
-
-int cue_find_track(const char *cue_path, bool first,
-      uint64_t *offset, uint64_t *size, char *track_path, uint64_t max_len)
-{
-   int rv;
-   intfstream_info_t info;
-   char tmp_token[MAX_TOKEN_LEN];
-   char last_file[PATH_MAX_LENGTH];
-   char cue_dir[PATH_MAX_LENGTH];
-   intfstream_t *fd           = NULL;
-   int64_t last_index         = -1;
-   int64_t cand_index         = -1;
-   int32_t cand_track         = -1;
-   int32_t track              = 0;
-   uint64_t largest             = 0;
-   int64_t volatile file_size = -1;
-   bool is_data               = false;
-   cue_dir[0] = last_file[0]  = '\0';
-
-   fill_pathname_basedir(cue_dir, cue_path, sizeof(cue_dir));
-
-   info.type                  = INTFSTREAM_FILE;
-
-   if (!(fd = (intfstream_t*)intfstream_init(&info)))
-      goto error;
-
-   if (!intfstream_open(fd, cue_path,
-            RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE))
-   {
-#ifdef DEBUG
-      RARCH_LOG("Could not open CUE file '%s'\n", cue_path);
-#endif
-      goto error;
-   }
-
-#ifdef DEBUG
-   RARCH_LOG("Parsing CUE file '%s'...\n", cue_path);
-#endif
-
-   tmp_token[0] = '\0';
-
-   rv = -1;
-
-   while (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) > 0)
-   {
-      if (string_is_equal_noncase(tmp_token, "FILE"))
-      {
-         /* Set last index to last EOF */
-         if (file_size != -1)
-            last_index = file_size;
-
-         /* We're changing files since the candidate, update it */
-         if (update_cand(&cand_index, &last_index,
-                  &largest, last_file, offset,
-                  size, track_path, max_len))
-         {
-            rv = 0;
-            if (first)
-               goto clean;
-         }
-
-         task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
-         fill_pathname_join_special(last_file, cue_dir,
-               tmp_token, sizeof(last_file));
-
-         file_size = intfstream_get_file_size(last_file);
-
-         task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
-
-      }
-      else if (string_is_equal_noncase(tmp_token, "TRACK"))
-      {
-         task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
-         task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
-         is_data = !string_is_equal_noncase(tmp_token, "AUDIO");
-         ++track;
-      }
-      else if (string_is_equal_noncase(tmp_token, "INDEX"))
-      {
-         int m, s, f;
-         task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
-         task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
-
-         if (sscanf(tmp_token, "%02d:%02d:%02d", &m, &s, &f) < 3)
-         {
-#ifdef DEBUG
-            RARCH_LOG("Error parsing time stamp '%s'\n", tmp_token);
-#endif
-            goto error;
-         }
-
-         last_index = (size_t) (((m * 60 + s) * 75) + f) * 2352;
-
-         /* If we've changed tracks since the candidate, update it */
-         if (cand_track != -1 && track != cand_track &&
-             update_cand(&cand_index, &last_index, &largest,
-                last_file, offset,
-                size, track_path, max_len))
-         {
-            rv = 0;
-            if (first)
-               goto clean;
-         }
-
-         if (!is_data)
-            continue;
-
-         if (cand_index == -1)
-         {
-            cand_index = last_index;
-            cand_track = track;
-         }
-      }
-   }
-
-   if (file_size != -1)
-      last_index = file_size;
-
-   if (update_cand(&cand_index, &last_index,
-            &largest, last_file, offset,
-            size, track_path, max_len))
-      rv = 0;
-
-clean:
-   intfstream_close(fd);
-   free(fd);
-   return rv;
-
-error:
-   if (fd)
-   {
-      intfstream_close(fd);
-      free(fd);
-   }
-   return -1;
-}
-
-bool cue_next_file(intfstream_t *fd,
-      const char *cue_path, char *s, uint64_t len)
-{
-   char tmp_token[MAX_TOKEN_LEN];
-   char cue_dir[PATH_MAX_LENGTH];
-   cue_dir[0]                 = '\0';
-
-   fill_pathname_basedir(cue_dir, cue_path, sizeof(cue_dir));
-
-   tmp_token[0] = '\0';
-
-   while (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) > 0)
-   {
-      if (string_is_equal_noncase(tmp_token, "FILE"))
-      {
-         task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
-         fill_pathname_join_special(s, cue_dir, tmp_token, (size_t)len);
-         return true;
-      }
-   }
-
-   return false;
-}
-
-int gdi_find_track(const char *gdi_path, bool first,
-      char *track_path, uint64_t max_len)
-{
-   intfstream_info_t info;
-   char tmp_token[MAX_TOKEN_LEN];
-   intfstream_t *fd  = NULL;
-   uint64_t largest  = 0;
-   int rv            = -1;
-   int size          = -1;
-   int mode          = -1;
-   int64_t file_size = -1;
-
-   info.type         = INTFSTREAM_FILE;
-
-   if (!(fd = (intfstream_t*)intfstream_init(&info)))
-      goto error;
-
-   if (!intfstream_open(fd, gdi_path,
-            RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE))
-   {
-#ifdef DEBUG
-      RARCH_LOG("Could not open GDI file '%s'\n", gdi_path);
-#endif
-      goto error;
-   }
-
-#ifdef DEBUG
-   RARCH_LOG("Parsing GDI file '%s'...\n", gdi_path);
-#endif
-
-   tmp_token[0] = '\0';
-
-   /* Skip track count */
-   task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
-
-   /* Track number */
-   while (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) > 0)
-   {
-      /* Offset */
-      if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) <= 0)
-         goto error;
-
-      /* Mode */
-      if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) <= 0)
-         goto error;
-
-      mode = atoi(tmp_token);
-
-      /* Sector size */
-      if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) <= 0)
-         goto error;
-
-      size = atoi(tmp_token);
-
-      /* File name */
-      if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) <= 0)
-         goto error;
-
-      /* Check for data track */
-      if (!(mode == 0 && size == 2352))
-      {
-         char last_file[PATH_MAX_LENGTH];
-         char gdi_dir[PATH_MAX_LENGTH];
-
-         fill_pathname_basedir(gdi_dir, gdi_path, sizeof(gdi_dir));
-         fill_pathname_join_special(last_file,
-               gdi_dir, tmp_token, sizeof(last_file));
-
-         if ((file_size = intfstream_get_file_size(last_file)) < 0)
-            goto error;
-
-         if ((uint64_t)file_size > largest)
-         {
-            strlcpy(track_path, last_file, (size_t)max_len);
-
-            rv      = 0;
-            largest = file_size;
-
-            if (first)
-               goto clean;
-         }
-      }
-
-      /* Disc offset (not used?) */
-      if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) <= 0)
-         goto error;
-   }
-
-clean:
-   intfstream_close(fd);
-   free(fd);
-   return rv;
-
-error:
-   if (fd)
-   {
-      intfstream_close(fd);
-      free(fd);
-   }
-   return -1;
-}
-
-bool gdi_next_file(intfstream_t *fd, const char *gdi_path,
-      char *path, uint64_t max_len)
-{
-   char tmp_token[MAX_TOKEN_LEN];
-
-   tmp_token[0]    = '\0';
-
-   /* Skip initial track count */
-   if (intfstream_tell(fd) == 0)
-      task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
-
-   task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)); /* Track number */
-   task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)); /* Offset       */
-   task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)); /* Mode         */
-   task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)); /* Sector size  */
-
-   /* File name */
-   if (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) > 0)
-   {
-      char gdi_dir[PATH_MAX_LENGTH];
-
-      fill_pathname_basedir(gdi_dir, gdi_path, sizeof(gdi_dir));
-      fill_pathname_join_special(path, gdi_dir, tmp_token, (size_t)max_len);
-
-      /* Disc offset */
-      task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
-      return true;
-   }
-
-   return false;
-}

+ 0 - 59
app/src/main/cpp/tasks/task_database_cue.h

@@ -1,59 +0,0 @@
-/*  RetroArch - A frontend for libretro.
- *
- *  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 TASK_DATABASE_CUE
-#define TASK_DATABASE_CUE
-
-#include <ctype.h>
-#include <streams/interface_stream.h>
-
-RETRO_BEGIN_DECLS
-
-struct magic_entry
-{
-   const char *system_name;
-   const char *magic;
-   int32_t offset;
-};
-
-int detect_ps1_game(intfstream_t *fd, char *s, size_t len,
-      const char *filename);
-int detect_ps2_game(intfstream_t *fd, char *s, size_t len,
-      const char *filename);
-int detect_psp_game(intfstream_t *fd, char *s, size_t len,
-      const char *filename);
-int detect_gc_game(intfstream_t *fd, char *s, size_t len,
-      const char *filename);
-int detect_scd_game(intfstream_t *fd, char *s, size_t len,
-      const char *filename);
-int detect_sat_game(intfstream_t *fd,
-      char *s, size_t len, const char *filename);
-int detect_dc_game(intfstream_t *fd, char *s, size_t len,
-      const char *filename);
-int detect_wii_game(intfstream_t *fd, char *s, size_t len,
-      const char *filename);
-int detect_system(intfstream_t *fd, const char **system_name,
-      const char * filename);
-int cue_find_track(const char *cue_path, bool first, uint64_t *offset,
-      uint64_t *size, char *track_path, uint64_t max_len);
-bool cue_next_file(intfstream_t *fd, const char *cue_path,
-      char *s, uint64_t len);
-int gdi_find_track(const char *gdi_path, bool first, char *track_path,
-      uint64_t max_len);
-bool gdi_next_file(intfstream_t *fd, const char *gdi_path, char *path,
-      uint64_t max_len);
-
-RETRO_END_DECLS
-
-#endif
-