ui/common/properties.c

branch
newapi
changeset 379
958bae372271
parent 378
d41b1ffc5f77
equal deleted inserted replaced
378:d41b1ffc5f77 379:958bae372271
37 37
38 #include "properties.h" 38 #include "properties.h"
39 #include <cx/string.h> 39 #include <cx/string.h>
40 #include <cx/buffer.h> 40 #include <cx/buffer.h>
41 41
42 #include <cx/hash_map.h>
42 #include "ucx_properties.h" 43 #include "ucx_properties.h"
43 44
44 static CxMap *application_properties; 45 static CxMap *application_properties;
45 static CxMap *language; 46 static CxMap *language;
46 47
57 return NULL; 58 return NULL;
58 } 59 }
59 60
60 return ui_configfile(NULL); 61 return ui_configfile(NULL);
61 } 62 }
63
64 #ifndef _WIN32
65 #define UI_PATH_SEPARATOR '/'
66 #define UI_ENV_HOME "HOME"
67 #else
68 #define UI_PATH_SEPARATOR '\\'
69 #define UI_ENV_HOME "USERPROFILE"
70 #endif
62 71
63 char* ui_configfile(char *name) { 72 char* ui_configfile(char *name) {
64 const char *appname = ui_appname(); 73 const char *appname = ui_appname();
65 if(!appname) { 74 if(!appname) {
66 return NULL; 75 return NULL;
68 77
69 CxBuffer buf; 78 CxBuffer buf;
70 cxBufferInit(&buf, NULL, 128, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); 79 cxBufferInit(&buf, NULL, 128, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
71 80
72 // add base dir 81 // add base dir
73 char *homeenv = getenv("HOME"); 82 char *homeenv = getenv(UI_ENV_HOME);
74 if(homeenv == NULL) { 83 if(homeenv == NULL) {
75 cxBufferDestroy(&buf); 84 cxBufferDestroy(&buf);
76 return NULL; 85 return NULL;
77 } 86 }
78 cxstring home = cx_str(homeenv); 87 cxstring home = cx_str(homeenv);
79 88
80 cxBufferWrite(home.ptr, 1, home.length, &buf); 89 cxBufferWrite(home.ptr, 1, home.length, &buf);
81 if(home.ptr[home.length-1] != '/') { 90 if(home.ptr[home.length-1] != UI_PATH_SEPARATOR) {
82 cxBufferPut(&buf, '/'); 91 cxBufferPut(&buf, UI_PATH_SEPARATOR);
83 } 92 }
84 93
85 #ifdef UI_COCOA 94 #ifdef UI_COCOA
86 // on OS X the app dir is $HOME/Library/Application Support/$APPNAME/ 95 // on OS X the app dir is $HOME/Library/Application Support/$APPNAME/
87 ucx_buffer_puts(buf, "Library/Application Support/"); 96 cxBufferPutString(&buf, "Library/Application Support/");
97 #elif defined(_WIN32)
98 // on Windows the app dir is $USERPROFILE/AppData/Local/$APPNAME/
99 cxBufferPutString(&buf, "AppData\\Local\\");
88 #else 100 #else
89 // app dir is $HOME/.$APPNAME/ 101 // app dir is $HOME/.$APPNAME/
90 cxBufferPut(&buf, '.'); 102 cxBufferPut(&buf, '.');
91 #endif 103 #endif
92 cxBufferPutString(&buf, appname); 104 cxBufferPutString(&buf, appname);
93 cxBufferPut(&buf, '/'); 105 cxBufferPut(&buf, UI_PATH_SEPARATOR);
94 106
95 // add file name 107 // add file name
96 if(name) { 108 if(name) {
97 cxBufferPutString(&buf, name); 109 cxBufferPutString(&buf, name);
98 } 110 }

mercurial