From 57dae32b6688f92247f8a749cef39518a991e0af Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 17 Aug 2014 17:42:45 +0200 Subject: [PATCH] Refactor away core_info_get_custom_config --- apple/common/main.m | 3 +-- apple/iOS/menu.m | 10 +++------- core_info.c | 19 +++++-------------- core_info.h | 3 +-- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/apple/common/main.m b/apple/common/main.m index ec16c1f59e..db680102bd 100644 --- a/apple/common/main.m +++ b/apple/common/main.m @@ -42,8 +42,7 @@ void apple_run_core(int argc, char **argv, const char* core, strlcpy(core_path, core, sizeof(core_path)); strlcpy(config_path, g_defaults.config_path, sizeof(config_path)); - if (core_info_has_custom_config(core)) - core_info_get_custom_config(core, config_path, sizeof(config_path)); + core_info_has_custom_config(core, config_path, sizeof(config_path)); static const char* const argv_game[] = { "retroarch", "-c", config_path, "-L", core_path, file_path, 0 }; static const char* const argv_menu[] = { "retroarch", "-c", config_path, "--menu", 0 }; diff --git a/apple/iOS/menu.m b/apple/iOS/menu.m index 5023de0fee..4dbef0106b 100644 --- a/apple/iOS/menu.m +++ b/apple/iOS/menu.m @@ -787,13 +787,11 @@ static void RunActionSheet(const char* title, const struct string_list* items, U rarch_setting_t *setting_data, *setting; NSMutableArray* settings; - _isCustom = core_info_has_custom_config(core.UTF8String); + _isCustom = core_info_has_custom_config(core.UTF8String, buffer, sizeof(buffer)); if (_isCustom) { const core_info_t *tmp = (const core_info_t*)core_info_list_get_by_id(core.UTF8String); self.title = tmp ? BOXSTRING(tmp->display_name) : BOXSTRING(core.UTF8String); - - core_info_get_custom_config(core.UTF8String, buffer, sizeof(buffer)); _pathToSave = BOXSTRING(buffer); self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteCustom)]; } @@ -979,11 +977,9 @@ static bool copy_config(const char *src_path, const char *dst_path) RAMenuCoreList* list = [[RAMenuCoreList alloc] initWithPath:nil allowAutoDetect:false action:^(NSString* core) { - if (!core_info_has_custom_config(core.UTF8String)) + char path[PATH_MAX]; + if (!core_info_has_custom_config(core.UTF8String, path, sizeof(path))) { - char path[PATH_MAX]; - core_info_get_custom_config(core.UTF8String, path, sizeof(path)); - if (g_defaults.config_path[0] != '\0' && path[0] != '\0') { if (!copy_config(g_defaults.config_path, path)) diff --git a/core_info.c b/core_info.c index 7bb00609f5..dd72ac34bb 100644 --- a/core_info.c +++ b/core_info.c @@ -456,26 +456,17 @@ const core_info_t *core_info_list_get_by_id(const char *core_id) return 0; } -void core_info_get_custom_config(const char *core_id, char *buf, size_t sizeof_buf) +bool core_info_has_custom_config(const char *core_id, + char *buf, size_t sizeof_buf) { if (!core_id || !buf || !sizeof_buf) - return; + return false; fill_pathname_join(buf, g_defaults.menu_config_dir, path_basename(core_id), sizeof_buf); fill_pathname(buf, buf, ".cfg", sizeof_buf); -} -bool core_info_has_custom_config(const char *core_id) -{ - char path[PATH_MAX]; - - if (!core_id) + if (buf[0] == '\0') return false; - core_info_get_custom_config(core_id, path, sizeof(path)); - - if (path[0] != '\0') - return path_file_exists(path); - - return false; + return path_file_exists(buf); } diff --git a/core_info.h b/core_info.h index 0750b3102c..d6a4807d43 100644 --- a/core_info.h +++ b/core_info.h @@ -92,8 +92,7 @@ void core_info_set_core_path(void); core_info_list_t *core_info_list_get(void); const core_info_t *core_info_list_get_by_id(const char *core_id); -void core_info_get_custom_config(const char *core_id, char *buf, size_t sizeof_buf); -bool core_info_has_custom_config(const char *core_id); +bool core_info_has_custom_config(const char *core_id, char *buf, size_t sizeof_buf); #ifdef __cplusplus }