|
22 | 22 |
|
23 | 23 | #include <compat/strl.h> |
24 | 24 | #include <file/file_path.h> |
25 | | -#include <lists/string_list.h> |
| 25 | +#include <retro_dirent.h> |
26 | 26 | #include <string/stdstring.h> |
27 | 27 | #include <file/config_file.h> |
28 | 28 |
|
@@ -260,108 +260,93 @@ static bool input_autoconfigure_scan_config_files_external( |
260 | 260 | { |
261 | 261 | const char *dir_autoconfig = autoconfig_handle->dir_autoconfig; |
262 | 262 | const char *dir_driver_autoconfig = autoconfig_handle->dir_driver_autoconfig; |
263 | | - struct string_list *config_file_list = NULL; |
264 | 263 | unsigned max_affinity = 0; |
265 | 264 | bool match_found = false; |
266 | | - bool dir_driver_iterated = false; |
| 265 | + config_file_t *best_config = NULL; |
| 266 | + const char *dirs[2]; |
| 267 | + unsigned num_dirs = 0; |
| 268 | + unsigned d; |
267 | 269 |
|
268 | | - /* First attempt to fetch from autoconfig base directory */ |
269 | 270 | if ( !string_is_empty(dir_autoconfig) |
270 | 271 | && path_is_directory(dir_autoconfig)) |
271 | | - config_file_list = dir_list_new_special( |
272 | | - dir_autoconfig, DIR_LIST_AUTOCONFIG, |
273 | | - "cfg", false); |
| 272 | + dirs[num_dirs++] = dir_autoconfig; |
274 | 273 |
|
275 | | -list_iterate: |
276 | | - if (config_file_list && config_file_list->size) |
| 274 | + if ( !string_is_empty(dir_driver_autoconfig) |
| 275 | + && path_is_directory(dir_driver_autoconfig)) |
| 276 | + dirs[num_dirs++] = dir_driver_autoconfig; |
| 277 | + |
| 278 | + for (d = 0; d < num_dirs; d++) |
277 | 279 | { |
278 | | - size_t i; |
279 | | - config_file_t *best_config = NULL; |
| 280 | + struct RDIR *rdir = retro_opendir(dirs[d]); |
| 281 | + if (!rdir) |
| 282 | + continue; |
280 | 283 |
|
281 | | - /* Loop through external config files */ |
282 | | - for (i = 0; i < config_file_list->size; i++) |
| 284 | + while (retro_readdir(rdir)) |
283 | 285 | { |
284 | | - const char *config_file_path = config_file_list->elems[i].data; |
285 | | - config_file_t *config = NULL; |
286 | | - unsigned affinity = 0; |
287 | | - |
288 | | - if (string_is_empty(config_file_path)) |
| 286 | + const char *entry_name = retro_dirent_get_name(rdir); |
| 287 | + char config_file_path[PATH_MAX_LENGTH]; |
| 288 | + config_file_t *config = NULL; |
| 289 | + unsigned affinity = 0; |
| 290 | + |
| 291 | + if ( string_is_empty(entry_name) |
| 292 | + || !string_is_equal_noncase( |
| 293 | + path_get_extension(entry_name), "cfg")) |
289 | 294 | continue; |
290 | 295 |
|
291 | | - /* Load autoconfig file */ |
| 296 | + fill_pathname_join_special(config_file_path, |
| 297 | + dirs[d], entry_name, sizeof(config_file_path)); |
| 298 | + |
292 | 299 | if (!(config = config_file_new_from_path_to_string(config_file_path))) |
293 | 300 | continue; |
294 | 301 |
|
295 | | - /* Check for a match */ |
296 | | - if (autoconfig_handle && config) |
297 | | - affinity = input_autoconfigure_get_config_file_affinity( |
298 | | - autoconfig_handle, config); |
| 302 | + affinity = input_autoconfigure_get_config_file_affinity( |
| 303 | + autoconfig_handle, config); |
299 | 304 |
|
300 | 305 | if (affinity > max_affinity) |
301 | 306 | { |
302 | 307 | if (best_config) |
303 | | - { |
304 | 308 | config_file_free(best_config); |
305 | | - best_config = NULL; |
306 | | - } |
307 | 309 |
|
308 | | - /* 'Cache' config file for later processing */ |
309 | 310 | best_config = config; |
310 | 311 | config = NULL; |
311 | 312 | max_affinity = affinity; |
312 | 313 |
|
313 | | - /* An affinity of 6x is a 'perfect' match, |
314 | | - * and means we can return immediately */ |
315 | 314 | if (affinity >= 60) |
316 | | - break; |
| 315 | + { |
| 316 | + retro_closedir(rdir); |
| 317 | + goto done; |
| 318 | + } |
317 | 319 | } |
318 | | - /* No match - just clean up config file */ |
319 | 320 | else |
320 | 321 | { |
321 | 322 | config_file_free(config); |
322 | 323 | config = NULL; |
323 | 324 | } |
324 | 325 | } |
325 | 326 |
|
326 | | - /* If we reach this point and a config file has |
327 | | - * been cached, then we have a match */ |
328 | | - if (best_config) |
329 | | - { |
330 | | - if (autoconfig_handle && best_config) |
331 | | - input_autoconfigure_set_config_file( |
332 | | - autoconfig_handle, best_config, |
333 | | - max_affinity % 10); |
334 | | - match_found = true; |
335 | | - } |
| 327 | + retro_closedir(rdir); |
336 | 328 |
|
337 | | - RARCH_DBG("[Autoconf] Config files scanned: driver \"%s\", name \"%s\" (%04x/%04x), phys \"%s\", affinity %d.\n", |
338 | | - autoconfig_handle->device_info.joypad_driver, |
339 | | - autoconfig_handle->device_info.name, |
340 | | - autoconfig_handle->device_info.vid, autoconfig_handle->device_info.pid, |
341 | | - autoconfig_handle->device_info.phys, |
342 | | - max_affinity); |
| 329 | + if (best_config) |
| 330 | + break; |
343 | 331 | } |
344 | 332 |
|
345 | | - string_list_free(config_file_list); |
346 | | - config_file_list = NULL; |
347 | | - |
348 | | - if (match_found) |
349 | | - return true; |
350 | | - else if (!match_found && !dir_driver_iterated) |
| 333 | +done: |
| 334 | + if (best_config) |
351 | 335 | { |
352 | | - /* Attempt to fetch file listing from driver-specific |
353 | | - * autoconfig directory */ |
354 | | - if ( !string_is_empty(dir_driver_autoconfig) |
355 | | - && path_is_directory(dir_driver_autoconfig)) |
356 | | - config_file_list = dir_list_new_special( |
357 | | - dir_driver_autoconfig, DIR_LIST_AUTOCONFIG, |
358 | | - "cfg", false); |
359 | | - |
360 | | - dir_driver_iterated = true; |
361 | | - goto list_iterate; |
| 336 | + input_autoconfigure_set_config_file( |
| 337 | + autoconfig_handle, best_config, |
| 338 | + max_affinity % 10); |
| 339 | + match_found = true; |
362 | 340 | } |
363 | 341 |
|
364 | | - return false; |
| 342 | + RARCH_DBG("[Autoconf] Config files scanned: driver \"%s\", name \"%s\" (%04x/%04x), phys \"%s\", affinity %d.\n", |
| 343 | + autoconfig_handle->device_info.joypad_driver, |
| 344 | + autoconfig_handle->device_info.name, |
| 345 | + autoconfig_handle->device_info.vid, autoconfig_handle->device_info.pid, |
| 346 | + autoconfig_handle->device_info.phys, |
| 347 | + max_affinity); |
| 348 | + |
| 349 | + return match_found; |
365 | 350 | } |
366 | 351 |
|
367 | 352 | /* Attempts to find an internal autoconfig definition |
|
0 commit comments