summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'config.c')
-rw-r--r--config.c93
1 files changed, 26 insertions, 67 deletions
diff --git a/config.c b/config.c
index a4187d5..f64ef4a 100644
--- a/config.c
+++ b/config.c
@@ -82,13 +82,13 @@ tern_node * parse_config_int(char **state, int started, int *line)
return head;
}
-tern_node * parse_config(char * config_data)
+tern_node *parse_config(char * config_data)
{
int line = 1;
return parse_config_int(&config_data, 0, &line);
}
-tern_node * parse_config_file(char * config_path)
+tern_node *parse_config_file(char *config_path)
{
tern_node * ret = NULL;
FILE * config_file = fopen(config_path, "rb");
@@ -114,85 +114,44 @@ open_fail:
return ret;
}
-#ifdef __ANDROID__
-#include <SDL.h>
-
-tern_node * parse_config_file_assets(char *config_path)
+tern_node *parse_bundled_config(char *config_name)
{
- tern_node * ret = NULL;
- SDL_RWops *rw = SDL_RWFromFile(config_path, "rb");
- if (!rw) {
- goto open_fail;
- }
- size_t config_size = rw->size(rw);
- if (!config_size) {
- goto config_empty;
+ long confsize;
+ char *confdata = read_bundled_file(config_name, &confsize);
+ tern_node *ret = NULL;
+ if (confdata) {
+ confdata[confsize] = 0;
+ ret = parse_config(confdata);
+ free(confdata);
}
-
- char * config_data = malloc(config_size+1);
- if (SDL_RWread(rw, config_data, 1, config_size) != config_size) {
- goto config_read_fail;
- }
- config_data[config_size] = '\0';
-
- ret = parse_config(config_data);
-config_read_fail:
- free(config_data);
-config_empty:
- SDL_RWclose(rw);
-open_fail:
return ret;
}
-tern_node * load_config()
+tern_node *load_config()
{
- char *path = alloc_concat(SDL_AndroidGetInternalStoragePath(), "/blastem.cfg");
- tern_node * ret = parse_config_file(path);
- free(path);
- if (ret) {
- return ret;
- }
-
- ret = parse_config_file_assets("default.cfg");
- if (ret) {
- return ret;
- }
-
- fatal_error("Failed to find a config file in internal storage or in the blastem APK\n");
- //this will never get reached, but the compiler doesn't know that. Let's make it happy
- return NULL;
-}
-
-#else
-
-tern_node * load_config()
-{
- char * exe_dir;
- char * home = get_home_dir();
+ char *confdir = get_config_dir();
+ char *confpath = NULL;
tern_node *ret;
- if (home) {
- char * path = alloc_concat(home, "/.config/blastem/blastem.cfg");
- ret = parse_config_file(path);
- free(path);
+ if (confdir) {
+ confpath = alloc_concat(confdir, "/blastem.cfg");
+ ret = parse_config_file(confpath);
if (ret) {
+ free(confpath);
return ret;
}
}
- exe_dir = get_exe_dir();
- if (exe_dir) {
- char *path = alloc_concat(exe_dir, "/default.cfg");
- ret = parse_config_file(path);
- free(path);
- if (ret) {
- return ret;
- }
+ ret = parse_bundled_config("default.cfg");
+ if (ret) {
+ free(confpath);
+ return ret;
}
- fatal_error("Failed to find a config file in ~/.config/blastem/blastem.cfg or in the blastem executable directory\n");
+ if (confpath) {
+ fatal_error("Failed to find a config file at %s or in the blastem executable directory\n", confpath);
+ } else {
+ fatal_error("Failed to find a config file in the BlastEm executable directory and the config directory path could not be determined\n");
+ }
//this will never get reached, but the compiler doesn't know that. Let's make it happy
return NULL;
}
-
-#endif
-