int fs_config_read_file(const char *path, int force) { if (!g_initialized) { initialize(); } fs_log("\n"); fs_log(LOG_LINE); fs_log("config (%s)\n", path); fs_log(LOG_LINE); fs_log("\n"); // FIXME: support checking a config key "end_config", which causes // later calls to fs_config_read_config_file to be ignored if (!force && fs_config_get_boolean("end_config") == 1) { fs_log("end_config is set, ignoring this config file\n"); return 1; } if (!fs_path_is_file(path)) { fs_log("config file %s does not exist\n", path); return 0; } fs_ini_file *ini_file = fs_ini_file_open(path); if (ini_file == NULL) { fs_log("error loading config file\n"); return 0; } char **groups = fs_ini_file_get_groups(ini_file, NULL); for (char **group = groups; *group; group++) { const char *prefix = ""; if (strcmp(*group, "theme") == 0) { prefix = "theme_"; } char **keys = fs_ini_file_get_keys(ini_file, *group, NULL); for (char **key = keys; *key; key++) { char *value = fs_ini_file_get_value(ini_file, *group, *key); if (value) { char *key2 = g_strconcat(prefix, *key, NULL); process_key_value(key2, value, 0); g_free(key2); } } g_strfreev(keys); } g_strfreev(groups); fs_ini_file_destroy(ini_file); return 1; }
static int load_config_file() { fs_log("load config file\n"); const char *msg = "checking config file %s\n"; char *data; int size; if (fs_data_file_content("META-INF/Config.fs-uae", &data, &size) == 0) { fs_ini_file *ini_file = fs_ini_file_open_data(data, size); if (ini_file == NULL) { fs_log("error loading config file\n"); return 1; } fs_config_parse_ini_file(ini_file); fs_ini_file_destroy(ini_file); return 0; } //g_fs_uae_config = g_key_file_new(); if (g_fs_uae_config_file_path == NULL) { char *path = g_build_filename(fs_uae_exe_dir(), "Config.fs-uae", NULL); fs_log(msg, path); if (fs_path_exists(path)) { g_fs_uae_config_file_path = path; } else { free(path); } } #ifdef MACOSX if (g_fs_uae_config_file_path == NULL) { char *path = g_build_filename(fs_uae_exe_dir(), "..", "..", "Config.fs-uae", NULL); fs_log(msg, path); if (fs_path_exists(path)) { g_fs_uae_config_file_path = path; } else { free(path); } } #endif if (g_fs_uae_config_file_path == NULL) { fs_log(msg, "Config.fs-uae"); if (fs_path_exists("Config.fs-uae")) { g_fs_uae_config_file_path = "Config.fs-uae"; } } if (g_fs_uae_config_file_path == NULL) { fs_log(msg, "fs-uae.conf"); if (fs_path_exists("fs-uae.conf")) { g_fs_uae_config_file_path = "fs-uae.conf"; } } if (g_fs_uae_config_file_path == NULL) { char *path = g_build_filename(fs_get_user_config_dir(), "fs-uae", "fs-uae.conf", NULL); fs_log(msg, path); if (fs_path_exists(path)) { g_fs_uae_config_file_path = path; } else { free(path); } } if (g_fs_uae_config_file_path == NULL) { char *path = g_build_filename(fs_uae_configurations_dir(), "Default.fs-uae", NULL); fs_log(msg, path); if (fs_path_exists(path)) { g_fs_uae_config_file_path = path; } else { free(path); } } if (g_fs_uae_config_file_path) { fs_log("loading config from %s\n", g_fs_uae_config_file_path); fs_config_read_file(g_fs_uae_config_file_path, 0); g_fs_uae_config_dir_path = g_path_get_dirname( g_fs_uae_config_file_path); } #if 0 else { if (fs_config_get_boolean("end_config") == 1) { // do not warn in case end_config was specified via argv } else { fs_log("No configuration file was found"); g_warn_about_missing_config_file = 1; } } #endif char *path = g_build_filename(fs_uae_configurations_dir(), "Host.fs-uae", NULL); fs_log(msg, path); if (fs_path_exists(path)) { fs_config_read_file(path, 0); free(path); } return 0; }