/** * @brief Initializes the config system * @return Returns true if initialization was successful, false otherwise */ Etk_Bool etk_config_init(void) { char *home; char buf[PATH_MAX]; home = getenv("HOME"); if (!home) { ETK_WARNING("Cant find home directory!"); return ETK_FALSE; } /* make sure ~/.e exists and is a dir */ snprintf(buf, sizeof(buf), "%s/.e", home); if (!ecore_file_is_dir(buf)) { if (ecore_file_exists(buf)) { ETK_WARNING("Cant create config path!"); return ETK_FALSE; } if (!ecore_file_mkdir(buf)) { ETK_WARNING("Cant create config path!"); return ETK_FALSE; } } /* make sure ~/.e/etk exists and is a dir */ snprintf(buf, sizeof(buf), "%s/.e/etk", home); if (!ecore_file_is_dir(buf)) { if (ecore_file_exists(buf)) { ETK_WARNING("Cant create config path!"); return ETK_FALSE; } if (!ecore_file_mkdir(buf)) { ETK_WARNING("Cant create config path!"); return ETK_FALSE; } } _etk_config_gen_edd = NEWD("Etk_Config_General", Etk_Config_General); CFG_GEN_NEWI("wmt", wm_theme, EET_T_STRING); CFG_GEN_NEWI("wt", widget_theme, EET_T_STRING); CFG_GEN_NEWI("fn", font, EET_T_STRING); CFG_GEN_NEWI("en", engine, EET_T_STRING); _etk_config_ver_edd = NEWD("Etk_Config_Version", Etk_Config_Version); CFG_VER_NEWI("mj", major, EET_T_INT); CFG_VER_NEWI("mn", minor, EET_T_INT); CFG_VER_NEWI("pa", patch, EET_T_INT); CFG_VER_NEWI("sp", subpatch, EET_T_INT); return ETK_TRUE; }
int enna_util_init() { EVT("enna util init"); /* Prevent multiple loads */ if (_util_init_count > 0) return ++_util_init_count; sd = calloc(1, sizeof(Smart_Data)); sd->cache = eina_stringshare_printf("%s/%s", efreet_cache_home_get(), "/enna"); sd->config = eina_stringshare_printf("%s/%s", efreet_config_home_get(), "/enna"); sd->data = eina_stringshare_printf("%s/%s", efreet_data_home_get(), "/enna"); if (!ecore_file_is_dir(sd->cache)) ecore_file_mkdir(sd->cache); if (!ecore_file_is_dir(sd->config)) ecore_file_mkdir(sd->config); if (!ecore_file_is_dir(sd->data)) ecore_file_mkdir(sd->data); DBG("Set data directory to %s", sd->data); DBG("Set config directory to : %s", sd->config); DBG("Set cache directory to : %s", sd->cache); _util_init_count = 1; EVT("enna util init done"); return 1; }
std::string Utils::getConfigFile(const char *configType) { if (_configBase.empty()) { std::string home; if (getenv("HOME")) { home = getenv("HOME"); } else { struct passwd *pw = getpwuid(getuid()); home = pw->pw_dir; } std::list<std::string> confDirs; confDirs.push_back(home + "/" + HOME_CONFIG_PATH); confDirs.push_back(ETC_CONFIG_PATH); confDirs.push_back(PREFIX_CONFIG_PATH); //Check config in that order: // - $HOME/.config/calaos/ // - /etc/calaos // - pkg_prefix/etc/calaos // - create $HOME/.config/calaos/ if nothing found std::list<std::string>::iterator it = confDirs.begin(); for (;it != confDirs.end();it++) { std::string conf = *it; conf += "/" IO_CONFIG; if (ecore_file_exists(conf.c_str())) { _configBase = *it; break; } } if (_configBase.empty()) { //no config dir found, create $HOME/.config/calaos ecore_file_mkdir(std::string(home + "/.config").c_str()); ecore_file_mkdir(std::string(home + "/.config/calaos").c_str()); _configBase = home + "/" + HOME_CONFIG_PATH; } } return _configBase + "/" + configType; }
/** * @return Return 1 on success or 0 on failure * @brief Delete all the files inside the trash. */ EAPI int efreet_trash_empty_trash(void) { char buf[PATH_MAX]; snprintf(buf, sizeof(buf), "%s/info", efreet_trash_dir_get(NULL)); if (!ecore_file_recursive_rm(buf)) return 0; ecore_file_mkdir(buf); snprintf(buf, sizeof(buf), "%s/files", efreet_trash_dir_get(NULL)); if (!ecore_file_recursive_rm(buf)) return 0; ecore_file_mkdir(buf); /* TODO Empty also trash in other filesystems */ return 1; }
static void _dialog_create_folder_ok_clicked_cb(void *data, Evas_Object *btn, void *ev) { Enna_Localfiles_Priv *priv = data; Enna_File *file; Evas_Object *entry; const char *new_name; const char *new_path; char uri[4096]; file = evas_object_data_get(priv->dialog, "file"); entry = evas_object_data_get(priv->dialog, "entry"); new_name = elm_object_text_get(entry); new_path = eina_stringshare_printf("%s/%s", ecore_file_dir_get(file->mrl), new_name); if (ecore_file_mkdir(new_name)) { Enna_File *f; snprintf(uri, sizeof(uri), "file://%s", new_path); printf(" uri : %s\n", uri); f = enna_file_directory_add(new_name, uri, new_path, new_name, "icon/directory"); enna_browser_file_add(priv->browser, f); } evas_object_del(priv->dialog); }
/** * @brief Create complete directory in a batch. * * @param dirs The list of directories, null terminated. * @return The number of successful directories created, -1 if dirs is * @c NULL. * * This function creates all the directories that are in the null * terminated array @p dirs. The function loops over the directories * and call ecore_file_mkdir(). This function returns -1 if @p dirs is * @c NULL, otherwise if returns the number of suceesfully created * directories. */ EAPI int ecore_file_mkdirs(const char **dirs) { int i = 0; if (!dirs) return -1; for (; *dirs; dirs++) if (ecore_file_mkdir(*dirs)) i++; return i; }
std::string Utils::getCacheFile(const char *cacheFile) { if (_cacheBase.empty()) { std::string home; if (getenv("HOME")) { home = getenv("HOME"); } else { struct passwd *pw = getpwuid(getuid()); home = pw->pw_dir; } //force the creation of .cache/calaos ecore_file_mkdir(std::string(home + "/.cache").c_str()); ecore_file_mkdir(std::string(home + "/.cache/calaos").c_str()); _cacheBase = home + "/.cache/calaos"; } return _cacheBase + "/" + cacheFile; }
char *utils_file_move_in_pres(const char *file) { const char *pres_file = eyelight_object_presentation_file_get(pres); char *dir = ecore_file_dir_get(pres_file); char *res; int ok = 1; int i; //test if file is in a subdirectory of dir for(i=0;i<strlen(dir);i++) { if(i >= strlen(file) || dir[i] != file[i]) { ok = 0; break; } else i++; } if(!ok) { const char* file_name = ecore_file_file_get(file); char buf[PATH_MAX]; res = calloc(PATH_MAX, sizeof(char)); snprintf(buf, PATH_MAX, "%s/images/", dir); if(!ecore_file_exists(buf)) ecore_file_mkdir(buf); snprintf(buf, PATH_MAX, "%s/images/%s", dir, file_name); ecore_file_cp(file, buf); snprintf(res,PATH_MAX,"images/%s", file_name); } else { const char *_file = file + strlen(dir) + 1; res = strdup(_file); } EYELIGHT_FREE(dir); return res; }
EflResources::EflResources() : resources_loaded__( 0 ) , max_width__( 0 ) , max_height__( 0 ) , window__( nullptr ) , preloaded_images__() , signals__() { for( int i = 0; i < SIGNALS_CNT; ++i ) { signals__[i] = std::shared_ptr< Events::Signal >( new Events::Signal() ); } if( init_images__.empty() ) init_images__ = FileManager::findFilesOfType( "png" , IMG_DIR ); ecore_file_mkdir( cache_dir.c_str() ); }
static Ems_Config * _config_get(Eet_Data_Descriptor *edd) { Ems_Config *config = NULL; Eet_File *file; if (!ecore_file_is_dir(ems_config_tmp_dirname_get())) ecore_file_mkdir(ems_config_tmp_dirname_get()); file = eet_open(ems_config_tmp_filename_get(), EET_FILE_MODE_READ_WRITE); config = eet_data_read(file, edd, "config"); if (!config) { WRN("Warning no configuration found! This must not happen, we will go back to a void configuration"); return NULL; } eet_close(file); return config; }
int ex_config_init() { char *home; char buf[PATH_MAX]; home = getenv("HOME"); if(!home) { ERROR(_("Cant find home directory!")); return 0; } /* make sure ~/.e exists and is a dir */ snprintf(buf, sizeof(buf), "%s/.e", home); if(!ecore_file_is_dir(buf)) { if(ecore_file_exists(buf)) { ERROR(_("Cant create config path!")); return 0; } if(!ecore_file_mkdir(buf)) { ERROR(_("Cant create config path!")); return 0; } } /* make sure ~/.e/extrackt exists and is a dir */ snprintf(buf, sizeof(buf), "%s/.e/extrackt", home); if(!ecore_file_is_dir(buf)) { if(ecore_file_exists(buf)) { ERROR(_("Cant create config path!")); return 0; } if(!ecore_file_mkdir(buf)) { ERROR(_("Cant create config path!")); return 0; } } _ex_config_version_edd = NEWD("Ex_Config_Version", Ex_Config_Version); VER_NEWI("mj", major, EET_T_INT); VER_NEWI("mn", minor, EET_T_INT); VER_NEWI("pa", patch, EET_T_INT); _ex_config_cd_edd = NEWD("Ex_Config_Cd", Ex_Config_Cd); CD_NEWI("cd", cdrom, EET_T_STRING); CD_NEWI("rs", interrupt_playback, EET_T_INT); CD_NEWI("rw", rewind_stopped, EET_T_INT); CD_NEWI("sf", startup_first_track, EET_T_INT); CD_NEWI("ai", autoplay_insert, EET_T_INT); CD_NEWI("rp", reshuffle_playback, EET_T_INT); CD_NEWI("wf", workaround_eject, EET_T_INT); CD_NEWI("pd", poll_drive, EET_T_INT); CD_NEWI("pi", poll_interval, EET_T_INT); _ex_config_cddb_server_edd = NEWD("Ex_Config_Cddb_Server", Ex_Config_Cddb_Server); CDDBS_NEWI("nm", name ,EET_T_STRING); CDDBS_NEWI("cg", cgi_prog, EET_T_STRING); CDDBS_NEWI("pt", port, EET_T_INT); CDDBS_NEWI("up", use_proxy, EET_T_INT); _ex_config_cddb_edd = NEWD("Ex_Config_Cddb", Ex_Config_Cddb); CDDB_NEWI("al", automatic_lookup, EET_T_INT); CDDB_NEWS("pr", primary, _ex_config_cddb_server_edd); CDDB_NEWS("sc", secondary, _ex_config_cddb_server_edd); _ex_config_exe_edd = NEWD("Ex_Config_Exe", Ex_Config_Exe); EXE_NEWI("nm", name, EET_T_STRING); EXE_NEWI("ex", exe, EET_T_STRING); EXE_NEWI("cl", command_line_opts, EET_T_STRING); EXE_NEWI("ff", file_format, EET_T_STRING); EXE_NEWI("df", def, EET_T_INT); EXE_NEWI("ty", type, EET_T_INT); _ex_config_encode_edd = NEWD("Ex_Config_Encode", Ex_Config_Cddb); ENC_NEWL("es", encoders, _ex_config_exe_edd); ENC_NEWI("wd", wav_delete, EET_T_INT); return 1; }
static Eina_Bool _etui_epub_file_unzip(Etui_Provider_Data *pd) { struct archive *a; struct archive_entry *entry; int r; if (!eina_file_mkdtemp("etui-epub-tmp-XXXXXX", &pd->doc.path)) return EINA_FALSE; a = archive_read_new(); if (!a) goto free_path; if (archive_read_support_filter_all(a) != ARCHIVE_OK) goto free_path; if (archive_read_support_format_zip(a) != ARCHIVE_OK) goto free_path; r = archive_read_open_filename(a, pd->doc.filename, 16384); if (r != ARCHIVE_OK) goto free_path; while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { if (archive_entry_filetype(entry) == AE_IFREG) { char buf[PATH_MAX]; const char *name; char *dir; char *base; size_t size; void *data; name = archive_entry_pathname(entry); dir = strdup(name); base = strdup(name); if (dir && base && (strcmp(dir, ".") != 0)) { snprintf(buf, sizeof(buf), "%s/%s", pd->doc.path, dirname(dir)); buf[sizeof(buf) - 1] = '\0'; ecore_file_mkdir(buf); printf(" * %s %s %s\n", name, dirname(dir), basename(base)); } if (base) free(base); if (dir) free(dir); size = archive_entry_size(entry); data = malloc(size); if (data) { size_t res; res = archive_read_data(a, data, size); if (res > 0) { FILE *f; snprintf(buf, sizeof(buf), "%s/%s", pd->doc.path, name); buf[sizeof(buf) - 1] = '\0'; printf(" $ %s\n", buf); f = fopen(buf, "wb"); if (f) { fwrite(data, 1, size, f); fclose(f); } } free(data); } } archive_read_data_skip(a); } archive_read_free(a); return EINA_TRUE; free_path: eina_tmpstr_del(pd->doc.path); return EINA_FALSE; }
static void _make_config(const char *config_file) { Eet_File *ef; FILE *f; int textlen; char *text; /* Create default config path and file */ if (!config_file) { conf_filename = eina_stringshare_add(ems_config_filename_default_get()); if (!ecore_file_is_dir(ems_config_dirname_get())) ecore_file_mkpath(ems_config_dirname_get()); } else if (!ecore_file_exists(config_file)) { conf_filename = eina_stringshare_add(config_file); ecore_file_mkpath(ecore_file_dir_get(config_file)); } else { conf_filename = eina_stringshare_add(config_file); } INF("Config file : %s", conf_filename); if (!ecore_file_is_dir(ems_config_tmp_dirname_get())) ecore_file_mkdir(ems_config_tmp_dirname_get()); ef = eet_open(ems_config_tmp_filename_get(), EET_FILE_MODE_READ_WRITE); if (!ef) ef = eet_open(ems_config_tmp_filename_get(), EET_FILE_MODE_WRITE); f = fopen(conf_filename, "rb"); if (!f) { WRN("Could not open '%s', setup default config.", ems_config_filename_get()); if (ecore_file_exists(ems_config_default_filename_get())) { ecore_file_cp(ems_config_default_filename_get(), ems_config_filename_get()); f = fopen(ems_config_filename_get(), "rb"); if (!f) return; } else return; } fseek(f, 0, SEEK_END); textlen = ftell(f); rewind(f); text = (char *)malloc(textlen); if (!text) { fclose(f); eet_close(ef); return; } if (fread(text, textlen, 1, f) != 1) { free(text); fclose(f); eet_close(ef); return; } fclose(f); if (eet_data_undump(ef, "config", text, textlen, 1)) INF("Updating configuration %s", conf_filename); free(text); eet_close(ef); }
AudioModel::AudioModel(CalaosConnection *con): connection(con) { ecore_file_mkdir(Utils::getCacheFile(".cover_cache").c_str()); ecore_event_handler_add(ECORE_EXE_EVENT_DEL, exe_callback, this); }