Mercurial > repos > blastem
comparison menu.c @ 1434:b9dbc823c014
Added a config file option for remembering the last path in the menu
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 16 Aug 2017 20:45:51 -0700 |
parents | c886c54d8cf1 |
children | e2bd03ed3190 |
comparison
equal
deleted
inserted
replaced
1433:c886c54d8cf1 | 1434:b9dbc823c014 |
---|---|
8 #include "backend.h" | 8 #include "backend.h" |
9 #include "util.h" | 9 #include "util.h" |
10 #include "gst.h" | 10 #include "gst.h" |
11 #include "m68k_internal.h" //needed for get_native_address_trans, should be eliminated once handling of PC is cleaned up | 11 #include "m68k_internal.h" //needed for get_native_address_trans, should be eliminated once handling of PC is cleaned up |
12 | 12 |
13 static menu_context *persist_path_menu; | |
14 static void persist_path(void) | |
15 { | |
16 char const *parts[] = {get_userdata_dir(), PATH_SEP, "sticky_path"}; | |
17 char *pathfname = alloc_concat_m(3, parts); | |
18 FILE *f = fopen(pathfname, "wb"); | |
19 if (f) { | |
20 if (fwrite(persist_path_menu->curpath, 1, strlen(persist_path_menu->curpath), f) != strlen(persist_path_menu->curpath)) { | |
21 warning("Failed to save menu path"); | |
22 } | |
23 fclose(f); | |
24 } else { | |
25 warning("Failed to save menu path: Could not open %s for writing\n", pathfname); | |
26 | |
27 } | |
28 free(pathfname); | |
29 } | |
30 | |
13 static menu_context *get_menu(genesis_context *gen) | 31 static menu_context *get_menu(genesis_context *gen) |
14 { | 32 { |
15 menu_context *menu = gen->extra; | 33 menu_context *menu = gen->extra; |
16 if (!menu) { | 34 if (!menu) { |
17 gen->extra = menu = calloc(1, sizeof(menu_context)); | 35 gen->extra = menu = calloc(1, sizeof(menu_context)); |
18 menu->curpath = tern_find_path(config, "ui\0initial_path\0", TVAL_PTR).ptrval; | 36 menu->curpath = NULL; |
37 char *remember_path = tern_find_path(config, "ui\0remember_path\0", TVAL_PTR).ptrval; | |
38 if (!remember_path || !strcmp("on", remember_path)) { | |
39 char const *parts[] = {get_userdata_dir(), PATH_SEP, "sticky_path"}; | |
40 char *pathfname = alloc_concat_m(3, parts); | |
41 FILE *f = fopen(pathfname, "rb"); | |
42 if (f) { | |
43 long pathsize = file_size(f); | |
44 if (pathsize > 0) { | |
45 menu->curpath = malloc(pathsize + 1); | |
46 if (fread(menu->curpath, 1, pathsize, f) != pathsize) { | |
47 warning("Error restoring saved menu path"); | |
48 free(menu->curpath); | |
49 menu->curpath = NULL; | |
50 } else { | |
51 menu->curpath[pathsize] = 0; | |
52 } | |
53 } | |
54 fclose(f); | |
55 } | |
56 free(pathfname); | |
57 if (!persist_path_menu) { | |
58 atexit(persist_path); | |
59 } | |
60 persist_path_menu = menu; | |
61 } | |
62 if (!menu->curpath) { | |
63 menu->curpath = tern_find_path(config, "ui\0initial_path\0", TVAL_PTR).ptrval; | |
64 } | |
19 if (!menu->curpath){ | 65 if (!menu->curpath){ |
20 #ifdef __ANDROID__ | 66 #ifdef __ANDROID__ |
21 menu->curpath = get_external_storage_path(); | 67 menu->curpath = get_external_storage_path(); |
22 #else | 68 #else |
23 menu->curpath = "$HOME"; | 69 menu->curpath = "$HOME"; |