Create config_file_new_from_path_to_string

This commit is contained in:
twinaphex 2019-07-18 12:03:50 +02:00
parent d77488cd89
commit 41a2fabb4e
11 changed files with 39 additions and 129 deletions

View File

@ -225,16 +225,7 @@ static config_file_t *core_info_list_iterate(
info_path_base = NULL; info_path_base = NULL;
if (path_is_valid(info_path)) if (path_is_valid(info_path))
{ conf = config_file_new_from_path_to_string(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);
}
}
free(info_path); free(info_path);
return conf; 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) bool core_info_get_display_name(const char *path, char *s, size_t len)
{ {
int64_t length = 0;
char *tmp = NULL; char *tmp = NULL;
config_file_t *conf = NULL; config_file_t *conf = config_file_new_from_path_to_string(path);
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);
}
if (!conf) if (!conf)
return false; return false;

View File

@ -21,6 +21,7 @@
#include <retro_miscellaneous.h> #include <retro_miscellaneous.h>
#include <file/file_path.h> #include <file/file_path.h>
#include <file/config_file.h>
#include <streams/file_stream.h> #include <streams/file_stream.h>
#include <lists/string_list.h> #include <lists/string_list.h>
#include <string/stdstring.h> #include <string/stdstring.h>

View File

@ -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); bool glslang_parse_meta(const std::vector<std::string> &lines, glslang_meta *meta);
#endif #endif
void *config_file_new_wrapper(const char *path);
#endif #endif

View File

@ -2409,7 +2409,7 @@ gl_core_filter_chain_t *gl_core_filter_chain_create_from_preset(
if (!shader) if (!shader)
return nullptr; 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) if (!conf)
return nullptr; return nullptr;

View File

@ -2886,7 +2886,7 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
if (!shader) if (!shader)
return nullptr; 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) if (!conf)
return nullptr; return nullptr;

View File

@ -593,6 +593,23 @@ config_file_t *config_file_new_from_string(const char *from_string)
return conf; 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( config_file_t *config_file_new_with_callback(
const char *path, config_file_cb_t *cb) const char *path, config_file_cb_t *cb)
{ {

View File

@ -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. */ /* 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_string(const char *from_string);
config_file_t *config_file_new_from_path_to_string(const char *path);
/* Frees config file. */ /* Frees config file. */
void config_file_free(config_file_t *conf); void config_file_free(config_file_t *conf);

View File

@ -78,19 +78,8 @@ bool menu_shader_manager_init(void)
if (is_preset) if (is_preset)
{ {
int64_t length = 0;
uint8_t *ret_buf = NULL;
if (path_is_valid(path_shader)) if (path_is_valid(path_shader))
{ conf = config_file_new_from_path_to_string(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);
}
}
new_path = strdup(path_shader); new_path = strdup(path_shader);
} }
@ -118,16 +107,7 @@ bool menu_shader_manager_init(void)
"menu.glslp", sizeof(preset_path)); "menu.glslp", sizeof(preset_path));
if (path_is_valid(preset_path)) if (path_is_valid(preset_path))
{ conf = config_file_new_from_path_to_string(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);
}
}
#endif #endif
#ifdef HAVE_CG #ifdef HAVE_CG
@ -137,16 +117,7 @@ bool menu_shader_manager_init(void)
"menu.cgp", sizeof(preset_path)); "menu.cgp", sizeof(preset_path));
if (path_is_valid(preset_path)) if (path_is_valid(preset_path))
{ conf = config_file_new_from_path_to_string(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);
}
}
} }
#endif #endif
@ -157,16 +128,7 @@ bool menu_shader_manager_init(void)
"menu.slangp", sizeof(preset_path)); "menu.slangp", sizeof(preset_path));
if (path_is_valid(preset_path)) if (path_is_valid(preset_path))
{ conf = config_file_new_from_path_to_string(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);
}
}
} }
#endif #endif
@ -229,17 +191,9 @@ bool menu_shader_manager_set_preset(void *data,
* Used when a preset is directly loaded. * Used when a preset is directly loaded.
* No point in updating when the Preset was * No point in updating when the Preset was
* created from the menu itself. */ * created from the menu itself. */
if (filestream_read_file(preset_path, (void**)&ret_buf, &length)) if (!(conf = config_file_new_from_path_to_string(preset_path)))
{
if (length >= 0)
conf = config_file_new_from_string((const char*)ret_buf);
free((void*)ret_buf);
}
if (!conf)
return false; return false;
conf->path = strdup(preset_path);
RARCH_LOG("Setting Menu shader: %s.\n", preset_path); RARCH_LOG("Setting Menu shader: %s.\n", preset_path);
if (video_shader_read_conf_preset(conf, shader)) if (video_shader_read_conf_preset(conf, shader))

View File

@ -2072,22 +2072,9 @@ static core_option_manager_t *core_option_manager_new_vars(const char *conf_path
return NULL; return NULL;
if (!string_is_empty(conf_path)) if (!string_is_empty(conf_path))
{ if (!(opt->conf = config_file_new_from_path_to_string(conf_path)))
int64_t length = 0; if (!(opt->conf = config_file_new_alloc()))
uint8_t *ret_buf = NULL; goto error;
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;
strlcpy(opt->conf_path, conf_path, sizeof(opt->conf_path)); 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; return NULL;
if (!string_is_empty(conf_path)) if (!string_is_empty(conf_path))
{ if (!(opt->conf = config_file_new_from_path_to_string(conf_path)))
int64_t length = 0; if (!(opt->conf = config_file_new_alloc()))
uint8_t *ret_buf = NULL; goto error;
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;
strlcpy(opt->conf_path, conf_path, sizeof(opt->conf_path)); strlcpy(opt->conf_path, conf_path, sizeof(opt->conf_path));

View File

@ -360,22 +360,8 @@ static bool input_autoconfigure_joypad_from_conf_dir(
for (i = 0; i < list->size; i++) for (i = 0; i < list->size; i++)
{ {
int res; int res;
int64_t length = 0; config_file_t *conf = config_file_new_from_path_to_string(list->elems[i].data);
uint8_t *ret_buf = NULL;
config_file_t *conf = NULL;
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) if (!conf)
continue; continue;

View File

@ -735,8 +735,6 @@ bool task_push_overlay_load_default(
void *user_data) void *user_data)
{ {
task_finder_data_t find_data; task_finder_data_t find_data;
int64_t length = 0;
uint8_t *ret_buf = NULL;
retro_task_t *t = NULL; retro_task_t *t = NULL;
config_file_t *conf = NULL; config_file_t *conf = NULL;
overlay_loader_t *loader = NULL; overlay_loader_t *loader = NULL;
@ -756,14 +754,7 @@ bool task_push_overlay_load_default(
if (!loader) if (!loader)
return false; return false;
if (filestream_read_file(overlay_path, (void**)&ret_buf, &length)) if (!(conf = config_file_new_from_path_to_string(overlay_path)))
{
if (length >= 0)
conf = config_file_new_from_string((const char*)ret_buf);
free((void*)ret_buf);
}
if (!conf)
{ {
free(loader); free(loader);
return false; return false;