10 #include <sys/param.h>
11 #include <sys/types.h>
15 #include "Ecore_Config.h"
16 #include "ecore_config_private.h"
19 * Loads the default configuration.
20 * @return @c ECORE_CONFIG_ERR_SUCC on success. @c ECORE_CONFIG_ERR_NODATA
21 * is returned if the file cannot be loaded.
22 * @ingroup Ecore_Config_File_Group
25 ecore_config_load(void)
29 if (!__ecore_config_app_name)
30 return ECORE_CONFIG_ERR_FAIL;
32 snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.eet", getenv("HOME"),
33 __ecore_config_app_name);
34 return ecore_config_file_load(file);
38 * Saves the current configuration to the default file.
39 * @return @c ECORE_CONFIG_ERR_SUCC is returned on success.
40 * @c ECORE_CONFIG_ERR_FAIL is returned if the data cannot be
42 * @ingroup Ecore_Config_File_Group
45 ecore_config_save(void)
49 if (!__ecore_config_app_name)
50 return ECORE_CONFIG_ERR_FAIL;
52 snprintf(file, PATH_MAX, "%s/.e/apps/%s/config.eet", getenv("HOME"),
53 __ecore_config_app_name);
54 return ecore_config_file_save(file);
58 * Load the given configuration file to the local configuration.
59 * @param file Name of the file to load.
60 * @return @c ECORE_CONFIG_ERR_SUCC on success. @c ECORE_CONFIG_ERR_NODATA
61 * is returned if the file cannot be loaded.
62 * @ingroup Ecore_Config_File_Group
65 ecore_config_file_load(const char *file)
67 Ecore_Config_DB_File *db;
71 // double ftmp; UNUSED
74 // Ecore_Config_Type type; UNUSED
80 db = _ecore_config_db_open_read(file);
83 ERR("Cannot open database from file %s!", file);
84 return ECORE_CONFIG_ERR_NODATA;
87 keys = _ecore_config_db_keys_get(db, &key_count);
90 for (x = 0; x < key_count; x++)
92 _ecore_config_db_read(db, keys[x]);
95 _ecore_config_db_close(db);
98 for (x = 0; x < key_count; x++)
104 return ECORE_CONFIG_ERR_SUCC;
108 _ecore_config_recurse_mkdir(const char *file)
114 file_tmp = strdup(file);
115 file_ptr = file_tmp + strlen(file_tmp);
116 while (*file_ptr != '/' && file_ptr > file_tmp)
120 if ((file_tmp[0] != 0) && stat(file_tmp, &status))
122 _ecore_config_recurse_mkdir(file_tmp);
123 mkdir(file_tmp, S_IRUSR | S_IWUSR | S_IXUSR);
129 * Saves the local configuration to the given file.
130 * @param file Name of the file to save to.
131 * @return @c ECORE_CONFIG_ERR_SUCC is returned on success.
132 * @c ECORE_CONFIG_ERR_FAIL is returned if the data cannot be
134 * @ingroup Ecore_Config_File_Group
137 ecore_config_file_save(const char *file)
139 Ecore_Config_Prop *next;
140 Ecore_Config_DB_File *db;
143 next = __ecore_config_bundle_local->data;
146 /* if file does not exist check to see if the dirs exist, creating if not */
147 if (stat(file, &status))
148 _ecore_config_recurse_mkdir(file);
150 db = _ecore_config_db_open_write(file);
153 ERR("Cannot open database from file %s!", file);
154 return ECORE_CONFIG_ERR_FAIL;
159 /* let the config_db deal with this
160 * handyande: hmm, not sure that it ever does - reinstating until
161 * further discussions satisfy me!
163 if (!(next->flags & ECORE_CONFIG_FLAG_MODIFIED) || next->flags & ECORE_CONFIG_FLAG_CMDLN)
169 _ecore_config_db_write(db, next);
174 _ecore_config_db_close(db);
175 return ECORE_CONFIG_ERR_SUCC;