(Database) Serial scanning for Gamecube/MegaCD/SegaCD/Saturn/PSX/PSP/Dreamcast/Wii

This commit is contained in:
pkos 2021-12-30 08:43:02 -05:00
parent d017ce7b03
commit a192064403
4 changed files with 929 additions and 283 deletions

View file

@ -264,6 +264,24 @@ void string_set(char **string, const char *src);
extern const unsigned char lr_char_props[256];
/* Get the total number of occurrences of a character in the given string. */
int string_count_occurrences_single_character(char *str, char t);
/* Replaces all spaces with the given character. */
void string_replace_whitespace_with_single_character(char *str, char t);
/* Replaces multiple spaces with a single space in a string. */
void string_replace_multi_space_with_single_space(char *str);
/* Remove all spaces from the given string. */
void string_remove_all_whitespace(char* str_trimmed, const char* str_untrimmed);
/* Retrieve the last occurance of the given character in a string. */
int string_index_last_occurance(char str[], char t);
/* Find the position of a substring in a string. */
int string_find_index_substring_string(const char* str1, const char* str2);
RETRO_END_DECLS
#endif

View file

@ -534,3 +534,99 @@ unsigned string_hex_to_unsigned(const char *str)
return (unsigned)strtoul(hex_str, NULL, 16);
}
/**
* Get the total number of occurrences of a character in the given string.
*/
int string_count_occurrences_single_character(char *str, char t)
{
int ctr = 0;
int i;
for (i = 0; str[i] != '\0'; ++i) {
if (t == str[i])
++ctr;
}
return ctr;
}
/**
* Replaces all spaces with the given character.
*/
void string_replace_whitespace_with_single_character(char *str, char t)
{
while (*str) {
if (isspace(*str))
*str = t;
str++;
}
}
/**
* Replaces multiple spaces with a single space in a string.
*/
void string_replace_multi_space_with_single_space(char *str)
{
char *dest = str;
while (*str != '\0')
{
while (*str == ' ' && *(str + 1) == ' ')
str++;
*dest++ = *str++;
}
*dest = '\0';
}
/**
* Remove all spaces from the given string.
*/
void string_remove_all_whitespace(char* str_trimmed, const char* str_untrimmed)
{
while (*str_untrimmed != '\0')
{
if(!isspace(*str_untrimmed))
{
*str_trimmed = *str_untrimmed;
str_trimmed++;
}
str_untrimmed++;
}
*str_trimmed = '\0';
}
/**
* Retrieve the last occurance of the given character in a string.
*/
int string_index_last_occurance(char *str, char t)
{
const char * ret = strrchr(str, t);
if (ret)
return ret-str;
return -1;
}
/**
* Find the position of a substring in a string.
*/
int string_find_index_substring_string(const char* str1, const char* str2)
{
int index;
if (str1[0] != '\0')
{
const char *pfound = strstr(str1, str2);
if (pfound != NULL)
{
index = (pfound - str1);
return index;
}
}
return -1;
}

View file

