/* check if old and new caches contain the same number of entries, * and are the same version */ static int check_changed(const char *old_name, Eet_File *new_ef, unsigned char major, unsigned char minor) { Eet_File *old_ef; Efreet_Cache_Version *old_version = NULL; old_ef = eet_open(old_name, EET_FILE_MODE_READ); if (!old_ef) return 1; if (eet_num_entries(old_ef) != eet_num_entries(new_ef)) goto changed; old_version = eet_data_read(old_ef, efreet_version_edd(), EFREET_CACHE_VERSION); if (!old_version) goto changed; if ((old_version->major != major) || (old_version->minor != minor)) goto changed; free(old_version); eet_close(old_ef); return 0; changed: free(old_version); eet_close(old_ef); return 1; }
static Eina_Bool config_save(Eet_Data_Descriptor *descriptor, const char *filename, const char *section, const void *data) { Eet_File *ef; FILE *f; char buffer[PATH_MAX]; int i; /* human readable version */ snprintf(buffer, PATH_MAX, "%s.%s", filename, section); f = fopen(buffer, "w"); if (!f) { fprintf(stderr, "Not able to open human readable config file.\n"); goto on_error; } /* save the configuration */ snprintf(buffer, PATH_MAX, "%s.eet", filename); ef = eet_open(buffer, EET_FILE_MODE_READ_WRITE); if (!ef) { fprintf(stderr, "Not able to open config file for read write mode.\n"); goto on_error; } if (!eet_data_write(ef, descriptor, section, data, 1)) { fprintf(stderr, "Can't write data inside the config file.\n"); goto on_write_error; } if (!eet_data_dump(ef, section, invert_fputs, f)) { fprintf(stderr, "Can't dump section `%s`.\n"); goto on_write_error; } eet_close(ef); sleep(2); fclose(f); return EINA_TRUE; on_write_error: eet_close(ef); snprintf(buffer, PATH_MAX, "%s.eet", filename); unlink(buffer); on_error: if (f) { fclose(f); snprintf(buffer, PATH_MAX, "%s.%s", filename, section); unlink(buffer); } return EINA_FALSE; }
static int _evas_gl_common_shader_binary_save(Evas_GL_Shared *shared) { /* check eet */ Eet_File *et = NULL; //check eet file int tmpfd; int res = 0; char bin_dir_path[PATH_MAX]; char bin_file_path[PATH_MAX]; char tmp_file[PATH_MAX]; unsigned int i; if (!_evas_gl_shader_dir_check(bin_dir_path, sizeof(bin_dir_path))) { res = _evas_gl_shader_file_mkpath(bin_dir_path); if (!res) return 0; /* we can't make directory */ } _evas_gl_shader_file_check(bin_dir_path, bin_file_path, sizeof(bin_dir_path)); /* use mkstemp for writing */ snprintf(tmp_file, sizeof(tmp_file), "%s.XXXXXX", bin_file_path); tmpfd = mkstemp(tmp_file); if (tmpfd < 0) goto error; close(tmpfd); /* use eet */ if (!eet_init()) goto error; et = eet_open(tmp_file, EET_FILE_MODE_WRITE); if (!et) goto error; for (i = 0; i < sizeof (_shaders_source) / sizeof (_shaders_source[0]); ++i) if (!_evas_gl_common_shader_program_binary_save(&(shared->shader[_shaders_source[i].id]), _shaders_source[i].name, et)) goto error; if (eet_close(et) != EET_ERROR_NONE) goto error; if (rename(tmp_file,bin_file_path) < 0) goto error; eet_shutdown(); return 1; error: if (et) eet_close(et); if (_evas_gl_shader_file_exists(tmp_file)) unlink(tmp_file); eet_shutdown(); return 0; }
void _ecore_config_db_close(Ecore_Config_DB_File *db) { eet_close(db->ef); free(db); eet_shutdown(); }
/* * @brief load the list of interfaces from a file * @param file the configuration file * @return Returns the list of interfaces */ Boot_Process_List *waiting_iface_load(const char* file) { Eet_Data_Descriptor*edd; Eet_File *f; Boot_Process_List *data; edd = waiting_iface_edd_new(); f = eet_open(file, EET_FILE_MODE_READ); EXALT_ASSERT_ADV(f!=NULL, data = malloc(sizeof(Boot_Process_List)); data->timeout = 30; data->l=NULL, "f!=NULL failed"); data = eet_data_read(f, edd, "boot process interface list"); eet_close(f); eet_data_descriptor_free(edd); EXALT_ASSERT_ADV(data!=NULL, data = malloc(sizeof(Boot_Process_List)); data->timeout = 30; data->l=NULL, "data!=NULL failed"); return data; }
void evas_model_load_file_eet(Evas_Canvas3D_Mesh *mesh, Eina_File *file) { Eet_File *ef; Evas_Canvas3D_File_Eet* eet_file; Eet_Data_Descriptor *_file_descriptor; eet_init(); _file_descriptor = _evas_canvas3d_eet_file_get(); ef = eet_mmap(file); eet_file = eet_data_read(ef, _file_descriptor, EVAS_CANVAS3D_FILE_CACHE_FILE_ENTRY); eet_close(ef); if (!eet_file || !eet_file->mesh || !eet_file->header) { ERR("Failed to read model file"); goto on_error; } _set_geometry_to_mesh_from_eet_file(mesh, eet_file->mesh); _set_material_to_mesh_from_eet_file(mesh, eet_file->mesh); on_error: _evas_canvas3d_eet_file_free(eet_file); eet_shutdown(); }
static Eina_Bool _ephoto_on_config_save(void *data) { Ephoto *ephoto = data; Eet_File *ef; char buf[4096], buf2[4096]; snprintf(buf, sizeof(buf), "%s/.config/ephoto/ephoto.cfg", getenv("HOME")); snprintf(buf2, sizeof(buf2), "%s.tmp", buf); ef = eet_open(buf2, EET_FILE_MODE_WRITE); if (!ef) goto save_end; eet_data_write(ef, edd, "config", ephoto->config, 1); if (eet_close(ef)) goto save_end; if (!ecore_file_mv(buf2, buf)) goto save_end; INF("Config saved"); save_end: ecore_file_unlink(buf2); if (save_timer) { ecore_timer_del(save_timer); save_timer = NULL; } return ECORE_CALLBACK_CANCEL; }
void efreet_cache_shutdown(void) { Efreet_Old_Cache *d; IF_RELEASE(theme_name); icon_cache = efreet_cache_close(icon_cache); icon_theme_cache = efreet_cache_close(icon_theme_cache); IF_FREE_HASH(themes); IF_FREE_HASH(icons); IF_FREE_HASH(fallbacks); IF_FREE_HASH_CB(desktops, EINA_FREE_CB(efreet_cache_desktop_free)); desktop_cache = efreet_cache_close(desktop_cache); IF_RELEASE(desktop_cache_file); efreet_cache_edd_shutdown(); IF_RELEASE(icon_theme_cache_file); if (old_desktop_caches) ERR("This application has not properly closed all its desktop references!"); EINA_LIST_FREE(old_desktop_caches, d) { eina_hash_free(d->hash); eet_close(d->ef); free(d); }
/** * @internal * @returns the number of initializations left for this system * @brief Attempts to shut down the subsystem if nothing else is using it */ void efreet_desktop_shutdown(void) { Efreet_Desktop_Type_Info *info; char *dir; if (efreet_desktop_exe_handler) ecore_event_handler_del(efreet_desktop_exe_handler); IF_RELEASE(desktop_environment); IF_FREE_HASH(efreet_desktop_cache); while (efreet_desktop_types) { info = eina_list_data_get(efreet_desktop_types); efreet_desktop_type_info_free(info); efreet_desktop_types = eina_list_remove_list(efreet_desktop_types, efreet_desktop_types); } EINA_LIST_FREE(efreet_desktop_dirs, dir) eina_stringshare_del(dir); if (cache_monitor) ecore_file_monitor_del(cache_monitor); if (change_monitors) eina_hash_free(change_monitors); if (cache) eet_close(cache); efreet_desktop_edd_shutdown(desktop_edd); ecore_file_shutdown(); eina_log_domain_unregister(_efreet_desktop_log_dom); IF_RELEASE(cache_file); IF_RELEASE(cache_dirs); if (efreet_desktop_job) ecore_job_del(efreet_desktop_job); efreet_desktop_job = NULL; }
static int _evas_gl_common_shader_binary_init(Evas_GL_Shared *shared) { Eet_File *ef = NULL; char bin_dir_path[PATH_MAX]; char bin_file_path[PATH_MAX]; if (!shared || !shared->info.bin_program) return 1; if (shared->shaders_cache) return 1; if (!evas_gl_common_file_cache_dir_check(bin_dir_path, sizeof(bin_dir_path))) return 0; if (!evas_gl_common_file_cache_file_check(bin_dir_path, SHADER_EET_CACHENAME, bin_file_path, sizeof(bin_dir_path))) return 0; if (!eet_init()) return 0; ef = eet_open(bin_file_path, EET_FILE_MODE_READ); if (!_evas_gl_common_shader_binary_checksum_check(shared, ef)) goto error; shared->shaders_cache = ef; return 1; error: if (ef) eet_close(ef); eet_shutdown(); return 0; }
void _show_hs(void *data, Evas_Object *obj, void *event_info) { elm_genlist_clear(highscores_genlist); if(!_itc) { _itc = elm_genlist_item_class_new(); _itc->item_style = "default"; _itc->func.text_get = _item_label_get; _itc->func.content_get = NULL; _itc->func.state_get = NULL; _itc->func.del = NULL; } Eet_File *eef = eet_open(RESULTS_FILE, EET_FILE_MODE_READ); int game_type = (int)(uintptr_t)(data); int j = 0; for(; j < 10; ++j) { char buf[50]; int *res; sprintf(buf, "%d%d", game_type, j); res = eet_read(eef, buf, NULL); if(res && res[0] != -1) { elm_genlist_item_append(highscores_genlist, _itc, res, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); } } //free(res); //MEMORY LEAK? eet_close(eef); }
/** * @brief Saves Etk's config to disk * @return Returns ETK_TRUE on a successful save, ETK_FALSE otherwise. */ Etk_Bool etk_config_save(void) { Eet_File *ef; char buf[PATH_MAX]; char *home; Etk_Bool ret; home = getenv("HOME"); if (!home) return 0; snprintf(buf, sizeof(buf), "%s/.e/etk/config.eet", home); ef = eet_open(buf, EET_FILE_MODE_WRITE); if (!ef) return 0; ret = eet_data_write(ef, _etk_config_ver_edd, "config/version", _etk_config->version, 1); if (!ret) ETK_WARNING("Problem saving config!"); ret = eet_data_write(ef, _etk_config_gen_edd, "config/general", _etk_config->general, 1); if (!ret) ETK_WARNING("Problem saving config/stickies!"); eet_close(ef); return ret; }
static int _ephoto_config_load(Ephoto *ephoto) { Eet_File *ef; char buf[4096], buf2[4096]; snprintf(buf2, sizeof(buf2), "%s/.config/ephoto", getenv("HOME")); ecore_file_mkpath(buf2); snprintf(buf, sizeof(buf), "%s/ephoto.cfg", buf2); ef = eet_open(buf, EET_FILE_MODE_READ); if (!ef) { ephoto_config_free(ephoto); ephoto->config = calloc(1, sizeof(Ephoto_Config)); return 0; } ephoto->config = eet_data_read(ef, edd, "config"); eet_close(ef); if (!ephoto->config || ephoto->config->config_version > CONFIG_VERSION) { ephoto_config_free(ephoto); ephoto->config = calloc(1, sizeof(Ephoto_Config)); return 0; } if (ephoto->config->config_version < CONFIG_VERSION) return -1; return 1; }
static My_Conf_Type * _my_conf_load(const char *filename) { My_Conf_Type *my_conf; Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); if (!ef) { fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); return NULL; } my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY); if (!my_conf) goto end; if (my_conf->version < 0x112233) { fprintf(stderr, "WARNING: version %#x was too old, upgrading it to %#x\n", my_conf->version, 0x112233); my_conf->version = 0x112233; my_conf->enabled = EINA_TRUE; } end: eet_close(ef); return my_conf; } /* _my_conf_load */
void config_flush(void) { Eet_File *cf; char path[PATH_MAX]; if (!config) return; snprintf(path, sizeof(path), "%s/%s", efreet_config_home_get(), "jesus.eet"); cf = eet_open(path, EET_FILE_MODE_WRITE); if (!cf) { printf("Failed to open config file"); } if (!eet_data_write(cf, edd, CONFIG_KEY, config, 0)) { printf("Failed to write config file"); } eet_close(cf); }
void on_btn_save_clicked(Etk_Object *object, void *data) { Cover_Entry *ce; Eet_File *ef; Eina_List *list; char *cover_file; list = cover_changed; asprintf(&cover_file, "%s/.e/apps/emphasis/cover.eet", getenv("HOME")); ef = eet_open(cover_file, EET_FILE_MODE_READ_WRITE); if (!ef) { fprintf(stderr, "can't open %s\n", cover_file); free(cover_file); return; } while (cover_changed) { ce = eina_list_data_get(cover_changed); eet_write(ef, ce->key, ce->path, strlen(ce->path)+1, 0); eet_clearcache(); free(ce->key); free(ce->path); free(ce); cover_changed = eina_list_next(cover_changed); } eina_list_free(list); eet_close(ef); free(cover_file); }
void _config_read() { Eet_File *cf; char path[PATH_MAX]; if (config) { _config_free(config); config = NULL; } snprintf(path, sizeof(path), "%s/%s", efreet_config_home_get(), "jesus.eet"); cf = eet_open(path, EET_FILE_MODE_READ); if (cf) { config = eet_data_read(cf, edd, CONFIG_KEY); eet_close(cf); } if (!config) { config = _config_standart_new(); config_flush(); } }
char * emphasis_cover_db_search(const char *artist, const char *album) { char *config_path; char *cover_path = NULL; char *key; int size; void *cover = NULL; Eet_File *ef; asprintf(&config_path, "%s/.e/apps/emphasis/cover.eet", getenv("HOME")); ef = eet_open(config_path, EET_FILE_MODE_READ); asprintf(&key, "/%s/%s", artist, album); cover_path = eet_read(ef, key, &size); eet_close(ef); if (!cover_path) { cover = emphasis_cover_file_get_from_amazon(artist, album, &size); cover_path = emphasis_cover_db_add(artist, album, cover, size); } if (cover_path && !strcmp(cover_path, "not found")) { free(cover_path); cover_path = NULL; } free(config_path); free(key); return cover_path; }
void Config::saveStateCache() { Eet_File *ef; std::string file = Utils::getCacheFile("iostates.cache"); std::string tmp = file + "_tmp"; ConfigStateCache *cache; cache = new ConfigStateCache; cache->version = CONFIG_STATES_CACHE_VERSION; cache->states = cache_states; ef = eet_open(tmp.c_str(), EET_FILE_MODE_WRITE); if (!ef) { cWarning() << "Could not open iostates.cache for write !"; delete cache; return; } Eina_Bool ret = eet_data_write(ef, edd_cache, "calaos/states/cache", cache, EINA_TRUE); eet_close(ef); delete cache; if (ret) { ecore_file_unlink(file.c_str()); ecore_file_mv(tmp.c_str(), file.c_str()); } cInfo() << "State cache file written successfully (" << file << ")"; }
void Config::loadStateCache() { ConfigStateCache *cache; std::string file = Utils::getCacheFile("iostates.cache"); Eet_File *ef = eet_open(file.c_str(), EET_FILE_MODE_READ); if (!ef) { cWarning() << "Could not open iostates.cache for read !"; return; } cache = (ConfigStateCache *)eet_data_read(ef, edd_cache, "calaos/states/cache"); if (!cache) { eet_close(ef); cWarning() << "Could not read iostates.cache, corrupted file?"; return; } if (cache->version < CONFIG_STATES_CACHE_VERSION) { cWarning() << "File version too old, upgrading to new format"; cache->version = CONFIG_STATES_CACHE_VERSION; } //read all states and put it in cache_states Eina_Iterator *it = eina_hash_iterator_tuple_new(cache->states); void *data; while (eina_iterator_next(it, &data)) { Eina_Hash_Tuple *t = (Eina_Hash_Tuple *)data; ConfigStateValue *state = (ConfigStateValue *)t->data; std::string skey = state->id; std::string svalue = state->value; SaveValueIO(skey, svalue, false); } eina_iterator_free(it); eina_hash_free(cache->states); free(cache); eet_close(ef); cInfo() << "States cache read successfully."; }
void histogram_cache_descriptor_shutdown(void) { eet_data_descriptor_free(_histogram_descriptor); eet_data_descriptor_free(_histogram_cache_descriptor); if(cache_file) { eet_close(cache_file); } eet_shutdown(); eina_shutdown(); }
static void _elixir_eet_filename_free(Elixir_Eet_Filename *eef) { if (eef->reference == 0) { eet_close(eef->eet); free(eef->filename); free(eef); } }
void depose_storage(StorageData *sd) { CALLED(); storage_rewrite_all_items(sd); dump_items(sd); if (sd->ef) eet_close(sd->ef); sd->ef = NULL; eet_shutdown(); ecore_file_shutdown(); }
int ex_config_write(Extrackt *ex) { Eet_File *ef; char buf[PATH_MAX]; char *home; int ret; Eina_List *l; home = getenv("HOME"); if(!home) return 0; snprintf(buf, sizeof(buf), "%s/.e/extrackt/config.eet", home); ef = eet_open(buf, EET_FILE_MODE_WRITE); if(!ef) return 0; ret = eet_data_write(ef, _ex_config_version_edd, "config/version", ex->config.version, 1); if(!ret) DEBUG(_("Problem saving config!")); ret = eet_data_write(ef, _ex_config_cd_edd, "config/cd", ex->config.cd, 1); if(!ret) DEBUG(_("Problem saving config!")); ret = eet_data_write(ef, _ex_config_cddb_edd, "config/cddb", ex->config.cddb, 1); if(!ret) DEBUG(_("Problem saving config!")); for(l = ex->config.rippers; l; l = l->next) { Ex_Config_Exe *ripper; char *buf; int size; ripper = l->data; size = strlen("config/rippers/") + strlen(ripper->name) + 1; buf = E_NEW(size, char); snprintf(buf, size, "config/rippers/%s", ripper->name); ret = eet_data_write(ef, _ex_config_exe_edd, buf, ripper, 1); if(!ret) DEBUG(_("Problem saving config!")); } ret = eet_data_write(ef, _ex_config_encode_edd, "config/encode", ex->config.encode, 1); if(!ret) DEBUG(_("Problem saving config!")); eet_close(ef); return ret; }
void error_and_abort(Eet_File *ef, const char *fmt, ...) { va_list ap; va_start(ap, fmt); eina_log_vprint(_edje_cc_log_dom, EINA_LOG_LEVEL_CRITICAL, "unknown", "unknown", 0, fmt, ap); va_end(ap); eet_close(ef); exit(-1); }
int main(void) { Eet_File *ef; char *ret; int size; char *entries[] = { "Entry 1", "Big text string here compared to others", "Eet is cool" }; eet_init(); // blindly open an file for output and write strings with their NUL char ef = eet_open("test.eet", EET_FILE_MODE_WRITE); eet_write(ef, "Entry 1", entries[0], strlen(entries[0]) + 1, 0); eet_write(ef, "Entry 2", entries[1], strlen(entries[1]) + 1, 1); eet_write(ef, "Entry 3", entries[2], strlen(entries[2]) + 1, 0); eet_close(ef); // open the file again and blindly get the entries we wrote ef = eet_open("test.eet", EET_FILE_MODE_READ); ret = eet_read(ef, "Entry 1", &size); printf("%s\n", ret); free(ret); ret = eet_read(ef, "Entry 2", &size); printf("%s\n", ret); free(ret); ret = eet_read(ef, "Entry 3", &size); printf("%s\n", ret); free(ret); eet_close(ef); eet_shutdown(); }
static int _evas_gl_common_shader_binary_init(Evas_GL_Shared *shared) { /* check eet */ Eet_File *et = NULL; char bin_dir_path[PATH_MAX]; char bin_file_path[PATH_MAX]; unsigned int i; if (!_evas_gl_shader_dir_check(bin_dir_path, sizeof(bin_dir_path))) return 0; if (!_evas_gl_shader_file_check(bin_dir_path, bin_file_path, sizeof(bin_dir_path))) return 0; /* use eet */ if (!eet_init()) return 0; et = eet_open(bin_file_path, EET_FILE_MODE_READ); if (!et) goto error; for (i = 0; i < sizeof (_shaders_source) / sizeof (_shaders_source[0]); ++i) if (!_evas_gl_common_shader_program_binary_init(&(shared->shader[_shaders_source[i].id]), _shaders_source[i].name, et)) goto error; if (et) eet_close(et); eet_shutdown(); return 1; error: if (et) eet_close(et); eet_shutdown(); return 0; }
static void storage_rewrite_all_items(StorageData *sd) { CALLED(); if (sd->ef) eet_close(sd->ef); ecore_file_remove(STORAGE_FILEPATH); sd->ef = eet_open(STORAGE_FILEPATH, EET_FILE_MODE_READ_WRITE); int i; for (i = 0; i < STORAGE_ITEM_CNT; i++) { if ((sd->indexTable[i] != STORAGE_INDEX_ITEM_NONE) && (sd->itemTable[i])) item_write(sd->ef, i, sd->itemTable[i]); } storage_index_write(sd); }
void fill_tree_with_db(Etk_Tree *tree) { int num, i; char **entries; char *cover_path; Etk_Tree_Col *col; Etk_Tree_Row *row; Eet_File *ef; char *cover_db_path; asprintf(&cover_db_path, "%s/.e/apps/emphasis/cover.eet", getenv("HOME")); ef = eet_open(cover_db_path, EET_FILE_MODE_READ); if (!ef) { fprintf(stderr, "Can't open %s\n", cover_db_path); free(cover_db_path); exit(-1); } col = etk_tree_col_new(tree, "/artist/album", 0, 0.0); etk_tree_col_model_add(col, etk_tree_model_text_new()); etk_tree_build(tree); etk_tree_freeze(tree); entries = eet_list(ef, "*", &num); for (i=0; i<num; i++) { cover_path = eet_read(ef, entries[i], NULL); row = etk_tree_row_append(tree, NULL, col, entries[i], NULL); if (strcmp("not found", cover_path)) { etk_tree_row_data_set(row, cover_path); } else { etk_tree_row_data_set(row, NULL); } } eet_close(ef); free(cover_db_path); etk_tree_col_sort_set(etk_tree_nth_col_get(tree, 0), tree_sort, NULL); etk_tree_thaw(tree); }
/** * @brief Save the connection associated to an essid in the configuration file * @param file the configuration file * @param c the connection * @return Returns 1 if success, else 0 */ int _exalt_eet_wireless_conn_save(const char*file, Exalt_Connection* c) { Eet_Data_Descriptor* edd; Eet_File* f; int res; edd = exalt_conn_edd_new(); f = eet_open(file, EET_FILE_MODE_READ_WRITE); if(!f) f = eet_open(file, EET_FILE_MODE_WRITE); res=eet_data_write(f, edd,exalt_conn_get_essid(c), c, 0); EXALT_ASSERT(res!=0); eet_close(f); eet_data_descriptor_free(edd); return res; }