Cleanup action_ok_option_create

This commit is contained in:
twinaphex 2016-01-26 02:21:03 +01:00
parent 8d1aaa4905
commit 04616522b9
2 changed files with 52 additions and 29 deletions

View File

@ -1323,21 +1323,26 @@ static int action_ok_disk_cycle_tray_status(const char *path,
return generic_action_ok_command(EVENT_CMD_DISK_EJECT_TOGGLE); return generic_action_ok_command(EVENT_CMD_DISK_EJECT_TOGGLE);
} }
/* creates folder and core options stub file for subsequent runs */ bool rarch_option_create(char *path, size_t len)
static int action_ok_option_create(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{ {
settings_t *settings = config_get_ptr(); char core_path[PATH_MAX_LENGTH];
global_t *global = global_get_ptr(); char config_directory[PATH_MAX_LENGTH];
rarch_system_info_t *system = NULL; const char *core_name = NULL;
const char *core_name = NULL; const char *game_name = NULL;
const char *game_name = NULL; global_t *global = global_get_ptr();
char core_path[PATH_MAX_LENGTH] = {0}; settings_t *settings = config_get_ptr();
char game_path[PATH_MAX_LENGTH] = {0}; rarch_system_info_t *system = NULL;
char config_directory[PATH_MAX_LENGTH] = {0};
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system);
if (system)
core_name = system->info.library_name;
if (global)
game_name = path_basename(global->name.base);
if (string_is_empty(core_name) || string_is_empty(game_name))
return false;
/* Config directory: config_directory. /* Config directory: config_directory.
* Try config directory setting first, * Try config directory setting first,
* fallback to the location of the current configuration file. */ * fallback to the location of the current configuration file. */
@ -1353,27 +1358,41 @@ static int action_ok_option_create(const char *path,
return false; return false;
} }
core_name = system ? system->info.library_name : NULL;
game_name = global ? path_basename(global->name.base) : NULL;
if (string_is_empty(core_name) || string_is_empty(game_name))
return false;
/* Concatenate strings into full paths for game_path */ /* Concatenate strings into full paths for game_path */
fill_pathname_join(core_path, config_directory, core_name, sizeof(core_path)); fill_pathname_join(path,
fill_pathname_join(game_path, config_directory, core_name, sizeof(game_path)); config_directory, core_name, len);
fill_pathname_join(game_path, game_path, game_name, sizeof(game_path)); fill_string_join(path, game_name, len);
strlcat(game_path, ".opt", sizeof(game_path)); strlcat(path, ".opt", len);
fill_pathname_join(core_path,
config_directory, core_name, sizeof(core_path));
if (!path_is_directory(core_path)) if (!path_is_directory(core_path))
path_mkdir(core_path); path_mkdir(core_path);
if(core_option_flush_game_specific(system->core_options,game_path)) return true;
menu_display_msg_queue_push("Core options file saved successfully", }
1, 100, true);
else /* 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];
rarch_system_info_t *system = NULL;
if (!rarch_option_create(game_path, sizeof(game_path)))
{
menu_display_msg_queue_push("Error saving core options file", menu_display_msg_queue_push("Error saving core options file",
1, 100, true); 1, 100, true);
return 0;
}
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system);
if(core_option_flush_game_specific(system->core_options,
game_path))
menu_display_msg_queue_push("Core options file saved successfully",
1, 100, true);
return 0; return 0;
} }

View File

@ -429,9 +429,11 @@ static bool rarch_game_specific_options(char **output)
* Try config directory setting first, * Try config directory setting first,
* fallback to the location of the current configuration file. */ * fallback to the location of the current configuration file. */
if (!string_is_empty(settings->menu_config_directory)) if (!string_is_empty(settings->menu_config_directory))
strlcpy(config_directory, settings->menu_config_directory, sizeof(config_directory)); strlcpy(config_directory,
settings->menu_config_directory, sizeof(config_directory));
else if (!string_is_empty(global->path.config)) else if (!string_is_empty(global->path.config))
fill_pathname_basedir(config_directory, global->path.config, sizeof(config_directory)); fill_pathname_basedir(config_directory,
global->path.config, sizeof(config_directory));
else else
{ {
RARCH_WARN("Per-Game Options: no config directory set\n"); RARCH_WARN("Per-Game Options: no config directory set\n");
@ -439,8 +441,10 @@ static bool rarch_game_specific_options(char **output)
} }
/* Concatenate strings into full paths for game_path */ /* Concatenate strings into full paths for game_path */
fill_pathname_join(game_path, config_directory, core_name, sizeof(game_path)); fill_pathname_join(game_path,
fill_pathname_join(game_path, game_path, game_name, sizeof(game_path)); config_directory, core_name, sizeof(game_path));
fill_pathname_join(game_path,
game_path, game_name, sizeof(game_path));
strlcat(game_path, ".opt", sizeof(game_path)); strlcat(game_path, ".opt", sizeof(game_path));
option_file = config_file_new(game_path); option_file = config_file_new(game_path);