Skip to content

Commit 9ec4a6a

Browse files
committed
input_autoconfigure_scan_config_files_external - don't use string_list
anymore and use retro_dirent instead
1 parent d17ac55 commit 9ec4a6a

1 file changed

Lines changed: 49 additions & 64 deletions

File tree

tasks/task_autodetect.c

Lines changed: 49 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include <compat/strl.h>
2424
#include <file/file_path.h>
25-
#include <lists/string_list.h>
25+
#include <retro_dirent.h>
2626
#include <string/stdstring.h>
2727
#include <file/config_file.h>
2828

@@ -260,108 +260,93 @@ static bool input_autoconfigure_scan_config_files_external(
260260
{
261261
const char *dir_autoconfig = autoconfig_handle->dir_autoconfig;
262262
const char *dir_driver_autoconfig = autoconfig_handle->dir_driver_autoconfig;
263-
struct string_list *config_file_list = NULL;
264263
unsigned max_affinity = 0;
265264
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;
267269

268-
/* First attempt to fetch from autoconfig base directory */
269270
if ( !string_is_empty(dir_autoconfig)
270271
&& 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;
274273

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++)
277279
{
278-
size_t i;
279-
config_file_t *best_config = NULL;
280+
struct RDIR *rdir = retro_opendir(dirs[d]);
281+
if (!rdir)
282+
continue;
280283

281-
/* Loop through external config files */
282-
for (i = 0; i < config_file_list->size; i++)
284+
while (retro_readdir(rdir))
283285
{
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"))
289294
continue;
290295

291-
/* Load autoconfig file */
296+
fill_pathname_join_special(config_file_path,
297+
dirs[d], entry_name, sizeof(config_file_path));
298+
292299
if (!(config = config_file_new_from_path_to_string(config_file_path)))
293300
continue;
294301

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);
299304

300305
if (affinity > max_affinity)
301306
{
302307
if (best_config)
303-
{
304308
config_file_free(best_config);
305-
best_config = NULL;
306-
}
307309

308-
/* 'Cache' config file for later processing */
309310
best_config = config;
310311
config = NULL;
311312
max_affinity = affinity;
312313

313-
/* An affinity of 6x is a 'perfect' match,
314-
* and means we can return immediately */
315314
if (affinity >= 60)
316-
break;
315+
{
316+
retro_closedir(rdir);
317+
goto done;
318+
}
317319
}
318-
/* No match - just clean up config file */
319320
else
320321
{
321322
config_file_free(config);
322323
config = NULL;
323324
}
324325
}
325326

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);
336328

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;
343331
}
344332

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)
351335
{
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;
362340
}
363341

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;
365350
}
366351

367352
/* Attempts to find an internal autoconfig definition

0 commit comments

Comments
 (0)