2015-05-05 16:05:59 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 12:40:32 +00:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
|
|
|
* Copyright (C) 2014-2017 - Jean-André Santoni
|
|
|
|
* Copyright (C) 2016-2017 - Brad Parker
|
2015-05-05 16:05:59 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2015-05-24 05:36:30 +00:00
|
|
|
|
2015-06-02 14:49:35 +00:00
|
|
|
#include <compat/strcasestr.h>
|
2015-05-25 22:25:07 +00:00
|
|
|
#include <compat/strl.h>
|
2016-02-09 16:12:39 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
2015-09-14 01:33:50 +00:00
|
|
|
#include <retro_endianness.h>
|
2015-12-26 06:23:13 +00:00
|
|
|
#include <string/stdstring.h>
|
2016-03-20 13:53:54 +00:00
|
|
|
#include <lists/dir_list.h>
|
2016-02-07 00:50:08 +00:00
|
|
|
#include <file/file_path.h>
|
2016-09-20 17:34:56 +00:00
|
|
|
#include <encodings/crc32.h>
|
2016-09-29 08:37:31 +00:00
|
|
|
#include <streams/file_stream.h>
|
2017-09-17 05:31:58 +00:00
|
|
|
#include <streams/chd_stream.h>
|
|
|
|
#include <streams/interface_stream.h>
|
2016-02-09 16:12:39 +00:00
|
|
|
#include "tasks_internal.h"
|
2015-05-25 22:25:07 +00:00
|
|
|
|
2015-07-08 20:03:23 +00:00
|
|
|
#include "../database_info.h"
|
|
|
|
|
2016-06-26 08:12:28 +00:00
|
|
|
#include "../file_path_special.h"
|
2016-03-20 16:28:24 +00:00
|
|
|
#include "../list_special.h"
|
2015-07-01 17:40:50 +00:00
|
|
|
#include "../msg_hash.h"
|
2016-01-25 06:06:58 +00:00
|
|
|
#include "../playlist.h"
|
2017-05-11 07:11:46 +00:00
|
|
|
#include "../retroarch.h"
|
2015-11-23 11:03:38 +00:00
|
|
|
#include "../verbosity.h"
|
2016-10-03 20:08:55 +00:00
|
|
|
#include "../core_info.h"
|
2015-05-05 16:05:59 +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
|
|
|
|
|
2016-12-20 20:08:31 +00:00
|
|
|
typedef struct database_state_handle
|
|
|
|
{
|
|
|
|
uint32_t crc;
|
|
|
|
uint32_t archive_crc;
|
2017-09-29 18:51:20 +00:00
|
|
|
size_t list_index;
|
|
|
|
size_t entry_index;
|
2016-12-20 20:08:31 +00:00
|
|
|
uint8_t *buf;
|
2017-02-27 08:28:24 +00:00
|
|
|
char archive_name[511];
|
2016-12-20 20:08:31 +00:00
|
|
|
char serial[4096];
|
2017-09-29 18:51:20 +00:00
|
|
|
database_info_list_t *info;
|
|
|
|
struct string_list *list;
|
2016-12-20 20:08:31 +00:00
|
|
|
} database_state_handle_t;
|
|
|
|
|
2015-07-08 20:03:23 +00:00
|
|
|
typedef struct db_handle
|
|
|
|
{
|
2017-07-09 04:44:02 +00:00
|
|
|
bool is_directory;
|
|
|
|
bool scan_started;
|
2017-09-29 18:47:54 +00:00
|
|
|
unsigned status;
|
|
|
|
char *playlist_directory;
|
|
|
|
char *content_database_path;
|
|
|
|
char *fullpath;
|
|
|
|
database_info_handle_t *handle;
|
|
|
|
database_state_handle_t state;
|
2015-07-08 20:03:23 +00:00
|
|
|
} db_handle_t;
|
|
|
|
|
2017-09-29 18:51:20 +00:00
|
|
|
int cue_find_track(const char *cue_path, bool first,
|
|
|
|
size_t *offset, size_t *size,
|
|
|
|
char *track_path, size_t max_len);
|
2017-05-13 16:08:37 +00:00
|
|
|
|
2017-09-29 18:51:20 +00:00
|
|
|
bool cue_next_file(intfstream_t *fd, const char *cue_path,
|
|
|
|
char *path, size_t max_len);
|
2017-09-18 02:18:50 +00:00
|
|
|
|
2017-09-29 18:51:20 +00:00
|
|
|
int gdi_find_track(const char *gdi_path, bool first,
|
|
|
|
char *track_path, size_t max_len);
|
2017-09-18 00:39:41 +00:00
|
|
|
|
2017-09-29 18:51:20 +00:00
|
|
|
bool gdi_next_file(intfstream_t *fd, const char *gdi_path,
|
|
|
|
char *path, size_t max_len);
|
2017-05-13 16:08:37 +00:00
|
|
|
|
2017-09-17 05:31:58 +00:00
|
|
|
int detect_system(intfstream_t *fd, const char** system_name);
|
2017-05-13 16:08:37 +00:00
|
|
|
|
2017-09-17 05:31:58 +00:00
|
|
|
int detect_ps1_game(intfstream_t *fd, char *game_id);
|
2017-05-13 16:08:37 +00:00
|
|
|
|
2017-09-17 05:31:58 +00:00
|
|
|
int detect_psp_game(intfstream_t *fd, char *game_id);
|
2017-05-13 16:08:37 +00:00
|
|
|
|
2017-10-27 07:58:19 +00:00
|
|
|
int detect_gc_game(intfstream_t *fd, char *game_id);
|
|
|
|
|
2017-09-17 05:31:58 +00:00
|
|
|
int detect_serial_ascii_game(intfstream_t *fd, char *game_id);
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
static intfstream_t* intfstream_open_file(const char *path)
|
2017-09-17 05:31:58 +00:00
|
|
|
{
|
|
|
|
intfstream_info_t info;
|
|
|
|
intfstream_t *fd = NULL;
|
|
|
|
|
2017-09-18 13:57:05 +00:00
|
|
|
info.type = INTFSTREAM_FILE;
|
2017-09-19 19:29:28 +00:00
|
|
|
fd = (intfstream_t*)intfstream_init(&info);
|
2017-09-17 05:31:58 +00:00
|
|
|
|
|
|
|
if (!fd)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!intfstream_open(fd, path, RFILE_MODE_READ, -1))
|
2017-09-21 21:38:29 +00:00
|
|
|
goto error;
|
2017-09-17 05:31:58 +00:00
|
|
|
|
|
|
|
return fd;
|
2017-09-21 21:38:29 +00:00
|
|
|
|
|
|
|
error:
|
2017-09-29 19:32:05 +00:00
|
|
|
if (fd)
|
|
|
|
{
|
|
|
|
intfstream_close(fd);
|
|
|
|
free(fd);
|
|
|
|
}
|
2017-09-21 21:38:29 +00:00
|
|
|
return NULL;
|
2017-09-17 05:31:58 +00:00
|
|
|
}
|
|
|
|
|
2017-09-19 19:29:28 +00:00
|
|
|
static intfstream_t *open_memory(void *data, size_t size)
|
2017-09-17 21:26:06 +00:00
|
|
|
{
|
|
|
|
intfstream_info_t info;
|
2017-09-19 19:29:28 +00:00
|
|
|
intfstream_t *fd = NULL;
|
2017-09-17 21:26:06 +00:00
|
|
|
|
2017-09-19 19:29:28 +00:00
|
|
|
info.type = INTFSTREAM_MEMORY;
|
|
|
|
info.memory.buf.data = (uint8_t*)data;
|
2017-09-17 21:26:06 +00:00
|
|
|
info.memory.buf.size = size;
|
|
|
|
info.memory.writable = false;
|
|
|
|
|
2017-09-19 19:29:28 +00:00
|
|
|
fd = (intfstream_t*)intfstream_init(&info);
|
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
if (!fd)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!intfstream_open(fd, NULL, RFILE_MODE_READ, -1))
|
2017-09-21 21:38:29 +00:00
|
|
|
goto error;
|
2017-09-17 21:26:06 +00:00
|
|
|
|
|
|
|
return fd;
|
2017-09-21 21:38:29 +00:00
|
|
|
|
|
|
|
error:
|
2017-09-29 19:32:05 +00:00
|
|
|
if (fd)
|
|
|
|
{
|
|
|
|
intfstream_close(fd);
|
|
|
|
free(fd);
|
|
|
|
}
|
2017-09-21 21:38:29 +00:00
|
|
|
return NULL;
|
2017-09-17 21:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static intfstream_t*
|
|
|
|
open_chd_track(const char *path, int32_t track)
|
2017-09-17 05:31:58 +00:00
|
|
|
{
|
|
|
|
intfstream_info_t info;
|
|
|
|
intfstream_t *fd = NULL;
|
|
|
|
|
2017-09-18 13:57:05 +00:00
|
|
|
info.type = INTFSTREAM_CHD;
|
|
|
|
info.chd.track = track;
|
|
|
|
|
2017-09-19 19:29:28 +00:00
|
|
|
fd = (intfstream_t*)intfstream_init(&info);
|
2017-09-17 05:31:58 +00:00
|
|
|
|
|
|
|
if (!fd)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!intfstream_open(fd, path, RFILE_MODE_READ, -1))
|
2017-09-21 21:38:29 +00:00
|
|
|
goto error;
|
2017-09-17 05:31:58 +00:00
|
|
|
|
|
|
|
return fd;
|
2017-09-21 21:38:29 +00:00
|
|
|
|
|
|
|
error:
|
2017-09-29 19:32:05 +00:00
|
|
|
if (fd)
|
|
|
|
{
|
|
|
|
intfstream_close(fd);
|
|
|
|
free(fd);
|
|
|
|
}
|
2017-09-21 21:38:29 +00:00
|
|
|
return NULL;
|
2017-09-17 05:31:58 +00:00
|
|
|
}
|
2017-07-30 03:23:05 +00:00
|
|
|
|
2017-09-18 13:57:05 +00:00
|
|
|
static void database_info_set_type(
|
|
|
|
database_info_handle_t *handle,
|
|
|
|
enum database_type type)
|
2016-12-20 20:08:31 +00:00
|
|
|
{
|
|
|
|
if (!handle)
|
|
|
|
return;
|
|
|
|
handle->type = type;
|
|
|
|
}
|
|
|
|
|
2017-09-18 13:57:05 +00:00
|
|
|
static enum database_type database_info_get_type(
|
|
|
|
database_info_handle_t *handle)
|
2016-12-20 20:08:31 +00:00
|
|
|
{
|
|
|
|
if (!handle)
|
|
|
|
return DATABASE_TYPE_NONE;
|
|
|
|
return handle->type;
|
|
|
|
}
|
|
|
|
|
2017-09-18 13:57:05 +00:00
|
|
|
static const char *database_info_get_current_name(
|
|
|
|
database_state_handle_t *handle)
|
2016-12-20 20:08:31 +00:00
|
|
|
{
|
|
|
|
if (!handle || !handle->list)
|
|
|
|
return NULL;
|
|
|
|
return handle->list->elems[handle->list_index].data;
|
|
|
|
}
|
|
|
|
|
2017-09-18 13:57:05 +00:00
|
|
|
static const char *database_info_get_current_element_name(
|
|
|
|
database_info_handle_t *handle)
|
2016-12-20 20:08:31 +00:00
|
|
|
{
|
|
|
|
if (!handle || !handle->list)
|
|
|
|
return NULL;
|
2017-09-18 02:18:50 +00:00
|
|
|
/* Skip pruned entries */
|
|
|
|
while (handle->list->elems[handle->list_ptr].data == NULL)
|
|
|
|
{
|
|
|
|
if (++handle->list_ptr >= handle->list->size)
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-12-20 20:08:31 +00:00
|
|
|
return handle->list->elems[handle->list_ptr].data;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-02-27 08:28:24 +00:00
|
|
|
char msg[511];
|
2016-10-09 07:56:03 +00:00
|
|
|
|
2017-02-27 08:28:24 +00:00
|
|
|
msg[0] = msg[510] = '\0';
|
2015-06-12 20:37:06 +00:00
|
|
|
|
2015-11-19 12:43:48 +00:00
|
|
|
snprintf(msg, sizeof(msg),
|
2017-10-02 20:49:50 +00:00
|
|
|
STRING_REP_USIZE "/" STRING_REP_USIZE ": %s %s...\n",
|
|
|
|
(size_t)db->list_ptr,
|
|
|
|
(size_t)db->list->size,
|
2016-02-25 21:26:48 +00:00
|
|
|
msg_hash_to_str(MSG_SCANNING),
|
|
|
|
name);
|
2015-05-23 19:56:17 +00:00
|
|
|
|
2015-12-26 06:23:13 +00:00
|
|
|
if (!string_is_empty(msg))
|
2016-12-22 22:36:11 +00:00
|
|
|
runloop_msg_queue_push(msg, 1, 180, true);
|
2015-05-23 19:56:17 +00:00
|
|
|
|
2015-06-09 19:10:57 +00:00
|
|
|
#if 0
|
2015-05-23 19:56:17 +00:00
|
|
|
RARCH_LOG("msg: %s\n", msg);
|
2015-06-09 19:10:57 +00:00
|
|
|
#endif
|
2015-05-23 19:56:17 +00:00
|
|
|
|
2015-07-07 23:01:41 +00:00
|
|
|
|
2015-05-23 19:56:17 +00:00
|
|
|
db->status = DATABASE_STATUS_ITERATE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
static int intfstream_get_serial(intfstream_t *fd, char *serial)
|
2015-09-22 13:22:15 +00:00
|
|
|
{
|
2017-09-17 21:26:06 +00:00
|
|
|
const char *system_name = NULL;
|
|
|
|
|
|
|
|
/* Check if the system was not auto-detected. */
|
|
|
|
if (detect_system(fd, &system_name) < 0)
|
|
|
|
{
|
|
|
|
/* Attempt to read an ASCII serial, like Wii. */
|
|
|
|
if (detect_serial_ascii_game(fd, serial))
|
|
|
|
{
|
|
|
|
/* ASCII serial (Wii) was detected. */
|
|
|
|
RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-09-22 13:22:15 +00:00
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
/* Any other non-system specific detection methods? */
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-30 03:23:05 +00:00
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
if (string_is_equal_fast(system_name, "psp", 3))
|
|
|
|
{
|
|
|
|
if (detect_psp_game(fd, serial) == 0)
|
2017-07-30 03:23:05 +00:00
|
|
|
return 0;
|
2017-09-17 21:26:06 +00:00
|
|
|
RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial);
|
|
|
|
}
|
|
|
|
else if (string_is_equal_fast(system_name, "ps1", 3))
|
|
|
|
{
|
|
|
|
if (detect_ps1_game(fd, serial) == 0)
|
2017-09-17 05:31:58 +00:00
|
|
|
return 0;
|
2017-09-17 21:26:06 +00:00
|
|
|
RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial);
|
|
|
|
}
|
2017-10-27 07:58:19 +00:00
|
|
|
else if (string_is_equal_fast(system_name, "gc", 2))
|
|
|
|
{
|
|
|
|
if (detect_gc_game(fd, serial) == 0)
|
|
|
|
return 0;
|
|
|
|
RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial);
|
|
|
|
}
|
2017-09-17 21:26:06 +00:00
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-09-22 13:22:15 +00:00
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
return 1;
|
2017-09-17 05:31:58 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 18:51:20 +00:00
|
|
|
static bool intfstream_file_get_serial(const char *name,
|
|
|
|
size_t offset, size_t size, char *serial)
|
2017-09-17 05:31:58 +00:00
|
|
|
{
|
|
|
|
int rv;
|
2017-09-20 10:18:31 +00:00
|
|
|
uint8_t *data = NULL;
|
2017-09-17 21:26:06 +00:00
|
|
|
ssize_t file_size = -1;
|
2017-09-21 17:57:10 +00:00
|
|
|
intfstream_t *fd = intfstream_open_file(name);
|
2017-09-17 05:31:58 +00:00
|
|
|
|
|
|
|
if (!fd)
|
|
|
|
return 0;
|
|
|
|
|
2017-09-26 01:51:50 +00:00
|
|
|
if (intfstream_seek(fd, 0, SEEK_END) == -1)
|
|
|
|
goto error;
|
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
file_size = intfstream_tell(fd);
|
2017-09-26 01:51:50 +00:00
|
|
|
|
|
|
|
if (intfstream_seek(fd, 0, SEEK_SET) == -1)
|
|
|
|
goto error;
|
2017-09-20 10:18:31 +00:00
|
|
|
|
|
|
|
if (file_size < 0)
|
2017-09-21 21:38:29 +00:00
|
|
|
goto error;
|
2017-09-17 21:26:06 +00:00
|
|
|
|
|
|
|
if (offset != 0 || size < (size_t) file_size)
|
|
|
|
{
|
2017-09-26 01:51:50 +00:00
|
|
|
if (intfstream_seek(fd, offset, SEEK_SET) == -1)
|
|
|
|
goto error;
|
|
|
|
|
2017-09-19 19:29:28 +00:00
|
|
|
data = (uint8_t*)malloc(size);
|
2017-09-26 01:51:50 +00:00
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
if (intfstream_read(fd, data, size) != (ssize_t) size)
|
|
|
|
{
|
|
|
|
free(data);
|
2017-09-21 21:38:29 +00:00
|
|
|
goto error;
|
2017-09-17 21:26:06 +00:00
|
|
|
}
|
2017-09-20 10:18:31 +00:00
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
intfstream_close(fd);
|
2017-09-21 19:33:13 +00:00
|
|
|
free(fd);
|
2017-09-17 21:26:06 +00:00
|
|
|
fd = open_memory(data, size);
|
2017-09-20 10:18:31 +00:00
|
|
|
if (!fd)
|
|
|
|
{
|
2017-09-17 21:26:06 +00:00
|
|
|
free(data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
rv = intfstream_get_serial(fd, serial);
|
2017-09-17 05:31:58 +00:00
|
|
|
intfstream_close(fd);
|
2017-09-17 21:26:06 +00:00
|
|
|
free(data);
|
2017-09-20 10:18:31 +00:00
|
|
|
free(fd);
|
2017-09-17 05:31:58 +00:00
|
|
|
return rv;
|
2017-09-21 21:38:29 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
intfstream_close(fd);
|
|
|
|
free(fd);
|
|
|
|
return 0;
|
2015-09-22 13:22:15 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
static int task_database_cue_get_serial(const char *name, char* serial)
|
2015-09-26 22:12:17 +00:00
|
|
|
{
|
2017-09-12 03:26:38 +00:00
|
|
|
char *track_path = (char*)malloc(PATH_MAX_LENGTH
|
|
|
|
* sizeof(char));
|
2017-09-12 03:00:22 +00:00
|
|
|
int ret = 0;
|
2017-09-17 21:26:06 +00:00
|
|
|
size_t offset = 0;
|
|
|
|
size_t size = 0;
|
2016-10-09 07:56:03 +00:00
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
track_path[0] = '\0';
|
2016-10-12 20:14:00 +00:00
|
|
|
|
2017-09-18 00:39:41 +00:00
|
|
|
rv = cue_find_track(name, true, &offset, &size, track_path, PATH_MAX_LENGTH);
|
2016-09-18 04:38:59 +00:00
|
|
|
|
2015-09-27 00:14:24 +00:00
|
|
|
if (rv < 0)
|
|
|
|
{
|
2016-06-30 03:58:05 +00:00
|
|
|
RARCH_LOG("%s: %s\n",
|
|
|
|
msg_hash_to_str(MSG_COULD_NOT_FIND_VALID_DATA_TRACK),
|
|
|
|
strerror(-rv));
|
2017-09-12 03:26:38 +00:00
|
|
|
free(track_path);
|
2017-09-17 05:31:58 +00:00
|
|
|
return 0;
|
2015-09-27 00:14:24 +00:00
|
|
|
}
|
2015-09-26 22:12:17 +00:00
|
|
|
|
2016-06-30 03:58:05 +00:00
|
|
|
RARCH_LOG("%s\n", msg_hash_to_str(MSG_READING_FIRST_DATA_TRACK));
|
2015-09-26 22:12:17 +00:00
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
ret = intfstream_file_get_serial(track_path, offset, size, serial);
|
2017-09-12 03:00:22 +00:00
|
|
|
free(track_path);
|
|
|
|
|
|
|
|
return ret;
|
2015-09-26 22:12:17 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
static int task_database_gdi_get_serial(const char *name, char* serial)
|
2017-09-18 00:39:41 +00:00
|
|
|
{
|
|
|
|
char *track_path = (char*)malloc(PATH_MAX_LENGTH
|
|
|
|
* sizeof(char));
|
|
|
|
int ret = 0;
|
2016-10-09 07:56:03 +00:00
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
track_path[0] = '\0';
|
2016-10-12 20:14:00 +00:00
|
|
|
|
2017-09-18 00:39:41 +00:00
|
|
|
rv = gdi_find_track(name, true, track_path, PATH_MAX_LENGTH);
|
2016-09-18 04:38:59 +00:00
|
|
|
|
2015-09-27 00:14:24 +00:00
|
|
|
if (rv < 0)
|
|
|
|
{
|
2016-06-30 03:58:05 +00:00
|
|
|
RARCH_LOG("%s: %s\n",
|
|
|
|
msg_hash_to_str(MSG_COULD_NOT_FIND_VALID_DATA_TRACK),
|
|
|
|
strerror(-rv));
|
2017-09-12 03:26:38 +00:00
|
|
|
free(track_path);
|
2017-09-17 05:31:58 +00:00
|
|
|
return 0;
|
2015-09-27 00:14:24 +00:00
|
|
|
}
|
2015-09-26 22:12:17 +00:00
|
|
|
|
2016-06-30 03:58:05 +00:00
|
|
|
RARCH_LOG("%s\n", msg_hash_to_str(MSG_READING_FIRST_DATA_TRACK));
|
2015-09-26 22:12:17 +00:00
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
ret = intfstream_file_get_serial(track_path, 0, SIZE_MAX, serial);
|
2017-09-12 03:00:22 +00:00
|
|
|
free(track_path);
|
|
|
|
|
|
|
|
return ret;
|
2015-09-26 22:12:17 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
static int task_database_chd_get_serial(const char *name, char* serial)
|
2017-09-17 05:31:58 +00:00
|
|
|
{
|
|
|
|
int result;
|
2017-09-21 17:57:10 +00:00
|
|
|
intfstream_t *fd = open_chd_track(name, CHDSTREAM_TRACK_FIRST_DATA);
|
2017-09-17 05:31:58 +00:00
|
|
|
if (!fd)
|
|
|
|
return 0;
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
result = intfstream_get_serial(fd, serial);
|
2017-09-17 05:31:58 +00:00
|
|
|
intfstream_close(fd);
|
2017-09-21 19:33:13 +00:00
|
|
|
free(fd);
|
2017-09-17 05:31:58 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
static int intfstream_get_crc(intfstream_t *fd, uint32_t *crc)
|
2016-04-14 22:28:44 +00:00
|
|
|
{
|
2017-09-21 17:24:42 +00:00
|
|
|
ssize_t read = 0;
|
2017-09-17 21:26:06 +00:00
|
|
|
uint32_t acc = 0;
|
|
|
|
uint8_t buffer[4096];
|
2016-04-14 22:28:44 +00:00
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
while ((read = intfstream_read(fd, buffer, sizeof(buffer))) > 0)
|
|
|
|
acc = encoding_crc32(acc, buffer, read);
|
2016-04-14 22:28:44 +00:00
|
|
|
|
2017-09-19 23:49:45 +00:00
|
|
|
if (read < 0)
|
2016-04-14 22:28:44 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
*crc = acc;
|
2016-04-14 22:28:44 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
static bool intfstream_file_get_crc(const char *name,
|
|
|
|
size_t offset, size_t size, uint32_t *crc)
|
2017-09-17 05:31:58 +00:00
|
|
|
{
|
2017-09-17 21:26:06 +00:00
|
|
|
int rv;
|
2017-09-21 17:57:10 +00:00
|
|
|
intfstream_t *fd = intfstream_open_file(name);
|
2017-09-19 19:29:28 +00:00
|
|
|
uint8_t *data = NULL;
|
2017-09-17 21:26:06 +00:00
|
|
|
ssize_t file_size = -1;
|
2017-09-17 05:31:58 +00:00
|
|
|
|
|
|
|
if (!fd)
|
|
|
|
return 0;
|
|
|
|
|
2017-09-26 01:51:50 +00:00
|
|
|
if (intfstream_seek(fd, 0, SEEK_END) == -1)
|
|
|
|
goto error;
|
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
file_size = intfstream_tell(fd);
|
2017-09-26 01:51:50 +00:00
|
|
|
|
|
|
|
if (intfstream_seek(fd, 0, SEEK_SET) == -1)
|
|
|
|
goto error;
|
2017-09-19 19:29:28 +00:00
|
|
|
|
|
|
|
if (file_size < 0)
|
2017-09-26 01:51:50 +00:00
|
|
|
goto error;
|
2017-09-17 21:26:06 +00:00
|
|
|
|
2017-09-19 19:29:28 +00:00
|
|
|
if (offset != 0 || size < (size_t) file_size)
|
|
|
|
{
|
2017-09-26 01:51:50 +00:00
|
|
|
if (intfstream_seek(fd, offset, SEEK_SET) == -1)
|
|
|
|
goto error;
|
|
|
|
|
2017-09-19 19:29:28 +00:00
|
|
|
data = (uint8_t*)malloc(size);
|
|
|
|
|
|
|
|
if (intfstream_read(fd, data, size) != (ssize_t) size)
|
2017-09-26 01:51:50 +00:00
|
|
|
goto error;
|
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
intfstream_close(fd);
|
2017-09-21 19:33:13 +00:00
|
|
|
free(fd);
|
2017-09-17 21:26:06 +00:00
|
|
|
fd = open_memory(data, size);
|
2017-09-19 19:29:28 +00:00
|
|
|
|
|
|
|
if (!fd)
|
2017-09-26 01:51:50 +00:00
|
|
|
goto error;
|
2017-09-17 21:26:06 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
rv = intfstream_get_crc(fd, crc);
|
2017-09-17 21:26:06 +00:00
|
|
|
intfstream_close(fd);
|
2017-09-20 10:18:31 +00:00
|
|
|
free(fd);
|
2017-09-17 21:26:06 +00:00
|
|
|
free(data);
|
|
|
|
return rv;
|
2017-09-26 01:51:50 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (fd)
|
|
|
|
{
|
|
|
|
intfstream_close(fd);
|
|
|
|
free(fd);
|
|
|
|
}
|
|
|
|
if (data)
|
|
|
|
free(data);
|
|
|
|
return 0;
|
2017-09-17 21:26:06 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
static int task_database_cue_get_crc(const char *name, uint32_t *crc)
|
2017-09-17 21:26:06 +00:00
|
|
|
{
|
|
|
|
char *track_path = (char *)malloc(PATH_MAX_LENGTH);
|
2017-09-19 19:37:51 +00:00
|
|
|
size_t offset = 0;
|
|
|
|
size_t size = 0;
|
|
|
|
int rv = 0;
|
2017-09-17 21:26:06 +00:00
|
|
|
|
2017-09-19 19:37:51 +00:00
|
|
|
track_path[0] = '\0';
|
2017-09-17 21:26:06 +00:00
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
rv = cue_find_track(name, false, &offset, &size,
|
|
|
|
track_path, PATH_MAX_LENGTH);
|
2017-09-17 21:26:06 +00:00
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
if (rv < 0)
|
|
|
|
{
|
|
|
|
RARCH_LOG("%s: %s\n",
|
|
|
|
msg_hash_to_str(MSG_COULD_NOT_FIND_VALID_DATA_TRACK),
|
|
|
|
strerror(-rv));
|
2017-09-17 21:26:06 +00:00
|
|
|
free(track_path);
|
2017-09-17 05:31:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
RARCH_LOG("CUE '%s' primary track: %s\n (%Zu, %Zu)", name, track_path, offset, size);
|
2017-09-17 05:31:58 +00:00
|
|
|
|
2017-09-17 21:26:06 +00:00
|
|
|
RARCH_LOG("%s\n", msg_hash_to_str(MSG_READING_FIRST_DATA_TRACK));
|
2017-09-17 05:31:58 +00:00
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
rv = intfstream_file_get_crc(track_path, offset, size, crc);
|
2017-09-19 19:37:51 +00:00
|
|
|
if (rv == 1)
|
|
|
|
{
|
2017-09-17 21:26:06 +00:00
|
|
|
RARCH_LOG("CUE '%s' crc: %x\n", name, *crc);
|
|
|
|
}
|
|
|
|
free(track_path);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
static int task_database_gdi_get_crc(const char *name, uint32_t *crc)
|
2017-09-18 00:39:41 +00:00
|
|
|
{
|
|
|
|
char *track_path = (char *)malloc(PATH_MAX_LENGTH);
|
2017-09-19 19:37:51 +00:00
|
|
|
int rv = 0;
|
2017-09-18 00:39:41 +00:00
|
|
|
|
|
|
|
track_path[0] = '\0';
|
|
|
|
|
|
|
|
rv = gdi_find_track(name, false, track_path, PATH_MAX_LENGTH);
|
|
|
|
|
2017-09-19 19:37:51 +00:00
|
|
|
if (rv < 0)
|
|
|
|
{
|
2017-09-18 00:39:41 +00:00
|
|
|
RARCH_LOG("%s: %s\n", msg_hash_to_str(MSG_COULD_NOT_FIND_VALID_DATA_TRACK),
|
|
|
|
strerror(-rv));
|
|
|
|
free(track_path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RARCH_LOG("GDI '%s' primary track: %s\n", name, track_path);
|
|
|
|
|
|
|
|
RARCH_LOG("%s\n", msg_hash_to_str(MSG_READING_FIRST_DATA_TRACK));
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
rv = intfstream_file_get_crc(track_path, 0, SIZE_MAX, crc);
|
2017-09-19 19:37:51 +00:00
|
|
|
if (rv == 1)
|
|
|
|
{
|
2017-09-18 00:39:41 +00:00
|
|
|
RARCH_LOG("GDI '%s' crc: %x\n", name, *crc);
|
|
|
|
}
|
|
|
|
free(track_path);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
static bool task_database_chd_get_crc(const char *name, uint32_t *crc)
|
2017-09-17 05:31:58 +00:00
|
|
|
{
|
2017-09-17 21:26:06 +00:00
|
|
|
int rv;
|
2017-09-19 19:29:28 +00:00
|
|
|
intfstream_t *fd = open_chd_track(name, CHDSTREAM_TRACK_PRIMARY);
|
2017-09-17 05:31:58 +00:00
|
|
|
if (!fd)
|
|
|
|
return 0;
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
rv = intfstream_get_crc(fd, crc);
|
2017-09-19 19:29:28 +00:00
|
|
|
if (rv == 1)
|
|
|
|
{
|
2017-09-17 21:26:06 +00:00
|
|
|
RARCH_LOG("CHD '%s' crc: %x\n", name, *crc);
|
|
|
|
}
|
2017-09-29 19:32:05 +00:00
|
|
|
if (fd)
|
|
|
|
{
|
|
|
|
intfstream_close(fd);
|
|
|
|
free(fd);
|
|
|
|
}
|
2017-09-17 21:26:06 +00:00
|
|
|
return rv;
|
2017-09-17 05:31:58 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 17:57:10 +00:00
|
|
|
static void task_database_cue_prune(database_info_handle_t *db,
|
|
|
|
const char *name)
|
2017-09-18 02:18:50 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
2017-09-21 17:57:10 +00:00
|
|
|
char *path = (char *)malloc(PATH_MAX_LENGTH + 1);
|
|
|
|
intfstream_t *fd = intfstream_open_file(name);
|
2017-09-18 02:18:50 +00:00
|
|
|
|
|
|
|
if (!fd)
|
2017-09-20 10:13:44 +00:00
|
|
|
goto end;
|
2017-09-18 02:18:50 +00:00
|
|
|
|
|
|
|
while (cue_next_file(fd, name, path, PATH_MAX_LENGTH))
|
2017-09-17 05:31:58 +00:00
|
|
|
{
|
2017-09-18 02:18:50 +00:00
|
|
|
for (i = db->list_ptr; i < db->list->size; ++i)
|
|
|
|
{
|
2017-09-20 10:13:44 +00:00
|
|
|
if (db->list->elems[i].data
|
|
|
|
&& !strcmp(path, db->list->elems[i].data))
|
2017-09-18 02:18:50 +00:00
|
|
|
{
|
|
|
|
RARCH_LOG("Pruning file referenced by cue: %s\n", path);
|
|
|
|
free(db->list->elems[i].data);
|
|
|
|
db->list->elems[i].data = NULL;
|
|
|
|
}
|
|
|
|
}
|
2017-09-17 05:31:58 +00:00
|
|
|
}
|
2017-09-20 10:13:44 +00:00
|
|
|
|
|
|
|
end:
|
2017-09-21 19:33:13 +00:00
|
|
|
if (fd)
|
2017-09-29 19:32:05 +00:00
|
|
|
{
|
|
|
|
intfstream_close(fd);
|
2017-09-21 19:33:13 +00:00
|
|
|
free(fd);
|
2017-09-29 19:32:05 +00:00
|
|
|
}
|
2017-09-20 10:13:44 +00:00
|
|
|
free(path);
|
2017-09-18 02:18:50 +00:00
|
|
|
}
|
2017-09-17 05:31:58 +00:00
|
|
|
|
2017-09-18 02:18:50 +00:00
|
|
|
static void gdi_prune(database_info_handle_t *db, const char *name)
|
|
|
|
{
|
|
|
|
size_t i;
|
2017-09-20 07:55:53 +00:00
|
|
|
char *path = (char *)malloc(PATH_MAX_LENGTH + 1);
|
2017-09-21 17:57:10 +00:00
|
|
|
intfstream_t *fd = intfstream_open_file(name);
|
2017-09-17 05:31:58 +00:00
|
|
|
|
2017-09-18 02:18:50 +00:00
|
|
|
if (!fd)
|
2017-09-20 07:55:53 +00:00
|
|
|
goto end;
|
2017-09-17 05:31:58 +00:00
|
|
|
|
2017-09-18 02:18:50 +00:00
|
|
|
while (gdi_next_file(fd, name, path, PATH_MAX_LENGTH))
|
|
|
|
{
|
|
|
|
for (i = db->list_ptr; i < db->list->size; ++i)
|
|
|
|
{
|
|
|
|
if (db->list->elems[i].data && !strcmp(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-20 07:55:53 +00:00
|
|
|
|
|
|
|
end:
|
2017-09-20 10:18:31 +00:00
|
|
|
free(fd);
|
2017-09-20 07:55:53 +00:00
|
|
|
free(path);
|
2017-09-17 05:31:58 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2016-06-20 15:55:34 +00:00
|
|
|
switch (msg_hash_to_file_type(msg_hash_calculate(path_get_extension(name))))
|
2015-05-05 16:43:51 +00:00
|
|
|
{
|
2016-06-20 15:55:34 +00:00
|
|
|
case FILE_TYPE_COMPRESSED:
|
2016-09-18 04:38:59 +00:00
|
|
|
#ifdef HAVE_COMPRESSION
|
2016-09-29 08:43:38 +00:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
|
2016-09-25 04:13:33 +00:00
|
|
|
/* first check crc of archive itself */
|
2017-09-21 17:57:10 +00:00
|
|
|
return intfstream_file_get_crc(name,
|
|
|
|
0, SIZE_MAX, &db_state->archive_crc);
|
2016-06-20 15:55:34 +00:00
|
|
|
#else
|
|
|
|
break;
|
2015-05-05 16:43:51 +00:00
|
|
|
#endif
|
2016-06-20 15:55:34 +00:00
|
|
|
case FILE_TYPE_CUE:
|
2017-09-21 17:57:10 +00:00
|
|
|
task_database_cue_prune(db, name);
|
2015-09-24 22:36:12 +00:00
|
|
|
db_state->serial[0] = '\0';
|
2017-09-21 17:57:10 +00:00
|
|
|
if (task_database_cue_get_serial(name, db_state->serial))
|
2017-09-17 05:31:58 +00:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_SERIAL_LOOKUP);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
|
2017-09-21 17:57:10 +00:00
|
|
|
return task_database_cue_get_crc(name, &db_state->crc);
|
2017-09-17 05:31:58 +00:00
|
|
|
}
|
2016-06-20 15:55:34 +00:00
|
|
|
break;
|
2017-09-18 00:39:41 +00:00
|
|
|
case FILE_TYPE_GDI:
|
2017-09-18 02:18:50 +00:00
|
|
|
gdi_prune(db, name);
|
2015-09-24 22:36:12 +00:00
|
|
|
db_state->serial[0] = '\0';
|
2017-09-18 04:04:01 +00:00
|
|
|
/* There are no serial databases, so don't bother with
|
|
|
|
serials at the moment */
|
2017-09-21 17:57:10 +00:00
|
|
|
if (0 && task_database_gdi_get_serial(name, db_state->serial))
|
2017-09-17 05:31:58 +00:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_SERIAL_LOOKUP);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
|
2017-09-21 17:57:10 +00:00
|
|
|
return task_database_gdi_get_crc(name, &db_state->crc);
|
2017-09-17 05:31:58 +00:00
|
|
|
}
|
2016-06-20 15:55:34 +00:00
|
|
|
break;
|
|
|
|
case FILE_TYPE_ISO:
|
2015-09-26 22:12:17 +00:00
|
|
|
db_state->serial[0] = '\0';
|
2017-09-21 17:57:10 +00:00
|
|
|
intfstream_file_get_serial(name, 0, SIZE_MAX, db_state->serial);
|
2016-09-29 08:43:38 +00:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_SERIAL_LOOKUP);
|
2015-06-14 15:11:48 +00:00
|
|
|
break;
|
2017-09-17 05:31:58 +00:00
|
|
|
case FILE_TYPE_CHD:
|
|
|
|
db_state->serial[0] = '\0';
|
2017-09-21 17:57:10 +00:00
|
|
|
if (task_database_chd_get_serial(name, db_state->serial))
|
2017-09-17 05:31:58 +00:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_SERIAL_LOOKUP);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
|
2017-09-21 17:57:10 +00:00
|
|
|
return task_database_chd_get_crc(name, &db_state->crc);
|
2017-09-17 05:31:58 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-06-29 13:07:12 +00:00
|
|
|
case FILE_TYPE_LUTRO:
|
2016-09-29 08:43:38 +00:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_ITERATE_LUTRO);
|
2016-06-29 13:07:12 +00:00
|
|
|
break;
|
2016-06-20 15:55:34 +00:00
|
|
|
default:
|
2016-09-29 08:43:38 +00:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
|
2017-09-21 17:57:10 +00:00
|
|
|
return intfstream_file_get_crc(name, 0, SIZE_MAX, &db_state->crc);
|
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(
|
2017-09-19 06:15:28 +00:00
|
|
|
database_info_handle_t *db,
|
|
|
|
database_state_handle_t *db_state,
|
|
|
|
const char *path)
|
2015-05-26 23:36:15 +00:00
|
|
|
{
|
2016-09-18 04:38:59 +00:00
|
|
|
/* Reached end of database list,
|
2016-02-04 09:25:22 +00:00
|
|
|
* CRC match probably didn't succeed. */
|
2017-09-19 06:15:28 +00:00
|
|
|
|
|
|
|
/* 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_is_compressed_file(path) && !path_contains_compressed_file(path))
|
|
|
|
{
|
|
|
|
struct string_list *archive_list =
|
|
|
|
file_archive_get_file_list(path, NULL);
|
|
|
|
|
|
|
|
if (archive_list && archive_list->size > 0)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < archive_list->size; i++)
|
|
|
|
{
|
|
|
|
char *new_path = (char*)malloc(
|
|
|
|
PATH_MAX_LENGTH * sizeof(char));
|
|
|
|
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
|
|
|
|
size_t path_len = strlen(path);
|
|
|
|
|
|
|
|
new_path[0] = '\0';
|
|
|
|
|
|
|
|
strlcpy(new_path, path, path_size);
|
|
|
|
|
|
|
|
if (path_len + strlen(archive_list->elems[i].data)
|
|
|
|
+ 1 < PATH_MAX_LENGTH)
|
|
|
|
{
|
|
|
|
new_path[path_len] = '#';
|
|
|
|
strlcpy(new_path + path_len + 1,
|
|
|
|
archive_list->elems[i].data,
|
|
|
|
path_size - path_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
string_list_append(db->list, new_path,
|
|
|
|
archive_list->elems[i].attr);
|
|
|
|
|
|
|
|
free(new_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
string_list_free(archive_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 01:23:27 +00:00
|
|
|
db_state->list_index = 0;
|
|
|
|
db_state->entry_index = 0;
|
2015-05-26 23:36:15 +00:00
|
|
|
|
2015-05-27 01:23:27 +00:00
|
|
|
if (db_state->crc != 0)
|
|
|
|
db_state->crc = 0;
|
2016-04-14 22:28:44 +00:00
|
|
|
|
2015-05-27 01:23:27 +00:00
|
|
|
return 0;
|
2015-05-26 23:36:15 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-09-29 09:03:59 +00:00
|
|
|
const char *new_database = database_info_get_current_name(db_state);
|
2016-10-03 20:08:55 +00:00
|
|
|
|
2015-06-09 19:10:57 +00:00
|
|
|
#if 0
|
2016-09-18 04:38:59 +00:00
|
|
|
RARCH_LOG("Check database [%d/%d] : %s\n", (unsigned)db_state->list_index,
|
2015-05-25 05:54:44 +00:00
|
|
|
(unsigned)db_state->list->size, new_database);
|
2015-06-09 19:10:57 +00:00
|
|
|
#endif
|
2015-05-27 23:25:42 +00:00
|
|
|
if (db_state->info)
|
2016-09-25 03:55:55 +00:00
|
|
|
{
|
2015-05-27 23:25:42 +00:00
|
|
|
database_info_list_free(db_state->info);
|
2016-09-25 03:55:55 +00:00
|
|
|
free(db_state->info);
|
|
|
|
}
|
2015-06-10 17:51:26 +00:00
|
|
|
db_state->info = database_info_list_new(new_database, query);
|
2015-05-25 05:54:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-25 16:46:16 +00:00
|
|
|
static int database_info_list_iterate_found_match(
|
2016-12-31 06:03:29 +00:00
|
|
|
db_handle_t *_db,
|
2015-05-25 16:46:16 +00:00
|
|
|
database_state_handle_t *db_state,
|
2015-05-27 02:42:22 +00:00
|
|
|
database_info_handle_t *db,
|
2016-09-18 04:38:59 +00:00
|
|
|
const char *archive_name
|
2015-05-25 16:46:16 +00:00
|
|
|
)
|
|
|
|
{
|
2017-09-20 14:35:18 +00:00
|
|
|
char *db_crc = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
|
|
|
char *db_playlist_base_str = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
2017-09-12 03:00:22 +00:00
|
|
|
char *db_playlist_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
|
|
|
char *entry_path_str = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
|
|
|
playlist_t *playlist = NULL;
|
|
|
|
const char *db_path =
|
2016-09-29 09:03:59 +00:00
|
|
|
database_info_get_current_name(db_state);
|
2017-09-12 03:00:22 +00:00
|
|
|
const char *entry_path =
|
2016-09-29 08:59:50 +00:00
|
|
|
database_info_get_current_element_name(db);
|
2017-09-12 03:00:22 +00:00
|
|
|
database_info_t *db_info_entry =
|
2016-06-30 04:07:44 +00:00
|
|
|
&db_state->info->list[db_state->entry_index];
|
2017-11-09 00:59:52 +00:00
|
|
|
char *hash;
|
2015-05-25 16:46:16 +00:00
|
|
|
|
2017-09-29 18:51:20 +00:00
|
|
|
db_crc[0] = '\0';
|
|
|
|
db_playlist_path[0] = '\0';
|
|
|
|
db_playlist_base_str[0] = '\0';
|
|
|
|
entry_path_str[0] = '\0';
|
2016-10-08 16:31:43 +00:00
|
|
|
|
2016-06-28 11:05:46 +00:00
|
|
|
fill_short_pathname_representation_noext(db_playlist_base_str,
|
2017-09-20 14:35:18 +00:00
|
|
|
db_path, PATH_MAX_LENGTH * sizeof(char));
|
2015-05-25 22:25:07 +00:00
|
|
|
|
2016-06-26 08:12:28 +00:00
|
|
|
strlcat(db_playlist_base_str,
|
|
|
|
file_path_str(FILE_PATH_LPL_EXTENSION),
|
2017-09-20 14:35:18 +00:00
|
|
|
PATH_MAX_LENGTH * sizeof(char));
|
2017-09-29 18:47:54 +00:00
|
|
|
|
2017-09-30 04:21:38 +00:00
|
|
|
if (!string_is_empty(_db->playlist_directory))
|
2017-09-29 18:47:54 +00:00
|
|
|
fill_pathname_join(db_playlist_path, _db->playlist_directory,
|
|
|
|
db_playlist_base_str, PATH_MAX_LENGTH * sizeof(char));
|
2015-05-25 16:46:16 +00:00
|
|
|
|
2016-05-16 07:07:44 +00:00
|
|
|
playlist = playlist_init(db_playlist_path, COLLECTION_SIZE);
|
2015-05-25 16:46:16 +00:00
|
|
|
|
2017-09-20 14:35:18 +00:00
|
|
|
snprintf(db_crc, PATH_MAX_LENGTH * sizeof(char),
|
2017-09-12 03:00:22 +00:00
|
|
|
"%08X|crc", db_info_entry->crc32);
|
2015-05-25 19:39:50 +00:00
|
|
|
|
2016-06-01 02:05:14 +00:00
|
|
|
if (entry_path)
|
2017-09-20 14:35:18 +00:00
|
|
|
strlcpy(entry_path_str, entry_path, PATH_MAX_LENGTH * sizeof(char));
|
2015-06-22 17:51:13 +00:00
|
|
|
|
2016-09-18 04:38:59 +00:00
|
|
|
if (!string_is_empty(archive_name))
|
2017-09-12 03:00:22 +00:00
|
|
|
fill_pathname_join_delim(entry_path_str,
|
|
|
|
entry_path_str, archive_name,
|
2017-09-20 14:35:18 +00:00
|
|
|
'#', PATH_MAX_LENGTH * sizeof(char));
|
2015-05-27 02:42:22 +00:00
|
|
|
|
2017-11-09 00:59:52 +00:00
|
|
|
if (core_info_database_match_archive_member(
|
|
|
|
db_state->list->elems[db_state->list_index].data) &&
|
|
|
|
(hash = strchr(entry_path_str, '#')))
|
|
|
|
*hash = '\0';
|
|
|
|
|
2015-05-27 05:23:09 +00:00
|
|
|
#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);
|
2016-09-18 04:38:59 +00:00
|
|
|
RARCH_LOG("ZIP entry: %s\n", archive_name);
|
2015-05-27 05:23:09 +00:00
|
|
|
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-01-26 20:21:01 +00:00
|
|
|
{
|
2016-05-16 07:07:44 +00:00
|
|
|
playlist_push(playlist, entry_path_str,
|
2016-06-30 04:07:44 +00:00
|
|
|
db_info_entry->name,
|
|
|
|
file_path_str(FILE_PATH_DETECT),
|
|
|
|
file_path_str(FILE_PATH_DETECT),
|
2016-02-04 09:25:22 +00:00
|
|
|
db_crc, db_playlist_base_str);
|
2016-01-26 20:21:01 +00:00
|
|
|
}
|
2015-05-25 16:46:16 +00:00
|
|
|
|
2016-05-16 07:07:44 +00:00
|
|
|
playlist_write_file(playlist);
|
|
|
|
playlist_free(playlist);
|
2015-11-14 22:42:56 +00:00
|
|
|
|
|
|
|
database_info_list_free(db_state->info);
|
2016-09-25 03:55:55 +00:00
|
|
|
free(db_state->info);
|
2016-01-26 20:24:17 +00:00
|
|
|
|
2015-11-14 22:42:56 +00:00
|
|
|
db_state->info = NULL;
|
|
|
|
db_state->crc = 0;
|
2016-01-26 20:24:17 +00:00
|
|
|
|
2017-09-12 03:00:22 +00:00
|
|
|
free(entry_path_str);
|
|
|
|
free(db_playlist_path);
|
|
|
|
free(db_playlist_base_str);
|
|
|
|
free(db_crc);
|
|
|
|
|
2015-05-25 16:46:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-18 04:38:59 +00:00
|
|
|
/* End of entries in database info list and didn't find a
|
2015-05-27 01:23:27 +00:00
|
|
|
* 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;
|
2015-05-28 00:55:39 +00:00
|
|
|
|
2015-05-27 01:23:27 +00:00
|
|
|
database_info_list_free(db_state->info);
|
2016-09-25 03:55:55 +00:00
|
|
|
free(db_state->info);
|
2015-05-28 00:55:39 +00:00
|
|
|
db_state->info = NULL;
|
2015-05-27 01:23:27 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-05-13 08:19:53 +00:00
|
|
|
static int task_database_iterate_crc_lookup(
|
2016-12-31 06:03:29 +00:00
|
|
|
db_handle_t *_db,
|
2015-05-25 01:20:43 +00:00
|
|
|
database_state_handle_t *db_state,
|
2015-05-27 02:42:22 +00:00
|
|
|
database_info_handle_t *db,
|
2016-10-03 20:08:55 +00:00
|
|
|
const char *name,
|
2016-09-19 22:38:33 +00:00
|
|
|
const char *archive_entry)
|
2015-05-25 01:20:43 +00:00
|
|
|
{
|
2015-05-25 05:05:00 +00:00
|
|
|
|
2016-09-18 04:38:59 +00:00
|
|
|
if (!db_state->list ||
|
2017-09-21 17:57:10 +00:00
|
|
|
(unsigned)db_state->list_index == (unsigned)db_state->list->size)
|
2017-09-19 06:15:28 +00:00
|
|
|
return database_info_list_iterate_end_no_match(db, db_state, name);
|
2015-05-25 05:05:00 +00:00
|
|
|
|
|
|
|
if (db_state->entry_index == 0)
|
2015-06-10 17:51:26 +00:00
|
|
|
{
|
2016-10-09 07:56:03 +00:00
|
|
|
char query[50];
|
|
|
|
|
|
|
|
query[0] = '\0';
|
2016-10-03 20:08:55 +00:00
|
|
|
|
2016-10-12 20:14:00 +00:00
|
|
|
/* don't scan files that can't be in this database */
|
2017-11-09 00:59:52 +00:00
|
|
|
if (!(path_contains_compressed_file(name) &&
|
|
|
|
core_info_database_match_archive_member(
|
|
|
|
db_state->list->elems[db_state->list_index].data)) &&
|
|
|
|
!core_info_database_supports_content_path(
|
2017-09-19 06:15:28 +00:00
|
|
|
db_state->list->elems[db_state->list_index].data, name))
|
2016-10-03 20:08:55 +00:00
|
|
|
return database_info_list_iterate_next(db_state);
|
|
|
|
|
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\")}",
|
2017-05-22 04:26:13 +00:00
|
|
|
db_state->crc, db_state->archive_crc);
|
2015-06-10 17:51:26 +00:00
|
|
|
|
|
|
|
database_info_list_iterate_new(db_state, query);
|
|
|
|
}
|
2015-05-25 03:36:23 +00:00
|
|
|
|
2015-05-25 05:05:00 +00:00
|
|
|
if (db_state->info)
|
|
|
|
{
|
2016-09-18 04:38:59 +00:00
|
|
|
database_info_t *db_info_entry =
|
2016-02-04 09:25:22 +00:00
|
|
|
&db_state->info->list[db_state->entry_index];
|
2015-05-25 05:05:00 +00:00
|
|
|
|
2015-06-09 23:13:03 +00:00
|
|
|
if (db_info_entry && db_info_entry->crc32)
|
2015-05-25 05:05:00 +00:00
|
|
|
{
|
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-09-18 04:38:59 +00:00
|
|
|
if (db_state->archive_crc == db_info_entry->crc32)
|
2016-04-14 22:55:11 +00:00
|
|
|
return database_info_list_iterate_found_match(
|
2016-12-31 06:03:29 +00:00
|
|
|
_db,
|
2016-04-14 22:55:11 +00:00
|
|
|
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(
|
2016-12-31 06:03:29 +00:00
|
|
|
_db,
|
2016-09-19 22:38:33 +00:00
|
|
|
db_state, db, archive_entry);
|
2015-05-25 05:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-25 03:36:23 +00:00
|
|
|
|
|
|
|
db_state->entry_index++;
|
|
|
|
|
2016-06-02 18:40:39 +00:00
|
|
|
if (db_state->info)
|
|
|
|
{
|
|
|
|
if (db_state->entry_index >= db_state->info->count)
|
|
|
|
return database_info_list_iterate_next(db_state);
|
|
|
|
}
|
2015-05-25 05:05:00 +00:00
|
|
|
|
2016-05-17 12:24:43 +00:00
|
|
|
/* If we haven't reached the end of the database list yet,
|
|
|
|
* continue iterating. */
|
2015-05-25 05:05:00 +00:00
|
|
|
if (db_state->list_index < db_state->list->size)
|
|
|
|
return 1;
|
|
|
|
|
2016-05-26 15:47:21 +00:00
|
|
|
database_info_list_free(db_state->info);
|
2016-10-03 20:08:55 +00:00
|
|
|
|
|
|
|
if (db_state->info)
|
|
|
|
free(db_state->info);
|
|
|
|
|
2015-05-25 01:20:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-18 04:38:59 +00:00
|
|
|
static int task_database_iterate_playlist_archive(
|
2016-12-31 06:03:29 +00:00
|
|
|
db_handle_t *_db,
|
2015-05-27 01:23:27 +00:00
|
|
|
database_state_handle_t *db_state,
|
|
|
|
database_info_handle_t *db, const char *name)
|
|
|
|
{
|
2016-09-18 16:31:24 +00:00
|
|
|
#ifdef HAVE_COMPRESSION
|
2015-05-27 01:23:27 +00:00
|
|
|
if (db_state->crc != 0)
|
2016-05-13 08:19:53 +00:00
|
|
|
return task_database_iterate_crc_lookup(
|
2016-12-31 06:03:29 +00:00
|
|
|
_db, db_state, db, name, db_state->archive_name);
|
2016-02-03 16:31:19 +00:00
|
|
|
|
2016-09-25 04:13:33 +00:00
|
|
|
db_state->crc = file_archive_get_file_crc32(name);
|
2015-05-27 01:23:27 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-06-29 13:07:12 +00:00
|
|
|
static int task_database_iterate_playlist_lutro(
|
2016-12-31 06:03:29 +00:00
|
|
|
db_handle_t *_db,
|
2016-06-29 13:07:12 +00:00
|
|
|
database_state_handle_t *db_state,
|
|
|
|
database_info_handle_t *db,
|
|
|
|
const char *path)
|
|
|
|
{
|
2017-09-12 03:00:22 +00:00
|
|
|
char *db_playlist_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
|
|
|
playlist_t *playlist = NULL;
|
2016-06-29 13:07:12 +00:00
|
|
|
|
2017-09-12 03:00:22 +00:00
|
|
|
db_playlist_path[0] = '\0';
|
2016-10-08 16:31:43 +00:00
|
|
|
|
2017-09-30 04:21:38 +00:00
|
|
|
if (!string_is_empty(_db->playlist_directory))
|
2017-09-29 18:47:54 +00:00
|
|
|
fill_pathname_join(db_playlist_path,
|
|
|
|
_db->playlist_directory,
|
|
|
|
file_path_str(FILE_PATH_LUTRO_PLAYLIST),
|
|
|
|
PATH_MAX_LENGTH * sizeof(char));
|
2016-06-29 13:07:12 +00:00
|
|
|
|
|
|
|
playlist = playlist_init(db_playlist_path, COLLECTION_SIZE);
|
|
|
|
|
2017-09-12 03:00:22 +00:00
|
|
|
free(db_playlist_path);
|
|
|
|
|
|
|
|
if(!playlist_entry_exists(playlist,
|
|
|
|
path, file_path_str(FILE_PATH_DETECT)))
|
2016-06-29 13:07:12 +00:00
|
|
|
{
|
2017-09-12 03:00:22 +00:00
|
|
|
char *game_title = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
2016-10-08 16:31:43 +00:00
|
|
|
|
|
|
|
game_title[0] = '\0';
|
2016-06-30 04:07:44 +00:00
|
|
|
|
|
|
|
fill_short_pathname_representation_noext(game_title,
|
2017-09-12 03:00:22 +00:00
|
|
|
path, PATH_MAX_LENGTH * sizeof(char));
|
2016-06-30 04:07:44 +00:00
|
|
|
|
2016-06-29 13:07:12 +00:00
|
|
|
playlist_push(playlist, path,
|
2016-06-30 03:19:25 +00:00
|
|
|
game_title,
|
2016-06-30 04:07:44 +00:00
|
|
|
file_path_str(FILE_PATH_DETECT),
|
|
|
|
file_path_str(FILE_PATH_DETECT),
|
|
|
|
file_path_str(FILE_PATH_DETECT),
|
2016-06-30 03:19:25 +00:00
|
|
|
file_path_str(FILE_PATH_LUTRO_PLAYLIST));
|
2017-09-12 03:00:22 +00:00
|
|
|
|
|
|
|
free(game_title);
|
2016-06-29 13:07:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
playlist_write_file(playlist);
|
|
|
|
playlist_free(playlist);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-13 08:19:53 +00:00
|
|
|
static int task_database_iterate_serial_lookup(
|
2016-12-31 06:03:29 +00:00
|
|
|
db_handle_t *_db,
|
2015-09-16 20:11:08 +00:00
|
|
|
database_state_handle_t *db_state,
|
|
|
|
database_info_handle_t *db, const char *name)
|
|
|
|
{
|
2016-09-18 04:38:59 +00:00
|
|
|
if (!db_state->list ||
|
2017-09-21 17:57:10 +00:00
|
|
|
(unsigned)db_state->list_index == (unsigned)db_state->list->size)
|
2017-09-19 06:15:28 +00:00
|
|
|
return database_info_list_iterate_end_no_match(db, db_state, name);
|
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
|
|
|
{
|
2016-10-09 07:56:03 +00:00
|
|
|
char query[50];
|
2016-09-18 04:38:59 +00:00
|
|
|
char *serial_buf =
|
2017-10-27 08:17:09 +00:00
|
|
|
bin_to_hex_alloc((uint8_t*)db_state->serial, strlen(db_state->serial) * sizeof(uint8_t));
|
2015-09-28 15:18:48 +00:00
|
|
|
|
|
|
|
if (!serial_buf)
|
|
|
|
return 1;
|
2015-09-22 13:22:15 +00:00
|
|
|
|
2016-10-09 07:56:03 +00:00
|
|
|
query[0] = '\0';
|
|
|
|
|
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))
|
2016-12-31 06:03:29 +00:00
|
|
|
return database_info_list_iterate_found_match(_db,
|
|
|
|
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
|
|
|
|
2016-06-02 18:40:39 +00:00
|
|
|
if (db_state->info)
|
|
|
|
{
|
|
|
|
if (db_state->entry_index >= db_state->info->count)
|
|
|
|
return database_info_list_iterate_next(db_state);
|
|
|
|
}
|
2015-09-22 13:22:15 +00:00
|
|
|
|
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
|
|
|
|
2016-05-26 15:47:21 +00:00
|
|
|
database_info_list_free(db_state->info);
|
2016-09-25 03:55:55 +00:00
|
|
|
free(db_state->info);
|
2015-09-16 20:11:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-31 06:03:29 +00:00
|
|
|
static int task_database_iterate(
|
|
|
|
db_handle_t *_db,
|
|
|
|
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
|
|
|
{
|
2016-09-29 09:07:56 +00:00
|
|
|
const char *name = database_info_get_current_element_name(db);
|
2016-09-29 08:55:50 +00:00
|
|
|
|
2015-05-05 16:43:51 +00:00
|
|
|
if (!name)
|
|
|
|
return 0;
|
|
|
|
|
2016-09-29 08:41:30 +00:00
|
|
|
if (database_info_get_type(db) == DATABASE_TYPE_ITERATE)
|
2016-09-25 04:13:33 +00:00
|
|
|
if (path_contains_compressed_file(name))
|
2016-09-29 08:43:38 +00:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_ITERATE_ARCHIVE);
|
2016-09-25 04:13:33 +00:00
|
|
|
|
2016-09-29 08:41:30 +00:00
|
|
|
switch (database_info_get_type(db))
|
2015-05-05 16:43:51 +00:00
|
|
|
{
|
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);
|
2016-09-18 04:38:59 +00:00
|
|
|
case DATABASE_TYPE_ITERATE_ARCHIVE:
|
2016-12-31 06:03:29 +00:00
|
|
|
return task_database_iterate_playlist_archive(_db, db_state, db, name);
|
2016-06-29 13:07:12 +00:00
|
|
|
case DATABASE_TYPE_ITERATE_LUTRO:
|
2016-12-31 06:03:29 +00:00
|
|
|
return task_database_iterate_playlist_lutro(_db, db_state, db, name);
|
2015-09-22 13:22:15 +00:00
|
|
|
case DATABASE_TYPE_SERIAL_LOOKUP:
|
2016-12-31 06:03:29 +00:00
|
|
|
return task_database_iterate_serial_lookup(_db, db_state, db, name);
|
2015-05-25 01:20:43 +00:00
|
|
|
case DATABASE_TYPE_CRC_LOOKUP:
|
2016-12-31 06:03:29 +00:00
|
|
|
return task_database_iterate_crc_lookup(_db, db_state, db, name, 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)
|
2015-05-23 20:52:22 +00:00
|
|
|
{
|
2015-05-25 01:46:03 +00:00
|
|
|
if (!db_state)
|
2015-05-23 20:52:22 +00:00
|
|
|
return;
|
|
|
|
|
2015-05-25 01:46:03 +00:00
|
|
|
if (db_state->buf)
|
|
|
|
free(db_state->buf);
|
|
|
|
db_state->buf = NULL;
|
2015-05-23 20:52:22 +00:00
|
|
|
}
|
|
|
|
|
2016-05-13 08:19:53 +00:00
|
|
|
static void task_database_handler(retro_task_t *task)
|
2015-05-05 16:05:59 +00:00
|
|
|
{
|
2016-09-29 08:55:50 +00:00
|
|
|
const char *name = NULL;
|
|
|
|
database_info_handle_t *dbinfo = NULL;
|
|
|
|
database_state_handle_t *dbstate = NULL;
|
|
|
|
db_handle_t *db = NULL;
|
2016-10-12 20:14:00 +00:00
|
|
|
|
2016-09-29 08:55:50 +00:00
|
|
|
if (!task)
|
|
|
|
goto task_finished;
|
2016-10-12 20:14:00 +00:00
|
|
|
|
2016-09-29 08:55:50 +00:00
|
|
|
db = (db_handle_t*)task->state;
|
2015-05-05 16:05:59 +00:00
|
|
|
|
2016-09-29 08:55:50 +00:00
|
|
|
if (!db)
|
|
|
|
goto task_finished;
|
|
|
|
|
2017-07-09 04:44:02 +00:00
|
|
|
if (!db->scan_started)
|
|
|
|
{
|
|
|
|
db->scan_started = true;
|
|
|
|
|
2017-09-30 04:21:38 +00:00
|
|
|
if (!string_is_empty(db->fullpath))
|
2017-09-29 18:47:54 +00:00
|
|
|
{
|
|
|
|
if (db->is_directory)
|
|
|
|
db->handle = database_info_dir_init(db->fullpath, DATABASE_TYPE_ITERATE, task);
|
|
|
|
else
|
|
|
|
db->handle = database_info_file_init(db->fullpath, DATABASE_TYPE_ITERATE, task);
|
|
|
|
}
|
2017-07-09 04:44:02 +00:00
|
|
|
|
|
|
|
task_free_title(task);
|
|
|
|
|
|
|
|
if (db->handle)
|
|
|
|
db->handle->status = DATABASE_STATUS_ITERATE_BEGIN;
|
|
|
|
}
|
|
|
|
|
2016-09-29 08:55:50 +00:00
|
|
|
dbinfo = db->handle;
|
|
|
|
dbstate = &db->state;
|
2016-10-12 20:14:00 +00:00
|
|
|
|
2016-12-29 05:50:18 +00:00
|
|
|
if (!dbinfo || task_get_cancelled(task))
|
2015-11-23 00:52:56 +00:00
|
|
|
goto task_finished;
|
2015-05-05 16:05:59 +00:00
|
|
|
|
2015-11-23 00:52:56 +00:00
|
|
|
switch (dbinfo->status)
|
2015-05-05 16:05:59 +00:00
|
|
|
{
|
2015-05-24 04:14:44 +00:00
|
|
|
case DATABASE_STATUS_ITERATE_BEGIN:
|
2016-09-29 09:07:56 +00:00
|
|
|
if (dbstate && !dbstate->list)
|
2016-09-29 08:55:50 +00:00
|
|
|
{
|
2017-09-30 04:21:38 +00:00
|
|
|
if (!string_is_empty(db->content_database_path))
|
2017-09-29 18:47:54 +00:00
|
|
|
dbstate->list = dir_list_new_special(
|
|
|
|
db->content_database_path,
|
|
|
|
DIR_LIST_DATABASES, NULL);
|
2017-09-19 23:58:28 +00:00
|
|
|
|
|
|
|
/* If the scan path matches a database path exactly then
|
|
|
|
* save time by only processing that database. */
|
|
|
|
if (dbstate->list && db->is_directory)
|
|
|
|
{
|
2017-09-29 18:47:54 +00:00
|
|
|
size_t i;
|
|
|
|
char *dirname = NULL;
|
|
|
|
|
2017-09-30 04:21:38 +00:00
|
|
|
if (!string_is_empty(db->fullpath))
|
2017-09-29 18:47:54 +00:00
|
|
|
dirname = find_last_slash(db->fullpath) + 1;
|
2017-09-19 23:58:28 +00:00
|
|
|
|
2017-09-22 03:12:26 +00:00
|
|
|
for (i = 0; i < dbstate->list->size; i++)
|
2017-09-19 23:58:28 +00:00
|
|
|
{
|
2017-09-29 18:47:54 +00:00
|
|
|
char *dbname;
|
2017-09-19 23:58:28 +00:00
|
|
|
char *dbpath = strdup(dbstate->list->elems[i].data);
|
|
|
|
path_remove_extension(dbpath);
|
2017-09-22 03:12:26 +00:00
|
|
|
|
|
|
|
dbname = find_last_slash(dbpath) + 1;
|
2017-09-19 23:58:28 +00:00
|
|
|
|
|
|
|
if (strcasecmp(dbname, dirname) == 0)
|
|
|
|
{
|
2017-09-22 03:12:26 +00:00
|
|
|
struct string_list *single_list = NULL;
|
2017-09-19 23:58:28 +00:00
|
|
|
free(dbpath);
|
2017-09-22 03:12:26 +00:00
|
|
|
single_list = string_list_new();
|
2017-09-19 23:58:28 +00:00
|
|
|
string_list_append(single_list, dbstate->list->elems[i].data,
|
2017-09-29 18:47:54 +00:00
|
|
|
dbstate->list->elems[i].attr);
|
2017-09-19 23:58:28 +00:00
|
|
|
dir_list_free(dbstate->list);
|
|
|
|
dbstate->list = single_list;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(dbpath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-29 08:55:50 +00:00
|
|
|
}
|
2015-11-23 00:52:56 +00:00
|
|
|
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-09-29 08:59:50 +00:00
|
|
|
name = database_info_get_current_element_name(dbinfo);
|
2016-05-13 08:19:53 +00:00
|
|
|
task_database_cleanup_state(dbstate);
|
2015-11-23 00:52:56 +00:00
|
|
|
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;
|
2015-05-05 16:05:59 +00:00
|
|
|
case DATABASE_STATUS_ITERATE:
|
2016-12-31 06:03:29 +00:00
|
|
|
if (task_database_iterate(db, dbstate, dbinfo) == 0)
|
2015-05-25 01:20:43 +00:00
|
|
|
{
|
2015-11-23 00:52:56 +00:00
|
|
|
dbinfo->status = DATABASE_STATUS_ITERATE_NEXT;
|
|
|
|
dbinfo->type = DATABASE_TYPE_ITERATE;
|
2015-05-25 01:20:43 +00:00
|
|
|
}
|
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)
|
2015-05-23 20:52:22 +00:00
|
|
|
{
|
2015-11-23 00:52:56 +00:00
|
|
|
dbinfo->status = DATABASE_STATUS_ITERATE_START;
|
|
|
|
dbinfo->type = DATABASE_TYPE_ITERATE;
|
2015-05-23 20:52:22 +00:00
|
|
|
}
|
2015-05-23 18:53:43 +00:00
|
|
|
else
|
2015-05-23 17:18:56 +00:00
|
|
|
{
|
2016-12-22 22:36:11 +00:00
|
|
|
runloop_msg_queue_push(
|
2016-01-29 13:30:09 +00:00
|
|
|
msg_hash_to_str(MSG_SCANNING_OF_DIRECTORY_FINISHED),
|
|
|
|
0, 180, true);
|
2015-11-23 00:52:56 +00:00
|
|
|
goto task_finished;
|
2015-05-23 17:18:56 +00:00
|
|
|
}
|
2015-05-05 16:05:59 +00:00
|
|
|
break;
|
2015-05-23 16:08:42 +00:00
|
|
|
default:
|
2015-11-23 00:52:56 +00:00
|
|
|
case DATABASE_STATUS_FREE:
|
2015-05-23 16:08:42 +00:00
|
|
|
case DATABASE_STATUS_NONE:
|
2015-11-23 00:52:56 +00:00
|
|
|
goto task_finished;
|
2015-05-23 17:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2015-11-23 00:52:56 +00:00
|
|
|
task_finished:
|
2016-09-29 08:55:50 +00:00
|
|
|
if (task)
|
2016-12-29 05:50:18 +00:00
|
|
|
task_set_finished(task, true);
|
2015-05-23 17:18:56 +00:00
|
|
|
|
2016-09-29 08:55:50 +00:00
|
|
|
if (dbstate)
|
|
|
|
{
|
|
|
|
if (dbstate->list)
|
|
|
|
dir_list_free(dbstate->list);
|
|
|
|
}
|
2015-07-08 19:48:58 +00:00
|
|
|
|
2016-09-29 08:55:50 +00:00
|
|
|
if (db)
|
|
|
|
{
|
2017-09-30 04:21:38 +00:00
|
|
|
if (!string_is_empty(db->playlist_directory))
|
2017-09-29 18:47:54 +00:00
|
|
|
free(db->playlist_directory);
|
2017-09-30 04:21:38 +00:00
|
|
|
if (!string_is_empty(db->content_database_path))
|
2017-09-29 18:47:54 +00:00
|
|
|
free(db->content_database_path);
|
2017-09-30 04:21:38 +00:00
|
|
|
if (!string_is_empty(db->fullpath))
|
2017-09-29 18:47:54 +00:00
|
|
|
free(db->fullpath);
|
2016-09-29 08:55:50 +00:00
|
|
|
if (db->state.buf)
|
|
|
|
free(db->state.buf);
|
2015-09-28 21:00:22 +00:00
|
|
|
|
2016-09-29 08:55:50 +00:00
|
|
|
if (db->handle)
|
|
|
|
database_info_free(db->handle);
|
|
|
|
free(db);
|
|
|
|
}
|
2015-07-08 19:48:58 +00:00
|
|
|
|
2016-09-29 08:55:50 +00:00
|
|
|
if (dbinfo)
|
|
|
|
free(dbinfo);
|
2015-07-08 19:48:58 +00:00
|
|
|
}
|
2015-07-08 20:03:23 +00:00
|
|
|
|
2017-01-18 00:23:09 +00:00
|
|
|
bool task_push_dbscan(
|
|
|
|
const char *playlist_directory,
|
|
|
|
const char *content_database,
|
|
|
|
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-12-31 06:03:29 +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));
|
2016-01-21 02:25:00 +00:00
|
|
|
|
|
|
|
if (!t || !db)
|
|
|
|
goto error;
|
|
|
|
|
2017-09-29 18:47:54 +00:00
|
|
|
t->handler = task_database_handler;
|
|
|
|
t->state = db;
|
|
|
|
t->callback = cb;
|
|
|
|
t->title = strdup(msg_hash_to_str(MSG_PREPARING_FOR_CONTENT_SCAN));
|
2015-11-23 00:52:56 +00:00
|
|
|
|
2017-09-29 18:47:54 +00:00
|
|
|
db->is_directory = directory;
|
|
|
|
db->playlist_directory = NULL;
|
|
|
|
db->fullpath = strdup(fullpath);
|
|
|
|
db->playlist_directory = strdup(playlist_directory);
|
|
|
|
db->content_database_path = strdup(content_database);
|
2016-12-31 06:03:29 +00:00
|
|
|
|
2017-05-14 18:43:39 +00:00
|
|
|
task_queue_push(t);
|
2015-07-08 20:03:23 +00:00
|
|
|
|
2015-11-23 00:52:56 +00:00
|
|
|
return true;
|
2016-01-21 02:25:00 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (t)
|
|
|
|
free(t);
|
|
|
|
if (db)
|
|
|
|
free(db);
|
|
|
|
return false;
|
2015-07-08 20:03:23 +00:00
|
|
|
}
|