(config_file) Use flags

This commit is contained in:
libretroadmin 2024-09-08 18:12:12 +02:00
parent f4e2fbb660
commit 9efb498bde
7 changed files with 33 additions and 32 deletions

View File

@ -183,7 +183,7 @@ bool cheat_manager_save(
if (!(conf = config_file_new_alloc()))
return false;
conf->guaranteed_no_duplicates = true;
conf->flags |= CONF_FILE_FLG_GUARANTEED_NO_DUPLICATES;
config_set_int(conf, "cheats", cheat_st->size);

View File

@ -5534,7 +5534,7 @@ int8_t config_save_overrides(enum override_type type,
tmp_i = sizeof(settings->paths) / sizeof(settings->paths.placeholder);
path_overrides = populate_settings_path(overrides, &tmp_i);
if (conf->modified)
if (conf->flags & CONF_FILE_FLG_MODIFIED)
RARCH_LOG("[Overrides]: Looking for changed settings..\n");
if (conf)
@ -5748,12 +5748,12 @@ int8_t config_save_overrides(enum override_type type,
break;
}
if (!conf->modified && !remove)
if (!(conf->flags & CONF_FILE_FLG_MODIFIED) && !remove)
ret = -1;
if (!string_is_empty(override_path))
{
if (!conf->modified && !remove)
if (!(conf->flags & CONF_FILE_FLG_MODIFIED) && !remove)
if (path_is_valid(override_path))
remove = true;
@ -5767,7 +5767,7 @@ int8_t config_save_overrides(enum override_type type,
"Deleted", override_path);
}
}
else if (conf->modified)
else if (conf->flags & CONF_FILE_FLG_MODIFIED)
{
ret = config_file_write(conf, override_path, true);

View File

@ -1601,9 +1601,9 @@ static bool video_shader_write_referenced_preset(
/* Add the reference path to the config */
config_file_add_reference(conf, path_to_ref);
/* Set modified to true so when you run config_file_write
* it will save a file */
conf->modified = true;
/* Set modified flag to true so when
* you run config_file_write it will save a file */
conf->flags |= CONF_FILE_FLG_MODIFIED;
/*
Compare the shader to a shader created from the referenced

View File

@ -255,7 +255,7 @@ static char *config_file_extract_value(char *line)
return strdup(value);
}
/* Note 2: This is an unrolled strldup call
/* Note 2: This is an unrolled strldup call
* to avoid an unnecessary dependency -
* call is strldup("", sizeof(""))
**/
@ -464,8 +464,8 @@ static int config_file_load_internal(
continue;
}
if (
!string_is_empty(line)
if (
!string_is_empty(line)
&& config_file_parse_line(conf, list, line, cb))
{
if (conf->entries)
@ -522,7 +522,7 @@ static bool config_file_parse_line(config_file_t *conf,
bool reference_found = string_starts_with_size(comment,
"reference ", STRLEN_CONST("reference "));
/* All comments except those starting with the include or
/* All comments except those starting with the include or
* reference directive are ignored */
if (!include_found && !reference_found)
return false;
@ -708,7 +708,7 @@ static int config_file_from_string_internal(
/* Get next line of config file */
line = strtok_r(NULL, "\n", &save_ptr);
}
return 0;
}
@ -826,7 +826,7 @@ config_file_t *config_file_new_from_string(char *from_string,
const char *path)
{
struct config_file *conf = config_file_new_alloc();
if ( conf
if ( conf
&& config_file_from_string_internal(
conf, from_string, path) != -1)
return conf;
@ -934,8 +934,7 @@ void config_file_initialize(struct config_file *conf)
conf->references = NULL;
conf->includes = NULL;
conf->include_depth = 0;
conf->guaranteed_no_duplicates = false;
conf->modified = false;
conf->flags = 0;
}
config_file_t *config_file_new_alloc(void)
@ -1195,7 +1194,7 @@ bool config_get_path(config_file_t *conf, const char *key,
/**
* config_get_bool:
*
*
* Extracts a boolean from config.
* Valid boolean true are "true" and "1". Valid false are "false" and "0".
* Other values will be treated as an error.
@ -1241,7 +1240,7 @@ void config_set_string(config_file_t *conf, const char *key, const char *val)
last = conf->entries;
if (conf->guaranteed_no_duplicates)
if (conf->flags & CONF_FILE_FLG_GUARANTEED_NO_DUPLICATES)
{
if (conf->last)
last = conf->last;
@ -1268,7 +1267,7 @@ void config_set_string(config_file_t *conf, const char *key, const char *val)
* is no longer considered 'read only' */
entry->value = strdup(val);
entry->readonly = false;
conf->modified = true;
conf->flags |= CONF_FILE_FLG_MODIFIED;
return;
}
}
@ -1282,7 +1281,7 @@ void config_set_string(config_file_t *conf, const char *key, const char *val)
entry->key = strdup(key);
entry->value = strdup(val);
entry->next = NULL;
conf->modified = true;
conf->flags |= CONF_FILE_FLG_MODIFIED;
if (last)
last->next = entry;
@ -1317,7 +1316,7 @@ void config_unset(config_file_t *conf, const char *key)
entry->key = NULL;
entry->value = NULL;
conf->modified = true;
conf->flags |= CONF_FILE_FLG_MODIFIED;
}
void config_set_path(config_file_t *conf, const char *entry, const char *val)
@ -1403,7 +1402,7 @@ bool config_file_write(config_file_t *conf, const char *path, bool sort)
if (!conf)
return false;
if (conf->modified)
if (conf->flags & CONF_FILE_FLG_MODIFIED)
{
if (string_is_empty(path))
config_file_dump(conf, stdout, sort);
@ -1426,7 +1425,7 @@ bool config_file_write(config_file_t *conf, const char *path, bool sort)
/* Only update modified flag if config file
* is actually written to disk */
conf->modified = false;
conf->flags &= ~CONF_FILE_FLG_MODIFIED;
}
}

View File

@ -51,6 +51,12 @@ RETRO_BEGIN_DECLS
base->var = tmp; \
} while(0)
enum config_file_flags
{
CONF_FILE_FLG_MODIFIED = (1 << 0),
CONF_FILE_FLG_GUARANTEED_NO_DUPLICATES = (1 << 1)
};
struct config_file
{
char *path;
@ -61,8 +67,7 @@ struct config_file
struct config_include_list *includes;
struct path_linked_list *references;
unsigned include_depth;
bool guaranteed_no_duplicates;
bool modified;
uint8_t flags;
};
typedef struct config_file config_file_t;
@ -277,7 +282,7 @@ bool config_get_path(config_file_t *conf, const char *entry, char *s, size_t len
/**
* config_get_bool:
*
*
* Extracts a boolean from config.
* Valid boolean true are "true" and "1". Valid false are "false" and "0".
* Other values will be treated as an error.

View File

@ -5239,7 +5239,7 @@ void core_options_flush(void)
* exist (e.g. if it gets deleted manually while
* a core is running) */
if (!path_is_valid(path_core_options))
runloop_st->core_options->conf->modified = true;
runloop_st->core_options->conf->flags |= CONF_FILE_FLG_MODIFIED;
success = config_file_write(runloop_st->core_options->conf,
path_core_options, true);

View File

@ -156,12 +156,9 @@ static void task_menu_explore_init_handler(retro_task_t *task)
}
}
static bool task_menu_explore_init_finder(
retro_task_t *task, void *user_data)
static bool task_menu_explore_init_finder(retro_task_t *task, void *user_data)
{
if (task && task->handler == task_menu_explore_init_handler)
return true;
return false;
return (task && task->handler == task_menu_explore_init_handler);
}
bool task_push_menu_explore_init(const char *directory_playlist,