58 } |
58 } |
59 |
59 |
60 return ui_configfile(NULL); |
60 return ui_configfile(NULL); |
61 } |
61 } |
62 |
62 |
|
63 #ifndef _WIN32 |
|
64 #define UI_PATH_SEPARATOR '/' |
|
65 #define UI_ENV_HOME "HOME" |
|
66 #else |
|
67 #define UI_PATH_SEPARATOR '\\' |
|
68 #define UI_ENV_HOME "USERPROFILE" |
|
69 #endif |
|
70 |
63 char* ui_configfile(char *name) { |
71 char* ui_configfile(char *name) { |
64 const char *appname = ui_appname(); |
72 const char *appname = ui_appname(); |
65 if(!appname) { |
73 if(!appname) { |
66 return NULL; |
74 return NULL; |
67 } |
75 } |
68 |
76 |
69 CxBuffer buf; |
77 CxBuffer buf; |
70 cxBufferInit(&buf, NULL, 128, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
78 cxBufferInit(&buf, NULL, 128, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
71 |
79 |
72 // add base dir |
80 // add base dir |
73 char *homeenv = getenv("HOME"); |
81 char *homeenv = getenv(UI_ENV_HOME); |
74 if(homeenv == NULL) { |
82 if(homeenv == NULL) { |
75 cxBufferDestroy(&buf); |
83 cxBufferDestroy(&buf); |
76 return NULL; |
84 return NULL; |
77 } |
85 } |
78 cxstring home = cx_str(homeenv); |
86 cxstring home = cx_str(homeenv); |
79 |
87 |
80 cxBufferWrite(home.ptr, 1, home.length, &buf); |
88 cxBufferWrite(home.ptr, 1, home.length, &buf); |
81 if(home.ptr[home.length-1] != '/') { |
89 if(home.ptr[home.length-1] != UI_PATH_SEPARATOR) { |
82 cxBufferPut(&buf, '/'); |
90 cxBufferPut(&buf, UI_PATH_SEPARATOR); |
83 } |
91 } |
84 |
92 |
85 #ifdef UI_COCOA |
93 #ifdef UI_COCOA |
86 // on OS X the app dir is $HOME/Library/Application Support/$APPNAME/ |
94 // on OS X the app dir is $HOME/Library/Application Support/$APPNAME/ |
87 ucx_buffer_puts(buf, "Library/Application Support/"); |
95 cxBufferPutString(&buf, "Library/Application Support/"); |
|
96 #elif defined(_WIN32) |
|
97 // on Windows the app dir is $USERPROFILE/AppData/Local/$APPNAME/ |
|
98 cxBufferPutString(&buf, "AppData\\Local\\"); |
88 #else |
99 #else |
89 // app dir is $HOME/.$APPNAME/ |
100 // app dir is $HOME/.$APPNAME/ |
90 cxBufferPut(&buf, '.'); |
101 cxBufferPut(&buf, '.'); |
91 #endif |
102 #endif |
92 cxBufferPutString(&buf, appname); |
103 cxBufferPutString(&buf, appname); |
93 cxBufferPut(&buf, '/'); |
104 cxBufferPut(&buf, UI_PATH_SEPARATOR); |
94 |
105 |
95 // add file name |
106 // add file name |
96 if(name) { |
107 if(name) { |
97 cxBufferPutString(&buf, name); |
108 cxBufferPutString(&buf, name); |
98 } |
109 } |