| 42 #include "properties.h" |
42 #include "properties.h" |
| 43 #include <cx/string.h> |
43 #include <cx/string.h> |
| 44 #include <cx/buffer.h> |
44 #include <cx/buffer.h> |
| 45 |
45 |
| 46 #include <cx/hash_map.h> |
46 #include <cx/hash_map.h> |
| 47 #include "ucx_properties.h" |
47 #include <cx/properties.h> |
| 48 |
48 |
| 49 static CxMap *application_properties; |
49 static CxMap *application_properties; |
| 50 static CxMap *language; |
50 static CxMap *language; |
| 51 |
51 |
| 52 #ifndef UI_COCOA |
52 #ifndef UI_COCOA |
| 142 return _mkdir(path); |
142 return _mkdir(path); |
| 143 #else |
143 #else |
| 144 return mkdir(path, S_IRWXU); |
144 return mkdir(path, S_IRWXU); |
| 145 #endif |
145 #endif |
| 146 } |
146 } |
| |
147 |
| |
148 static int load_properties(FILE *file, CxMap *map) { |
| |
149 CxProperties prop; |
| |
150 cxPropertiesInitDefault(&prop); |
| |
151 char buf[8192]; |
| |
152 size_t r; |
| |
153 CxPropertiesStatus status = CX_PROPERTIES_NO_ERROR; |
| |
154 while((r = fread(buf, 1, 8192, file)) > 0) { |
| |
155 cxPropertiesFilln(&prop, buf, r); |
| |
156 cxstring key; |
| |
157 cxstring value; |
| |
158 status = cxPropertiesNext(&prop, &key, &value); |
| |
159 if(status > CX_PROPERTIES_OK) { |
| |
160 break; |
| |
161 } |
| |
162 cxMapPut(map, key, cx_strdup(value).ptr); |
| |
163 } |
| |
164 return status == CX_PROPERTIES_NO_ERROR ? 0 : 1; |
| |
165 } |
| 147 |
166 |
| 148 void uic_load_app_properties() { |
167 void uic_load_app_properties() { |
| 149 application_properties = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 128); |
168 application_properties = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 128); |
| 150 application_properties->collection.simple_destructor = free; |
169 application_properties->collection.simple_destructor = free; |
| 151 |
170 |
| 226 free(path); |
245 free(path); |
| 227 return 1; |
246 return 1; |
| 228 } |
247 } |
| 229 |
248 |
| 230 int ret = 0; |
249 int ret = 0; |
| 231 if(ucx_properties_store(application_properties, file)) { |
250 CxMapIterator i = cxMapIterator(application_properties); |
| 232 fprintf(stderr, "Ui Error: Cannot store application properties.\n"); |
251 cx_foreach(CxMapEntry *, entry, i) { |
| 233 ret = 1; |
252 fprintf(file, "%.*s: %s\n", (int)entry->key->len, entry->key->data, entry->value); |
| 234 } |
253 } |
| |
254 |
| |
255 cxMapRehash(application_properties); |
| 235 |
256 |
| 236 fclose(file); |
257 fclose(file); |
| 237 free(path); |
258 free(path); |
| 238 |
259 |
| 239 return ret; |
260 return ret; |