Cut down on some code duplication and turn

retroarch_validate_game_options static
This commit is contained in:
twinaphex 2020-05-11 17:19:55 +02:00
parent dd721def41
commit 6a4a522244
4 changed files with 39 additions and 62 deletions

View File

@ -4640,37 +4640,10 @@ default_action_ok_download(action_ok_update_databases, MENU_ENUM_LABEL_CB_UPDATE
default_action_ok_download(action_ok_update_cheats, MENU_ENUM_LABEL_CB_UPDATE_CHEATS)
default_action_ok_download(action_ok_update_autoconfig_profiles, MENU_ENUM_LABEL_CB_UPDATE_AUTOCONFIG_PROFILES)
/* creates folder and core options stub file for subsequent runs */
static int action_ok_option_create(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
char game_path[PATH_MAX_LENGTH];
config_file_t *conf = NULL;
game_path[0] = '\0';
if (!retroarch_validate_game_options(game_path, sizeof(game_path), true))
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_ERROR_SAVING_CORE_OPTIONS_FILE),
1, 100, true,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
return 0;
}
if (!(conf = config_file_new_from_path_to_string(game_path)))
if (!(conf = config_file_new_alloc()))
return false;
if (config_file_write(conf, game_path, true))
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_CORE_OPTIONS_FILE_CREATED_SUCCESSFULLY),
1, 100, true,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
path_set(RARCH_PATH_CORE_OPTIONS, game_path);
}
config_file_free(conf);
create_folder_and_core_options();
return 0;
}

View File

@ -26169,7 +26169,7 @@ static void retroarch_parse_input_and_config(int argc, char *argv[])
dir_set(RARCH_DIR_SAVESTATE, global->name.savestate);
}
bool retroarch_validate_game_options(char *s, size_t len, bool mkdir)
static bool retroarch_validate_game_options(char *s, size_t len, bool mkdir)
{
char *config_directory = NULL;
size_t str_size = PATH_MAX_LENGTH * sizeof(char);
@ -29678,3 +29678,37 @@ void reset_gamepad_input_override(void)
gamepad_input_override = 0;
}
#endif
/* creates folder and core options stub file for subsequent runs */
bool create_folder_and_core_options(void)
{
char game_path[PATH_MAX_LENGTH];
config_file_t *conf = NULL;
game_path[0] = '\0';
if (!retroarch_validate_game_options(game_path, sizeof(game_path), true))
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_ERROR_SAVING_CORE_OPTIONS_FILE),
1, 100, true,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
return false;
}
if (!(conf = config_file_new_from_path_to_string(game_path)))
if (!(conf = config_file_new_alloc()))
return false;
if (config_file_write(conf, game_path, true))
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_CORE_OPTIONS_FILE_CREATED_SUCCESSFULLY),
1, 100, true,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
path_set(RARCH_PATH_CORE_OPTIONS, game_path);
}
config_file_free(conf);
return true;
}

View File

@ -301,8 +301,6 @@ void retroarch_override_setting_unset(enum rarch_override_setting enum_idx, void
bool retroarch_override_setting_is_set(enum rarch_override_setting enum_idx, void *data);
bool retroarch_validate_game_options(char *s, size_t len, bool mkdir);
bool retroarch_is_forced_fullscreen(void);
void retroarch_set_current_core_type(
@ -2007,6 +2005,8 @@ void retroarch_init_task_queue(void);
bool is_input_keyboard_display_on(void);
/* creates folder and core options stub file for subsequent runs */
bool create_folder_and_core_options(void);
/* Input overrides */

View File

@ -122,38 +122,8 @@ void CoreOptionsDialog::reload()
void CoreOptionsDialog::onSaveGameSpecificOptions()
{
char game_path[PATH_MAX_LENGTH];
config_file_t *conf = NULL;
game_path[0] = '\0';
if (!retroarch_validate_game_options(game_path, sizeof(game_path), true))
{
if (!create_folder_and_core_options())
QMessageBox::critical(this, msg_hash_to_str(MSG_ERROR), msg_hash_to_str(MSG_ERROR_SAVING_CORE_OPTIONS_FILE));
return;
}
if (!(conf = config_file_new_from_path_to_string(game_path)))
{
if (!(conf = config_file_new_alloc()))
{
QMessageBox::critical(this, msg_hash_to_str(MSG_ERROR), msg_hash_to_str(MSG_ERROR_SAVING_CORE_OPTIONS_FILE));
return;
}
}
if (config_file_write(conf, game_path, true))
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_CORE_OPTIONS_FILE_CREATED_SUCCESSFULLY),
1, 100, true, NULL,
MESSAGE_QUEUE_ICON_DEFAULT,
MESSAGE_QUEUE_CATEGORY_INFO
);
path_set(RARCH_PATH_CORE_OPTIONS, game_path);
}
config_file_free(conf);
}
void CoreOptionsDialog::onCoreOptionComboBoxCurrentIndexChanged(int index)