ui/common/properties.c

branch
newapi
changeset 379
958bae372271
parent 378
d41b1ffc5f77
--- a/ui/common/properties.c	Sun Nov 10 15:27:44 2024 +0100
+++ b/ui/common/properties.c	Tue Nov 12 14:58:03 2024 +0100
@@ -39,6 +39,7 @@
 #include <cx/string.h>
 #include <cx/buffer.h>
 
+#include <cx/hash_map.h>
 #include "ucx_properties.h"
 
 static CxMap *application_properties;
@@ -60,6 +61,14 @@
     return ui_configfile(NULL);
 }
 
+#ifndef _WIN32
+#define UI_PATH_SEPARATOR '/'
+#define UI_ENV_HOME "HOME"
+#else
+#define UI_PATH_SEPARATOR '\\'
+#define UI_ENV_HOME "USERPROFILE"
+#endif
+
 char* ui_configfile(char *name) {
     const char *appname = ui_appname();
     if(!appname) {
@@ -70,7 +79,7 @@
     cxBufferInit(&buf, NULL, 128, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
     
     // add base dir
-    char *homeenv = getenv("HOME");
+    char *homeenv = getenv(UI_ENV_HOME);
     if(homeenv == NULL) {
         cxBufferDestroy(&buf);
         return NULL;
@@ -78,19 +87,22 @@
     cxstring home = cx_str(homeenv);
     
     cxBufferWrite(home.ptr, 1, home.length, &buf);
-    if(home.ptr[home.length-1] != '/') {
-        cxBufferPut(&buf, '/');
+    if(home.ptr[home.length-1] != UI_PATH_SEPARATOR) {
+        cxBufferPut(&buf, UI_PATH_SEPARATOR);
     }
     
 #ifdef UI_COCOA
     // on OS X the app dir is $HOME/Library/Application Support/$APPNAME/
-    ucx_buffer_puts(buf, "Library/Application Support/");
+    cxBufferPutString(&buf, "Library/Application Support/");
+#elif defined(_WIN32)
+    // on Windows the app dir is $USERPROFILE/AppData/Local/$APPNAME/
+    cxBufferPutString(&buf, "AppData\\Local\\");
 #else
     // app dir is $HOME/.$APPNAME/
     cxBufferPut(&buf, '.');
 #endif
     cxBufferPutString(&buf, appname);
-    cxBufferPut(&buf, '/');
+    cxBufferPut(&buf, UI_PATH_SEPARATOR);
     
     // add file name
     if(name) {

mercurial