RetroArch/tasks/task_database.c

638 lines
17 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
2016-01-10 03:06:50 +00:00
* Copyright (C) 2011-2016 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
2015-06-02 14:49:35 +00:00
#include <compat/strcasestr.h>
#include <compat/strl.h>
#include <retro_miscellaneous.h>
#include <retro_endianness.h>
2015-12-26 06:23:13 +00:00
#include <string/stdstring.h>
#include <lists/dir_list.h>
2016-02-07 00:50:08 +00:00
#include <file/file_path.h>
2015-12-04 12:19:53 +00:00
#include <queues/message_queue.h>
#include "tasks_internal.h"
2015-07-08 20:03:23 +00:00
#ifdef HAVE_LIBRETRODB
#include "../database_info.h"
#endif
2016-03-20 16:28:24 +00:00
#include "../list_special.h"
2015-07-01 17:40:50 +00:00
#include "../msg_hash.h"
#include "../playlist.h"
2015-11-23 11:03:38 +00:00
#include "../verbosity.h"
2015-09-27 01:48:58 +00:00
#define CB_DB_SCAN_FILE 0x70ce56d2U
#define CB_DB_SCAN_FOLDER 0xde2bef8eU
2015-05-05 16:43:51 +00:00
2015-09-27 01:48:58 +00:00
#define HASH_EXTENSION_ZIP 0x0b88c7d8U
#define HASH_EXTENSION_CUE 0x0b886782U
2015-09-27 01:50:45 +00:00
#define HASH_EXTENSION_CUE_UPPERCASE 0x0b87db22U
2015-09-27 01:48:58 +00:00
#define HASH_EXTENSION_ISO 0x0b8880d0U
#define HASH_EXTENSION_ISO_UPPERCASE 0x0b87f470U
2015-06-14 15:11:48 +00:00
2015-07-25 22:40:24 +00:00
#ifndef COLLECTION_SIZE
2015-09-27 01:48:58 +00:00
#define COLLECTION_SIZE 99999
2015-07-25 22:40:24 +00:00
#endif
2015-07-08 20:03:23 +00:00
typedef struct database_state_handle
{
database_info_list_t *info;
struct string_list *list;
size_t list_index;
size_t entry_index;
uint32_t crc;
2016-04-14 22:28:44 +00:00
uint32_t zip_crc;
2015-07-08 20:03:23 +00:00
uint8_t *buf;
char zip_name[PATH_MAX_LENGTH];
2015-09-22 13:22:15 +00:00
char serial[4096];
2015-07-08 20:03:23 +00:00
} database_state_handle_t;
typedef struct db_handle
{
database_state_handle_t state;
database_info_handle_t *handle;
msg_queue_t *msg_queue;
unsigned status;
} db_handle_t;
#ifdef HAVE_LIBRETRODB
2015-05-05 16:43:51 +00:00
#ifdef HAVE_ZLIB
static int zlib_compare_crc32(const char *name, const char *valid_exts,
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
uint32_t crc32, void *userdata)
{
2015-05-24 06:06:29 +00:00
database_state_handle_t *db_state = (database_state_handle_t*)userdata;
db_state->crc = crc32;
2015-05-24 06:06:29 +00:00
strlcpy(db_state->zip_name, name, sizeof(db_state->zip_name));
#if 0
RARCH_LOG("Going to compare CRC 0x%x for %s\n", crc32, name);
#endif
2015-05-05 16:43:51 +00:00
return 1;
}
#endif
2015-05-23 19:56:17 +00:00
2016-05-13 08:19:53 +00:00
static int task_database_iterate_start(database_info_handle_t *db,
2015-12-06 14:55:05 +00:00
const char *name)
2015-05-23 19:56:17 +00:00
{
char msg[128] = {0};
2015-06-12 20:37:06 +00:00
#ifdef _WIN32
2015-11-19 12:43:48 +00:00
snprintf(msg, sizeof(msg),
2015-07-01 17:40:50 +00:00
"%Iu/%Iu: %s %s...\n",
2015-11-19 12:43:48 +00:00
db->list_ptr,
db->list->size,
msg_hash_to_str(MSG_SCANNING),
name);
2016-02-25 21:26:48 +00:00
#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
2015-11-19 12:43:48 +00:00
snprintf(msg, sizeof(msg),
2015-07-01 17:40:50 +00:00
"%zu/%zu: %s %s...\n",
db->list_ptr,
db->list->size,
msg_hash_to_str(MSG_SCANNING),
name);
2016-02-25 21:26:48 +00:00
#else
snprintf(msg, sizeof(msg),
"%lu/%lu: %s %s...\n",
(unsigned long)db->list_ptr,
(unsigned long)db->list->size,
msg_hash_to_str(MSG_SCANNING),
name);
2015-11-19 12:43:48 +00:00
#endif
2015-05-23 19:56:17 +00:00
2015-12-26 06:23:13 +00:00
if (!string_is_empty(msg))
2015-12-07 14:32:14 +00:00
runloop_msg_queue_push(msg, 1, 180, true);
2015-05-23 19:56:17 +00:00
#if 0
2015-05-23 19:56:17 +00:00
RARCH_LOG("msg: %s\n", msg);
#endif
2015-05-23 19:56:17 +00:00
2015-05-23 19:56:17 +00:00
db->status = DATABASE_STATUS_ITERATE;
return 0;
}
static int iso_get_serial(database_state_handle_t *db_state,
2015-09-22 13:22:15 +00:00
database_info_handle_t *db, const char *name, char* serial)
{
int rv;
int32_t offset = 0;
2015-09-22 13:22:15 +00:00
const char* system_name = NULL;
if ((rv = detect_system(name, offset, &system_name)) < 0)
2015-09-22 13:22:15 +00:00
return rv;
2016-01-20 03:07:24 +00:00
if (string_is_equal(system_name, "psp"))
{
if (detect_psp_game(name, serial) == 0)
return 0;
RARCH_LOG("Found disk label '%s'\n", serial);
}
2016-01-20 03:07:24 +00:00
else if (string_is_equal(system_name, "ps1"))
2015-09-22 13:22:15 +00:00
{
if (detect_ps1_game(name, serial) == 0)
2015-09-22 13:22:15 +00:00
return 0;
RARCH_LOG("Found disk label '%s'\n", serial);
}
return 0;
}
static int cue_get_serial(database_state_handle_t *db_state,
2015-09-26 22:12:17 +00:00
database_info_handle_t *db, const char *name, char* serial)
{
char track_path[PATH_MAX_LENGTH];
int32_t offset = 0;
int rv = find_first_data_track(name, &offset, track_path, PATH_MAX_LENGTH);
2015-09-28 01:31:09 +00:00
if (rv < 0)
{
RARCH_LOG("Could not find valid data track: %s\n", strerror(-rv));
return rv;
}
2015-09-26 22:12:17 +00:00
RARCH_LOG("Reading 1st data track...\n");
2015-09-26 22:12:17 +00:00
return iso_get_serial(db_state, db, track_path, serial);
2015-09-26 22:12:17 +00:00
}
2016-04-14 22:28:44 +00:00
static bool file_get_crc(database_state_handle_t *db_state,
const char *name, uint32_t *crc)
{
ssize_t ret;
int read_from = filestream_read_file(
name, (void**)&db_state->buf, &ret);
#ifdef HAVE_ZLIB
const struct file_archive_file_backend *stream_backend =
file_archive_get_default_file_backend();
#endif
if (read_from != 1 || ret <= 0)
return 0;
#ifdef HAVE_ZLIB
*crc = stream_backend->stream_crc_calculate(
0, db_state->buf, ret);
#endif
return 1;
}
2016-05-13 08:19:53 +00:00
static int task_database_iterate_playlist(
2015-05-23 19:56:17 +00:00
database_state_handle_t *db_state,
2015-05-05 16:43:51 +00:00
database_info_handle_t *db, const char *name)
{
2015-06-14 15:11:48 +00:00
uint32_t extension_hash = 0;
char parent_dir[PATH_MAX_LENGTH] = {0};
2015-05-05 16:43:51 +00:00
path_parent_dir(parent_dir);
2015-07-01 17:40:50 +00:00
extension_hash = msg_hash_calculate(path_get_extension(name));
2015-06-14 15:11:48 +00:00
switch (extension_hash)
2015-05-05 16:43:51 +00:00
{
2015-06-14 15:11:48 +00:00
case HASH_EXTENSION_ZIP:
2015-05-05 16:43:51 +00:00
#ifdef HAVE_ZLIB
2015-06-14 15:11:48 +00:00
db->type = DATABASE_TYPE_ITERATE_ZIP;
2016-01-24 21:17:11 +00:00
memset(&db->state, 0, sizeof(file_archive_transfer_t));
2015-06-14 15:11:48 +00:00
db_state->zip_name[0] = '\0';
db->state.type = ZLIB_TRANSFER_INIT;
2016-04-14 22:28:44 +00:00
return file_get_crc(db_state, name, &db_state->zip_crc);
2015-05-05 16:43:51 +00:00
#endif
2015-09-16 20:11:08 +00:00
case HASH_EXTENSION_CUE:
2015-09-27 01:50:45 +00:00
case HASH_EXTENSION_CUE_UPPERCASE:
db_state->serial[0] = '\0';
2015-09-22 13:22:15 +00:00
cue_get_serial(db_state, db, name, db_state->serial);
db->type = DATABASE_TYPE_SERIAL_LOOKUP;
2015-09-16 20:11:08 +00:00
return 1;
2015-09-26 22:12:17 +00:00
case HASH_EXTENSION_ISO:
2015-09-27 01:48:58 +00:00
case HASH_EXTENSION_ISO_UPPERCASE:
2015-09-26 22:12:17 +00:00
db_state->serial[0] = '\0';
iso_get_serial(db_state, db, name, db_state->serial);
db->type = DATABASE_TYPE_SERIAL_LOOKUP;
return 1;
2015-06-14 15:11:48 +00:00
default:
{
db->type = DATABASE_TYPE_CRC_LOOKUP;
2016-04-14 22:28:44 +00:00
return file_get_crc(db_state, name, &db_state->crc);
2015-06-14 15:11:48 +00:00
}
break;
2015-05-05 16:43:51 +00:00
}
2015-06-15 20:48:41 +00:00
return 1;
2015-05-23 18:53:43 +00:00
}
2016-02-04 09:25:22 +00:00
static int database_info_list_iterate_end_no_match(
database_state_handle_t *db_state)
{
2016-02-04 09:25:22 +00:00
/* Reached end of database list,
* CRC match probably didn't succeed. */
db_state->list_index = 0;
db_state->entry_index = 0;
if (db_state->crc != 0)
db_state->crc = 0;
2016-04-14 22:28:44 +00:00
return 0;
}
2016-05-13 08:19:53 +00:00
static int task_database_iterate_next(database_info_handle_t *db)
2015-05-23 18:53:43 +00:00
{
2015-05-05 16:43:51 +00:00
db->list_ptr++;
2015-05-23 17:18:56 +00:00
if (db->list_ptr < db->list->size)
return 0;
return -1;
2015-05-05 16:43:51 +00:00
}
2016-02-04 09:25:22 +00:00
static int database_info_list_iterate_new(database_state_handle_t *db_state,
const char *query)
2015-05-25 05:54:44 +00:00
{
const char *new_database = db_state->list->elems[db_state->list_index].data;
#if 0
2015-05-25 05:54:44 +00:00
RARCH_LOG("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);
db_state->info = database_info_list_new(new_database, query);
2015-05-25 05:54:44 +00:00
return 0;
}
static int database_info_list_iterate_found_match(
database_state_handle_t *db_state,
database_info_handle_t *db,
const char *zip_name
)
{
char db_crc[PATH_MAX_LENGTH] = {0};
char db_playlist_path[PATH_MAX_LENGTH] = {0};
char db_playlist_base_str[PATH_MAX_LENGTH] = {0};
char entry_path_str[PATH_MAX_LENGTH] = {0};
2016-05-16 07:07:44 +00:00
playlist_t *playlist = NULL;
2015-07-01 17:40:50 +00:00
settings_t *settings = config_get_ptr();
2016-02-04 09:25:22 +00:00
const char *db_path = db_state->list->elems[
db_state->list_index].data;
const char *entry_path = db ? db->list->elems[
db->list_ptr].data : NULL;
database_info_t *db_info_entry = &db_state->info->list[
db_state->entry_index];
2015-07-01 17:40:50 +00:00
fill_short_pathname_representation(db_playlist_base_str,
db_path, sizeof(db_playlist_base_str));
path_remove_extension(db_playlist_base_str);
strlcat(db_playlist_base_str, ".lpl", sizeof(db_playlist_base_str));
2016-04-28 17:26:02 +00:00
fill_pathname_join(db_playlist_path, settings->directory.playlist,
db_playlist_base_str, sizeof(db_playlist_path));
2016-05-16 07:07:44 +00:00
playlist = playlist_init(db_playlist_path, COLLECTION_SIZE);
2015-06-09 23:13:03 +00:00
snprintf(db_crc, sizeof(db_crc), "%08X|crc", db_info_entry->crc32);
2015-05-25 19:39:50 +00:00
strlcpy(entry_path_str, entry_path, sizeof(entry_path_str));
2015-12-26 06:23:13 +00:00
if (!string_is_empty(zip_name))
fill_pathname_join_delim(entry_path_str, entry_path_str, zip_name,
'#', sizeof(entry_path_str));
#if 0
RARCH_LOG("Found match in database !\n");
RARCH_LOG("Path: %s\n", db_path);
RARCH_LOG("CRC : %s\n", db_crc);
RARCH_LOG("Playlist Path: %s\n", db_playlist_path);
RARCH_LOG("Entry Path: %s\n", entry_path);
RARCH_LOG("Playlist not NULL: %d\n", playlist != NULL);
RARCH_LOG("ZIP entry: %s\n", zip_name);
RARCH_LOG("entry path str: %s\n", entry_path_str);
#endif
2016-05-16 07:07:44 +00:00
if(!playlist_entry_exists(playlist, entry_path_str, db_crc))
{
2016-05-16 07:07:44 +00:00
playlist_push(playlist, entry_path_str,
2016-02-04 09:25:22 +00:00
db_info_entry->name, "DETECT", "DETECT",
db_crc, db_playlist_base_str);
}
2016-05-16 07:07:44 +00:00
playlist_write_file(playlist);
playlist_free(playlist);
database_info_list_free(db_state->info);
2016-01-26 20:24:17 +00:00
db_state->info = NULL;
db_state->crc = 0;
2016-01-26 20:24:17 +00:00
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);
db_state->info = NULL;
return 1;
}
2016-05-13 08:19:53 +00:00
static int task_database_iterate_crc_lookup(
database_state_handle_t *db_state,
database_info_handle_t *db,
const char *zip_entry)
{
2016-02-04 09:25:22 +00:00
if (!db_state->list ||
(unsigned)db_state->list_index == (unsigned)db_state->list->size)
2015-05-25 05:54:44 +00:00
return database_info_list_iterate_end_no_match(db_state);
if (db_state->entry_index == 0)
{
2015-06-12 20:37:06 +00:00
char query[50] = {0};
2016-02-04 09:25:22 +00:00
snprintf(query, sizeof(query),
2016-04-14 22:28:44 +00:00
"{crc:or(b\"%08X\",b\"%08X\")}",
swap_if_big32(db_state->crc), swap_if_big32(db_state->zip_crc));
database_info_list_iterate_new(db_state, query);
}
if (db_state->info)
{
2016-02-04 09:25:22 +00:00
database_info_t *db_info_entry =
&db_state->info->list[db_state->entry_index];
2015-06-09 23:13:03 +00:00
if (db_info_entry && db_info_entry->crc32)
{
2015-05-25 05:54:44 +00:00
#if 0
2015-06-09 23:13:03 +00:00
RARCH_LOG("CRC32: 0x%08X , entry CRC32: 0x%08X (%s).\n",
2016-02-04 09:25:22 +00:00
db_state->crc, db_info_entry->crc32, db_info_entry->name);
2015-05-25 05:54:44 +00:00
#endif
2016-04-14 22:55:11 +00:00
if (db_state->zip_crc == db_info_entry->crc32)
return database_info_list_iterate_found_match(
db_state, db, NULL);
if (db_state->crc == db_info_entry->crc32)
2016-02-04 09:25:22 +00:00
return database_info_list_iterate_found_match(
db_state, db, zip_entry);
}
}
db_state->entry_index++;
if (db_state->entry_index >= db_state->info->count)
2015-05-25 05:54:44 +00:00
return database_info_list_iterate_next(db_state);
2016-05-17 12:24:43 +00:00
/* 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);
return 0;
}
2016-05-13 08:19:53 +00:00
static int task_database_iterate_playlist_zip(
database_state_handle_t *db_state,
database_info_handle_t *db, const char *name)
{
bool returnerr = true;
#ifdef HAVE_ZLIB
if (db_state->crc != 0)
2016-05-13 08:19:53 +00:00
return task_database_iterate_crc_lookup(
2016-02-04 09:25:22 +00:00
db_state, db, db_state->zip_name);
2016-02-03 16:31:19 +00:00
2016-02-04 09:25:22 +00:00
if (file_archive_parse_file_iterate(&db->state,
&returnerr, name, NULL, zlib_compare_crc32,
(void*)db_state) != 0)
return 0;
if (db_state->crc)
file_archive_parse_file_iterate_stop(&db->state);
#endif
return 1;
}
2016-05-13 08:19:53 +00:00
static int task_database_iterate_serial_lookup(
2015-09-16 20:11:08 +00:00
database_state_handle_t *db_state,
database_info_handle_t *db, const char *name)
{
2016-02-04 09:25:22 +00:00
if (!db_state->list ||
(unsigned)db_state->list_index == (unsigned)db_state->list->size)
2015-09-22 13:22:15 +00:00
return database_info_list_iterate_end_no_match(db_state);
2015-09-16 20:11:08 +00:00
2015-09-22 13:22:15 +00:00
if (db_state->entry_index == 0)
2015-09-16 20:11:08 +00:00
{
2015-09-28 15:18:48 +00:00
char query[50];
2016-02-04 09:25:22 +00:00
char *serial_buf =
bin_to_hex_alloc((uint8_t*)db_state->serial, 10 * sizeof(uint8_t));
2015-09-28 15:18:48 +00:00
if (!serial_buf)
return 1;
2015-09-22 13:22:15 +00:00
2015-09-28 15:18:48 +00:00
snprintf(query, sizeof(query), "{'serial': b'%s'}", serial_buf);
2015-09-22 13:22:15 +00:00
database_info_list_iterate_new(db_state, query);
2015-09-28 15:18:48 +00:00
free(serial_buf);
2015-09-16 20:11:08 +00:00
}
2015-09-22 13:22:15 +00:00
if (db_state->info)
{
2016-02-04 09:25:22 +00:00
database_info_t *db_info_entry = &db_state->info->list[
db_state->entry_index];
2015-09-16 20:11:08 +00:00
2015-09-22 13:22:15 +00:00
if (db_info_entry && db_info_entry->serial)
{
2015-09-24 12:14:42 +00:00
#if 0
2015-09-22 13:22:15 +00:00
RARCH_LOG("serial: %s , entry serial: %s (%s).\n",
2016-02-04 09:25:22 +00:00
db_state->serial, db_info_entry->serial,
db_info_entry->name);
2015-09-22 13:22:15 +00:00
#endif
2016-01-20 03:07:24 +00:00
if (string_is_equal(db_state->serial, db_info_entry->serial))
2015-11-16 23:49:51 +00:00
return database_info_list_iterate_found_match(db_state, db, NULL);
2015-09-22 13:22:15 +00:00
}
}
2015-09-16 20:11:08 +00:00
2015-09-22 13:22:15 +00:00
db_state->entry_index++;
2015-09-16 20:11:08 +00:00
2015-09-22 13:22:15 +00:00
if (db_state->entry_index >= db_state->info->count)
return database_info_list_iterate_next(db_state);
2016-05-17 12:24:43 +00:00
/* If we haven't reached the end of the database list yet,
* continue iterating. */
2015-09-22 13:22:15 +00:00
if (db_state->list_index < db_state->list->size)
return 1;
2015-09-16 20:11:08 +00:00
database_info_list_free(db_state->info);
2015-09-16 20:11:08 +00:00
return 0;
}
2016-05-13 08:19:53 +00:00
static int task_database_iterate(database_state_handle_t *db_state,
2016-02-04 09:25:22 +00:00
database_info_handle_t *db)
2015-05-05 16:43:51 +00:00
{
const char *name = db ? db->list->elems[db->list_ptr].data : NULL;
2015-05-05 16:43:51 +00:00
if (!db || !db->list)
return -1;
if (!name)
return 0;
switch (db->type)
{
2015-05-23 14:41:33 +00:00
case DATABASE_TYPE_ITERATE:
2016-05-13 08:19:53 +00:00
return task_database_iterate_playlist(db_state, db, name);
case DATABASE_TYPE_ITERATE_ZIP:
2016-05-13 08:19:53 +00:00
return task_database_iterate_playlist_zip(db_state, db, name);
2015-09-22 13:22:15 +00:00
case DATABASE_TYPE_SERIAL_LOOKUP:
2016-05-13 08:19:53 +00:00
return task_database_iterate_serial_lookup(db_state, db, name);
case DATABASE_TYPE_CRC_LOOKUP:
2016-05-13 08:19:53 +00:00
return task_database_iterate_crc_lookup(db_state, db, NULL);
2016-02-04 09:25:22 +00:00
case DATABASE_TYPE_NONE:
default:
break;
2015-05-05 16:43:51 +00:00
}
2016-02-04 09:25:22 +00:00
2015-05-05 16:43:51 +00:00
return 0;
}
2016-05-13 08:19:53 +00:00
static void task_database_cleanup_state(
2016-02-04 09:25:22 +00:00
database_state_handle_t *db_state)
{
if (!db_state)
return;
if (db_state->buf)
free(db_state->buf);
db_state->buf = NULL;
}
2016-05-13 08:19:53 +00:00
static void task_database_handler(retro_task_t *task)
{
2016-02-04 09:25:22 +00:00
db_handle_t *db = (db_handle_t*)task->state;
database_info_handle_t *dbinfo = db->handle;
database_state_handle_t *dbstate = &db->state;
2016-02-04 09:25:22 +00:00
const char *name = dbinfo ?
dbinfo->list->elems[dbinfo->list_ptr].data : NULL;
if (!dbinfo || task->cancelled)
goto task_finished;
switch (dbinfo->status)
{
2015-05-24 04:14:44 +00:00
case DATABASE_STATUS_ITERATE_BEGIN:
if (dbstate && !dbstate->list)
2016-02-04 09:25:22 +00:00
dbstate->list = dir_list_new_special(
NULL, DIR_LIST_DATABASES, NULL);
dbinfo->status = DATABASE_STATUS_ITERATE_START;
2015-05-24 04:14:44 +00:00
break;
2015-05-23 19:56:17 +00:00
case DATABASE_STATUS_ITERATE_START:
2016-05-13 08:19:53 +00:00
task_database_cleanup_state(dbstate);
dbstate->list_index = 0;
dbstate->entry_index = 0;
2016-05-13 08:19:53 +00:00
task_database_iterate_start(dbinfo, name);
2015-05-23 19:56:17 +00:00
break;
case DATABASE_STATUS_ITERATE:
2016-05-13 08:19:53 +00:00
if (task_database_iterate(&db->state, dbinfo) == 0)
{
dbinfo->status = DATABASE_STATUS_ITERATE_NEXT;
dbinfo->type = DATABASE_TYPE_ITERATE;
}
2015-05-23 18:53:43 +00:00
break;
case DATABASE_STATUS_ITERATE_NEXT:
2016-05-13 08:19:53 +00:00
if (task_database_iterate_next(dbinfo) == 0)
{
dbinfo->status = DATABASE_STATUS_ITERATE_START;
dbinfo->type = DATABASE_TYPE_ITERATE;
}
2015-05-23 18:53:43 +00:00
else
2015-05-23 17:18:56 +00:00
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_SCANNING_OF_DIRECTORY_FINISHED),
0, 180, true);
goto task_finished;
2015-05-23 17:18:56 +00:00
}
break;
2015-05-23 16:08:42 +00:00
default:
case DATABASE_STATUS_FREE:
2015-05-23 16:08:42 +00:00
case DATABASE_STATUS_NONE:
goto task_finished;
2015-05-23 17:18:56 +00:00
}
return;
task_finished:
task->finished = true;
2015-05-23 17:18:56 +00:00
2016-05-21 11:16:48 +00:00
if (dbstate->list)
dir_list_free(dbstate->list);
2015-07-08 19:48:58 +00:00
if (db->state.buf)
free(db->state.buf);
2015-09-28 21:00:22 +00:00
if (db->handle)
database_info_free(db->handle);
2015-07-08 19:48:58 +00:00
free(dbinfo);
free(db);
2015-07-08 19:48:58 +00:00
}
2015-07-08 20:03:23 +00:00
2016-02-04 09:25:22 +00:00
bool rarch_task_push_dbscan(const char *fullpath,
2016-02-09 16:47:04 +00:00
bool directory, retro_task_callback_t cb)
2015-07-08 20:03:23 +00:00
{
2016-02-09 16:47:04 +00:00
retro_task_t *t = (retro_task_t*)calloc(1, sizeof(*t));
db_handle_t *db = (db_handle_t*)calloc(1, sizeof(db_handle_t));
if (!t || !db)
goto error;
2016-05-13 08:19:53 +00:00
t->handler = task_database_handler;
t->state = db;
t->callback = cb;
if (directory)
db->handle = database_info_dir_init(fullpath, DATABASE_TYPE_ITERATE);
else
db->handle = database_info_file_init(fullpath, DATABASE_TYPE_ITERATE);
2015-07-08 20:03:23 +00:00
if (db->handle)
db->handle->status = DATABASE_STATUS_ITERATE_BEGIN;
2015-07-08 20:03:23 +00:00
2016-02-09 17:26:27 +00:00
task_queue_ctl(TASK_QUEUE_CTL_PUSH, t);
2015-07-08 20:03:23 +00:00
return true;
error:
if (t)
free(t);
if (db)
free(db);
return false;
2015-07-08 20:03:23 +00:00
}
#endif
2015-07-08 20:03:23 +00:00