diff menu.c @ 1292:5905593d6828

Allow initial_path to contain variable references which allows the default value to be actually specified in the default config file
author Michael Pavone <pavone@retrodev.com>
date Tue, 21 Mar 2017 00:40:25 -0700
parents 0a34e31c4fd0
children 72ea3885e7b5
line wrap: on
line diff
--- a/menu.c	Sun Mar 19 18:32:49 2017 -0700
+++ b/menu.c	Tue Mar 21 00:40:25 2017 -0700
@@ -167,15 +167,16 @@
 	if (!menu) {
 		gen->extra = menu = calloc(1, sizeof(menu_context));
 		menu->curpath = tern_find_path(config, "ui\0initial_path\0").ptrval;
-		if (menu->curpath) {
-			menu->curpath = strdup(menu->curpath);
-		} else {
+		if (!menu->curpath){
 #ifdef __ANDROID__
-			menu->curpath = strdup(get_external_storage_path());
+			menu->curpath = get_external_storage_path();
 #else
-			menu->curpath = strdup(get_home_dir());
+			menu->curpath = "$HOME";
 #endif
 		}
+		tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir());
+		vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir());
+		menu->curpath = replace_vars(menu->curpath, vars, 1);
 	}
 	if (menu->state) {
 		uint32_t dst = menu->latch << 16 | value;