Mercurial > repos > blastem
comparison config.c @ 859:46bb673eed4e
Load config file and rom.db from appropriate locations on Android
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 04 Nov 2015 22:48:27 -0800 |
parents | 7ed55a361e79 |
children | 69a6ec208111 |
comparison
equal
deleted
inserted
replaced
858:ba19bcc00483 | 859:46bb673eed4e |
---|---|
112 fclose(config_file); | 112 fclose(config_file); |
113 open_fail: | 113 open_fail: |
114 return ret; | 114 return ret; |
115 } | 115 } |
116 | 116 |
117 #ifdef __ANDROID__ | |
118 #include <SDL.h> | |
119 | |
120 tern_node * parse_config_file_assets(char *config_path) | |
121 { | |
122 tern_node * ret = NULL; | |
123 SDL_RWops *rw = SDL_RWFromFile(config_path, "rb"); | |
124 if (!rw) { | |
125 goto open_fail; | |
126 } | |
127 size_t config_size = rw->size(rw); | |
128 if (!config_size) { | |
129 goto config_empty; | |
130 } | |
131 | |
132 char * config_data = malloc(config_size+1); | |
133 if (SDL_RWread(rw, config_data, 1, config_size) != config_size) { | |
134 goto config_read_fail; | |
135 } | |
136 config_data[config_size] = '\0'; | |
137 | |
138 ret = parse_config(config_data); | |
139 config_read_fail: | |
140 free(config_data); | |
141 config_empty: | |
142 SDL_RWclose(rw); | |
143 open_fail: | |
144 return ret; | |
145 } | |
146 | |
147 tern_node * load_config() | |
148 { | |
149 char *path = alloc_concat(SDL_AndroidGetInternalStoragePath(), "/blastem.cfg"); | |
150 tern_node * ret = parse_config_file(path); | |
151 free(path); | |
152 if (ret) { | |
153 return ret; | |
154 } | |
155 | |
156 ret = parse_config_file_assets("default.cfg"); | |
157 if (ret) { | |
158 return ret; | |
159 } | |
160 | |
161 fatal_error("Failed to find a config file in internal storage or in the blastem APK\n"); | |
162 //this will never get reached, but the compiler doesn't know that. Let's make it happy | |
163 return NULL; | |
164 } | |
165 | |
166 #else | |
167 | |
117 tern_node * load_config() | 168 tern_node * load_config() |
118 { | 169 { |
119 char * exe_dir; | 170 char * exe_dir; |
120 char * home = get_home_dir(); | 171 char * home = get_home_dir(); |
121 if (!home) { | 172 if (home) { |
122 goto load_in_app_dir; | 173 char * path = alloc_concat(home, "/.config/blastem/blastem.cfg"); |
174 tern_node * ret = parse_config_file(path); | |
175 free(path); | |
176 if (ret) { | |
177 return ret; | |
178 } | |
123 } | 179 } |
124 char * path = alloc_concat(home, "/.config/blastem/blastem.cfg"); | 180 |
125 tern_node * ret = parse_config_file(path); | 181 exe_dir = get_exe_dir(); |
126 if (ret) { | 182 if (exe_dir) { |
127 goto success; | 183 path = alloc_concat(exe_dir, "/default.cfg"); |
184 ret = parse_config_file(path); | |
185 free(path); | |
186 if (ret) { | |
187 return ret; | |
188 } | |
128 } | 189 } |
129 free(path); | 190 |
130 load_in_app_dir: | |
131 exe_dir = get_exe_dir(); | |
132 if (!exe_dir) { | |
133 goto no_config; | |
134 } | |
135 path = alloc_concat(exe_dir, "/default.cfg"); | |
136 ret = parse_config_file(path); | |
137 free(path); | |
138 success: | |
139 if (ret) { | |
140 return ret; | |
141 } | |
142 no_config: | |
143 fatal_error("Failed to find a config file in ~/.config/blastem/blastem.cfg or in the blastem executable directory\n"); | 191 fatal_error("Failed to find a config file in ~/.config/blastem/blastem.cfg or in the blastem executable directory\n"); |
144 //this will never get reached, but the compiler doesn't know that. Let's make it happy | 192 //this will never get reached, but the compiler doesn't know that. Let's make it happy |
145 return NULL; | 193 return NULL; |
146 } | 194 } |
147 | 195 |
196 #endif | |
197 |