add ui_setappdir default tip

Thu, 08 Jan 2026 18:17:06 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 08 Jan 2026 18:17:06 +0100
changeset 1041
db47e814b4c5
parent 1040
473d8cb58a6c

add ui_setappdir

ui/common/properties.c file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
--- a/ui/common/properties.c	Wed Dec 31 16:40:12 2025 +0100
+++ b/ui/common/properties.c	Thu Jan 08 18:17:06 2026 +0100
@@ -62,6 +62,8 @@
 static void *properties_data = NULL;
 static size_t properties_data_length = 0;
 
+static char *config_root = NULL;
+
 void ui_load_properties_file_on_startup(UiBool enable) {
     load_on_startup = enable;
 }
@@ -77,13 +79,26 @@
 }
 
 char* ui_getappdir(void) {
-    if(ui_appname() == NULL) {
+    if(ui_appname() == NULL && config_root == NULL) {
         return NULL;
     }
 
     return ui_configfile(NULL);
 }
 
+void ui_setappdir(const char *path) {
+    free(config_root);
+    if(path) {
+        cxmutstr cfgpath = cx_strdup(path);
+        config_root = cfgpath.ptr;
+        if(cfgpath.length > 0 && cfgpath.ptr[cfgpath.length-1] == '/') {
+            config_root[cfgpath.length-1] = 0;
+        }
+    } else {
+        config_root = NULL;
+    }
+}
+
 #ifndef _WIN32
 #define UI_PATH_SEPARATOR '/'
 #define UI_ENV_HOME "HOME"
@@ -95,6 +110,16 @@
 #define UI_XDG_CONFIG_HOME_VAR "XDG_CONFIG_HOME"
 
 char* ui_configfile(const char *name) {
+    if(config_root) {
+        if(!name) {
+            return strdup(config_root);
+        } else if(name[0] == '/') {
+            return cx_strdup(cx_strcat(CX_NULLSTR, 2, cx_str(config_root), cx_str(name))).ptr;
+        } else {
+            return cx_strdup(cx_strcat(CX_NULLSTR, 3, cx_str(config_root), cx_str("/"), cx_str(name))).ptr;
+        }
+    }
+    
     const char *appname = ui_appname();
     if(!appname) {
         return NULL;
--- a/ui/ui/toolkit.h	Wed Dec 31 16:40:12 2025 +0100
+++ b/ui/ui/toolkit.h	Thu Jan 08 18:17:06 2026 +0100
@@ -700,6 +700,7 @@
 
 
 UIEXPORT char* ui_getappdir(void);
+UIEXPORT void ui_setappdir(const char *path);
 UIEXPORT char* ui_configfile(const char *name);
 
 UIEXPORT UiCondVar* ui_condvar_create(void);

mercurial