mirror of
https://github.com/libretro/RetroArch
synced 2025-03-30 07:20:36 +00:00
Create config_file_new_from_path_to_string
This commit is contained in:
parent
d77488cd89
commit
41a2fabb4e
21
core_info.c
21
core_info.c
@ -225,16 +225,7 @@ static config_file_t *core_info_list_iterate(
|
||||
info_path_base = NULL;
|
||||
|
||||
if (path_is_valid(info_path))
|
||||
{
|
||||
int64_t length = 0;
|
||||
uint8_t *ret_buf = NULL;
|
||||
if (filestream_read_file(info_path, (void**)&ret_buf, &length))
|
||||
{
|
||||
if (length >= 0)
|
||||
conf = config_file_new_from_string((const char*)ret_buf);
|
||||
free((void*)ret_buf);
|
||||
}
|
||||
}
|
||||
conf = config_file_new_from_path_to_string(info_path);
|
||||
free(info_path);
|
||||
|
||||
return conf;
|
||||
@ -923,16 +914,8 @@ bool core_info_list_get_display_name(core_info_list_t *core_info_list,
|
||||
|
||||
bool core_info_get_display_name(const char *path, char *s, size_t len)
|
||||
{
|
||||
int64_t length = 0;
|
||||
char *tmp = NULL;
|
||||
config_file_t *conf = NULL;
|
||||
uint8_t *ret_buf = NULL;
|
||||
if (filestream_read_file(path, (void**)&ret_buf, &length))
|
||||
{
|
||||
if (length >= 0)
|
||||
conf = config_file_new_from_string((const char*)ret_buf);
|
||||
free((void*)ret_buf);
|
||||
}
|
||||
config_file_t *conf = config_file_new_from_path_to_string(path);
|
||||
|
||||
if (!conf)
|
||||
return false;
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <retro_miscellaneous.h>
|
||||
#include <file/file_path.h>
|
||||
#include <file/config_file.h>
|
||||
#include <streams/file_stream.h>
|
||||
#include <lists/string_list.h>
|
||||
#include <string/stdstring.h>
|
||||
|
@ -110,4 +110,6 @@ bool glslang_read_shader_file(const char *path, std::vector<std::string> *output
|
||||
bool glslang_parse_meta(const std::vector<std::string> &lines, glslang_meta *meta);
|
||||
#endif
|
||||
|
||||
void *config_file_new_wrapper(const char *path);
|
||||
|
||||
#endif
|
||||
|
@ -2409,7 +2409,7 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
|
||||
if (!shader)
|
||||
return nullptr;
|
||||
|
||||
unique_ptr<config_file_t, gl_core::ConfigDeleter> conf{ config_file_new(path) };
|
||||
unique_ptr<config_file_t, gl_core::ConfigDeleter> conf{ config_file_new_from_path_to_string(path) };
|
||||
if (!conf)
|
||||
return nullptr;
|
||||
|
||||
|
@ -2886,7 +2886,7 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
|
||||
if (!shader)
|
||||
return nullptr;
|
||||
|
||||
unique_ptr<config_file_t, ConfigDeleter> conf{ config_file_new(path) };
|
||||
unique_ptr<config_file_t, ConfigDeleter> conf{ config_file_new_from_path_to_string(path) };
|
||||
if (!conf)
|
||||
return nullptr;
|
||||
|
||||
|
@ -593,6 +593,23 @@ config_file_t *config_file_new_from_string(const char *from_string)
|
||||
return conf;
|
||||
}
|
||||
|
||||
config_file_t *config_file_new_from_path_to_string(const char *path)
|
||||
{
|
||||
int64_t length = 0;
|
||||
uint8_t *ret_buf = NULL;
|
||||
config_file_t *conf = NULL;
|
||||
|
||||
if (filestream_read_file(path, (void**)&ret_buf, &length))
|
||||
{
|
||||
if (length >= 0)
|
||||
if ((conf = config_file_new_from_string((const char*)ret_buf)))
|
||||
conf->path = strdup(path);
|
||||
free((void*)ret_buf);
|
||||
}
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
config_file_t *config_file_new_with_callback(
|
||||
const char *path, config_file_cb_t *cb)
|
||||
{
|
||||
|
@ -96,6 +96,8 @@ config_file_t *config_file_new_with_callback(const char *path, config_file_cb_t
|
||||
/* Load a config file from a string. */
|
||||
config_file_t *config_file_new_from_string(const char *from_string);
|
||||
|
||||
config_file_t *config_file_new_from_path_to_string(const char *path);
|
||||
|
||||
/* Frees config file. */
|
||||
void config_file_free(config_file_t *conf);
|
||||
|
||||
|
@ -78,19 +78,8 @@ bool menu_shader_manager_init(void)
|
||||
|
||||
if (is_preset)
|
||||
{
|
||||
int64_t length = 0;
|
||||
uint8_t *ret_buf = NULL;
|
||||
|
||||
if (path_is_valid(path_shader))
|
||||
{
|
||||
if (filestream_read_file(path_shader, (void**)&ret_buf, &length))
|
||||
{
|
||||
if (length >= 0)
|
||||
if ((conf = config_file_new_from_string((const char*)ret_buf)))
|
||||
conf->path = strdup(path_shader);
|
||||
free((void*)ret_buf);
|
||||
}
|
||||
}
|
||||
conf = config_file_new_from_path_to_string(path_shader);
|
||||
|
||||
new_path = strdup(path_shader);
|
||||
}
|
||||
@ -118,16 +107,7 @@ bool menu_shader_manager_init(void)
|
||||
"menu.glslp", sizeof(preset_path));
|
||||
|
||||
if (path_is_valid(preset_path))
|
||||
{
|
||||
int64_t length = 0;
|
||||
uint8_t *ret_buf = NULL;
|
||||
if (filestream_read_file(preset_path, (void**)&ret_buf, &length))
|
||||
{
|
||||
if (length >= 0)
|
||||
conf = config_file_new_from_string((const char*)ret_buf);
|
||||
free((void*)ret_buf);
|
||||
}
|
||||
}
|
||||
conf = config_file_new_from_path_to_string(preset_path);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CG
|
||||
@ -137,16 +117,7 @@ bool menu_shader_manager_init(void)
|
||||
"menu.cgp", sizeof(preset_path));
|
||||
|
||||
if (path_is_valid(preset_path))
|
||||
{
|
||||
int64_t length = 0;
|
||||
uint8_t *ret_buf = NULL;
|
||||
if (filestream_read_file(preset_path, (void**)&ret_buf, &length))
|
||||
{
|
||||
if (length >= 0)
|
||||
conf = config_file_new_from_string((const char*)ret_buf);
|
||||
free((void*)ret_buf);
|
||||
}
|
||||
}
|
||||
conf = config_file_new_from_path_to_string(preset_path);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -157,16 +128,7 @@ bool menu_shader_manager_init(void)
|
||||
"menu.slangp", sizeof(preset_path));
|
||||
|
||||
if (path_is_valid(preset_path))
|
||||
{
|
||||
int64_t length = 0;
|
||||
uint8_t *ret_buf = NULL;
|
||||
if (filestream_read_file(preset_path, (void**)&ret_buf, &length))
|
||||
{
|
||||
if (length >= 0)
|
||||
conf = config_file_new_from_string((const char*)ret_buf);
|
||||
free((void*)ret_buf);
|
||||
}
|
||||
}
|
||||
conf = config_file_new_from_path_to_string(preset_path);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -229,17 +191,9 @@ bool menu_shader_manager_set_preset(void *data,
|
||||
* Used when a preset is directly loaded.
|
||||
* No point in updating when the Preset was
|
||||
* created from the menu itself. */
|
||||
if (filestream_read_file(preset_path, (void**)&ret_buf, &length))
|
||||
{
|
||||
if (length >= 0)
|
||||
conf = config_file_new_from_string((const char*)ret_buf);
|
||||
free((void*)ret_buf);
|
||||
}
|
||||
|
||||
if (!conf)
|
||||
if (!(conf = config_file_new_from_path_to_string(preset_path)))
|
||||
return false;
|
||||
|
||||
conf->path = strdup(preset_path);
|
||||
RARCH_LOG("Setting Menu shader: %s.\n", preset_path);
|
||||
|
||||
if (video_shader_read_conf_preset(conf, shader))
|
||||
|
38
retroarch.c
38
retroarch.c
@ -2072,22 +2072,9 @@ static core_option_manager_t *core_option_manager_new_vars(const char *conf_path
|
||||
return NULL;
|
||||
|
||||
if (!string_is_empty(conf_path))
|
||||
{
|
||||
int64_t length = 0;
|
||||
uint8_t *ret_buf = NULL;
|
||||
|
||||
if (filestream_read_file(conf_path, (void**)&ret_buf, &length))
|
||||
{
|
||||
if (length >= 0)
|
||||
if ((opt->conf = config_file_new_from_string((const char*)ret_buf)))
|
||||
opt->conf->path = strdup(conf_path);
|
||||
free((void*)ret_buf);
|
||||
}
|
||||
}
|
||||
|
||||
if (!opt->conf)
|
||||
if (!(opt->conf = config_file_new_alloc()))
|
||||
goto error;
|
||||
if (!(opt->conf = config_file_new_from_path_to_string(conf_path)))
|
||||
if (!(opt->conf = config_file_new_alloc()))
|
||||
goto error;
|
||||
|
||||
strlcpy(opt->conf_path, conf_path, sizeof(opt->conf_path));
|
||||
|
||||
@ -2138,22 +2125,9 @@ static core_option_manager_t *core_option_manager_new(const char *conf_path,
|
||||
return NULL;
|
||||
|
||||
if (!string_is_empty(conf_path))
|
||||
{
|
||||
int64_t length = 0;
|
||||
uint8_t *ret_buf = NULL;
|
||||
|
||||
if (filestream_read_file(conf_path, (void**)&ret_buf, &length))
|
||||
{
|
||||
if (length >= 0)
|
||||
if ((opt->conf = config_file_new_from_string((const char*)ret_buf)))
|
||||
opt->conf->path = strdup(conf_path);
|
||||
free((void*)ret_buf);
|
||||
}
|
||||
}
|
||||
|
||||
if (!opt->conf)
|
||||
if (!(opt->conf = config_file_new_alloc()))
|
||||
goto error;
|
||||
if (!(opt->conf = config_file_new_from_path_to_string(conf_path)))
|
||||
if (!(opt->conf = config_file_new_alloc()))
|
||||
goto error;
|
||||
|
||||
strlcpy(opt->conf_path, conf_path, sizeof(opt->conf_path));
|
||||
|
||||
|
@ -360,22 +360,8 @@ static bool input_autoconfigure_joypad_from_conf_dir(
|
||||
for (i = 0; i < list->size; i++)
|
||||
{
|
||||
int res;
|
||||
int64_t length = 0;
|
||||
uint8_t *ret_buf = NULL;
|
||||
config_file_t *conf = NULL;
|
||||
config_file_t *conf = config_file_new_from_path_to_string(list->elems[i].data);
|
||||
|
||||
if (!filestream_read_file(list->elems[i].data, (void**)&ret_buf, &length))
|
||||
continue;
|
||||
|
||||
if (length < 0)
|
||||
{
|
||||
free((void*)ret_buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
conf = config_file_new_from_string((const char*)ret_buf);
|
||||
free((void*)ret_buf);
|
||||
|
||||
if (!conf)
|
||||
continue;
|
||||
|
||||
|
@ -735,8 +735,6 @@ bool task_push_overlay_load_default(
|
||||
void *user_data)
|
||||
{
|
||||
task_finder_data_t find_data;
|
||||
int64_t length = 0;
|
||||
uint8_t *ret_buf = NULL;
|
||||
retro_task_t *t = NULL;
|
||||
config_file_t *conf = NULL;
|
||||
overlay_loader_t *loader = NULL;
|
||||
@ -756,14 +754,7 @@ bool task_push_overlay_load_default(
|
||||
if (!loader)
|
||||
return false;
|
||||
|
||||
if (filestream_read_file(overlay_path, (void**)&ret_buf, &length))
|
||||
{
|
||||
if (length >= 0)
|
||||
conf = config_file_new_from_string((const char*)ret_buf);
|
||||
free((void*)ret_buf);
|
||||
}
|
||||
|
||||
if (!conf)
|
||||
if (!(conf = config_file_new_from_path_to_string(overlay_path)))
|
||||
{
|
||||
free(loader);
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user