diff options
Diffstat (limited to 'apps/plugins/puzzles/rockbox.c')
-rw-r--r-- | apps/plugins/puzzles/rockbox.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/apps/plugins/puzzles/rockbox.c b/apps/plugins/puzzles/rockbox.c index 379b4230df..2f07b392a9 100644 --- a/apps/plugins/puzzles/rockbox.c +++ b/apps/plugins/puzzles/rockbox.c | |||
@@ -901,7 +901,7 @@ const char *config_choices_formatter(int sel, void *data, char *buf, size_t len) | |||
901 | return buf; | 901 | return buf; |
902 | } | 902 | } |
903 | 903 | ||
904 | static int list_choose(const char *list_str, const char *title) | 904 | static int list_choose(const char *list_str, const char *title, int sel) |
905 | { | 905 | { |
906 | char delim = *list_str; | 906 | char delim = *list_str; |
907 | 907 | ||
@@ -920,7 +920,7 @@ static int list_choose(const char *list_str, const char *title) | |||
920 | rb->gui_synclist_set_nb_items(&list, n); | 920 | rb->gui_synclist_set_nb_items(&list, n); |
921 | rb->gui_synclist_limit_scroll(&list, false); | 921 | rb->gui_synclist_limit_scroll(&list, false); |
922 | 922 | ||
923 | rb->gui_synclist_select_item(&list, 0); | 923 | rb->gui_synclist_select_item(&list, sel); |
924 | 924 | ||
925 | rb->gui_synclist_set_title(&list, (char*)title, NOICON); | 925 | rb->gui_synclist_set_title(&list, (char*)title, NOICON); |
926 | while (1) | 926 | while (1) |
@@ -1089,7 +1089,7 @@ static bool do_configure_item(config_item *cfgs, int idx) | |||
1089 | } | 1089 | } |
1090 | case C_CHOICES: | 1090 | case C_CHOICES: |
1091 | { | 1091 | { |
1092 | int sel = list_choose(cfg->sval, cfg->name); | 1092 | int sel = list_choose(cfg->sval, cfg->name, cfg->ival); |
1093 | if(sel >= 0) | 1093 | if(sel >= 0) |
1094 | cfg->ival = sel; | 1094 | cfg->ival = sel; |
1095 | break; | 1095 | break; |
@@ -1153,26 +1153,35 @@ static bool config_menu(void) | |||
1153 | { | 1153 | { |
1154 | case ACTION_STD_OK: | 1154 | case ACTION_STD_OK: |
1155 | { | 1155 | { |
1156 | config_item old; | ||
1157 | int pos = rb->gui_synclist_get_sel_pos(&list); | 1156 | int pos = rb->gui_synclist_get_sel_pos(&list); |
1157 | |||
1158 | /* store the initial state */ | ||
1159 | config_item old; | ||
1158 | memcpy(&old, config + pos, sizeof(old)); | 1160 | memcpy(&old, config + pos, sizeof(old)); |
1161 | |||
1159 | char *old_str = NULL; | 1162 | char *old_str = NULL; |
1160 | if(old.type == C_STRING) | 1163 | if(old.type == C_STRING) |
1161 | old_str = dupstr(old.sval); | 1164 | old_str = dupstr(old.sval); |
1162 | bool freed_str = do_configure_item(config + pos); | 1165 | |
1166 | bool freed_str = do_configure_item(config, pos); | ||
1163 | char *err = midend_set_config(me, CFG_SETTINGS, config); | 1167 | char *err = midend_set_config(me, CFG_SETTINGS, config); |
1168 | |||
1164 | if(err) | 1169 | if(err) |
1165 | { | 1170 | { |
1166 | rb->splash(HZ, err); | 1171 | rb->splash(HZ, err); |
1172 | |||
1173 | /* restore old state */ | ||
1167 | memcpy(config + pos, &old, sizeof(old)); | 1174 | memcpy(config + pos, &old, sizeof(old)); |
1168 | if(freed_str) | 1175 | |
1176 | if(old.type == C_STRING && freed_str) | ||
1169 | config[pos].sval = old_str; | 1177 | config[pos].sval = old_str; |
1170 | } | 1178 | } |
1171 | else | 1179 | else |
1172 | { | 1180 | { |
1173 | if(old.type == C_STRING) | 1181 | if(old.type == C_STRING) |
1174 | { | 1182 | { |
1175 | /* success, and we duplicated the old string, so free it */ | 1183 | /* success, and we duplicated the old string when |
1184 | * we didn't need to, so free it now */ | ||
1176 | sfree(old_str); | 1185 | sfree(old_str); |
1177 | } | 1186 | } |
1178 | success = true; | 1187 | success = true; |