Skip to content

Commit fc9c12c

Browse files
sonninnosLibretroAdmin
authored andcommitted
Fix 'Sort Remaps by Gamepad' from CLI
1 parent 04a98f3 commit fc9c12c

4 files changed

Lines changed: 49 additions & 42 deletions

File tree

configuration.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4947,9 +4947,8 @@ bool config_load_remap(const char *directory_input_remapping,
49474947
const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME);
49484948
enum msg_hash_enums msg_remap_loaded = MSG_GAME_REMAP_FILE_LOADED;
49494949
settings_t *settings = config_st;
4950-
bool notification_show_remap_load = settings->bools.notification_show_remap_load;
49514950
unsigned joypad_port = settings->uints.input_joypad_index[0];
4952-
const char *inp_dev_name = input_config_get_device_display_name(joypad_port);
4951+
bool notification_show_remap_load = settings->bools.notification_show_remap_load;
49534952
bool sort_remaps_by_controller = settings->bools.input_remap_sort_by_controller_enable;
49544953

49554954
/* > Cannot load remaps if we have no core
@@ -4958,28 +4957,24 @@ bool config_load_remap(const char *directory_input_remapping,
49584957
|| string_is_empty(directory_input_remapping))
49594958
return false;
49604959

4961-
game_path[0] = '\0';
4962-
content_path[0] = '\0';
4960+
core_path[0] = '\0';
4961+
game_path[0] = '\0';
4962+
content_path[0] = '\0';
4963+
4964+
strlcpy(remap_path, core_name, sizeof(remap_path));
49634965

4964-
if ( sort_remaps_by_controller
4965-
&& !string_is_empty(inp_dev_name)
4966-
)
4966+
if (sort_remaps_by_controller)
49674967
{
4968-
/* Ensure directory does not contain special chars */
4969-
const char *inp_dev_dir = sanitize_path_part(
4970-
inp_dev_name, strlen(inp_dev_name));
4971-
/* Build the new path with the controller name */
4972-
size_t _len = strlcpy(remap_path, core_name, sizeof(remap_path));
4973-
_len += strlcpy(remap_path + _len, PATH_DEFAULT_SLASH(),
4974-
sizeof(remap_path) - _len);
4975-
strlcpy(remap_path + _len, inp_dev_dir,
4976-
sizeof(remap_path) - _len);
4977-
/* Deallocate as we no longer need this */
4978-
free((char*)inp_dev_dir);
4979-
inp_dev_dir = NULL;
4968+
const char *input_device_name = input_config_get_device_display_name(joypad_port);
4969+
4970+
if (!string_is_empty(input_device_name))
4971+
{
4972+
/* Ensure directory does not contain special chars */
4973+
const char *input_device_dir = sanitize_path_part(input_device_name, strlen(input_device_name));
4974+
4975+
fill_pathname_join_special(remap_path, core_name, input_device_dir, sizeof(remap_path));
4976+
}
49804977
}
4981-
else /* We're not using controller path, just use core name */
4982-
strlcpy(remap_path, core_name, sizeof(remap_path));
49834978

49844979
if (!string_is_empty(rarch_path_basename))
49854980
{

menu/cbs/menu_cbs_ok.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,39 +3771,31 @@ static int generic_action_ok_remap_file_operation(const char *path,
37713771
const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME);
37723772
bool has_content = !string_is_empty(rarch_path_basename);
37733773
settings_t *settings = config_get_ptr();
3774-
const char *directory_input_remapping = settings->paths.directory_input_remapping;
37753774
unsigned joypad_port = settings->uints.input_joypad_index[0];
3776-
const char *input_device_name = input_config_get_device_display_name(joypad_port);
3777-
const char *input_device_dir = NULL;
37783775
bool sort_remaps_by_controller = settings->bools.input_remap_sort_by_controller_enable;
3779-
size_t _len = 0;
3776+
const char *directory_input_remapping = settings->paths.directory_input_remapping;
37803777

3781-
remap_file_path[0] = '\0';
3778+
remap_file_path[0] = '\0';
37823779

37833780
/* Cannot perform remap file operation if we
37843781
* have no core */
37853782
if (string_is_empty(core_name))
37863783
return -1;
37873784

3788-
if ( sort_remaps_by_controller
3789-
&& (input_device_name != NULL)
3790-
&& !string_is_empty(input_device_name))
3785+
strlcpy(remap_path, core_name, sizeof(remap_path));
3786+
3787+
if (sort_remaps_by_controller)
37913788
{
3792-
/* Ensure directory does not contain special chars */
3793-
input_device_dir = sanitize_path_part(input_device_name, strlen(input_device_name));
3789+
const char *input_device_name = input_config_get_device_display_name(joypad_port);
37943790

3795-
/* Allocate memory for the new path */
3796-
/* Build the new path with the controller name */
3797-
_len = strlcpy(remap_path, core_name, sizeof(remap_path));
3798-
_len += strlcpy(remap_path + _len, PATH_DEFAULT_SLASH(), sizeof(remap_path) - _len);
3799-
strlcpy(remap_path + _len, input_device_dir, sizeof(remap_path) - _len);
3791+
if (!string_is_empty(input_device_name))
3792+
{
3793+
/* Ensure directory does not contain special chars */
3794+
const char *input_device_dir = sanitize_path_part(input_device_name, strlen(input_device_name));
38003795

3801-
/* Deallocate as we no longer this */
3802-
free((char*)input_device_dir);
3803-
input_device_dir = NULL;
3796+
fill_pathname_join_special(remap_path, core_name, input_device_dir, sizeof(remap_path));
3797+
}
38043798
}
3805-
else /* We're not using controller path, just use core name */
3806-
strlcpy(remap_path, core_name, sizeof(remap_path));
38073799

38083800
switch (action_type)
38093801
{

retroarch.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8272,10 +8272,12 @@ bool retroarch_main_init(int argc, char *argv[])
82728272
settings->uints.input_max_users);
82738273
#endif
82748274
input_mapper_reset(&input_st->mapper);
8275+
command_event(CMD_EVENT_CONTROLLER_INIT, NULL);
8276+
82758277
#ifdef HAVE_REWIND
82768278
command_event(CMD_EVENT_REWIND_INIT, NULL);
82778279
#endif
8278-
command_event(CMD_EVENT_CONTROLLER_INIT, NULL);
8280+
82798281
if (!string_is_empty(rec_st->path))
82808282
command_event(CMD_EVENT_RECORD_INIT, NULL);
82818283

tasks/task_autodetect.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,24 @@ static void cb_input_autoconfigure_connect(
662662
input_config_set_autoconfig_binds(port,
663663
autoconfig_handle->autoconfig_file);
664664

665+
#ifdef HAVE_CONFIGFILE
666+
/* 'Sort Remaps by Gamepad' must reload remaps after
667+
* controller detection, because controller name
668+
* does not exist yet at core init when launched from CLI */
669+
if (!retroarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL))
670+
{
671+
settings_t *settings = config_get_ptr();
672+
673+
if ( settings->bools.auto_remaps_enable
674+
&& settings->bools.input_remap_sort_by_controller_enable)
675+
{
676+
runloop_state_t *runloop_st = runloop_state_get_ptr();
677+
678+
config_load_remap(settings->paths.directory_input_remapping, &runloop_st->system);
679+
}
680+
}
681+
#endif
682+
665683
reallocate_port_if_needed(port,autoconfig_handle->device_info.vid,
666684
autoconfig_handle->device_info.pid,
667685
autoconfig_handle->device_info.name,

0 commit comments

Comments
 (0)