2015-05-05 18:05:59 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
|
|
|
* Copyright (C) 2014-2017 - Jean-André Santoni
|
|
|
|
* Copyright (C) 2016-2017 - Brad Parker
|
2015-05-05 18:05:59 +02: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 07:36:30 +02:00
|
|
|
|
2015-06-02 16:49:35 +02:00
|
|
|
#include <compat/strcasestr.h>
|
2015-05-26 00:25:07 +02:00
|
|
|
#include <compat/strl.h>
|
2016-02-09 17:12:39 +01:00
|
|
|
#include <retro_miscellaneous.h>
|
2015-09-14 03:33:50 +02:00
|
|
|
#include <retro_endianness.h>
|
2015-12-26 07:23:13 +01:00
|
|
|
#include <string/stdstring.h>
|
2016-03-20 14:53:54 +01:00
|
|
|
#include <lists/dir_list.h>
|
2016-02-07 01:50:08 +01:00
|
|
|
#include <file/file_path.h>
|
2016-09-20 13:34:56 -04:00
|
|
|
#include <encodings/crc32.h>
|
2016-09-29 10:37:31 +02:00
|
|
|
#include <streams/file_stream.h>
|
2017-09-16 22:31:58 -07:00
|
|
|
#include <streams/chd_stream.h>
|
|
|
|
#include <streams/interface_stream.h>
|
2016-02-09 17:12:39 +01:00
|
|
|
#include "tasks_internal.h"
|
2015-05-26 00:25:07 +02:00
|
|
|
|
2015-07-08 22:03:23 +02:00
|
|
|
#include "../database_info.h"
|
|
|
|
|
2016-06-26 10:12:28 +02:00
|
|
|
#include "../file_path_special.h"
|
2016-03-20 17:28:24 +01:00
|
|
|
#include "../list_special.h"
|
2015-07-01 19:40:50 +02:00
|
|
|
#include "../msg_hash.h"
|
2016-01-25 07:06:58 +01:00
|
|
|
#include "../playlist.h"
|
2017-05-11 09:11:46 +02:00
|
|
|
#include "../retroarch.h"
|
2015-11-23 12:03:38 +01:00
|
|
|
#include "../verbosity.h"
|
2016-10-03 16:08:55 -04:00
|
|
|
#include "../core_info.h"
|
2015-05-05 18:05:59 +02:00
|
|
|
|
2015-07-26 00:40:24 +02:00
|
|
|
#ifndef COLLECTION_SIZE
|
2015-09-27 03:48:58 +02:00
|
|
|
#define COLLECTION_SIZE 99999
|
2015-07-26 00:40:24 +02:00
|
|
|
#endif
|
|
|
|
|
2016-12-20 21:08:31 +01: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;
|
|
|
|
uint32_t archive_crc;
|
|
|
|
uint8_t *buf;
|
2017-02-27 09:28:24 +01:00
|
|
|
char archive_name[511];
|
2016-12-20 21:08:31 +01:00
|
|
|
char serial[4096];
|
|
|
|
} database_state_handle_t;
|
|
|
|
|
2015-07-08 22:03:23 +02:00
|
|
|
typedef struct db_handle
|
|
|
|
{
|
|
|
|
database_state_handle_t state;
|
|
|
|
database_info_handle_t *handle;
|
|
|
|
unsigned status;
|
2016-12-31 07:03:29 +01:00
|
|
|
char playlist_directory[4096];
|
|
|
|
char content_database_path[4096];
|
2017-07-09 00:44:02 -04:00
|
|
|
|
|
|
|
bool is_directory;
|
|
|
|
char fullpath[4096];
|
|
|
|
bool scan_started;
|
2015-07-08 22:03:23 +02:00
|
|
|
} db_handle_t;
|
|
|
|
|
2017-05-13 18:08:37 +02:00
|
|
|
int find_first_data_track(const char* cue_path,
|
|
|
|
int32_t* offset, char* track_path, size_t max_len);
|
|
|
|
|
2017-09-16 22:31:58 -07:00
|
|
|
int detect_system(intfstream_t *fd, const char** system_name);
|
2017-05-13 18:08:37 +02:00
|
|
|
|
2017-09-16 22:31:58 -07:00
|
|
|
int detect_ps1_game(intfstream_t *fd, char *game_id);
|
2017-05-13 18:08:37 +02:00
|
|
|
|
2017-09-16 22:31:58 -07:00
|
|
|
int detect_psp_game(intfstream_t *fd, char *game_id);
|
2017-05-13 18:08:37 +02:00
|
|
|
|
2017-09-16 22:31:58 -07:00
|
|
|
int detect_serial_ascii_game(intfstream_t *fd, char *game_id);
|
|
|
|
|
2017-09-18 15:57:05 +02:00
|
|
|
static intfstream_t* open_file(const char *path)
|
2017-09-16 22:31:58 -07:00
|
|
|
{
|
|
|
|
intfstream_info_t info;
|
|
|
|
intfstream_t *fd = NULL;
|
|
|
|
|
2017-09-18 15:57:05 +02:00
|
|
|
info.type = INTFSTREAM_FILE;
|
|
|
|
fd = intfstream_init(&info);
|
2017-09-16 22:31:58 -07:00
|
|
|
|
|
|
|
if (!fd)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!intfstream_open(fd, path, RFILE_MODE_READ, -1))
|
|
|
|
{
|
|
|
|
intfstream_close(fd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2017-09-18 15:57:05 +02:00
|
|
|
static intfstream_t *open_chd_track(const char *path, int32_t track)
|
2017-09-16 22:31:58 -07:00
|
|
|
{
|
|
|
|
intfstream_info_t info;
|
|
|
|
intfstream_t *fd = NULL;
|
|
|
|
|
2017-09-18 15:57:05 +02:00
|
|
|
info.type = INTFSTREAM_CHD;
|
|
|
|
info.chd.track = track;
|
|
|
|
|
|
|
|
fd = intfstream_init(&info);
|
2017-09-16 22:31:58 -07:00
|
|
|
|
|
|
|
if (!fd)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!intfstream_open(fd, path, RFILE_MODE_READ, -1))
|
|
|
|
{
|
|
|
|
intfstream_close(fd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
2017-07-29 23:23:05 -04:00
|
|
|
|
2017-09-18 15:57:05 +02:00
|
|
|
static void database_info_set_type(
|
|
|
|
database_info_handle_t *handle,
|
|
|
|
enum database_type type)
|
2016-12-20 21:08:31 +01:00
|
|
|
{
|
|
|
|
if (!handle)
|
|
|
|
return;
|
|
|
|
handle->type = type;
|
|
|
|
}
|
|
|
|
|
2017-09-18 15:57:05 +02:00
|
|
|
static enum database_type database_info_get_type(
|
|
|
|
database_info_handle_t *handle)
|
2016-12-20 21:08:31 +01:00
|
|
|
{
|
|
|
|
if (!handle)
|
|
|
|
return DATABASE_TYPE_NONE;
|
|
|
|
return handle->type;
|
|
|
|
}
|
|
|
|
|
2017-09-18 15:57:05 +02:00
|
|
|
static const char *database_info_get_current_name(
|
|
|
|
database_state_handle_t *handle)
|
2016-12-20 21:08:31 +01:00
|
|
|
{
|
|
|
|
if (!handle || !handle->list)
|
|
|
|
return NULL;
|
|
|
|
return handle->list->elems[handle->list_index].data;
|
|
|
|
}
|
|
|
|
|
2017-09-18 15:57:05 +02:00
|
|
|
static const char *database_info_get_current_element_name(
|
|
|
|
database_info_handle_t *handle)
|
2016-12-20 21:08:31 +01:00
|
|
|
{
|
|
|
|
if (!handle || !handle->list)
|
|
|
|
return NULL;
|
|
|
|
return handle->list->elems[handle->list_ptr].data;
|
|
|
|
}
|
|
|
|
|
2016-05-13 10:19:53 +02:00
|
|
|
static int task_database_iterate_start(database_info_handle_t *db,
|
2015-12-06 15:55:05 +01:00
|
|
|
const char *name)
|
2015-05-23 21:56:17 +02:00
|
|
|
{
|
2017-02-27 09:28:24 +01:00
|
|
|
char msg[511];
|
2016-10-09 09:56:03 +02:00
|
|
|
|
2017-02-27 09:28:24 +01:00
|
|
|
msg[0] = msg[510] = '\0';
|
2015-06-12 22:37:06 +02:00
|
|
|
|
2015-11-19 13:43:48 +01:00
|
|
|
snprintf(msg, sizeof(msg),
|
2016-06-23 07:37:02 +02:00
|
|
|
STRING_REP_ULONG "/" STRING_REP_ULONG ": %s %s...\n",
|
2017-05-22 06:07:27 +01:00
|
|
|
#if defined(_WIN32) || defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L && !defined(VITA) &&!defined(WIIU)
|
2015-11-19 13:43:48 +01:00
|
|
|
db->list_ptr,
|
|
|
|
db->list->size,
|
2016-02-25 22:26:48 +01:00
|
|
|
#else
|
|
|
|
(unsigned long)db->list_ptr,
|
|
|
|
(unsigned long)db->list->size,
|
2016-06-23 07:37:02 +02:00
|
|
|
#endif
|
2016-02-25 22:26:48 +01:00
|
|
|
msg_hash_to_str(MSG_SCANNING),
|
|
|
|
name);
|
2015-05-23 21:56:17 +02:00
|
|
|
|
2015-12-26 07:23:13 +01:00
|
|
|
if (!string_is_empty(msg))
|
2016-12-22 23:36:11 +01:00
|
|
|
runloop_msg_queue_push(msg, 1, 180, true);
|
2015-05-23 21:56:17 +02:00
|
|
|
|
2015-06-09 21:10:57 +02:00
|
|
|
#if 0
|
2015-05-23 21:56:17 +02:00
|
|
|
RARCH_LOG("msg: %s\n", msg);
|
2015-06-09 21:10:57 +02:00
|
|
|
#endif
|
2015-05-23 21:56:17 +02:00
|
|
|
|
2015-07-08 01:01:41 +02:00
|
|
|
|
2015-05-23 21:56:17 +02:00
|
|
|
db->status = DATABASE_STATUS_ITERATE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-16 22:31:58 -07:00
|
|
|
static int stream_get_serial(database_state_handle_t *db_state,
|
|
|
|
database_info_handle_t *db, intfstream_t *fd, char* serial)
|
2015-09-22 15:22:15 +02:00
|
|
|
{
|
|
|
|
const char* system_name = NULL;
|
|
|
|
|
2017-07-30 10:11:41 +02:00
|
|
|
/* Check if the system was not auto-detected. */
|
2017-09-16 22:31:58 -07:00
|
|
|
if (detect_system(fd, &system_name) < 0)
|
2017-07-29 23:23:05 -04:00
|
|
|
{
|
2017-07-30 10:11:41 +02:00
|
|
|
/* Attempt to read an ASCII serial, like Wii. */
|
2017-09-16 22:31:58 -07:00
|
|
|
if (detect_serial_ascii_game(fd, serial))
|
2017-07-29 23:23:05 -04:00
|
|
|
{
|
2017-07-30 10:11:41 +02:00
|
|
|
/* ASCII serial (Wii) was detected. */
|
2017-09-18 15:57:05 +02:00
|
|
|
RARCH_LOG("%s '%s'\n",
|
|
|
|
msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial);
|
2017-07-29 23:23:05 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-30 10:11:41 +02:00
|
|
|
/* Any other non-system specific detection methods? */
|
2017-07-29 23:23:05 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2015-09-22 15:22:15 +02:00
|
|
|
|
2017-05-16 03:20:39 +02:00
|
|
|
if (string_is_equal_fast(system_name, "psp", 3))
|
2015-09-27 02:14:24 +02:00
|
|
|
{
|
2017-09-16 22:31:58 -07:00
|
|
|
if (detect_psp_game(fd, serial) == 0)
|
2015-09-27 02:14:24 +02:00
|
|
|
return 0;
|
2016-06-30 05:58:05 +02:00
|
|
|
RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial);
|
2015-09-27 02:14:24 +02:00
|
|
|
}
|
2017-05-16 03:20:39 +02:00
|
|
|
else if (string_is_equal_fast(system_name, "ps1", 3))
|
2015-09-22 15:22:15 +02:00
|
|
|
{
|
2017-09-16 22:31:58 -07:00
|
|
|
if (detect_ps1_game(fd, serial) == 0)
|
2015-09-22 15:22:15 +02:00
|
|
|
return 0;
|
2016-06-30 05:58:05 +02:00
|
|
|
RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial);
|
2015-09-22 15:22:15 +02:00
|
|
|
}
|
2017-09-16 22:31:58 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2015-09-22 15:22:15 +02:00
|
|
|
|
2017-09-16 22:31:58 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int iso_get_serial(database_state_handle_t *db_state,
|
|
|
|
database_info_handle_t *db, const char *name, char* serial)
|
|
|
|
{
|
|
|
|
intfstream_t *fd = open_file(name);
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (!fd)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rv = stream_get_serial(db_state, db, fd, serial);
|
|
|
|
intfstream_close(fd);
|
2017-09-18 15:57:05 +02:00
|
|
|
free(fd);
|
2017-09-16 22:31:58 -07:00
|
|
|
return rv;
|
2015-09-22 15:22:15 +02:00
|
|
|
}
|
|
|
|
|
2015-09-27 02:14:24 +02:00
|
|
|
static int cue_get_serial(database_state_handle_t *db_state,
|
2015-09-27 00:12:17 +02:00
|
|
|
database_info_handle_t *db, const char *name, char* serial)
|
|
|
|
{
|
2017-09-12 05:26:38 +02:00
|
|
|
char *track_path = (char*)malloc(PATH_MAX_LENGTH
|
|
|
|
* sizeof(char));
|
2017-09-12 05:00:22 +02:00
|
|
|
int ret = 0;
|
2016-06-03 05:24:14 +02:00
|
|
|
int32_t offset = 0;
|
2016-10-09 09:56:03 +02:00
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
track_path[0] = '\0';
|
2016-10-12 16:14:00 -04:00
|
|
|
|
2017-09-12 05:26:38 +02:00
|
|
|
rv = find_first_data_track(name,
|
2016-06-30 05:58:05 +02:00
|
|
|
&offset, track_path, PATH_MAX_LENGTH);
|
2016-09-18 00:38:59 -04:00
|
|
|
|
2015-09-27 02:14:24 +02:00
|
|
|
if (rv < 0)
|
|
|
|
{
|
2016-06-30 05:58:05 +02:00
|
|
|
RARCH_LOG("%s: %s\n",
|
|
|
|
msg_hash_to_str(MSG_COULD_NOT_FIND_VALID_DATA_TRACK),
|
|
|
|
strerror(-rv));
|
2017-09-12 05:26:38 +02:00
|
|
|
free(track_path);
|
2017-09-16 22:31:58 -07:00
|
|
|
return 0;
|
2015-09-27 02:14:24 +02:00
|
|
|
}
|
2015-09-27 00:12:17 +02:00
|
|
|
|
2016-06-30 05:58:05 +02:00
|
|
|
RARCH_LOG("%s\n", msg_hash_to_str(MSG_READING_FIRST_DATA_TRACK));
|
2015-09-27 00:12:17 +02:00
|
|
|
|
2017-09-12 05:00:22 +02:00
|
|
|
ret = iso_get_serial(db_state, db, track_path, serial);
|
|
|
|
free(track_path);
|
|
|
|
|
|
|
|
return ret;
|
2015-09-27 00:12:17 +02:00
|
|
|
}
|
|
|
|
|
2017-09-16 22:31:58 -07:00
|
|
|
static int chd_get_serial(database_state_handle_t *db_state,
|
|
|
|
database_info_handle_t *db, const char *name, char* serial)
|
|
|
|
{
|
|
|
|
intfstream_t *fd = NULL;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
fd = open_chd_track(name, CHDSTREAM_TRACK_FIRST_DATA);
|
|
|
|
if (!fd)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = stream_get_serial(db_state, db, fd, serial);
|
|
|
|
intfstream_close(fd);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-04-15 05:28:44 +07: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);
|
|
|
|
|
|
|
|
if (read_from != 1 || ret <= 0)
|
|
|
|
return 0;
|
|
|
|
|
2016-09-21 02:17:32 +02:00
|
|
|
*crc = encoding_crc32(0, db_state->buf, ret);
|
2016-04-15 05:28:44 +07:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-09-16 22:31:58 -07:00
|
|
|
static bool chd_get_crc(database_state_handle_t *db_state,
|
|
|
|
const char *name, uint32_t *crc)
|
|
|
|
{
|
|
|
|
intfstream_t *fd = NULL;
|
|
|
|
uint32_t acc = 0;
|
|
|
|
uint8_t buffer[4096];
|
|
|
|
ssize_t size;
|
|
|
|
|
|
|
|
fd = open_chd_track(name, CHDSTREAM_TRACK_FIRST_DATA);
|
|
|
|
if (!fd)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((size = intfstream_read(fd, buffer, sizeof(buffer))) > 0)
|
|
|
|
{
|
|
|
|
acc = encoding_crc32(acc, buffer, size);
|
|
|
|
}
|
|
|
|
if (size < 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RARCH_LOG("CHD '%s' crc: %x\n", name, acc);
|
|
|
|
|
|
|
|
*crc = acc;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-05-13 10:19:53 +02:00
|
|
|
static int task_database_iterate_playlist(
|
2015-05-23 21:56:17 +02:00
|
|
|
database_state_handle_t *db_state,
|
2015-05-05 18:43:51 +02:00
|
|
|
database_info_handle_t *db, const char *name)
|
|
|
|
{
|
2016-06-20 17:55:34 +02:00
|
|
|
switch (msg_hash_to_file_type(msg_hash_calculate(path_get_extension(name))))
|
2015-05-05 18:43:51 +02:00
|
|
|
{
|
2016-06-20 17:55:34 +02:00
|
|
|
case FILE_TYPE_COMPRESSED:
|
2016-09-18 00:38:59 -04:00
|
|
|
#ifdef HAVE_COMPRESSION
|
2016-09-29 10:43:38 +02:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
|
2016-09-25 00:13:33 -04:00
|
|
|
/* first check crc of archive itself */
|
2016-09-18 00:38:59 -04:00
|
|
|
return file_get_crc(db_state, name, &db_state->archive_crc);
|
2016-06-20 17:55:34 +02:00
|
|
|
#else
|
|
|
|
break;
|
2015-05-05 18:43:51 +02:00
|
|
|
#endif
|
2016-06-20 17:55:34 +02:00
|
|
|
case FILE_TYPE_CUE:
|
2015-09-25 00:36:12 +02:00
|
|
|
db_state->serial[0] = '\0';
|
2017-09-16 22:31:58 -07:00
|
|
|
if (cue_get_serial(db_state, db, name, db_state->serial))
|
|
|
|
{
|
|
|
|
database_info_set_type(db, DATABASE_TYPE_SERIAL_LOOKUP);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
|
|
|
|
return file_get_crc(db_state, name, &db_state->crc);
|
|
|
|
}
|
2016-06-20 17:55:34 +02:00
|
|
|
break;
|
|
|
|
case FILE_TYPE_ISO:
|
2015-09-27 00:12:17 +02:00
|
|
|
db_state->serial[0] = '\0';
|
|
|
|
iso_get_serial(db_state, db, name, db_state->serial);
|
2016-09-29 10:43:38 +02:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_SERIAL_LOOKUP);
|
2015-06-14 17:11:48 +02:00
|
|
|
break;
|
2017-09-16 22:31:58 -07:00
|
|
|
case FILE_TYPE_CHD:
|
|
|
|
db_state->serial[0] = '\0';
|
|
|
|
if (chd_get_serial(db_state, db, name, db_state->serial))
|
|
|
|
{
|
|
|
|
database_info_set_type(db, DATABASE_TYPE_SERIAL_LOOKUP);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
|
|
|
|
return chd_get_crc(db_state, name, &db_state->crc);
|
|
|
|
}
|
|
|
|
break;
|
2016-06-29 15:07:12 +02:00
|
|
|
case FILE_TYPE_LUTRO:
|
2016-09-29 10:43:38 +02:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_ITERATE_LUTRO);
|
2016-06-29 15:07:12 +02:00
|
|
|
break;
|
2016-06-20 17:55:34 +02:00
|
|
|
default:
|
2016-09-29 10:43:38 +02:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
|
2016-06-20 17:55:34 +02:00
|
|
|
return file_get_crc(db_state, name, &db_state->crc);
|
2015-05-05 18:43:51 +02:00
|
|
|
}
|
|
|
|
|
2015-06-15 22:48:41 +02:00
|
|
|
return 1;
|
2015-05-23 20:53:43 +02:00
|
|
|
}
|
|
|
|
|
2016-02-04 10:25:22 +01:00
|
|
|
static int database_info_list_iterate_end_no_match(
|
|
|
|
database_state_handle_t *db_state)
|
2015-05-27 01:36:15 +02:00
|
|
|
{
|
2016-09-18 00:38:59 -04:00
|
|
|
/* Reached end of database list,
|
2016-02-04 10:25:22 +01:00
|
|
|
* CRC match probably didn't succeed. */
|
2015-05-27 03:23:27 +02:00
|
|
|
db_state->list_index = 0;
|
|
|
|
db_state->entry_index = 0;
|
2015-05-27 01:36:15 +02:00
|
|
|
|
2015-05-27 03:23:27 +02:00
|
|
|
if (db_state->crc != 0)
|
|
|
|
db_state->crc = 0;
|
2016-04-15 05:28:44 +07:00
|
|
|
|
2015-05-27 03:23:27 +02:00
|
|
|
return 0;
|
2015-05-27 01:36:15 +02:00
|
|
|
}
|
|
|
|
|
2016-05-13 10:19:53 +02:00
|
|
|
static int task_database_iterate_next(database_info_handle_t *db)
|
2015-05-23 20:53:43 +02:00
|
|
|
{
|
2015-05-05 18:43:51 +02:00
|
|
|
db->list_ptr++;
|
|
|
|
|
2015-05-23 19:18:56 +02:00
|
|
|
if (db->list_ptr < db->list->size)
|
|
|
|
return 0;
|
|
|
|
return -1;
|
2015-05-05 18:43:51 +02:00
|
|
|
}
|
|
|
|
|
2016-02-04 10:25:22 +01:00
|
|
|
static int database_info_list_iterate_new(database_state_handle_t *db_state,
|
|
|
|
const char *query)
|
2015-05-25 07:54:44 +02:00
|
|
|
{
|
2016-09-29 11:03:59 +02:00
|
|
|
const char *new_database = database_info_get_current_name(db_state);
|
2016-10-03 16:08:55 -04:00
|
|
|
|
2015-06-09 21:10:57 +02:00
|
|
|
#if 0
|
2016-09-18 00:38:59 -04:00
|
|
|
RARCH_LOG("Check database [%d/%d] : %s\n", (unsigned)db_state->list_index,
|
2015-05-25 07:54:44 +02:00
|
|
|
(unsigned)db_state->list->size, new_database);
|
2015-06-09 21:10:57 +02:00
|
|
|
#endif
|
2015-05-28 01:25:42 +02:00
|
|
|
if (db_state->info)
|
2016-09-25 05:55:55 +02:00
|
|
|
{
|
2015-05-28 01:25:42 +02:00
|
|
|
database_info_list_free(db_state->info);
|
2016-09-25 05:55:55 +02:00
|
|
|
free(db_state->info);
|
|
|
|
}
|
2015-06-10 14:51:26 -03:00
|
|
|
db_state->info = database_info_list_new(new_database, query);
|
2015-05-25 07:54:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-25 18:46:16 +02:00
|
|
|
static int database_info_list_iterate_found_match(
|
2016-12-31 07:03:29 +01:00
|
|
|
db_handle_t *_db,
|
2015-05-25 18:46:16 +02:00
|
|
|
database_state_handle_t *db_state,
|
2015-05-27 04:42:22 +02:00
|
|
|
database_info_handle_t *db,
|
2016-09-18 00:38:59 -04:00
|
|
|
const char *archive_name
|
2015-05-25 18:46:16 +02:00
|
|
|
)
|
|
|
|
{
|
2017-09-12 05:00:22 +02:00
|
|
|
char *db_crc = (char*)malloc(128 * sizeof(char));
|
|
|
|
char *db_playlist_base_str = (char*)malloc(128 * sizeof(char));
|
|
|
|
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 11:03:59 +02:00
|
|
|
database_info_get_current_name(db_state);
|
2017-09-12 05:00:22 +02:00
|
|
|
const char *entry_path =
|
2016-09-29 10:59:50 +02:00
|
|
|
database_info_get_current_element_name(db);
|
2017-09-12 05:00:22 +02:00
|
|
|
database_info_t *db_info_entry =
|
2016-06-30 06:07:44 +02:00
|
|
|
&db_state->info->list[db_state->entry_index];
|
2015-05-25 18:46:16 +02:00
|
|
|
|
2016-10-08 18:31:43 +02:00
|
|
|
db_crc[0] = '\0';
|
|
|
|
db_playlist_path[0] = '\0';
|
|
|
|
db_playlist_base_str[0] = '\0';
|
|
|
|
entry_path_str[0] = '\0';
|
|
|
|
|
2016-06-28 13:05:46 +02:00
|
|
|
fill_short_pathname_representation_noext(db_playlist_base_str,
|
2017-09-12 05:00:22 +02:00
|
|
|
db_path, 128 * sizeof(char));
|
2015-05-26 00:25:07 +02:00
|
|
|
|
2016-06-26 10:12:28 +02:00
|
|
|
strlcat(db_playlist_base_str,
|
|
|
|
file_path_str(FILE_PATH_LPL_EXTENSION),
|
2017-09-12 05:00:22 +02:00
|
|
|
128 * sizeof(char));
|
2016-12-31 07:03:29 +01:00
|
|
|
fill_pathname_join(db_playlist_path, _db->playlist_directory,
|
2017-09-12 05:00:22 +02:00
|
|
|
db_playlist_base_str, PATH_MAX_LENGTH * sizeof(char));
|
2015-05-25 18:46:16 +02:00
|
|
|
|
2016-05-16 09:07:44 +02:00
|
|
|
playlist = playlist_init(db_playlist_path, COLLECTION_SIZE);
|
2015-05-25 18:46:16 +02:00
|
|
|
|
2017-09-12 05:00:22 +02:00
|
|
|
snprintf(db_crc, 128 * sizeof(char),
|
|
|
|
"%08X|crc", db_info_entry->crc32);
|
2015-05-25 21:39:50 +02:00
|
|
|
|
2016-06-01 04:05:14 +02:00
|
|
|
if (entry_path)
|
2017-09-12 05:00:22 +02:00
|
|
|
strlcpy(entry_path_str, entry_path, 128 * sizeof(char));
|
2015-06-22 19:51:13 +02:00
|
|
|
|
2016-09-18 00:38:59 -04:00
|
|
|
if (!string_is_empty(archive_name))
|
2017-09-12 05:00:22 +02:00
|
|
|
fill_pathname_join_delim(entry_path_str,
|
|
|
|
entry_path_str, archive_name,
|
|
|
|
'#', 128 * sizeof(char));
|
2015-05-27 04:42:22 +02:00
|
|
|
|
2015-05-27 07:23:09 +02: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 00:38:59 -04:00
|
|
|
RARCH_LOG("ZIP entry: %s\n", archive_name);
|
2015-05-27 07:23:09 +02:00
|
|
|
RARCH_LOG("entry path str: %s\n", entry_path_str);
|
|
|
|
#endif
|
|
|
|
|
2016-05-16 09:07:44 +02:00
|
|
|
if(!playlist_entry_exists(playlist, entry_path_str, db_crc))
|
2016-01-26 15:21:01 -05:00
|
|
|
{
|
2016-05-16 09:07:44 +02:00
|
|
|
playlist_push(playlist, entry_path_str,
|
2016-06-30 06:07:44 +02:00
|
|
|
db_info_entry->name,
|
|
|
|
file_path_str(FILE_PATH_DETECT),
|
|
|
|
file_path_str(FILE_PATH_DETECT),
|
2016-02-04 10:25:22 +01:00
|
|
|
db_crc, db_playlist_base_str);
|
2016-01-26 15:21:01 -05:00
|
|
|
}
|
2015-05-25 18:46:16 +02:00
|
|
|
|
2016-05-16 09:07:44 +02:00
|
|
|
playlist_write_file(playlist);
|
|
|
|
playlist_free(playlist);
|
2015-11-14 19:42:56 -03:00
|
|
|
|
|
|
|
database_info_list_free(db_state->info);
|
2016-09-25 05:55:55 +02:00
|
|
|
free(db_state->info);
|
2016-01-26 15:24:17 -05:00
|
|
|
|
2015-11-14 19:42:56 -03:00
|
|
|
db_state->info = NULL;
|
|
|
|
db_state->crc = 0;
|
2016-01-26 15:24:17 -05:00
|
|
|
|
2017-09-12 05:00:22 +02:00
|
|
|
free(entry_path_str);
|
|
|
|
free(db_playlist_path);
|
|
|
|
free(db_playlist_base_str);
|
|
|
|
free(db_crc);
|
|
|
|
|
2015-05-25 18:46:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-18 00:38:59 -04:00
|
|
|
/* End of entries in database info list and didn't find a
|
2015-05-27 03:23:27 +02: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 02:55:39 +02:00
|
|
|
|
2015-05-27 03:23:27 +02:00
|
|
|
database_info_list_free(db_state->info);
|
2016-09-25 05:55:55 +02:00
|
|
|
free(db_state->info);
|
2015-05-28 02:55:39 +02:00
|
|
|
db_state->info = NULL;
|
2015-05-27 03:23:27 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-05-13 10:19:53 +02:00
|
|
|
static int task_database_iterate_crc_lookup(
|
2016-12-31 07:03:29 +01:00
|
|
|
db_handle_t *_db,
|
2015-05-25 03:20:43 +02:00
|
|
|
database_state_handle_t *db_state,
|
2015-05-27 04:42:22 +02:00
|
|
|
database_info_handle_t *db,
|
2016-10-03 16:08:55 -04:00
|
|
|
const char *name,
|
2016-09-19 18:38:33 -04:00
|
|
|
const char *archive_entry)
|
2015-05-25 03:20:43 +02:00
|
|
|
{
|
2015-05-25 07:05:00 +02:00
|
|
|
|
2016-09-18 00:38:59 -04:00
|
|
|
if (!db_state->list ||
|
2016-02-04 10:25:22 +01:00
|
|
|
(unsigned)db_state->list_index == (unsigned)db_state->list->size)
|
2015-05-25 07:54:44 +02:00
|
|
|
return database_info_list_iterate_end_no_match(db_state);
|
2015-05-25 07:05:00 +02:00
|
|
|
|
|
|
|
if (db_state->entry_index == 0)
|
2015-06-10 14:51:26 -03:00
|
|
|
{
|
2016-10-12 16:14:00 -04:00
|
|
|
bool db_supports_content;
|
|
|
|
bool unsupported_content;
|
2016-10-09 09:56:03 +02:00
|
|
|
char query[50];
|
|
|
|
|
|
|
|
query[0] = '\0';
|
2016-10-03 16:08:55 -04:00
|
|
|
|
2016-12-04 19:12:25 +01:00
|
|
|
db_supports_content = core_info_database_supports_content_path(
|
|
|
|
db_state->list->elems[db_state->list_index].data, name);
|
2016-10-12 16:14:00 -04:00
|
|
|
unsupported_content = core_info_unsupported_content_path(name);
|
|
|
|
|
|
|
|
/* don't scan files that can't be in this database */
|
2017-09-06 20:49:47 -07:00
|
|
|
if(!db_supports_content || unsupported_content)
|
2016-10-03 16:08:55 -04:00
|
|
|
return database_info_list_iterate_next(db_state);
|
|
|
|
|
2016-02-04 10:25:22 +01:00
|
|
|
snprintf(query, sizeof(query),
|
2016-04-15 05:28:44 +07:00
|
|
|
"{crc:or(b\"%08X\",b\"%08X\")}",
|
2017-05-22 05:26:13 +01:00
|
|
|
db_state->crc, db_state->archive_crc);
|
2015-06-10 14:51:26 -03:00
|
|
|
|
|
|
|
database_info_list_iterate_new(db_state, query);
|
|
|
|
}
|
2015-05-25 05:36:23 +02:00
|
|
|
|
2015-05-25 07:05:00 +02:00
|
|
|
if (db_state->info)
|
|
|
|
{
|
2016-09-18 00:38:59 -04:00
|
|
|
database_info_t *db_info_entry =
|
2016-02-04 10:25:22 +01:00
|
|
|
&db_state->info->list[db_state->entry_index];
|
2015-05-25 07:05:00 +02:00
|
|
|
|
2015-06-09 20:13:03 -03:00
|
|
|
if (db_info_entry && db_info_entry->crc32)
|
2015-05-25 07:05:00 +02:00
|
|
|
{
|
2015-05-25 07:54:44 +02:00
|
|
|
#if 0
|
2015-06-09 20:13:03 -03:00
|
|
|
RARCH_LOG("CRC32: 0x%08X , entry CRC32: 0x%08X (%s).\n",
|
2016-02-04 10:25:22 +01:00
|
|
|
db_state->crc, db_info_entry->crc32, db_info_entry->name);
|
2015-05-25 07:54:44 +02:00
|
|
|
#endif
|
2016-09-18 00:38:59 -04:00
|
|
|
if (db_state->archive_crc == db_info_entry->crc32)
|
2016-04-15 05:55:11 +07:00
|
|
|
return database_info_list_iterate_found_match(
|
2016-12-31 07:03:29 +01:00
|
|
|
_db,
|
2016-04-15 05:55:11 +07:00
|
|
|
db_state, db, NULL);
|
|
|
|
if (db_state->crc == db_info_entry->crc32)
|
2016-02-04 10:25:22 +01:00
|
|
|
return database_info_list_iterate_found_match(
|
2016-12-31 07:03:29 +01:00
|
|
|
_db,
|
2016-09-19 18:38:33 -04:00
|
|
|
db_state, db, archive_entry);
|
2015-05-25 07:05:00 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-25 05:36:23 +02:00
|
|
|
|
|
|
|
db_state->entry_index++;
|
|
|
|
|
2016-06-02 20:40:39 +02: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 07:05:00 +02:00
|
|
|
|
2016-05-17 14:24:43 +02:00
|
|
|
/* If we haven't reached the end of the database list yet,
|
|
|
|
* continue iterating. */
|
2015-05-25 07:05:00 +02:00
|
|
|
if (db_state->list_index < db_state->list->size)
|
|
|
|
return 1;
|
|
|
|
|
2016-05-26 17:47:21 +02:00
|
|
|
database_info_list_free(db_state->info);
|
2016-10-03 16:08:55 -04:00
|
|
|
|
|
|
|
if (db_state->info)
|
|
|
|
free(db_state->info);
|
|
|
|
|
2015-05-25 03:20:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-18 00:38:59 -04:00
|
|
|
static int task_database_iterate_playlist_archive(
|
2016-12-31 07:03:29 +01:00
|
|
|
db_handle_t *_db,
|
2015-05-27 03:23:27 +02:00
|
|
|
database_state_handle_t *db_state,
|
|
|
|
database_info_handle_t *db, const char *name)
|
|
|
|
{
|
2016-09-18 12:31:24 -04:00
|
|
|
#ifdef HAVE_COMPRESSION
|
2015-05-27 03:23:27 +02:00
|
|
|
if (db_state->crc != 0)
|
2016-05-13 10:19:53 +02:00
|
|
|
return task_database_iterate_crc_lookup(
|
2016-12-31 07:03:29 +01:00
|
|
|
_db, db_state, db, name, db_state->archive_name);
|
2016-02-03 17:31:19 +01:00
|
|
|
|
2016-09-25 00:13:33 -04:00
|
|
|
db_state->crc = file_archive_get_file_crc32(name);
|
2015-05-27 03:23:27 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-06-29 15:07:12 +02:00
|
|
|
static int task_database_iterate_playlist_lutro(
|
2016-12-31 07:03:29 +01:00
|
|
|
db_handle_t *_db,
|
2016-06-29 15:07:12 +02:00
|
|
|
database_state_handle_t *db_state,
|
|
|
|
database_info_handle_t *db,
|
|
|
|
const char *path)
|
|
|
|
{
|
2017-09-12 05:00:22 +02:00
|
|
|
char *db_playlist_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
|
|
|
playlist_t *playlist = NULL;
|
2016-06-29 15:07:12 +02:00
|
|
|
|
2017-09-12 05:00:22 +02:00
|
|
|
db_playlist_path[0] = '\0';
|
2016-10-08 18:31:43 +02:00
|
|
|
|
2016-06-30 05:19:25 +02:00
|
|
|
fill_pathname_join(db_playlist_path,
|
2016-12-31 07:03:29 +01:00
|
|
|
_db->playlist_directory,
|
2016-06-30 05:19:25 +02:00
|
|
|
file_path_str(FILE_PATH_LUTRO_PLAYLIST),
|
2017-09-12 05:00:22 +02:00
|
|
|
PATH_MAX_LENGTH * sizeof(char));
|
2016-06-29 15:07:12 +02:00
|
|
|
|
|
|
|
playlist = playlist_init(db_playlist_path, COLLECTION_SIZE);
|
|
|
|
|
2017-09-12 05:00:22 +02:00
|
|
|
free(db_playlist_path);
|
|
|
|
|
|
|
|
if(!playlist_entry_exists(playlist,
|
|
|
|
path, file_path_str(FILE_PATH_DETECT)))
|
2016-06-29 15:07:12 +02:00
|
|
|
{
|
2017-09-12 05:00:22 +02:00
|
|
|
char *game_title = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
2016-10-08 18:31:43 +02:00
|
|
|
|
|
|
|
game_title[0] = '\0';
|
2016-06-30 06:07:44 +02:00
|
|
|
|
|
|
|
fill_short_pathname_representation_noext(game_title,
|
2017-09-12 05:00:22 +02:00
|
|
|
path, PATH_MAX_LENGTH * sizeof(char));
|
2016-06-30 06:07:44 +02:00
|
|
|
|
2016-06-29 15:07:12 +02:00
|
|
|
playlist_push(playlist, path,
|
2016-06-30 05:19:25 +02:00
|
|
|
game_title,
|
2016-06-30 06:07:44 +02:00
|
|
|
file_path_str(FILE_PATH_DETECT),
|
|
|
|
file_path_str(FILE_PATH_DETECT),
|
|
|
|
file_path_str(FILE_PATH_DETECT),
|
2016-06-30 05:19:25 +02:00
|
|
|
file_path_str(FILE_PATH_LUTRO_PLAYLIST));
|
2017-09-12 05:00:22 +02:00
|
|
|
|
|
|
|
free(game_title);
|
2016-06-29 15:07:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
playlist_write_file(playlist);
|
|
|
|
playlist_free(playlist);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-13 10:19:53 +02:00
|
|
|
static int task_database_iterate_serial_lookup(
|
2016-12-31 07:03:29 +01:00
|
|
|
db_handle_t *_db,
|
2015-09-16 22:11:08 +02:00
|
|
|
database_state_handle_t *db_state,
|
|
|
|
database_info_handle_t *db, const char *name)
|
|
|
|
{
|
2016-09-18 00:38:59 -04:00
|
|
|
if (!db_state->list ||
|
2016-02-04 10:25:22 +01:00
|
|
|
(unsigned)db_state->list_index == (unsigned)db_state->list->size)
|
2015-09-22 15:22:15 +02:00
|
|
|
return database_info_list_iterate_end_no_match(db_state);
|
2015-09-16 22:11:08 +02:00
|
|
|
|
2015-09-22 15:22:15 +02:00
|
|
|
if (db_state->entry_index == 0)
|
2015-09-16 22:11:08 +02:00
|
|
|
{
|
2016-10-09 09:56:03 +02:00
|
|
|
char query[50];
|
2016-09-18 00:38:59 -04:00
|
|
|
char *serial_buf =
|
2016-02-04 10:25:22 +01:00
|
|
|
bin_to_hex_alloc((uint8_t*)db_state->serial, 10 * sizeof(uint8_t));
|
2015-09-28 17:18:48 +02:00
|
|
|
|
|
|
|
if (!serial_buf)
|
|
|
|
return 1;
|
2015-09-22 15:22:15 +02:00
|
|
|
|
2016-10-09 09:56:03 +02:00
|
|
|
query[0] = '\0';
|
|
|
|
|
2015-09-28 17:18:48 +02:00
|
|
|
snprintf(query, sizeof(query), "{'serial': b'%s'}", serial_buf);
|
2015-09-22 15:22:15 +02:00
|
|
|
database_info_list_iterate_new(db_state, query);
|
2015-09-28 17:18:48 +02:00
|
|
|
|
|
|
|
free(serial_buf);
|
2015-09-16 22:11:08 +02:00
|
|
|
}
|
|
|
|
|
2015-09-22 15:22:15 +02:00
|
|
|
if (db_state->info)
|
|
|
|
{
|
2016-02-04 10:25:22 +01:00
|
|
|
database_info_t *db_info_entry = &db_state->info->list[
|
|
|
|
db_state->entry_index];
|
2015-09-16 22:11:08 +02:00
|
|
|
|
2015-09-22 15:22:15 +02:00
|
|
|
if (db_info_entry && db_info_entry->serial)
|
|
|
|
{
|
2015-09-24 14:14:42 +02:00
|
|
|
#if 0
|
2015-09-22 15:22:15 +02:00
|
|
|
RARCH_LOG("serial: %s , entry serial: %s (%s).\n",
|
2016-02-04 10:25:22 +01:00
|
|
|
db_state->serial, db_info_entry->serial,
|
|
|
|
db_info_entry->name);
|
2015-09-22 15:22:15 +02:00
|
|
|
#endif
|
2016-01-20 04:07:24 +01:00
|
|
|
if (string_is_equal(db_state->serial, db_info_entry->serial))
|
2016-12-31 07:03:29 +01:00
|
|
|
return database_info_list_iterate_found_match(_db,
|
|
|
|
db_state, db, NULL);
|
2015-09-22 15:22:15 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-16 22:11:08 +02:00
|
|
|
|
2015-09-22 15:22:15 +02:00
|
|
|
db_state->entry_index++;
|
2015-09-16 22:11:08 +02:00
|
|
|
|
2016-06-02 20:40:39 +02: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 15:22:15 +02:00
|
|
|
|
2016-05-17 14:24:43 +02:00
|
|
|
/* If we haven't reached the end of the database list yet,
|
|
|
|
* continue iterating. */
|
2015-09-22 15:22:15 +02:00
|
|
|
if (db_state->list_index < db_state->list->size)
|
|
|
|
return 1;
|
2015-09-16 22:11:08 +02:00
|
|
|
|
2016-05-26 17:47:21 +02:00
|
|
|
database_info_list_free(db_state->info);
|
2016-09-25 05:55:55 +02:00
|
|
|
free(db_state->info);
|
2015-09-16 22:11:08 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-31 07:03:29 +01:00
|
|
|
static int task_database_iterate(
|
|
|
|
db_handle_t *_db,
|
|
|
|
database_state_handle_t *db_state,
|
2016-02-04 10:25:22 +01:00
|
|
|
database_info_handle_t *db)
|
2015-05-05 18:43:51 +02:00
|
|
|
{
|
2016-09-29 11:07:56 +02:00
|
|
|
const char *name = database_info_get_current_element_name(db);
|
2016-09-29 10:55:50 +02:00
|
|
|
|
2015-05-05 18:43:51 +02:00
|
|
|
if (!name)
|
|
|
|
return 0;
|
|
|
|
|
2016-09-29 10:41:30 +02:00
|
|
|
if (database_info_get_type(db) == DATABASE_TYPE_ITERATE)
|
2016-09-25 00:13:33 -04:00
|
|
|
if (path_contains_compressed_file(name))
|
2016-09-29 10:43:38 +02:00
|
|
|
database_info_set_type(db, DATABASE_TYPE_ITERATE_ARCHIVE);
|
2016-09-25 00:13:33 -04:00
|
|
|
|
2016-09-29 10:41:30 +02:00
|
|
|
switch (database_info_get_type(db))
|
2015-05-05 18:43:51 +02:00
|
|
|
{
|
2015-05-23 16:41:33 +02:00
|
|
|
case DATABASE_TYPE_ITERATE:
|
2016-05-13 10:19:53 +02:00
|
|
|
return task_database_iterate_playlist(db_state, db, name);
|
2016-09-18 00:38:59 -04:00
|
|
|
case DATABASE_TYPE_ITERATE_ARCHIVE:
|
2016-12-31 07:03:29 +01:00
|
|
|
return task_database_iterate_playlist_archive(_db, db_state, db, name);
|
2016-06-29 15:07:12 +02:00
|
|
|
case DATABASE_TYPE_ITERATE_LUTRO:
|
2016-12-31 07:03:29 +01:00
|
|
|
return task_database_iterate_playlist_lutro(_db, db_state, db, name);
|
2015-09-22 15:22:15 +02:00
|
|
|
case DATABASE_TYPE_SERIAL_LOOKUP:
|
2016-12-31 07:03:29 +01:00
|
|
|
return task_database_iterate_serial_lookup(_db, db_state, db, name);
|
2015-05-25 03:20:43 +02:00
|
|
|
case DATABASE_TYPE_CRC_LOOKUP:
|
2016-12-31 07:03:29 +01:00
|
|
|
return task_database_iterate_crc_lookup(_db, db_state, db, name, NULL);
|
2016-02-04 10:25:22 +01:00
|
|
|
case DATABASE_TYPE_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-05 18:43:51 +02:00
|
|
|
}
|
2016-02-04 10:25:22 +01:00
|
|
|
|
2015-05-05 18:43:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-13 10:19:53 +02:00
|
|
|
static void task_database_cleanup_state(
|
2016-02-04 10:25:22 +01:00
|
|
|
database_state_handle_t *db_state)
|
2015-05-23 22:52:22 +02:00
|
|
|
{
|
2015-05-25 03:46:03 +02:00
|
|
|
if (!db_state)
|
2015-05-23 22:52:22 +02:00
|
|
|
return;
|
|
|
|
|
2015-05-25 03:46:03 +02:00
|
|
|
if (db_state->buf)
|
|
|
|
free(db_state->buf);
|
|
|
|
db_state->buf = NULL;
|
2015-05-23 22:52:22 +02:00
|
|
|
}
|
|
|
|
|
2016-05-13 10:19:53 +02:00
|
|
|
static void task_database_handler(retro_task_t *task)
|
2015-05-05 18:05:59 +02:00
|
|
|
{
|
2016-09-29 10:55:50 +02: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 16:14:00 -04:00
|
|
|
|
2016-09-29 10:55:50 +02:00
|
|
|
if (!task)
|
|
|
|
goto task_finished;
|
2016-10-12 16:14:00 -04:00
|
|
|
|
2016-09-29 10:55:50 +02:00
|
|
|
db = (db_handle_t*)task->state;
|
2015-05-05 18:05:59 +02:00
|
|
|
|
2016-09-29 10:55:50 +02:00
|
|
|
if (!db)
|
|
|
|
goto task_finished;
|
|
|
|
|
2017-07-09 00:44:02 -04:00
|
|
|
if (!db->scan_started)
|
|
|
|
{
|
|
|
|
db->scan_started = true;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
task_free_title(task);
|
|
|
|
|
|
|
|
if (db->handle)
|
|
|
|
db->handle->status = DATABASE_STATUS_ITERATE_BEGIN;
|
|
|
|
}
|
|
|
|
|
2016-09-29 10:55:50 +02:00
|
|
|
dbinfo = db->handle;
|
|
|
|
dbstate = &db->state;
|
2016-10-12 16:14:00 -04:00
|
|
|
|
2016-12-29 00:50:18 -05:00
|
|
|
if (!dbinfo || task_get_cancelled(task))
|
2015-11-22 21:52:56 -03:00
|
|
|
goto task_finished;
|
2015-05-05 18:05:59 +02:00
|
|
|
|
2015-11-22 21:52:56 -03:00
|
|
|
switch (dbinfo->status)
|
2015-05-05 18:05:59 +02:00
|
|
|
{
|
2015-05-24 06:14:44 +02:00
|
|
|
case DATABASE_STATUS_ITERATE_BEGIN:
|
2016-09-29 11:07:56 +02:00
|
|
|
if (dbstate && !dbstate->list)
|
2016-09-29 10:55:50 +02:00
|
|
|
{
|
2016-09-29 11:07:56 +02:00
|
|
|
dbstate->list = dir_list_new_special(
|
2016-12-31 07:03:29 +01:00
|
|
|
db->content_database_path,
|
2016-09-29 11:07:56 +02:00
|
|
|
DIR_LIST_DATABASES, NULL);
|
2016-09-29 10:55:50 +02:00
|
|
|
}
|
2015-11-22 21:52:56 -03:00
|
|
|
dbinfo->status = DATABASE_STATUS_ITERATE_START;
|
2015-05-24 06:14:44 +02:00
|
|
|
break;
|
2015-05-23 21:56:17 +02:00
|
|
|
case DATABASE_STATUS_ITERATE_START:
|
2016-09-29 10:59:50 +02:00
|
|
|
name = database_info_get_current_element_name(dbinfo);
|
2016-05-13 10:19:53 +02:00
|
|
|
task_database_cleanup_state(dbstate);
|
2015-11-22 21:52:56 -03:00
|
|
|
dbstate->list_index = 0;
|
|
|
|
dbstate->entry_index = 0;
|
2016-05-13 10:19:53 +02:00
|
|
|
task_database_iterate_start(dbinfo, name);
|
2015-05-23 21:56:17 +02:00
|
|
|
break;
|
2015-05-05 18:05:59 +02:00
|
|
|
case DATABASE_STATUS_ITERATE:
|
2016-12-31 07:03:29 +01:00
|
|
|
if (task_database_iterate(db, dbstate, dbinfo) == 0)
|
2015-05-25 03:20:43 +02:00
|
|
|
{
|
2015-11-22 21:52:56 -03:00
|
|
|
dbinfo->status = DATABASE_STATUS_ITERATE_NEXT;
|
|
|
|
dbinfo->type = DATABASE_TYPE_ITERATE;
|
2015-05-25 03:20:43 +02:00
|
|
|
}
|
2015-05-23 20:53:43 +02:00
|
|
|
break;
|
|
|
|
case DATABASE_STATUS_ITERATE_NEXT:
|
2016-05-13 10:19:53 +02:00
|
|
|
if (task_database_iterate_next(dbinfo) == 0)
|
2015-05-23 22:52:22 +02:00
|
|
|
{
|
2015-11-22 21:52:56 -03:00
|
|
|
dbinfo->status = DATABASE_STATUS_ITERATE_START;
|
|
|
|
dbinfo->type = DATABASE_TYPE_ITERATE;
|
2015-05-23 22:52:22 +02:00
|
|
|
}
|
2015-05-23 20:53:43 +02:00
|
|
|
else
|
2015-05-23 19:18:56 +02:00
|
|
|
{
|
2016-12-22 23:36:11 +01:00
|
|
|
runloop_msg_queue_push(
|
2016-01-29 14:30:09 +01:00
|
|
|
msg_hash_to_str(MSG_SCANNING_OF_DIRECTORY_FINISHED),
|
|
|
|
0, 180, true);
|
2015-11-22 21:52:56 -03:00
|
|
|
goto task_finished;
|
2015-05-23 19:18:56 +02:00
|
|
|
}
|
2015-05-05 18:05:59 +02:00
|
|
|
break;
|
2015-05-23 18:08:42 +02:00
|
|
|
default:
|
2015-11-22 21:52:56 -03:00
|
|
|
case DATABASE_STATUS_FREE:
|
2015-05-23 18:08:42 +02:00
|
|
|
case DATABASE_STATUS_NONE:
|
2015-11-22 21:52:56 -03:00
|
|
|
goto task_finished;
|
2015-05-23 19:18:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2015-11-22 21:52:56 -03:00
|
|
|
task_finished:
|
2016-09-29 10:55:50 +02:00
|
|
|
if (task)
|
2016-12-29 00:50:18 -05:00
|
|
|
task_set_finished(task, true);
|
2015-05-23 19:18:56 +02:00
|
|
|
|
2016-09-29 10:55:50 +02:00
|
|
|
if (dbstate)
|
|
|
|
{
|
|
|
|
if (dbstate->list)
|
|
|
|
dir_list_free(dbstate->list);
|
|
|
|
}
|
2015-07-08 21:48:58 +02:00
|
|
|
|
2016-09-29 10:55:50 +02:00
|
|
|
if (db)
|
|
|
|
{
|
|
|
|
if (db->state.buf)
|
|
|
|
free(db->state.buf);
|
2015-09-28 23:00:22 +02:00
|
|
|
|
2016-09-29 10:55:50 +02:00
|
|
|
if (db->handle)
|
|
|
|
database_info_free(db->handle);
|
|
|
|
free(db);
|
|
|
|
}
|
2015-07-08 21:48:58 +02:00
|
|
|
|
2016-09-29 10:55:50 +02:00
|
|
|
if (dbinfo)
|
|
|
|
free(dbinfo);
|
2015-07-08 21:48:58 +02:00
|
|
|
}
|
2015-07-08 22:03:23 +02:00
|
|
|
|
2017-01-18 01:23:09 +01:00
|
|
|
bool task_push_dbscan(
|
|
|
|
const char *playlist_directory,
|
|
|
|
const char *content_database,
|
|
|
|
const char *fullpath,
|
2016-02-09 17:47:04 +01:00
|
|
|
bool directory, retro_task_callback_t cb)
|
2015-07-08 22:03:23 +02:00
|
|
|
{
|
2016-12-31 07:03:29 +01: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 03:25:00 +01:00
|
|
|
|
|
|
|
if (!t || !db)
|
|
|
|
goto error;
|
|
|
|
|
2016-05-13 10:19:53 +02:00
|
|
|
t->handler = task_database_handler;
|
2016-01-21 03:25:00 +01:00
|
|
|
t->state = db;
|
|
|
|
t->callback = cb;
|
2017-07-09 00:44:02 -04:00
|
|
|
t->title = strdup(msg_hash_to_str(MSG_PREPARING_FOR_CONTENT_SCAN));
|
|
|
|
|
|
|
|
db->is_directory = directory;
|
2015-11-22 21:52:56 -03:00
|
|
|
|
2017-07-09 00:44:02 -04:00
|
|
|
strlcpy(db->fullpath, fullpath, sizeof(db->fullpath));
|
2017-01-18 01:23:09 +01:00
|
|
|
strlcpy(db->playlist_directory, playlist_directory,
|
2016-12-31 07:03:29 +01:00
|
|
|
sizeof(db->playlist_directory));
|
2017-01-18 01:23:09 +01:00
|
|
|
strlcpy(db->content_database_path, content_database,
|
2016-12-31 07:03:29 +01:00
|
|
|
sizeof(db->content_database_path));
|
|
|
|
|
2017-05-14 20:43:39 +02:00
|
|
|
task_queue_push(t);
|
2015-07-08 22:03:23 +02:00
|
|
|
|
2015-11-22 21:52:56 -03:00
|
|
|
return true;
|
2016-01-21 03:25:00 +01:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (t)
|
|
|
|
free(t);
|
|
|
|
if (db)
|
|
|
|
free(db);
|
|
|
|
return false;
|
2015-07-08 22:03:23 +02:00
|
|
|
}
|