summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2015-11-04 22:48:27 -0800
committerMichael Pavone <pavone@retrodev.com>2015-11-04 22:48:27 -0800
commit3324456c65b747ab56158e9c7683be302761ed7a (patch)
treea135a98bb14a76d2507108e2ceb248401b41e44f /config.c
parente26893e5625ceffa1214024ed3191b155d56de6f (diff)
Load config file and rom.db from appropriate locations on Android
Diffstat (limited to 'config.c')
-rw-r--r--config.c86
1 files changed, 68 insertions, 18 deletions
diff --git a/config.c b/config.c
index ad4d929..fa1d6cb 100644
--- a/config.c
+++ b/config.c
@@ -114,34 +114,84 @@ open_fail:
return ret;
}
-tern_node * load_config()
+#ifdef __ANDROID__
+#include <SDL.h>
+
+tern_node * parse_config_file_assets(char *config_path)
{
- char * exe_dir;
- char * home = get_home_dir();
- if (!home) {
- goto load_in_app_dir;
+ tern_node * ret = NULL;
+ SDL_RWops *rw = SDL_RWFromFile(config_path, "rb");
+ if (!rw) {
+ goto open_fail;
}
- char * path = alloc_concat(home, "/.config/blastem/blastem.cfg");
- tern_node * ret = parse_config_file(path);
- if (ret) {
- goto success;
+ size_t config_size = rw->size(rw);
+ if (!config_size) {
+ goto config_empty;
}
- free(path);
-load_in_app_dir:
- exe_dir = get_exe_dir();
- if (!exe_dir) {
- goto no_config;
+
+ char * config_data = malloc(config_size+1);
+ if (SDL_RWread(rw, config_data, 1, config_size) != config_size) {
+ goto config_read_fail;
}
- path = alloc_concat(exe_dir, "/default.cfg");
- ret = parse_config_file(path);
+ 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()
+{
+ char *path = alloc_concat(SDL_AndroidGetInternalStoragePath(), "/blastem.cfg");
+ tern_node * ret = parse_config_file(path);
free(path);
-success:
if (ret) {
return ret;
}
-no_config:
+
+ 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();
+ if (home) {
+ char * path = alloc_concat(home, "/.config/blastem/blastem.cfg");
+ tern_node * ret = parse_config_file(path);
+ free(path);
+ if (ret) {
+ return ret;
+ }
+ }
+
+ exe_dir = get_exe_dir();
+ if (exe_dir) {
+ path = alloc_concat(exe_dir, "/default.cfg");
+ ret = parse_config_file(path);
+ free(path);
+ if (ret) {
+ return ret;
+ }
+ }
+
fatal_error("Failed to find a config file in ~/.config/blastem/blastem.cfg or in the blastem executable directory\n");
//this will never get reached, but the compiler doesn't know that. Let's make it happy
return NULL;
}
+#endif
+