comparison paths.c @ 2477:2972a8e16ed2

Make sticky_path respect save config with EXE option
author Michael Pavone <pavone@retrodev.com>
date Tue, 05 Mar 2024 23:23:06 -0800
parents bc68560b4a04
children
comparison
equal deleted inserted replaced
2476:aaf7bb58ffca 2477:2972a8e16ed2
1 #include <string.h> 1 #include <string.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include "blastem.h" 3 #include "blastem.h"
4 #include "util.h" 4 #include "util.h"
5 #include "config.h"
6 #include "paths.h"
5 #ifdef _WIN32 7 #ifdef _WIN32
6 #include <windows.h> 8 #include <windows.h>
7 #else 9 #else
8 #include <unistd.h> 10 #include <unistd.h>
9 #include <errno.h> 11 #include <errno.h>
10 #endif 12 #endif
11 13
12 static char **current_path; 14 static char **current_path;
13 15
16 static char *sticky_path_path(void)
17 {
18 if (is_config_in_exe_dir(config)) {
19 return path_append(get_exe_dir(), "sticky_path");
20 } else {
21 return path_append(get_config_dir(), "sticky_path");
22 }
23 }
24
14 static void persist_path(void) 25 static void persist_path(void)
15 { 26 {
16 char *pathfname = alloc_concat(get_userdata_dir(), PATH_SEP "blastem" PATH_SEP "sticky_path"); 27 char *pathfname = sticky_path_path();
17 FILE *f = fopen(pathfname, "wb"); 28 FILE *f = fopen(pathfname, "wb");
18 if (f) { 29 if (f) {
19 if (fwrite(*current_path, 1, strlen(*current_path), f) != strlen(*current_path)) { 30 if (fwrite(*current_path, 1, strlen(*current_path), f) != strlen(*current_path)) {
20 warning("Failed to save menu path"); 31 warning("Failed to save menu path");
21 } 32 }
66 void get_initial_browse_path(char **dst) 77 void get_initial_browse_path(char **dst)
67 { 78 {
68 char *base = NULL; 79 char *base = NULL;
69 char *remember_path = tern_find_path(config, "ui\0remember_path\0", TVAL_PTR).ptrval; 80 char *remember_path = tern_find_path(config, "ui\0remember_path\0", TVAL_PTR).ptrval;
70 if (!remember_path || !strcmp("on", remember_path)) { 81 if (!remember_path || !strcmp("on", remember_path)) {
71 char *pathfname = alloc_concat(get_userdata_dir(), PATH_SEP "blastem" PATH_SEP "sticky_path"); 82 char *pathfname = sticky_path_path();
72 FILE *f = fopen(pathfname, "rb"); 83 FILE *f = fopen(pathfname, "rb");
73 if (f) { 84 if (f) {
74 long pathsize = file_size(f); 85 long pathsize = file_size(f);
75 if (pathsize > 0) { 86 if (pathsize > 0) {
76 base = malloc(pathsize + 1); 87 base = malloc(pathsize + 1);