[ORBIS] Add support to config save for orbis

This commit is contained in:
psxdev 2019-01-03 12:48:40 +01:00 committed by Francisco José García García
parent 66ba53c79b
commit d52de24e79
2 changed files with 46 additions and 4 deletions

View File

@ -34,7 +34,10 @@
#elif defined(_XBOX)
#include <xtl.h>
#endif
#ifdef ORBIS
#include <sys/fcntl.h>
#include <orbisFile.h>
#endif
#include <retro_miscellaneous.h>
#include <compat/strl.h>
#include <compat/posix_string.h>
@ -413,10 +416,10 @@ static config_file_t *config_file_new_internal(
if (!path || !*path)
return conf;
#if !defined(ORBIS)
if (path_is_directory(path))
goto error;
#endif
conf->path = strdup(path);
if (!conf->path)
goto error;
@ -981,6 +984,15 @@ bool config_file_write(config_file_t *conf, const char *path)
if (!string_is_empty(path))
{
void* buf = NULL;
#ifdef ORBIS
int fd = orbisOpen(path,O_RDWR|O_CREAT,0644);
RARCH_LOG("[Config]config_file_write orbisOpen path=%s fd=%d\n", path, fd);
if (fd<0)
return false;
config_file_dump_orbis(conf,fd);
orbisClose(fd);
RARCH_LOG("[Config]config_file_write orbisClose path=%s fd=%d\n", path, fd);
#else
FILE *file = (FILE*)fopen_utf8(path, "wb");
if (!file)
return false;
@ -994,13 +1006,41 @@ bool config_file_write(config_file_t *conf, const char *path)
if (file != stdout)
fclose(file);
free(buf);
#endif
}
else
config_file_dump(conf, stdout);
return true;
}
#ifdef ORBIS
void config_file_dump_orbis(config_file_t *conf, int fd)
{
struct config_entry_list *list = NULL;
struct config_include_list *includes = conf->includes;
while (includes)
{
char cad[256];
sprintf(cad,"#include %s\n", includes->path);
orbisWrite(fd,cad,strlen(cad));
includes = includes->next;
}
list = merge_sort_linked_list((struct config_entry_list*)conf->entries, config_sort_compare_func);
conf->entries = list;
while (list)
{
if (!list->readonly && list->key)
{
char newlist[256];
sprintf(newlist,"%s = %s\n", list->key, list->value);
orbisWrite(fd,newlist,strlen(newlist));
}
list = list->next;
}
}
#endif
void config_file_dump(config_file_t *conf, FILE *file)
{
struct config_entry_list *list = NULL;

View File

@ -186,7 +186,9 @@ bool config_file_write(config_file_t *conf, const char *path);
/* Dump the current config to an already opened file.
* Does not close the file. */
void config_file_dump(config_file_t *conf, FILE *file);
#ifdef ORBIS
void config_file_dump_orbis(config_file_t *conf, int fd);
#endif
bool config_file_exists(const char *path);
RETRO_END_DECLS