From 9d59fcaded7c1bdf43b36ef38306efde8bb9c2c0 Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Wed, 4 Mar 2020 11:52:20 +0000 Subject: [PATCH] (Manual content scanner) Add 'Arcade DAT Filter' Option --- intl/msg_hash_lbl.h | 2 ++ intl/msg_hash_us.h | 8 +++++ manual_content_scan.c | 65 ++++++++++++++++++++++-------------- manual_content_scan.h | 5 +++ menu/cbs/menu_cbs_sublabel.c | 4 +++ menu/menu_displaylist.c | 6 ++++ menu/menu_setting.c | 15 +++++++++ msg_hash.h | 1 + 8 files changed, 81 insertions(+), 25 deletions(-) diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index 5b8936b17d..55bdec12c8 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -2200,6 +2200,8 @@ MSG_HASH(MENU_ENUM_LABEL_MANUAL_CONTENT_SCAN_SEARCH_ARCHIVES, "manual_content_scan_search_archives") MSG_HASH(MENU_ENUM_LABEL_MANUAL_CONTENT_SCAN_DAT_FILE, "manual_content_scan_dat_file") +MSG_HASH(MENU_ENUM_LABEL_MANUAL_CONTENT_SCAN_DAT_FILE_FILTER, + "manual_content_scan_dat_file_filter") MSG_HASH(MENU_ENUM_LABEL_MANUAL_CONTENT_SCAN_OVERWRITE, "manual_content_scan_overwrite") MSG_HASH(MENU_ENUM_LABEL_MANUAL_CONTENT_SCAN_START, diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 18c51879ec..2b21ba6e8c 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -10299,6 +10299,14 @@ MSG_HASH( MENU_ENUM_SUBLABEL_MANUAL_CONTENT_SCAN_DAT_FILE, "Select a Logiqx or MAME List XML DAT file to enable automatic naming of scanned arcade content (MAME, FinalBurn Neo, etc.)." ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_MANUAL_CONTENT_SCAN_DAT_FILE_FILTER, + "Arcade DAT Filter" + ) +MSG_HASH( + MENU_ENUM_SUBLABEL_MANUAL_CONTENT_SCAN_DAT_FILE_FILTER, + "When using an arcade DAT file, only add content to playlist if a matching DAT file entry is found." + ) MSG_HASH( MENU_ENUM_LABEL_VALUE_MANUAL_CONTENT_SCAN_OVERWRITE, "Overwrite Existing Playlist" diff --git a/manual_content_scan.c b/manual_content_scan.c index 3425bad5d4..ae5f345e33 100644 --- a/manual_content_scan.c +++ b/manual_content_scan.c @@ -51,6 +51,7 @@ typedef struct enum manual_content_scan_system_name_type system_name_type; enum manual_content_scan_core_type core_type; bool search_archives; + bool filter_dat_content; bool overwrite_playlist; } scan_settings_t; @@ -76,6 +77,7 @@ static scan_settings_t scan_settings = { MANUAL_CONTENT_SCAN_SYSTEM_NAME_CONTENT_DIR, /* system_name_type */ MANUAL_CONTENT_SCAN_CORE_DETECT, /* core_type */ false, /* search_archives */ + false, /* filter_dat_content */ false /* overwrite_playlist */ }; @@ -134,6 +136,13 @@ bool *manual_content_scan_get_search_archives_ptr(void) return &scan_settings.search_archives; } +/* Returns a pointer to the internal + * 'filter_dat_content' bool */ +bool *manual_content_scan_get_filter_dat_content_ptr(void) +{ + return &scan_settings.filter_dat_content; +} + /* Returns a pointer to the internal * 'overwrite_playlist' bool */ bool *manual_content_scan_get_overwrite_playlist_ptr(void) @@ -857,6 +866,9 @@ bool manual_content_scan_get_task_config( /* Copy 'search inside archives' setting */ task_config->search_archives = scan_settings.search_archives; + /* Copy 'DAT file filter' setting */ + task_config->filter_dat_content = scan_settings.filter_dat_content; + /* Copy 'overwrite playlist' setting */ task_config->overwrite_playlist = scan_settings.overwrite_playlist; @@ -1017,12 +1029,13 @@ error: } /* Extracts content 'label' (name) from content path - * > If a DAT file is specified and content is an - * archive, performs a lookup of content file name - * in an attempt to find a valid 'description' string. + * > If a DAT file is specified, performs a lookup + * of content file name in an attempt to find a + * valid 'description' string. * Returns false if specified content is invalid. */ static bool manual_content_scan_get_playlist_content_label( const char *content_path, logiqx_dat_t *dat_file, + bool filter_dat_content, char *content_label, size_t len) { /* Sanity check */ @@ -1040,33 +1053,34 @@ static bool manual_content_scan_get_playlist_content_label( /* Check if a DAT file has been specified */ if (dat_file) { - /* DAT files are only relevant for arcade - * content. We have no idea what kind of - * content we are dealing with here, but - * since arcade ROMs are always archives - * we can at least filter by file type... */ - if (path_is_compressed_file(content_path)) + bool content_found = false; + logiqx_dat_game_info_t game_info; + + /* Search for current content + * > If content is not listed in DAT file, + * use existing filename without extension */ + if (logiqx_dat_search(dat_file, content_label, &game_info)) { - logiqx_dat_game_info_t game_info; + /* BIOS files should always be skipped */ + if (game_info.is_bios) + return false; - /* Search for current content - * > If content is not listed in DAT file, - * use existing filename without extension */ - if (logiqx_dat_search(dat_file, content_label, &game_info)) + /* Only include 'runnable' content */ + if (!game_info.is_runnable) + return false; + + /* Copy game description */ + if (!string_is_empty(game_info.description)) { - /* BIOS files should always be skipped */ - if (game_info.is_bios) - return false; - - /* Only include 'runnable' content */ - if (!game_info.is_runnable) - return false; - - /* Copy game description */ - if (!string_is_empty(game_info.description)) - strlcpy(content_label, game_info.description, len); + strlcpy(content_label, game_info.description, len); + content_found = true; } } + + /* If we are applying a DAT file filter, + * unlisted content should be skipped */ + if (!content_found && filter_dat_content) + return false; } return true; @@ -1106,6 +1120,7 @@ void manual_content_scan_add_content_to_playlist( /* Get entry label */ if (!manual_content_scan_get_playlist_content_label( playlist_content_path, dat_file, + task_config->filter_dat_content, label, sizeof(label))) return; diff --git a/manual_content_scan.h b/manual_content_scan.h index 2c8168e8b1..cd09c712aa 100644 --- a/manual_content_scan.h +++ b/manual_content_scan.h @@ -79,6 +79,7 @@ typedef struct char dat_file_path[PATH_MAX_LENGTH]; bool core_set; bool search_archives; + bool filter_dat_content; bool overwrite_playlist; } manual_content_scan_task_config_t; @@ -120,6 +121,10 @@ size_t manual_content_scan_get_dat_file_path_size(void); * 'search_archives' bool */ bool *manual_content_scan_get_search_archives_ptr(void); +/* Returns a pointer to the internal + * 'filter_dat_content' bool */ +bool *manual_content_scan_get_filter_dat_content_ptr(void); + /* Returns a pointer to the internal * 'overwrite_playlist' bool */ bool *manual_content_scan_get_overwrite_playlist_ptr(void); diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 02b6cc5cc6..ce10ec14d7 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -764,6 +764,7 @@ default_sublabel_macro(action_bind_sublabel_manual_content_scan_core_name, default_sublabel_macro(action_bind_sublabel_manual_content_scan_file_exts, MENU_ENUM_SUBLABEL_MANUAL_CONTENT_SCAN_FILE_EXTS) default_sublabel_macro(action_bind_sublabel_manual_content_scan_search_archives, MENU_ENUM_SUBLABEL_MANUAL_CONTENT_SCAN_SEARCH_ARCHIVES) default_sublabel_macro(action_bind_sublabel_manual_content_scan_dat_file, MENU_ENUM_SUBLABEL_MANUAL_CONTENT_SCAN_DAT_FILE) +default_sublabel_macro(action_bind_sublabel_manual_content_scan_dat_file_filter, MENU_ENUM_SUBLABEL_MANUAL_CONTENT_SCAN_DAT_FILE_FILTER) default_sublabel_macro(action_bind_sublabel_manual_content_scan_overwrite, MENU_ENUM_SUBLABEL_MANUAL_CONTENT_SCAN_OVERWRITE) default_sublabel_macro(action_bind_sublabel_manual_content_scan_start, MENU_ENUM_SUBLABEL_MANUAL_CONTENT_SCAN_START) @@ -3273,6 +3274,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_MANUAL_CONTENT_SCAN_DAT_FILE: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_manual_content_scan_dat_file); break; + case MENU_ENUM_LABEL_MANUAL_CONTENT_SCAN_DAT_FILE_FILTER: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_manual_content_scan_dat_file_filter); + break; case MENU_ENUM_LABEL_MANUAL_CONTENT_SCAN_OVERWRITE: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_manual_content_scan_overwrite); break; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 7fb373bc0d..fd64d0b54d 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -3939,6 +3939,12 @@ static bool menu_displaylist_parse_manual_content_scan_list( false) == 0) count++; + /* Arcade DAT filter */ + if (menu_displaylist_parse_settings_enum(info->list, + MENU_ENUM_LABEL_MANUAL_CONTENT_SCAN_DAT_FILE_FILTER, PARSE_ONLY_BOOL, + false) == 0) + count++; + /* Overwrite playlist */ if (menu_displaylist_parse_settings_enum(info->list, MENU_ENUM_LABEL_MANUAL_CONTENT_SCAN_OVERWRITE, PARSE_ONLY_BOOL, diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 015e03a630..c779d3722e 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -17080,6 +17080,21 @@ static bool setting_append_list( general_read_handler); menu_settings_list_current_add_values(list, list_info, "dat|xml"); + CONFIG_BOOL( + list, list_info, + manual_content_scan_get_filter_dat_content_ptr(), + MENU_ENUM_LABEL_MANUAL_CONTENT_SCAN_DAT_FILE_FILTER, + MENU_ENUM_LABEL_VALUE_MANUAL_CONTENT_SCAN_DAT_FILE_FILTER, + false, + MENU_ENUM_LABEL_VALUE_OFF, + MENU_ENUM_LABEL_VALUE_ON, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler, + SD_FLAG_NONE); + CONFIG_BOOL( list, list_info, manual_content_scan_get_overwrite_playlist_ptr(), diff --git a/msg_hash.h b/msg_hash.h index bb2eefc22f..fe556d4715 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -2754,6 +2754,7 @@ enum msg_hash_enums MENU_LABEL(MANUAL_CONTENT_SCAN_FILE_EXTS), MENU_LABEL(MANUAL_CONTENT_SCAN_SEARCH_ARCHIVES), MENU_LABEL(MANUAL_CONTENT_SCAN_DAT_FILE), + MENU_LABEL(MANUAL_CONTENT_SCAN_DAT_FILE_FILTER), MENU_LABEL(MANUAL_CONTENT_SCAN_OVERWRITE), MENU_LABEL(MANUAL_CONTENT_SCAN_START),