# HG changeset patch # User Michael Pavone # Date 1709709786 28800 # Node ID 2972a8e16ed2ad20bf6a2d285d2dd249e13db945 # Parent aaf7bb58ffcacf84585014733362194fdaccb157 Make sticky_path respect save config with EXE option diff -r aaf7bb58ffca -r 2972a8e16ed2 config.c --- a/config.c Sun Mar 03 13:47:59 2024 -0800 +++ b/config.c Tue Mar 05 23:23:06 2024 -0800 @@ -505,11 +505,16 @@ return ret; } -void persist_config_at(tern_node *app_config, tern_node *to_save, char *fname) +uint8_t is_config_in_exe_dir(tern_node *app_config) { char*use_exe_dir = tern_find_path_default(app_config, "ui\0config_in_exe_dir\0", (tern_val){.ptrval = "off"}, TVAL_PTR).ptrval; + return !strcmp(use_exe_dir, "on"); +} + +void persist_config_at(tern_node *app_config, tern_node *to_save, char *fname) +{ char *confpath; - if (!strcmp(use_exe_dir, "on")) { + if (is_config_in_exe_dir(app_config)) { confpath = path_append(get_exe_dir(), fname); if (app_config == to_save && app_config_in_config_dir) { //user switched to "portable" configs this session and there is an diff -r aaf7bb58ffca -r 2972a8e16ed2 config.h --- a/config.h Sun Mar 03 13:47:59 2024 -0800 +++ b/config.h Tue Mar 05 23:23:06 2024 -0800 @@ -23,6 +23,7 @@ uint32_t get_lowpass_cutoff(tern_node *config); tern_node *get_systems_config(void); tern_node *get_model(tern_node *config, system_type stype); +uint8_t is_config_in_exe_dir(tern_node *app_config); #endif //CONFIG_H_ diff -r aaf7bb58ffca -r 2972a8e16ed2 paths.c --- a/paths.c Sun Mar 03 13:47:59 2024 -0800 +++ b/paths.c Tue Mar 05 23:23:06 2024 -0800 @@ -2,6 +2,8 @@ #include #include "blastem.h" #include "util.h" +#include "config.h" +#include "paths.h" #ifdef _WIN32 #include #else @@ -11,9 +13,18 @@ static char **current_path; +static char *sticky_path_path(void) +{ + if (is_config_in_exe_dir(config)) { + return path_append(get_exe_dir(), "sticky_path"); + } else { + return path_append(get_config_dir(), "sticky_path"); + } +} + static void persist_path(void) { - char *pathfname = alloc_concat(get_userdata_dir(), PATH_SEP "blastem" PATH_SEP "sticky_path"); + char *pathfname = sticky_path_path(); FILE *f = fopen(pathfname, "wb"); if (f) { if (fwrite(*current_path, 1, strlen(*current_path), f) != strlen(*current_path)) { @@ -68,7 +79,7 @@ char *base = NULL; char *remember_path = tern_find_path(config, "ui\0remember_path\0", TVAL_PTR).ptrval; if (!remember_path || !strcmp("on", remember_path)) { - char *pathfname = alloc_concat(get_userdata_dir(), PATH_SEP "blastem" PATH_SEP "sticky_path"); + char *pathfname = sticky_path_path(); FILE *f = fopen(pathfname, "rb"); if (f) { long pathsize = file_size(f);