Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Fix #746 (CLI) Auto-detect Core when -L isn't present #15458

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"xiosbase": "c",
"xstring": "c",
"xtree": "c",
"xutility": "c"
"xutility": "c",
"*.all": "c"
},
"C_Cpp.dimInactiveRegions": false,
}
21 changes: 17 additions & 4 deletions core_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -2621,10 +2621,11 @@ core_updater_info_t *core_info_get_core_updater_info(
if (!(info = (core_updater_info_t*)malloc(sizeof(*info))))
return NULL;

info->is_experimental = false;
info->display_name = NULL;
info->description = NULL;
info->licenses = NULL;
info->is_experimental = false;
info->display_name = NULL;
info->description = NULL;
info->licenses = NULL;
info->supported_extensions = NULL;

/* Fetch required parameters */

Expand Down Expand Up @@ -2659,6 +2660,15 @@ core_updater_info_t *core_info_get_core_updater_info(
entry->value = NULL;
}

/* > licenses */
entry = config_get_entry(conf, "supported_extensions");

if (entry && !string_is_empty(entry->value))
{
info->supported_extensions = entry->value;
entry->value = NULL;
}

/* Clean up */
config_file_free(conf);

Expand All @@ -2679,6 +2689,9 @@ void core_info_free_core_updater_info(core_updater_info_t *info)
if (info->licenses)
free(info->licenses);

if(info->supported_extensions)
free(info->supported_extensions);

free(info);
info = NULL;
}
Expand Down
1 change: 1 addition & 0 deletions core_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ typedef struct
char *display_name;
char *description;
char *licenses;
char *supported_extensions;
bool is_experimental;
} core_updater_info_t;

Expand Down
34 changes: 25 additions & 9 deletions core_updater_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ static void core_updater_list_free_entry(core_updater_list_entry_t *entry)
string_list_free(entry->licenses_list);
entry->licenses_list = NULL;
}

if(entry->supported_extensions)
{
string_list_free(entry->supported_extensions);
entry->supported_extensions = NULL;
}
}

/* Creates a new, empty core updater list.
Expand Down Expand Up @@ -547,6 +553,12 @@ static bool core_updater_list_set_core_info(
entry->licenses_list = NULL;
}

if(entry->supported_extensions)
{
string_list_free(entry->supported_extensions);
entry->supported_extensions = NULL;
}

entry->is_experimental = false;

/* Read core info file
Expand Down Expand Up @@ -582,6 +594,9 @@ static bool core_updater_list_set_core_info(
if (!string_is_empty(core_info->licenses))
entry->licenses_list = string_split(core_info->licenses, "|");

if (!string_is_empty(core_info->supported_extensions))
entry->supported_extensions = string_split(core_info->supported_extensions, "|");

/* Clean up */
core_info_free_core_updater_info(core_info);
}
Expand Down Expand Up @@ -628,19 +643,20 @@ static bool core_updater_list_push_entry(
memset(list_entry, 0, sizeof(*list_entry));

/* Assign paths */
list_entry->remote_filename = entry->remote_filename;
list_entry->remote_core_path = entry->remote_core_path;
list_entry->local_core_path = entry->local_core_path;
list_entry->local_info_path = entry->local_info_path;
list_entry->remote_filename = entry->remote_filename;
list_entry->remote_core_path = entry->remote_core_path;
list_entry->local_core_path = entry->local_core_path;
list_entry->local_info_path = entry->local_info_path;

/* Assign core info */
list_entry->display_name = entry->display_name;
list_entry->description = entry->description;
list_entry->licenses_list = entry->licenses_list;
list_entry->is_experimental = entry->is_experimental;
list_entry->display_name = entry->display_name;
list_entry->description = entry->description;
list_entry->licenses_list = entry->licenses_list;
list_entry->is_experimental = entry->is_experimental;
list_entry->supported_extensions = entry->supported_extensions;

/* Copy crc */
list_entry->crc = entry->crc;
list_entry->crc = entry->crc;

/* Copy date */
memcpy(&list_entry->date, &entry->date, sizeof(core_updater_list_date_t));
Expand Down
1 change: 1 addition & 0 deletions core_updater_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef struct
core_updater_list_date_t date; /* unsigned alignment */
uint32_t crc;
bool is_experimental;
struct string_list* supported_extensions;
} core_updater_list_entry_t;

