/** * input_remapping_save_file: * @path : Path to remapping file (relative path). * * Saves remapping values to file. * * Returns: true (1) if successful, otherwise false (0). **/ bool input_remapping_save_file(const char *path) { bool ret; unsigned i, j; char buf[PATH_MAX_LENGTH] = {0}; char remap_file[PATH_MAX_LENGTH] = {0}; config_file_t *conf = NULL; settings_t *settings = config_get_ptr(); fill_pathname_join(buf, settings->directory.input_remapping, path, sizeof(buf)); fill_pathname_noext(remap_file, buf, ".rmp", sizeof(remap_file)); conf = config_file_new(remap_file); if (!conf) { conf = config_file_new(NULL); if (!conf) return false; } for (i = 0; i < settings->input.max_users; i++) { char buf[64] = {0}; char key_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; char key_strings[RARCH_FIRST_CUSTOM_BIND + 4][128] = { "b", "y", "select", "start", "up", "down", "left", "right", "a", "x", "l", "r", "l2", "r2", "l3", "r3", "l_x", "l_y", "r_x", "r_y" }; snprintf(buf, sizeof(buf), "input_player%u", i + 1); for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 4; j++) { fill_pathname_join_delim(key_ident[j], buf, key_strings[j], '_', sizeof(key_ident[j])); /* only save values that have been modified */ if(j < RARCH_FIRST_CUSTOM_BIND) { if(settings->input.remap_ids[i][j] != j) config_set_int(conf, key_ident[j], settings->input.remap_ids[i][j]); else config_unset(conf,key_ident[j]); } else { if(settings->input.remap_ids[i][j] != j - RARCH_FIRST_CUSTOM_BIND) config_set_int(conf, key_ident[j], settings->input.remap_ids[i][j]); else config_unset(conf,key_ident[j]); } } snprintf(buf, sizeof(buf), "input_libretro_device_p%u", i + 1); config_set_int(conf, buf, settings->input.libretro_device[i]); snprintf(buf, sizeof(buf), "input_player%u_analog_dpad_mode", i + 1); config_set_int(conf, buf, settings->input.analog_dpad_mode[i]); } ret = config_file_write(conf, remap_file); config_file_free(conf); return ret; }
/** * input_remapping_save_file: * @path : Path to remapping file (relative path). * * Saves remapping values to file. * * Returns: true (1) if successful, otherwise false (0). **/ bool input_remapping_save_file(const char *path) { bool ret; unsigned i, j, k; size_t path_size = PATH_MAX_LENGTH * sizeof(char); char *buf = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char *remap_file = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); config_file_t *conf = NULL; unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS)); settings_t *settings = config_get_ptr(); buf[0] = remap_file[0] = '\0'; fill_pathname_join(buf, settings->paths.directory_input_remapping, path, path_size); fill_pathname_noext(remap_file, buf, ".rmp", path_size); free(buf); conf = config_file_new(remap_file); if (!conf) { conf = config_file_new(NULL); if (!conf) { free(remap_file); return false; } } for (i = 0; i < max_users; i++) { char s1[64], s2[64], s3[64]; char btn_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}}; char key_ident[RARCH_FIRST_CUSTOM_BIND][128] = {{0}}; char stk_ident[8][128] = {{0}}; char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][128] = { "b", "y", "select", "start", "up", "down", "left", "right", "a", "x", "l", "r", "l2", "r2", "l3", "r3", "l_x+", "l_x-", "l_y+", "l_y-", "r_x+", "r_x-", "r_y+", "r_y-" }; s1[0] = '\0'; s2[0] = '\0'; snprintf(s1, sizeof(s1), "input_player%u_btn", i + 1); snprintf(s2, sizeof(s2), "input_player%u_key", i + 1); snprintf(s3, sizeof(s1), "input_player%u_stk", i + 1); for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++) { if(j < RARCH_FIRST_CUSTOM_BIND) { fill_pathname_join_delim(btn_ident[j], s1, key_strings[j], '_', sizeof(btn_ident[j])); fill_pathname_join_delim(key_ident[j], s2, key_strings[j], '_', sizeof(btn_ident[j])); /* only save values that have been modified */ if(settings->uints.input_remap_ids[i][j] != j && settings->uints.input_remap_ids[i][j] != RARCH_UNMAPPED) config_set_int(conf, btn_ident[j], settings->uints.input_remap_ids[i][j]); else if (settings->uints.input_remap_ids[i][j] != j && settings->uints.input_remap_ids[i][j] == RARCH_UNMAPPED) config_set_int(conf, btn_ident[j], -1); else config_unset(conf,btn_ident[j]); if (settings->uints.input_keymapper_ids[i][j] != RETROK_UNKNOWN) config_set_int(conf, key_ident[j], settings->uints.input_keymapper_ids[i][j]); } else { k = j - RARCH_FIRST_CUSTOM_BIND; fill_pathname_join_delim(stk_ident[k], s3, key_strings[j], '_', sizeof(stk_ident[k])); if(settings->uints.input_remap_ids[i][j] != j && settings->uints.input_remap_ids[i][j] != RARCH_UNMAPPED) config_set_int(conf, stk_ident[k], settings->uints.input_remap_ids[i][j]); else if(settings->uints.input_remap_ids[i][j] != j && settings->uints.input_remap_ids[i][j] == RARCH_UNMAPPED) config_set_int(conf, stk_ident[k], -1); else config_unset(conf, stk_ident[k]); } } snprintf(s1, sizeof(s1), "input_libretro_device_p%u", i + 1); config_set_int(conf, s1, input_config_get_device(i)); snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1); config_set_int(conf, s1, settings->uints.input_analog_dpad_mode[i]); } ret = config_file_write(conf, remap_file); config_file_free(conf); free(remap_file); return ret; }