Mercurial > repos > blastem
comparison config.c @ 1599:1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 27 Jul 2018 22:40:56 -0700 |
parents | 24508cb54f87 |
children | ba3fb7a3be6b |
comparison
equal
deleted
inserted
replaced
1598:5e2af89c3467 | 1599:1fc61c844ec5 |
---|---|
214 free(confdata); | 214 free(confdata); |
215 } | 215 } |
216 return ret; | 216 return ret; |
217 } | 217 } |
218 | 218 |
219 tern_node *load_config() | 219 tern_node *load_overrideable_config(char *name, char *bundled_name) |
220 { | 220 { |
221 char const *confdir = get_config_dir(); | 221 char const *confdir = get_config_dir(); |
222 char *confpath = NULL; | 222 char *confpath = NULL; |
223 tern_node *ret; | 223 tern_node *ret; |
224 if (confdir) { | |
225 confpath = path_append(confdir, name); | |
226 ret = parse_config_file(confpath); | |
227 if (ret) { | |
228 free(confpath); | |
229 return ret; | |
230 } | |
231 } | |
232 | |
233 ret = parse_bundled_config(bundled_name); | |
234 if (ret) { | |
235 free(confpath); | |
236 return ret; | |
237 } | |
238 return NULL; | |
239 } | |
240 | |
241 tern_node *load_config() | |
242 { | |
243 char const *confdir = get_config_dir(); | |
244 char *confpath = NULL; | |
245 tern_node *ret = load_overrideable_config("blastem.cfg", "default.cfg"); | |
224 if (confdir) { | 246 if (confdir) { |
225 confpath = path_append(confdir, "blastem.cfg"); | 247 confpath = path_append(confdir, "blastem.cfg"); |
226 ret = parse_config_file(confpath); | 248 ret = parse_config_file(confpath); |
227 if (ret) { | 249 if (ret) { |
228 free(confpath); | 250 free(confpath); |
234 if (ret) { | 256 if (ret) { |
235 free(confpath); | 257 free(confpath); |
236 return ret; | 258 return ret; |
237 } | 259 } |
238 | 260 |
239 if (confpath) { | 261 if (get_config_dir()) { |
240 fatal_error("Failed to find a config file at %s or in the blastem executable directory\n", confpath); | 262 fatal_error("Failed to find a config file at %s or in the blastem executable directory\n", get_config_dir()); |
241 } else { | 263 } else { |
242 fatal_error("Failed to find a config file in the BlastEm executable directory and the config directory path could not be determined\n"); | 264 fatal_error("Failed to find a config file in the BlastEm executable directory and the config directory path could not be determined\n"); |
243 } | 265 } |
244 //this will never get reached, but the compiler doesn't know that. Let's make it happy | 266 //this will never get reached, but the compiler doesn't know that. Let's make it happy |
245 return NULL; | 267 return NULL; |
246 } | 268 } |
247 | 269 |
248 void persist_config(tern_node *config) | 270 void persist_config_at(tern_node *config, char *fname) |
249 { | 271 { |
250 char const *confdir = get_config_dir(); | 272 char const *confdir = get_config_dir(); |
251 if (!confdir) { | 273 if (!confdir) { |
252 fatal_error("Failed to locate config file directory\n"); | 274 fatal_error("Failed to locate config file directory\n"); |
253 } | 275 } |
254 ensure_dir_exists(confdir); | 276 ensure_dir_exists(confdir); |
255 char *confpath = path_append(confdir, "blastem.cfg"); | 277 char *confpath = path_append(confdir, fname); |
256 if (!serialize_config_file(config, confpath)) { | 278 if (!serialize_config_file(config, confpath)) { |
257 fatal_error("Failed to write config to %s\n", confpath); | 279 fatal_error("Failed to write config to %s\n", confpath); |
258 } | 280 } |
259 free(confpath); | 281 free(confpath); |
282 } | |
283 | |
284 void persist_config(tern_node *config) | |
285 { | |
286 persist_config_at(config, "blastem.cfg"); | |
260 } | 287 } |
261 | 288 |
262 char **get_extension_list(tern_node *config, uint32_t *num_exts_out) | 289 char **get_extension_list(tern_node *config, uint32_t *num_exts_out) |
263 { | 290 { |
264 char *ext_filter = strdup(tern_find_path_default(config, "ui\0extensions\0", (tern_val){.ptrval = "bin gen md smd sms gg"}, TVAL_PTR).ptrval); | 291 char *ext_filter = strdup(tern_find_path_default(config, "ui\0extensions\0", (tern_val){.ptrval = "bin gen md smd sms gg"}, TVAL_PTR).ptrval); |