mirror of
https://github.com/libretro/RetroArch
synced 2025-04-02 07:20:34 +00:00
Simple Shader Save Cleanup
This commit is contained in:
parent
70bf90c5d8
commit
f6e35420bc
@ -603,19 +603,20 @@ bool video_shader_write_referenced_preset(const char *path,
|
||||
const struct video_shader *shader)
|
||||
{
|
||||
unsigned i;
|
||||
config_file_t *conf = NULL;
|
||||
bool ret = false;
|
||||
bool continue_saving_reference = true;
|
||||
char preset_dir[PATH_MAX_LENGTH];
|
||||
config_file_t *conf;
|
||||
char *preset_dir = (char*)malloc(PATH_MAX_LENGTH);
|
||||
char *absolute_root_preset_path = (char*)malloc(PATH_MAX_LENGTH);
|
||||
char *absolute_new_preset_basedir = (char*)malloc(PATH_MAX_LENGTH);
|
||||
char *relative_root_preset_path = (char*)malloc(PATH_MAX_LENGTH);
|
||||
char *absolute_new_preset_basedir = NULL;
|
||||
|
||||
preset_dir[0] = '\0';
|
||||
absolute_new_preset_basedir = strdup(path);
|
||||
path_basedir(absolute_new_preset_basedir);
|
||||
absolute_root_preset_path[0] = '\0';
|
||||
relative_root_preset_path[0] = '\0';
|
||||
absolute_new_preset_basedir = strdup(path);
|
||||
|
||||
path_basedir(absolute_new_preset_basedir);
|
||||
|
||||
/* Get the absolute path to the root preset, this is the one which is used in the #reference directive */
|
||||
strlcpy(absolute_root_preset_path, shader->path, PATH_MAX_LENGTH);
|
||||
@ -634,21 +635,6 @@ bool video_shader_write_referenced_preset(const char *path,
|
||||
continue_saving_reference = false;
|
||||
}
|
||||
|
||||
/* Auto-shaders can be written as copies or references.
|
||||
* If we write a reference to a copy, we could then overwrite the copy
|
||||
* with any reference, thus creating a reference to a reference.
|
||||
* To prevent this, we disallow saving references to auto-shaders. */
|
||||
fill_pathname_join(preset_dir,
|
||||
shader_dir,
|
||||
"presets",
|
||||
sizeof(preset_dir));
|
||||
if (continue_saving_reference && !strncmp(preset_dir, absolute_root_preset_path, strlen(preset_dir)))
|
||||
{
|
||||
RARCH_WARN("[Shaders-Save Reference]: Saving Full Preset because we can't save a "
|
||||
"reference to an auto-loaded shader (E.G. Game Preset, Core Preset).\n");
|
||||
continue_saving_reference = false;
|
||||
}
|
||||
|
||||
/* Don't ever create a reference to the ever-changing retroarch preset
|
||||
* TODO remove once we don't write this preset anymore */
|
||||
if (continue_saving_reference && !strncmp(path_basename(absolute_root_preset_path), "retroarch", STRLEN_CONST("retroarch")))
|
||||
@ -674,7 +660,7 @@ bool video_shader_write_referenced_preset(const char *path,
|
||||
/* Create a new EMPTY config */
|
||||
conf = config_file_new_alloc();
|
||||
if (!(conf))
|
||||
return false;
|
||||
goto end;
|
||||
conf->path = strdup(path);
|
||||
|
||||
/* Add the reference path to the config */
|
||||
@ -879,19 +865,16 @@ bool video_shader_write_referenced_preset(const char *path,
|
||||
/* If the shader has textures */
|
||||
if (shader->luts)
|
||||
{
|
||||
char *shader_tex_path = (char*)malloc(3*PATH_MAX_LENGTH);
|
||||
char *shader_tex_relative_path = shader_tex_path + PATH_MAX_LENGTH;
|
||||
char *shader_tex_base_path = shader_tex_path + 2*PATH_MAX_LENGTH;
|
||||
char *shader_tex_path = (char*)malloc(PATH_MAX_LENGTH);
|
||||
char *shader_tex_relative_path = (char*)malloc(PATH_MAX_LENGTH);
|
||||
char *shader_tex_base_path = (char*)malloc(PATH_MAX_LENGTH);
|
||||
char *referenced_tex_absolute_path = (char*)malloc(PATH_MAX_LENGTH);
|
||||
char *referenced_tex_path = (char*)malloc(PATH_MAX_LENGTH);
|
||||
size_t tex_size = 4096 * sizeof(char);
|
||||
char *textures = (char*)malloc(tex_size);
|
||||
unsigned i;
|
||||
|
||||
shader_tex_path[0] = '\0';
|
||||
shader_tex_relative_path[0] = '\0';
|
||||
shader_tex_base_path[0] = '\0';
|
||||
textures[0] = '\0';
|
||||
referenced_tex_absolute_path[0] = '\0';
|
||||
referenced_tex_path[0] = '\0';
|
||||
|
||||
@ -928,6 +911,12 @@ bool video_shader_write_referenced_preset(const char *path,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(shader_tex_path);
|
||||
free(shader_tex_relative_path);
|
||||
free(shader_tex_base_path);
|
||||
free(referenced_tex_absolute_path);
|
||||
free(referenced_tex_path);
|
||||
}
|
||||
/* Write the file, return will be true if successful */
|
||||
ret = config_file_write(conf, path, false);
|
||||
@ -937,10 +926,18 @@ bool video_shader_write_referenced_preset(const char *path,
|
||||
"Full Preset Will be Saved instead of Simple Preset\n", path);
|
||||
}
|
||||
config_file_free(root_conf);
|
||||
free(root_shader);
|
||||
}
|
||||
config_file_free(conf);
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
free(preset_dir);
|
||||
free(absolute_root_preset_path);
|
||||
free(relative_root_preset_path);
|
||||
free(absolute_new_preset_basedir);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1075,6 +1072,10 @@ bool override_config_values(config_file_t *conf, config_file_t *override_conf)
|
||||
{
|
||||
/* Get the string for the parameters from the root config */
|
||||
char *parameters = NULL;
|
||||
const char *override_id = NULL;
|
||||
char *override_save = NULL;
|
||||
bool param_found = false;
|
||||
|
||||
parameters = (char*)malloc(param_size);
|
||||
parameters[0] = '\0';
|
||||
|
||||
@ -1086,19 +1087,31 @@ bool override_config_values(config_file_t *conf, config_file_t *override_conf)
|
||||
}
|
||||
|
||||
/* Step through each parameter in override config */
|
||||
for ( id = strtok_r(override_parameters, ";", &save);
|
||||
for ( override_id = strtok_r(override_parameters, ";", &override_save);
|
||||
override_id;
|
||||
override_id = strtok_r(NULL, ";", &override_save))
|
||||
{
|
||||
/* Check all ids in the parameters array to see if the
|
||||
* override id is already there */
|
||||
for ( id = strtok_r(parameters, ";", &save);
|
||||
id;
|
||||
id = strtok_r(NULL, ";", &save))
|
||||
if (string_is_equal(id, override_id))
|
||||
{
|
||||
/* If the parameter is not in the root config's parameter list add it */
|
||||
if (!strstr(parameters, id))
|
||||
param_found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
/* If the parameter is not in the config's parameter list yet add it */
|
||||
if (!param_found)
|
||||
{
|
||||
strlcat(parameters, ";", param_size);
|
||||
strlcat(parameters, id, param_size);
|
||||
strlcat(parameters, override_id, param_size);
|
||||
return_val = 1;
|
||||
}
|
||||
param_found = false;
|
||||
}
|
||||
config_set_string(conf, "parameters", strdup(parameters));
|
||||
config_set_string(conf, "parameters", parameters);
|
||||
|
||||
free(parameters);
|
||||
}
|
||||
@ -1114,7 +1127,7 @@ bool override_config_values(config_file_t *conf, config_file_t *override_conf)
|
||||
{
|
||||
RARCH_LOG("[Shaders-Load Reference]: Entry overridden %s = %s.\n",
|
||||
override_entry->key, override_entry->value);
|
||||
config_set_string(conf, override_entry->key, strdup(override_entry->value));
|
||||
config_set_string(conf, override_entry->key, override_entry->value);
|
||||
return_val = 1;
|
||||
}
|
||||
}
|
||||
|
@ -463,24 +463,26 @@ static bool config_file_parse_line(config_file_t *conf,
|
||||
if (comment)
|
||||
{
|
||||
config_file_t sub_conf;
|
||||
bool include_found = false;
|
||||
bool reference_found = false;
|
||||
char real_path[PATH_MAX_LENGTH];
|
||||
char *path = NULL;
|
||||
char *include_line = NULL;
|
||||
char *reference_line = NULL;
|
||||
|
||||
/* Starting a line with an 'include' directive
|
||||
* appends a sub-config file
|
||||
* > All other comments are ignored */
|
||||
if (!string_starts_with_size(comment, "include ",
|
||||
STRLEN_CONST("include ")) &&
|
||||
!string_starts_with_size(comment, "reference ",
|
||||
STRLEN_CONST("reference ")))
|
||||
include_found = string_starts_with_size(comment, "include ",
|
||||
STRLEN_CONST("include "));
|
||||
reference_found = string_starts_with_size(comment, "reference ",
|
||||
STRLEN_CONST("reference "));
|
||||
|
||||
/* All comments except those starting with the include or
|
||||
* reference directive are ignored */
|
||||
if (!include_found && !reference_found)
|
||||
return false;
|
||||
|
||||
/* Starting a line with an 'include' directive
|
||||
* appends a sub-config file */
|
||||
if (string_starts_with_size(comment, "include ",
|
||||
STRLEN_CONST("include ")))
|
||||
if (include_found)
|
||||
{
|
||||
include_line = comment + STRLEN_CONST("include ");
|
||||
|
||||
@ -521,9 +523,9 @@ static bool config_file_parse_line(config_file_t *conf,
|
||||
}
|
||||
}
|
||||
|
||||
/* If it's a 'reference' directive */
|
||||
if (string_starts_with_size(comment, "reference ",
|
||||
STRLEN_CONST("reference ")))
|
||||
/* Starting a line with an 'reference' directive
|
||||
* sets the reference path */
|
||||
if (reference_found)
|
||||
{
|
||||
reference_line = comment + STRLEN_CONST("reference ");
|
||||
|
||||
@ -648,13 +650,19 @@ static int config_file_from_string_internal(
|
||||
|
||||
void config_file_set_reference_path(config_file_t *conf, char *path)
|
||||
{
|
||||
if (conf)
|
||||
/* If a relative path the input path is desired the caller is
|
||||
* responsible for preparing and supplying the relative path*/
|
||||
if (!conf)
|
||||
return;
|
||||
|
||||
if (conf->reference)
|
||||
{
|
||||
/* Assumes if you wanted a relative path the input path is
|
||||
* already relative to the config
|
||||
*/
|
||||
conf->reference = strdup(path);
|
||||
free(conf->reference);
|
||||
conf->reference = NULL;
|
||||
}
|
||||
|
||||
|
||||
conf->reference = strdup(path);
|
||||
}
|
||||
|
||||
bool config_file_deinitialize(config_file_t *conf)
|
||||
@ -695,6 +703,9 @@ bool config_file_deinitialize(config_file_t *conf)
|
||||
free(hold);
|
||||
}
|
||||
|
||||
if (conf->reference)
|
||||
free(conf->reference);
|
||||
|
||||
if (conf->path)
|
||||
free(conf->path);
|
||||
return true;
|
||||
|
@ -799,6 +799,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_shader_num_passes,
|
||||
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_shader_preset, MENU_ENUM_SUBLABEL_VIDEO_SHADER_PRESET)
|
||||
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_shader_preset_save, MENU_ENUM_SUBLABEL_VIDEO_SHADER_PRESET_SAVE)
|
||||
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_shader_preset_remove, MENU_ENUM_SUBLABEL_VIDEO_SHADER_PRESET_REMOVE)
|
||||
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_shader_preset_save_reference, MENU_ENUM_SUBLABEL_VIDEO_SHADER_PRESET_SAVE_REFERENCE)
|
||||
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_shader_preset_save_as, MENU_ENUM_SUBLABEL_VIDEO_SHADER_PRESET_SAVE_AS)
|
||||
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_shader_preset_save_global, MENU_ENUM_SUBLABEL_VIDEO_SHADER_PRESET_SAVE_GLOBAL)
|
||||
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_shader_preset_save_core, MENU_ENUM_SUBLABEL_VIDEO_SHADER_PRESET_SAVE_CORE)
|
||||
@ -1864,6 +1865,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
|
||||
case MENU_ENUM_LABEL_VIDEO_SHADER_PRESET_REMOVE:
|
||||
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_shader_preset_remove);
|
||||
break;
|
||||
case MENU_ENUM_LABEL_VIDEO_SHADER_PRESET_SAVE_REFERENCE:
|
||||
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_shader_preset_save_reference);
|
||||
break;
|
||||
case MENU_ENUM_LABEL_VIDEO_SHADER_PRESET_SAVE_AS:
|
||||
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_shader_preset_save_as);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user