ui/common/properties.c

changeset 1041
db47e814b4c5
parent 1016
ccde46662db7
equal deleted inserted replaced
1040:473d8cb58a6c 1041:db47e814b4c5
60 60
61 static UiBool load_on_startup = TRUE; 61 static UiBool load_on_startup = TRUE;
62 static void *properties_data = NULL; 62 static void *properties_data = NULL;
63 static size_t properties_data_length = 0; 63 static size_t properties_data_length = 0;
64 64
65 static char *config_root = NULL;
66
65 void ui_load_properties_file_on_startup(UiBool enable) { 67 void ui_load_properties_file_on_startup(UiBool enable) {
66 load_on_startup = enable; 68 load_on_startup = enable;
67 } 69 }
68 70
69 void ui_set_properties_data(const char *str, size_t len) { 71 void ui_set_properties_data(const char *str, size_t len) {
75 properties_data_length = 0; 77 properties_data_length = 0;
76 } 78 }
77 } 79 }
78 80
79 char* ui_getappdir(void) { 81 char* ui_getappdir(void) {
80 if(ui_appname() == NULL) { 82 if(ui_appname() == NULL && config_root == NULL) {
81 return NULL; 83 return NULL;
82 } 84 }
83 85
84 return ui_configfile(NULL); 86 return ui_configfile(NULL);
87 }
88
89 void ui_setappdir(const char *path) {
90 free(config_root);
91 if(path) {
92 cxmutstr cfgpath = cx_strdup(path);
93 config_root = cfgpath.ptr;
94 if(cfgpath.length > 0 && cfgpath.ptr[cfgpath.length-1] == '/') {
95 config_root[cfgpath.length-1] = 0;
96 }
97 } else {
98 config_root = NULL;
99 }
85 } 100 }
86 101
87 #ifndef _WIN32 102 #ifndef _WIN32
88 #define UI_PATH_SEPARATOR '/' 103 #define UI_PATH_SEPARATOR '/'
89 #define UI_ENV_HOME "HOME" 104 #define UI_ENV_HOME "HOME"
93 #endif 108 #endif
94 109
95 #define UI_XDG_CONFIG_HOME_VAR "XDG_CONFIG_HOME" 110 #define UI_XDG_CONFIG_HOME_VAR "XDG_CONFIG_HOME"
96 111
97 char* ui_configfile(const char *name) { 112 char* ui_configfile(const char *name) {
113 if(config_root) {
114 if(!name) {
115 return strdup(config_root);
116 } else if(name[0] == '/') {
117 return cx_strdup(cx_strcat(CX_NULLSTR, 2, cx_str(config_root), cx_str(name))).ptr;
118 } else {
119 return cx_strdup(cx_strcat(CX_NULLSTR, 3, cx_str(config_root), cx_str("/"), cx_str(name))).ptr;
120 }
121 }
122
98 const char *appname = ui_appname(); 123 const char *appname = ui_appname();
99 if(!appname) { 124 if(!appname) {
100 return NULL; 125 return NULL;
101 } 126 }
102 127

mercurial