@ -81,11 +81,14 @@ int gdi_find_track(const char *gdi_path, bool first,
char *track_path, uint64_t max_len);
bool gdi_next_file(intfstream_t *fd, const char *gdi_path,
char *path, uint64_t max_len);
int detect_system(intfstream_t *fd, const char** system_name);
int detect_ps1_game(intfstream_t *fd, char *game_id);
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);
int detect_system(intfstream_t *fd, const char** system_name, const char *filename);
int detect_ps1_game(intfstream_t *fd, char *serial, const char *filename);
int detect_psp_game(intfstream_t *fd, char *serial, const char *filename);
int detect_gc_game(intfstream_t *fd, char *serial, const char *filename);
int detect_scd_game(intfstream_t *fd, char *serial, const char *filename);
int detect_sat_game(intfstream_t *fd, char *serial, const char *filename);
int detect_dc_game(intfstream_t *fd, char *serial, const char *filename);
int detect_wii_game(intfstream_t *fd, char *serial, const char *filename);
static const char *database_info_get_current_name(
database_state_handle_t *handle)
@ -145,47 +148,62 @@ static int task_database_iterate_start(retro_task_t *task,
return 0;
}
static int intfstream_get_serial(intfstream_t *fd, char *serial)
static int intfstream_get_serial(intfstream_t *fd, char *serial, const char *filename)
{
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;
}
/* Any other non-system specific detection methods? */
return 0;
}
if (string_is_equal(system_name, "psp"))
{
if (detect_psp_game(fd, serial) == 0)
return 0;
RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial);
}
else if (string_is_equal(system_name, "ps1"))
{
if (detect_ps1_game(fd, serial) == 0)
return 0;
RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial);
}
else if (string_is_equal(system_name, "gc"))
{
if (detect_gc_game(fd, serial) == 0)
return 0;
RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial);
}
else
return 0;
return 1;
const char *system_name = NULL;
if (detect_system(fd, &system_name, filename) >= 1)
{
if (string_is_equal(system_name, "Sony - PlayStation Portable"))
{
if (detect_psp_game(fd, serial, filename) == 0)
return 0;
RARCH_LOG("[Scanner]: Serial: %s\n", serial);
return 1;
}
else if (string_is_equal(system_name, "Sony - PlayStation"))
{
if (detect_ps1_game(fd, serial, filename) == 0)
return 0;
RARCH_LOG("[Scanner]: Serial: %s\n", serial);
return 1;
}
else if (string_is_equal(system_name, "Nintendo - GameCube"))
{
if (detect_gc_game(fd, serial, filename) == 0)
return 0;
RARCH_LOG("[Scanner]: Serial: %s\n", serial);
return 1;
}
else if (string_is_equal(system_name, "Sega - Mega-CD - Sega CD"))
{
if (detect_scd_game(fd, serial, filename) == 0)
return 0;
RARCH_LOG("[Scanner]: Serial: %s\n", serial);
return 1;
}
else if (string_is_equal(system_name, "Sega - Saturn"))
{
if (detect_sat_game(fd, serial, filename) == 0)
return 0;
RARCH_LOG("[Scanner]: Serial: %s\n", serial);
return 1;
}
else if (string_is_equal(system_name, "Sega - Dreamcast"))
{
if (detect_dc_game(fd, serial, filename) == 0)
return 0;
RARCH_LOG("[Scanner]: Serial: %s\n", serial);
return 1;
}
else if (string_is_equal(system_name, "Nintendo - Wii"))
{
if (detect_wii_game(fd, serial, filename) == 0)
return 0;
RARCH_LOG("[Scanner]: Serial: %s\n", serial);
return 1;
}
}
return 0;
}
static bool intfstream_file_get_serial(const char *name,
@ -236,7 +254,7 @@ static bool intfstream_file_get_serial(const char *name,
}
}
rv = intfstream_get_serial(fd, serial);
rv = intfstream_get_serial(fd, serial, name);
intfstream_close(fd);
free(fd);
free(data);
@ -305,7 +323,7 @@ static int task_database_chd_get_serial(const char *name, char* serial)
if (!fd)
return 0;
result = intfstream_get_serial(fd, serial);
result = intfstream_get_serial(fd, serial, name);
intfstream_close(fd);
free(fd);
return result;
@ -617,6 +635,7 @@ static int task_database_iterate_playlist(
db->type = DATABASE_TYPE_ITERATE_LUTRO;
break;
default:
db_state->serial[0] = '\0';
db->type = DATABASE_TYPE_CRC_LOOKUP;
return intfstream_file_get_crc(name, 0, SIZE_MAX, &db_state->crc);
}
@ -743,7 +762,14 @@ static int database_info_list_iterate_found_match(
playlist_config_set_path(&_db->playlist_config, db_playlist_path);
playlist = playlist_init(&_db->playlist_config);
snprintf(db_crc, str_len, "%08lX|crc", (unsigned long)db_info_entry->crc32);
if (!string_is_empty(db_state->serial))
{
snprintf(db_crc, str_len, "%s|serial", db_state->serial);
}
else
{
snprintf(db_crc, str_len, "%08lX|crc", (unsigned long)db_info_entry->crc32);
}
if (entry_path)
strlcpy(entry_path_str, entry_path, str_len);

File diff suppressed because it is too large Load diff