(Task database) Cleanups

This commit is contained in:
twinaphex 2020-06-10 16:24:52 +02:00
parent b2f5262a3b
commit 8eee7b3bb9
2 changed files with 123 additions and 136 deletions

View File

@ -89,23 +89,6 @@ int detect_psp_game(intfstream_t *fd, char *game_id);
int detect_gc_game(intfstream_t *fd, char *game_id);
int detect_serial_ascii_game(intfstream_t *fd, char *game_id);
static void database_info_set_type(
database_info_handle_t *handle,
enum database_type type)
{
if (!handle)
return;
handle->type = type;
}
static enum database_type database_info_get_type(
database_info_handle_t *handle)
{
if (!handle)
return DATABASE_TYPE_NONE;
return handle->type;
}
static const char *database_info_get_current_name(
database_state_handle_t *handle)
{
@ -201,9 +184,8 @@ static int intfstream_get_serial(intfstream_t *fd, char *serial)
return 0;
RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial);
}
else {
else
return 0;
}
return 1;
}
@ -605,7 +587,7 @@ static int task_database_iterate_playlist(
{
case FILE_TYPE_COMPRESSED:
#ifdef HAVE_COMPRESSION
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
db->type = DATABASE_TYPE_CRC_LOOKUP;
/* first check crc of archive itself */
return intfstream_file_get_crc(name,
0, SIZE_MAX, &db_state->archive_crc);
@ -616,10 +598,10 @@ static int task_database_iterate_playlist(
task_database_cue_prune(db, name);
db_state->serial[0] = '\0';
if (task_database_cue_get_serial(name, db_state->serial))
database_info_set_type(db, DATABASE_TYPE_SERIAL_LOOKUP);
db->type = DATABASE_TYPE_SERIAL_LOOKUP;
else
{
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
db->type = DATABASE_TYPE_CRC_LOOKUP;
return task_database_cue_get_crc(name, &db_state->crc);
}
break;
@ -629,10 +611,10 @@ static int task_database_iterate_playlist(
/* There are no serial databases, so don't bother with
serials at the moment */
if (0 && task_database_gdi_get_serial(name, db_state->serial))
database_info_set_type(db, DATABASE_TYPE_SERIAL_LOOKUP);
db->type = DATABASE_TYPE_SERIAL_LOOKUP;
else
{
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
db->type = DATABASE_TYPE_CRC_LOOKUP;
return task_database_gdi_get_crc(name, &db_state->crc);
}
break;
@ -641,23 +623,23 @@ static int task_database_iterate_playlist(
case FILE_TYPE_ISO:
db_state->serial[0] = '\0';
intfstream_file_get_serial(name, 0, SIZE_MAX, db_state->serial);
database_info_set_type(db, DATABASE_TYPE_SERIAL_LOOKUP);
db->type = DATABASE_TYPE_SERIAL_LOOKUP;
break;
case FILE_TYPE_CHD:
db_state->serial[0] = '\0';
if (task_database_chd_get_serial(name, db_state->serial))
database_info_set_type(db, DATABASE_TYPE_SERIAL_LOOKUP);
db->type = DATABASE_TYPE_SERIAL_LOOKUP;
else
{
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
db->type = DATABASE_TYPE_CRC_LOOKUP;
return task_database_chd_get_crc(name, &db_state->crc);
}
break;
case FILE_TYPE_LUTRO:
database_info_set_type(db, DATABASE_TYPE_ITERATE_LUTRO);
db->type = DATABASE_TYPE_ITERATE_LUTRO;
break;
default:
database_info_set_type(db, DATABASE_TYPE_CRC_LOOKUP);
db->type = DATABASE_TYPE_CRC_LOOKUP;
return intfstream_file_get_crc(name, 0, SIZE_MAX, &db_state->crc);
}
@ -726,22 +708,14 @@ static int database_info_list_iterate_end_no_match(
return 0;
}
static int task_database_iterate_next(database_info_handle_t *db)
{
db->list_ptr++;
if (db->list_ptr < db->list->size)
return 0;
return -1;
}
static int database_info_list_iterate_new(database_state_handle_t *db_state,
const char *query)
{
const char *new_database = database_info_get_current_name(db_state);
#ifndef RARCH_INTERNAL
fprintf(stderr, "Check database [%d/%d] : %s\n", (unsigned)db_state->list_index,
fprintf(stderr, "Check database [%d/%d] : %s\n",
(unsigned)db_state->list_index,
(unsigned)db_state->list->size, new_database);
#endif
if (db_state->info)
@ -836,7 +810,8 @@ static int database_info_list_iterate_found_match(
{
struct playlist_entry entry;
/* the push function reads our entry as const, so these casts are safe */
/* the push function reads our entry as const,
* so these casts are safe */
entry.path = entry_path_str;
entry.label = db_info_entry->name;
entry.core_path = (char*)"DETECT";
@ -879,7 +854,8 @@ static int database_info_list_iterate_found_match(
again */
if (db_state->list_index != 0)
{
struct string_list_elem entry = db_state->list->elems[db_state->list_index];
struct string_list_elem entry =
db_state->list->elems[db_state->list_index];
memmove(&db_state->list->elems[1],
&db_state->list->elems[0],
sizeof(entry) * db_state->list_index);
@ -912,12 +888,12 @@ static int task_database_iterate_crc_lookup(
const char *name,
const char *archive_entry)
{
if (!db_state->list ||
(unsigned)db_state->list_index == (unsigned)db_state->list->size)
return database_info_list_iterate_end_no_match(db, db_state, name);
/* archive did not contain a CRC for this entry, or the file is empty */
/* Archive did not contain a CRC for this entry,
* or the file is empty. */
if (!db_state->crc)
{
db_state->crc = file_archive_get_file_crc32(name);
@ -1001,19 +977,6 @@ static int task_database_iterate_crc_lookup(
return 0;
}
static int task_database_iterate_playlist_archive(
db_handle_t *_db,
database_state_handle_t *db_state,
database_info_handle_t *db, const char *name)
{
#ifdef HAVE_COMPRESSION
return task_database_iterate_crc_lookup(
_db, db_state, db, name, db_state->archive_name);
#else
return 1;
#endif
}
static int task_database_iterate_playlist_lutro(
db_handle_t *_db,
database_state_handle_t *db_state,
@ -1039,32 +1002,34 @@ static int task_database_iterate_playlist_lutro(
_db->pl_fuzzy_archive_match))
{
struct playlist_entry entry;
char *game_title = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
char *game_title = (char*)
malloc(PATH_MAX_LENGTH * sizeof(char));
game_title[0] = '\0';
game_title[0] = '\0';
fill_short_pathname_representation_noext(game_title,
path, PATH_MAX_LENGTH * sizeof(char));
/* the push function reads our entry as const, so these casts are safe */
entry.path = (char*)path;
entry.label = game_title;
entry.core_path = (char*)"DETECT";
entry.core_name = (char*)"DETECT";
entry.db_name = (char*)"Lutro.lpl";
entry.crc32 = (char*)"DETECT";
entry.subsystem_ident = NULL;
entry.subsystem_name = NULL;
entry.subsystem_roms = NULL;
entry.runtime_hours = 0;
entry.runtime_minutes = 0;
entry.runtime_seconds = 0;
entry.last_played_year = 0;
entry.last_played_month = 0;
entry.last_played_day = 0;
entry.last_played_hour = 0;
entry.last_played_minute= 0;
entry.last_played_second= 0;
/* the push function reads our entry as const,
* so these casts are safe */
entry.path = (char*)path;
entry.label = game_title;
entry.core_path = (char*)"DETECT";
entry.core_name = (char*)"DETECT";
entry.db_name = (char*)"Lutro.lpl";
entry.crc32 = (char*)"DETECT";
entry.subsystem_ident = NULL;
entry.subsystem_name = NULL;
entry.subsystem_roms = NULL;
entry.runtime_hours = 0;
entry.runtime_minutes = 0;
entry.runtime_seconds = 0;
entry.last_played_year = 0;
entry.last_played_month = 0;
entry.last_played_day = 0;
entry.last_played_hour = 0;
entry.last_played_minute = 0;
entry.last_played_second = 0;
playlist_push(playlist, &entry, _db->pl_fuzzy_archive_match);
@ -1083,15 +1048,18 @@ static int task_database_iterate_serial_lookup(
database_state_handle_t *db_state,
database_info_handle_t *db, const char *name)
{
if (!db_state->list ||
(unsigned)db_state->list_index == (unsigned)db_state->list->size)
if (
!db_state->list ||
(unsigned)db_state->list_index == (unsigned)db_state->list->size
)
return database_info_list_iterate_end_no_match(db, db_state, name);
if (db_state->entry_index == 0)
{
char query[50];
char *serial_buf =
bin_to_hex_alloc((uint8_t*)db_state->serial, strlen(db_state->serial) * sizeof(uint8_t));
char *serial_buf = bin_to_hex_alloc(
(uint8_t*)db_state->serial,
strlen(db_state->serial) * sizeof(uint8_t));
if (!serial_buf)
return 1;
@ -1142,24 +1110,21 @@ static int task_database_iterate_serial_lookup(
static int task_database_iterate(
db_handle_t *_db,
const char *name,
database_state_handle_t *db_state,
database_info_handle_t *db)
{
const char *name = database_info_get_current_element_name(db);
if (!name)
return 0;
if (database_info_get_type(db) == DATABASE_TYPE_ITERATE)
if (path_contains_compressed_file(name))
database_info_set_type(db, DATABASE_TYPE_ITERATE_ARCHIVE);
switch (database_info_get_type(db))
switch (db->type)
{
case DATABASE_TYPE_ITERATE:
return task_database_iterate_playlist(db_state, db, name);
case DATABASE_TYPE_ITERATE_ARCHIVE:
return task_database_iterate_playlist_archive(_db, db_state, db, name);
#ifdef HAVE_COMPRESSION
return task_database_iterate_crc_lookup(
_db, db_state, db, name, db_state->archive_name);
#else
return 1;
#endif
case DATABASE_TYPE_ITERATE_LUTRO:
return task_database_iterate_playlist_lutro(_db, db_state, db, name);
case DATABASE_TYPE_SERIAL_LOOKUP:
@ -1207,9 +1172,13 @@ static void task_database_handler(retro_task_t *task)
if (!string_is_empty(db->fullpath))
{
if (db->is_directory)
db->handle = database_info_dir_init(db->fullpath, DATABASE_TYPE_ITERATE, task, db->show_hidden_files);
db->handle = database_info_dir_init(
db->fullpath, DATABASE_TYPE_ITERATE,
task, db->show_hidden_files);
else
db->handle = database_info_file_init(db->fullpath, DATABASE_TYPE_ITERATE, task);
db->handle = database_info_file_init(
db->fullpath, DATABASE_TYPE_ITERATE,
task);
}
if (db->handle)
@ -1255,8 +1224,8 @@ static void task_database_handler(retro_task_t *task)
path_remove_extension(dbpath);
dbname = find_last_slash(dbpath) + 1;
strmatch = strcasecmp(dbname, dirname) == 0;
dbname = find_last_slash(dbpath) + 1;
strmatch = strcasecmp(dbname, dirname) == 0;
free(dbpath);
@ -1277,21 +1246,32 @@ static void task_database_handler(retro_task_t *task)
dbinfo->status = DATABASE_STATUS_ITERATE_START;
break;
case DATABASE_STATUS_ITERATE_START:
name = database_info_get_current_element_name(dbinfo);
name = database_info_get_current_element_name(dbinfo);
task_database_cleanup_state(dbstate);
dbstate->list_index = 0;
dbstate->entry_index = 0;
task_database_iterate_start(task, dbinfo, name);
break;
case DATABASE_STATUS_ITERATE:
if (task_database_iterate(db, dbstate, dbinfo) == 0)
{
dbinfo->status = DATABASE_STATUS_ITERATE_NEXT;
dbinfo->type = DATABASE_TYPE_ITERATE;
const char *name = database_info_get_current_element_name(
dbinfo);
if (dbinfo->type == DATABASE_TYPE_ITERATE)
if (path_contains_compressed_file(name))
dbinfo->type = DATABASE_TYPE_ITERATE_ARCHIVE;
if (task_database_iterate(db, name, dbstate, dbinfo) == 0)
{
dbinfo->status = DATABASE_STATUS_ITERATE_NEXT;
dbinfo->type = DATABASE_TYPE_ITERATE;
}
}
break;
case DATABASE_STATUS_ITERATE_NEXT:
if (task_database_iterate_next(dbinfo) == 0)
dbinfo->list_ptr++;
if (dbinfo->list_ptr < dbinfo->list->size)
{
dbinfo->status = DATABASE_STATUS_ITERATE_START;
dbinfo->type = DATABASE_TYPE_ITERATE;
@ -1354,9 +1334,9 @@ task_finished:
#ifdef RARCH_INTERNAL
static void task_database_progress_cb(retro_task_t *task)
{
if (!task)
return;
video_display_server_set_window_progress(task->progress, task->finished);
if (task)
video_display_server_set_window_progress(task->progress,
task->finished);
}
#endif
@ -1380,7 +1360,8 @@ bool task_push_dbscan(
t->handler = task_database_handler;
t->state = db;
t->callback = cb;
t->title = strdup(msg_hash_to_str(MSG_PREPARING_FOR_CONTENT_SCAN));
t->title = strdup(msg_hash_to_str(
MSG_PREPARING_FOR_CONTENT_SCAN));
t->alternative_look = true;
#ifdef RARCH_INTERNAL

View File

@ -323,8 +323,8 @@ int detect_gc_game(intfstream_t *fd, char *game_id)
int detect_serial_ascii_game(intfstream_t *fd, char *game_id)
{
unsigned pos;
int numberOfAscii = 0;
bool rv = false;
int number_of_ascii = 0;
bool rv = false;
for (pos = 0; pos < 10000; pos++)
{
@ -332,30 +332,32 @@ int detect_serial_ascii_game(intfstream_t *fd, char *game_id)
if (intfstream_read(fd, game_id, 15) > 0)
{
unsigned i;
game_id[15] = '\0';
numberOfAscii = 0;
game_id[15] = '\0';
number_of_ascii = 0;
/* When scanning WBFS files, "WBFS" is discovered as the first serial. Ignore it. */
if (string_is_equal(game_id, "WBFS")) {
if (string_is_equal(game_id, "WBFS"))
continue;
}
/* Loop through until we run out of ASCII characters. */
for (i = 0; i < 15; i++)
{
/* Is the given character ASCII? A-Z, 0-9, - */
if (game_id[i] == 45 || (game_id[i] >= 48 && game_id[i] <= 57) || (game_id[i] >= 65 && game_id[i] <= 90))
numberOfAscii++;
if ( (game_id[i] == 45) ||
(game_id[i] >= 48 && game_id[i] <= 57) ||
(game_id[i] >= 65 && game_id[i] <= 90))
number_of_ascii++;
else
break;
}
/* If the length of the text is between 3 and 9 characters, it could be a serial. */
if (numberOfAscii > 3 && numberOfAscii < 9)
/* If the length of the text is between 3 and 9 characters,
* it could be a serial. */
if (number_of_ascii > 3 && number_of_ascii < 9)
{
/* Cut the string off, and return it as a valid serial. */
game_id[numberOfAscii] = '\0';
rv = true;
game_id[number_of_ascii] = '\0';
rv = true;
break;
}
}
@ -366,17 +368,17 @@ int detect_serial_ascii_game(intfstream_t *fd, char *game_id)
int detect_system(intfstream_t *fd, const char **system_name)
{
int rv;
char magic[MAGIC_LEN];
int i;
int rv;
int64_t read;
char magic[MAGIC_LEN];
RARCH_LOG("%s\n", msg_hash_to_str(MSG_COMPARING_WITH_KNOWN_MAGIC_NUMBERS));
for (i = 0; MAGIC_NUMBERS[i].system_name != NULL; i++)
{
intfstream_seek(fd, MAGIC_NUMBERS[i].offset, SEEK_SET);
read = intfstream_read(fd, magic, MAGIC_LEN);
if (read < 0)
{
RARCH_LOG("Could not read data at offset %d: %s\n",
@ -430,8 +432,8 @@ static int64_t intfstream_get_file_size(const char *path)
}
static bool update_cand(int64_t *cand_index, int64_t *last_index,
uint64_t *largest, char *last_file, uint64_t *offset,
uint64_t *size, char *track_path, uint64_t max_len)
uint64_t *largest, char *last_file, uint64_t *offset,
uint64_t *size, char *track_path, uint64_t max_len)
{
if (*cand_index != -1)
{
@ -444,7 +446,7 @@ static bool update_cand(int64_t *cand_index, int64_t *last_index,
*cand_index = -1;
return true;
}
*cand_index = -1;
*cand_index = -1;
}
return false;
}
@ -469,8 +471,8 @@ int cue_find_track(const char *cue_path, bool first,
fill_pathname_basedir(cue_dir, cue_path, PATH_MAX_LENGTH);
info.type = INTFSTREAM_FILE;
fd = (intfstream_t*)intfstream_init(&info);
info.type = INTFSTREAM_FILE;
fd = (intfstream_t*)intfstream_init(&info);
if (!fd)
goto error;
@ -498,8 +500,9 @@ int cue_find_track(const char *cue_path, bool first,
last_index = file_size;
/* We're changing files since the candidate, update it */
if (update_cand(&cand_index, &last_index, &largest, last_file, offset,
size, track_path, max_len))
if (update_cand(&cand_index, &last_index,
&largest, last_file, offset,
size, track_path, max_len))
{
rv = 0;
if (first)
@ -507,7 +510,8 @@ int cue_find_track(const char *cue_path, bool first,
}
get_token(fd, tmp_token, MAX_TOKEN_LEN);
fill_pathname_join(last_file, cue_dir, tmp_token, PATH_MAX_LENGTH);
fill_pathname_join(last_file, cue_dir,
tmp_token, PATH_MAX_LENGTH);
file_size = intfstream_get_file_size(last_file);
@ -537,8 +541,9 @@ int cue_find_track(const char *cue_path, bool first,
/* If we've changed tracks since the candidate, update it */
if (cand_track != -1 && track != cand_track &&
update_cand(&cand_index, &last_index, &largest, last_file, offset,
size, track_path, max_len))
update_cand(&cand_index, &last_index, &largest,
last_file, offset,
size, track_path, max_len))
{
rv = 0;
if (first)
@ -559,8 +564,9 @@ int cue_find_track(const char *cue_path, bool first,
if (file_size != -1)
last_index = file_size;
if (update_cand(&cand_index, &last_index, &largest, last_file, offset,
size, track_path, max_len))
if (update_cand(&cand_index, &last_index,
&largest, last_file, offset,
size, track_path, max_len))
rv = 0;
clean:
@ -663,6 +669,7 @@ int gdi_find_track(const char *gdi_path, bool first,
errno = EINVAL;
goto error;
}
mode = atoi(tmp_token);
/* Sector size */
@ -671,6 +678,7 @@ int gdi_find_track(const char *gdi_path, bool first,
errno = EINVAL;
goto error;
}
size = atoi(tmp_token);
/* File name */
@ -758,13 +766,10 @@ bool gdi_next_file(intfstream_t *fd, const char *gdi_path,
/* Track number */
get_token(fd, tmp_token, MAX_TOKEN_LEN);
/* Offset */
get_token(fd, tmp_token, MAX_TOKEN_LEN);
/* Mode */
get_token(fd, tmp_token, MAX_TOKEN_LEN);
/* Sector size */
get_token(fd, tmp_token, MAX_TOKEN_LEN);
@ -778,7 +783,8 @@ bool gdi_next_file(intfstream_t *fd, const char *gdi_path,
fill_pathname_basedir(gdi_dir, gdi_path, PATH_MAX_LENGTH);
fill_pathname_join(path, gdi_dir, tmp_token, (size_t)max_len);
rv = true;
rv = true;
/* Disc offset */
get_token(fd, tmp_token, MAX_TOKEN_LEN);