/* Prevent direct access to core_updater_list_t
Expand Down
62 changes: 57 additions & 5 deletions menu/cbs/menu_cbs_cancel.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int action_cancel_pop_default(const char *path,
if (menu_st->driver_ctx->navigation_set)
menu_st->driver_ctx->navigation_set(menu_st->userdata, false);
/* Refresh menu */
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH
| MENU_ST_FLAG_PREVENT_POPULATE;
return 0;
}
Expand Down Expand Up @@ -113,16 +113,56 @@ static int action_cancel_cheat_details(const char *path,
}
#endif

static const char* find_core_updater_list_flush_target()
{
struct menu_state* menu_st = menu_state_get_ptr();
menu_list_t* list = menu_st->entries.list;
file_list_t const * const menu_list = MENU_LIST_GET(list, 0);
const size_t menu_stack_size = MENU_LIST_GET_STACK_SIZE(list, 0);
const char *candidate_label;
int all_targets_hashes[] = {
MENU_ENUM_LABEL_ONLINE_UPDATER,
MENU_ENUM_LABEL_CORE_LIST,
MENU_ENUM_LABEL_DEFERRED_CORE_LIST,
MSG_UNKNOWN,
};

size_t i;
int target_idx;
/* Iterate from the top of the stack to the bottom. If we hit zero we hit the bottom of the stack, can choose as last resort. */
for(i = menu_stack_size - 1; i > 0; i--)
{
candidate_label = menu_list->list[i].label;
target_idx = 0;
while (all_targets_hashes[target_idx] != MSG_UNKNOWN)
{
if (string_is_equal(candidate_label, msg_hash_to_str(all_targets_hashes[target_idx++]))) return candidate_label;
}
}
return msg_hash_to_str(all_targets_hashes[0]);
}

static int action_cancel_core_list(const char* path,
const char* label, unsigned type, size_t idx)
{
/* When we back out of the filtered core list, clear out any filters we used */
struct menu_state* menu_st = menu_state_get_ptr();
menu_st->driver_data->deferred_path[0] = '\0';
menu_st->driver_data->detect_content_path[0] = '\0';
return action_cancel_pop_default(path, label, type, idx);
}

static int action_cancel_core_content(const char *path,
const char *label, unsigned type, size_t idx)
{
const char *menu_label = NULL;

size_t online_updater_idx = 0;
size_t load_core_idx = 0;
menu_entries_get_last_stack(NULL, &menu_label, NULL, NULL, NULL);

if (string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_CORE_UPDATER_LIST)))
{
menu_search_terms_t *menu_search_terms =
menu_search_terms_t *menu_search_terms =
menu_entries_search_get_terms();

/* Check whether search terms have been set
Expand All @@ -136,12 +176,14 @@ static int action_cancel_core_content(const char *path,
if (menu_st->driver_ctx->navigation_set)
menu_st->driver_ctx->navigation_set(menu_st->userdata, false);
/* Refresh menu */
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH
| MENU_ST_FLAG_PREVENT_POPULATE;
return 0;
}

menu_entries_flush_stack(msg_hash_to_str(MENU_ENUM_LABEL_ONLINE_UPDATER), 0);

