changeset 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 aaf7bb58ffca
children ea37200967c7
files config.c config.h paths.c
diffstat 3 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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_
 
--- 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 <stdlib.h>
 #include "blastem.h"
 #include "util.h"
+#include "config.h"
+#include "paths.h"
 #ifdef _WIN32
 #include <windows.h>
 #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);