char *_bks_model_path_get(void) { char *path = NULL; FILE *fp; int c,i; path = calloc(MAX_PATH,1); fname = calloc(MAX_PATH,1); snprintf(fname, (MAX_PATH - 1), "%s/bksystem/" BKS_DB_PATH_FILE, efreet_config_home_get()); if (!ecore_file_exists(fname)) ecore_file_mkpath(ecore_file_dir_get(fname)); fp = fopen(fname, "r"); i = 0; if (fp) { c = fgetc(fp); while (c != EOF && c != '\n' && i < (MAX_PATH - 1)) { *(path + i) = c; i++; c = fgetc(fp); } *(path + i) = '\0'; fclose(fp); } else { fprintf(stderr, "cannot open file: %s \n", fname); free(path); path = NULL; } return path; }
EAPI int efreet_ini_save(Efreet_Ini *ini, const char *file) { char *dir; FILE *f; EINA_SAFETY_ON_NULL_RETURN_VAL(ini, 0); EINA_SAFETY_ON_NULL_RETURN_VAL(ini->data, 0); EINA_SAFETY_ON_NULL_RETURN_VAL(file, 0); dir = ecore_file_dir_get(file); if (!ecore_file_mkpath(dir)) { free(dir); return 0; } free(dir); f = fopen(file, "wb"); if (!f) return 0; if (ini->data) eina_hash_foreach(ini->data, efreet_ini_section_save, f); fclose(f); return 1; }
/* Called when the iconbox is pressed by the mouse */ static Etk_Bool _etk_test_iconbox_mouse_down_cb(Etk_Object *object, Etk_Event_Mouse_Up *event, void *data) { Etk_Iconbox *iconbox; Etk_Iconbox_Icon *icon; Etk_String *new_folder; char *parent; if (!(iconbox = ETK_ICONBOX(object))) return ETK_TRUE; if (event->button != 1 || !(event->flags & ETK_MOUSE_DOUBLE_CLICK) || (event->flags & ETK_MOUSE_TRIPLE_CLICK)) return ETK_TRUE; if (!(icon = etk_iconbox_icon_get_at_xy(iconbox, event->canvas.x, event->canvas.y, ETK_FALSE, ETK_TRUE, ETK_TRUE))) return ETK_TRUE; if (!strcmp(etk_iconbox_icon_label_get(icon), "..")) { parent = ecore_file_dir_get(etk_string_get(_etk_test_iconbox_current_folder)); _etk_test_iconbox_folder_set(iconbox, parent); free(parent); } else { if (etk_string_length_get(_etk_test_iconbox_current_folder) == 1) new_folder = etk_string_new_printf("/%s", etk_iconbox_icon_label_get(icon)); else new_folder = etk_string_new_printf("%s/%s", etk_string_get(_etk_test_iconbox_current_folder), etk_iconbox_icon_label_get(icon)); _etk_test_iconbox_folder_set(iconbox, etk_string_get(new_folder)); etk_object_destroy(ETK_OBJECT(new_folder)); } return ETK_TRUE; }
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); }
int config_save (rockon_config *config) { FILE *fd; char *dir; if (config == NULL) return 0; if (config->config_filename == NULL) return 0; dir = ecore_file_dir_get(config->config_filename); if (! ecore_file_is_dir(dir)) { if (! ecore_file_mkpath(dir)) { free(dir); return 0; } } free(dir); fd = fopen(config->config_filename, "w"); if (fd) { fprintf(fd,"launch_server = \"%d\"\n", config->launch_server); fprintf(fd,"terminate_server = \"%d\"\n", config->terminate_server); fprintf(fd,"auto_reconnect = \"%d\"\n", config->auto_reconnect); fprintf(fd,"reconnect_interval = \"%d\"\n", config->reconnect_interval); fprintf(fd,"ipc_path = \"%s\"\n", config->ipc_path); fclose(fd); return 1; } return 0; }
static const char * ems_config_dirname_get(void) { static const char *dir_name = NULL; char *tmp; if (dir_name) return dir_name; tmp = ecore_file_dir_get(ems_config_filename_get()); dir_name = eina_stringshare_add(tmp); free(tmp); return tmp; }
static void _rename_done_cb(void *data, Eio_File *handler) { Enna_Localfiles_Priv *priv = data; const char *new_path = priv->new_path; const char *new_uri; const char *new_mrl; new_uri = eina_stringshare_printf("%s/%s", ecore_file_dir_get(priv->file_dialog->uri), ecore_file_file_get(new_path)); new_mrl = eina_stringshare_printf("%s/%s", ecore_file_dir_get(priv->file_dialog->mrl), ecore_file_file_get(new_path)); priv->file_dialog->name = eina_stringshare_add(ecore_file_dir_get(new_path)); priv->file_dialog->uri = new_uri; priv->file_dialog->label = eina_stringshare_add(ecore_file_file_get(new_path)); priv->file_dialog->mrl = new_mrl; enna_browser_file_update(priv->browser, priv->file_dialog); eina_stringshare_del(new_path); priv->new_path = NULL; }
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; }
static void _dialog_rename_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; 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); priv->new_path = new_path; if (priv->file_dialog) enna_file_free(priv->file_dialog); priv->file_dialog = enna_file_ref(file); if (file->type == ENNA_FILE_DIRECTORY) { eio_dir_move(file->mrl, new_path, _dir_filter_cb, _dir_progress_cb, _rename_done_cb, _error_cb, priv); } else if (file->type == ENNA_FILE_FILE) { eio_file_move(file->mrl, new_path, _dir_progress_cb, _rename_done_cb, _error_cb, priv); } evas_object_del(priv->dialog); }
/** * @param ini The Efreet_Ini to work with * @param file The file to load * @return Returns no value * @brief Saves the given Efree_Ini structure. */ EAPI int efreet_ini_save(Efreet_Ini *ini, const char *file) { char *dir; FILE *f; if (!ini || !ini->data) return 0; dir = ecore_file_dir_get(file); if (!ecore_file_mkpath(dir)) { free(dir); return 0; } free(dir); f = fopen(file, "wb"); if (!f) return 0; eina_hash_foreach(ini->data, efreet_ini_section_save, f); fclose(f); return 1; }
void evry_util_file_detail_set(Evry_Item_File *file) { char *dir = NULL; const char *tmp; if (EVRY_ITEM(file)->detail) return; if (!home_dir) { home_dir = e_user_homedir_get(); home_dir_len = strlen(home_dir); } dir = ecore_file_dir_get(file->path); if (!dir || !home_dir) return; if (!strncmp(dir, home_dir, home_dir_len)) { tmp = dir + home_dir_len; if (*(tmp) == '\0') snprintf(dir_buf, sizeof(dir_buf), "~%s", tmp); else snprintf(dir_buf, sizeof(dir_buf), "~%s/", tmp); EVRY_ITEM(file)->detail = eina_stringshare_add(dir_buf); } else { if (!strncmp(dir, "//", 2)) EVRY_ITEM(file)->detail = eina_stringshare_add(dir + 1); else EVRY_ITEM(file)->detail = eina_stringshare_add(dir); } E_FREE(dir); }
static void usr_click_ok(void *data, Evas_Object *obj, void *event_info) { evas_object_del(e->win); FILE *f; int fd,sw,sh; char enc[128]; char *path, *bs_name, cmd[1024],bg_file[1024],set_bg[1024], *home; const char *image_file; home = getenv("HOME"); path = ecore_file_dir_get(e->image_file); image_file = ecore_file_file_get(e->image_file); bs_name = ecore_file_strip_ext(image_file); get_correct_size(900,e->w,e->h,&sw,&sh,BY_WIDTH); if ( e->quality > 99.5 ) snprintf(enc, sizeof(enc), "COMP"); else snprintf(enc, sizeof(enc), "LOSSY %1.0f", e->quality); //printf ("ENC:%s \n",enc); strcpy(e->tmpn, "/tmp/e_bgdlg_new.edc-tmp-XXXXXX"); fd = mkstemp(e->tmpn); close(fd); f = fopen(e->tmpn, "w"); switch (e->sel) { case IMPORT_STRETCH: fprintf(f,"//Created by PrinceAMD\n" "images { image: \"%s\" %s; }\n" "collections {\n" "group { name: \"e/desktop/background\";\n" "data { item: \"style\" \"0\"; }\n" "max: %i %i;\n" "parts {\n" "part { name: \"bg\"; mouse_events: 0;\n" "description { state: \"default\" 0.0;\n" "image { normal: \"%s\"; }\n" "} } } } }\n",image_file,enc,e->w,e->h,image_file); break; case IMPORT_TILE: fprintf(f,"//Created by PrinceAMD\n" "images { image: \"%s\" %s; }\n" "collections {\n" "group { name: \"e/desktop/background\";\n" "data { item: \"style\" \"1\"; }\n" "max: %i %i;\n" "parts {\n" "part { name: \"bg\"; mouse_events: 0;\n" "description { state: \"default\" 0.0;\n" "image { normal: \"%s\"; }\n" "fill { size {\n" "relative: 0.0 0.0;\n" "offset: %i %i;\n" "} } } } } } }\n",image_file,enc,e->w,e->h,image_file,e->w,e->h); break; case IMPORT_CENTER: fprintf(f,"//Created by PrinceAMD\n" "images { image: \"%s\" %s; }\n" "collections {\n" "group { name: \"e/desktop/background\";\n" "data { item: \"style\" \"2\"; }\n" "max: %i %i;\n" "parts {\n" "part { name: \"bg\"; mouse_events: 0;\n" "description { state: \"default\" 0.0;\n" "min: %i %i; max: %i %i;\n" "image { normal: \"%s\"; }\n" "} } } } }\n",image_file,enc,e->w,e->h,e->w,e->h,e->w,e->h,image_file); break; case IMPORT_SCALE_ASPECT_IN: fprintf(f,"//Created by PrinceAMD\n" "images { image: \"%s\" %s; }\n" "collections {\n" "group { name: \"e/desktop/background\";\n" "data { item: \"style\" \"3\"; }\n" "max: %i %i;\n" "parts {\n" "part { name: \"bg\"; mouse_events: 0;\n" "description { state: \"default\" 0.0;\n" "aspect: %1.9f %1.9f; aspect_preference: BOTH;\n" "image { normal: \"%s\"; }\n" "} } } } }\n",image_file,enc,e->w,e->h,(double)e->w / (double)e->h,(double)e->w / (double)e->h,image_file); break; case IMPORT_SCALE_ASPECT_OUT: fprintf(f,"//Created by PrinceAMD\n" "images { image: \"%s\" %s; }\n" "collections {\n" "group { name: \"e/desktop/background\";\n" "data { item: \"style\" \"4\"; }\n" "max: %i %i;\n" "parts {\n" "part { name: \"bg\"; mouse_events: 0;\n" "description { state: \"default\" 0.0;\n" "image { normal: \"%s\"; }\n" "aspect: %1.9f %1.9f; aspect_preference: NONE;\n" "} } } } }\n",image_file,enc,e->w,e->h,image_file,(double)e->w / (double)e->h,(double)e->w / (double)e->h); break; case IMPORT_SCALE_ASPECT_IN_TILE: fprintf(f,"//Created by PrinceAMD\n" "images { image: \"%s\" %s; }\n" "collections {\n" "group { name: \"e/desktop/background\";\n" "data { item: \"style\" \"1\"; }\n" "max: %i %i;\n" "parts {\n" "part { name: \"bg\"; mouse_events: 0;\n" "description { state: \"default\" 0.0;\n" "image { normal: \"%s\"; }\n" "fill { size {\n" "relative: 0.0 0.0;\n" "offset: %i %i;\n" "} } } } } } }\n",image_file,enc,e->w,e->h,image_file,sw,sh); break; default: /*seriously ?*/ break; } fclose(f); if (strcmp(path, image_file)) { snprintf(cmd, sizeof(cmd), "cd \"%s\" && edje_cc %s $HOME/.e/e/backgrounds/\"%s\".edj",path,e->tmpn,bs_name); } else { snprintf(cmd, sizeof(cmd), "edje_cc %s $HOME/.e/e/backgrounds/\"%s\".edj",e->tmpn,bs_name); } snprintf(set_bg, sizeof(set_bg), "%s/.e/e/backgrounds/%s.edj",home,bs_name); e->edj = eina_stringshare_add(set_bg); Ecore_Exe *exe; exe = ecore_exe_run(cmd, NULL); ecore_timer_add(0.1,set_bg_timer,NULL); //need code here to end the window session. }
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); }
static Volume_Item * volume_file_scan(char *file) { Volume_Item *vi; char *ext; vi = calloc(1, sizeof(Volume_Item)); vi->path = strdup(file); vi->rpath = ecore_file_realpath(vi->path); printf("%s -> %s\n", vi->path, vi->rpath); if (!vi->rpath) { free(vi->path); free(vi); return NULL; } ext = strrchr(vi->path, '.'); if (!ext) { free(vi->path); free(vi->rpath); free(vi); return NULL; } ext++; if ((!strcasecmp(ext, "avi")) || (!strcasecmp(ext, "mov")) || (!strcasecmp(ext, "mpg")) || (!strcasecmp(ext, "mpeg")) || (!strcasecmp(ext, "vob")) || (!strcasecmp(ext, "wmv")) || (!strcasecmp(ext, "asf")) || (!strcasecmp(ext, "mng")) || (!strcasecmp(ext, "3gp")) || (!strcasecmp(ext, "wmx")) || (!strcasecmp(ext, "wvx")) || (!strcasecmp(ext, "mp4")) || (!strcasecmp(ext, "mpe")) || (!strcasecmp(ext, "qt")) || (!strcasecmp(ext, "fli")) || (!strcasecmp(ext, "dv")) || (!strcasecmp(ext, "asx")) || (!strcasecmp(ext, "wm")) || (!strcasecmp(ext, "lsf")) || (!strcasecmp(ext, "movie") || (!strcasecmp(ext, "mkv"))) ) { vi->type = "video"; video_count++; } else if ((!strcasecmp(ext, "mp3")) || (!strcasecmp(ext, "ogg")) || (!strcasecmp(ext, "aac")) || (!strcasecmp(ext, "wav")) ) { vi->type = "audio"; audio_count++; } else if ((!strcasecmp(ext, "jpg")) || (!strcasecmp(ext, "jpeg")) || (!strcasecmp(ext, "jpe")) || (!strcasecmp(ext, "jfif")) ) { vi->type = "photo"; photo_count++; } else { free(vi->path); free(vi); return NULL; } /* FIXME: get name and genre from local "database" first - if this doesn't * hold the info we want - then invent it from the filesystem */ /* 1. look for full path in db */ /* 2. look for just filename in db */ /* invent the data */ if (!vi->name) { const char *f; /* guess name from filename minus extension with _ converted to space */ f = ecore_file_file_get(file); if (f) { char *c; vi->name = strdup(f); c = strrchr(vi->name, '.'); if (c) *c = 0; for (c = vi->name; *c; c++) { if (*c == '_') *c = ' '; } } } if (!vi->genre) { char *f; /* guess genre from parent directory name with _ converted to space */ f = ecore_file_dir_get(file); if (f) { char *c, *ff; ff = ecore_file_dir_get(f); if (ff) { char buf[4096]; snprintf(buf, sizeof(buf), "%s/%s", ecore_file_file_get(ff), ecore_file_file_get(f)); for (c = buf; *c; c++) { if (*c == '_') *c = ' '; } vi->genre = eina_stringshare_add(buf); free(ff); } else { vi->genre = eina_stringshare_add(f); } free(f); } else vi->genre = eina_stringshare_add("Unknown"); } ecore_event_add(VOLUME_TYPE_ADD, strdup(vi->path), NULL, NULL); /* FIXME: check last played and play count db entry */ return vi; }
/** * @brief Download the given url to the given destination. * * @param url The complete url to download. * @param dst The local file to save the downloaded to. * @param completion_cb A callback called on download complete. * @param progress_cb A callback called during the download operation. * @param data User data passed to both callbacks. * @param job_ret Job used to abort the download. * @return EINA_TRUE if the download start or EINA_FALSE on failure * * This function starts the download of the URL @p url and saves it to * @p dst. @p url must provide the protocol, including 'http://', * 'ftp://' or 'file://'. Ecore_File must be compiled with CURL to * download using http and ftp protocols. If @p dst is ill-formed, or * if it already exists, the function returns EINA_FALSE. When the * download is complete, the callback @p completion_cb is called and * @p data is passed to it. The @p status parameter of @p completion_cb * will be filled with the status of the download (200, 404,...). The * @p progress_cb is called during the download operation, each time a * packet is received or when CURL wants. It can be used to display the * percentage of the downloaded file. Return 0 from this callback, if provided, * to continue the operation or anything else to abort the download. The only * operations that can be aborted are those with protocol 'http' or 'ftp'. In * that case @p job_ret can be filled. It can be used with * ecore_file_download_abort() or ecore_file_download_abort_all() to * respectively abort one or all download operations. This function returns * EINA_TRUE if the download starts, EINA_FALSE otherwise. */ EAPI Eina_Bool ecore_file_download(const char *url, const char *dst, Ecore_File_Download_Completion_Cb completion_cb, Ecore_File_Download_Progress_Cb progress_cb, void *data, Ecore_File_Download_Job **job_ret) { #ifdef BUILD_ECORE_CON char *dir = ecore_file_dir_get(dst); if (!ecore_file_is_dir(dir)) { EINA_LOG_ERR("%s is not a directory", dir); free(dir); return EINA_FALSE; } free(dir); if (ecore_file_exists(dst)) { EINA_LOG_ERR("%s already exists", dst); return EINA_FALSE; } if (!strncmp(url, "file://", 7)) { /* FIXME: Maybe fork? Might take a while to copy. * Check filesize? */ /* Just copy it */ url += 7; /* skip hostname */ url = strchr(url, '/'); return ecore_file_cp(url, dst); } # ifdef HAVE_CURL else if ((!strncmp(url, "http://", 7)) || (!strncmp(url, "https://", 8)) || (!strncmp(url, "ftp://", 6))) { /* download */ Ecore_File_Download_Job *job; job = _ecore_file_download_curl(url, dst, completion_cb, progress_cb, data); if(job_ret) *job_ret = job; if(job) return EINA_TRUE; else { EINA_LOG_ERR("no job returned\n"); return EINA_FALSE; } return job ? EINA_TRUE : EINA_FALSE; } # else else if ((!strncmp(url, "http://", 7)) || (!strncmp(url, "https://", 8)) || (!strncmp(url, "ftp://", 6))) { (void)completion_cb; (void)progress_cb; (void)data; (void)job_ret; return EINA_FALSE; } # endif else { return EINA_FALSE; } #else completion_cb = NULL; progress_cb = NULL; data = NULL; return EINA_FALSE; #endif /* BUILD_ECORE_CON */ }