menu_entries_flush_stack(find_core_updater_list_flush_target(), 0);

}
else if (string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_CORE_CONTENT_DIRS_LIST)))
menu_entries_flush_stack(msg_hash_to_str(MENU_ENUM_LABEL_ONLINE_UPDATER), 0);
Expand All @@ -160,6 +202,13 @@ static int action_cancel_core_content(const char *path,
static int menu_cbs_init_bind_cancel_compare_label(menu_file_list_cbs_t *cbs,
const char *label)
{
if (string_is_equal(label, msg_hash_to_str(MENU_ENUM_LABEL_CORE_UPDATER_LIST)) ||
string_is_equal(label, msg_hash_to_str(MENU_ENUM_LABEL_SIDELOAD_CORE_LIST)) ||
string_is_equal(label, msg_hash_to_str(MENU_ENUM_LABEL_NO_CORES_AVAILABLE)))
{
BIND_ACTION_CANCEL(cbs, action_cancel_core_list);
}

return -1;
}

Expand All @@ -174,6 +223,9 @@ static int menu_cbs_init_bind_cancel_compare_type(
case FILE_TYPE_DOWNLOAD_CORE:
BIND_ACTION_CANCEL(cbs, action_cancel_core_content);
return 0;
case FILE_TYPE_CORE:
BIND_ACTION_CANCEL(cbs, action_cancel_core_list);
return 0;
case MENU_SETTING_ACTION_CONTENTLESS_CORE_RUN:
BIND_ACTION_CANCEL(cbs, action_cancel_contentless_core);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion menu/cbs/menu_cbs_ok.c
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ static void menu_driver_set_last_start_content(struct menu_state *menu_st, const
}


static int file_load_with_detect_core_wrapper(
int file_load_with_detect_core_wrapper(
enum msg_hash_enums enum_label_idx,
size_t idx, size_t entry_idx,
const char *path, const char *label,
Expand Down
6 changes: 6 additions & 0 deletions menu/menu_cbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ int action_scan_file(const char *path,
int action_ok_core_option_dropdown_list(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx);

int file_load_with_detect_core_wrapper(
enum msg_hash_enums enum_label_idx,
size_t idx, size_t entry_idx,
const char *path, const char *label,
unsigned type, bool is_carchive);

void cb_generic_download(retro_task_t *task,
void *task_data,
void *user_data, const char *err);
Expand Down
15 changes: 12 additions & 3 deletions menu/menu_displaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1660,11 +1660,12 @@ static unsigned menu_displaylist_parse_supported_cores(menu_displaylist_info_t *
MENU_ENUM_LABEL_NO_CORES_AVAILABLE,
0, 0, 0, NULL))
count++;

info->flags |= MD_FLAG_DOWNLOAD_CORE;
}

}

info->flags |= MD_FLAG_DOWNLOAD_CORE;

return count;
}

Expand Down Expand Up @@ -12693,7 +12694,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
struct menu_state *menu_st = menu_state_get_ptr();
bool show_experimental_cores = settings->bools.network_buildbot_show_experimental_cores;
size_t selection = menu_st->selection_ptr;

if (core_list)
{
size_t menu_index = 0;
Expand Down Expand Up @@ -12738,6 +12739,14 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
continue;
}

if (!string_is_empty(menu_st->driver_data->detect_content_path))
{
char const * const ext = path_get_extension(menu_st->driver_data->detect_content_path);

if (string_list_find_elem(entry->supported_extensions, ext) == 0)
continue;
}

if (menu_entries_append(info->list,
entry->remote_filename,
"",
Expand Down
4 changes: 1 addition & 3 deletions menu/menu_displaylist.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ enum menu_dl_flags
MD_FLAG_NEED_CLEAR = (1 << 5), /* Should we clear the displaylist before we push
* entries onto it? */
MD_FLAG_PUSH_BUILTIN_CORES = (1 << 6),
MD_FLAG_DOWNLOAD_CORE = (1 << 7), /* Should a 'download core' entry be pushed onto the list?
* This will be set to true in case there are no currently
* installed cores. */
MD_FLAG_DOWNLOAD_CORE = (1 << 7), /* Should a 'download core' entry be pushed onto the list? */
MD_FLAG_NEED_NAVIGATION_CLEAR = (1 << 8) /* Does the navigation index need to be cleared
* to 0 (first entry) ? */
};
Expand Down
Loading