int
main(int argc, char **argv)
{
    Eet_File *theme_ef;
    Eina_List *l = NULL;
    Efreet_Icon_Theme *theme;
    int i;

    efreet_cache_update = 0;

    if (!efreet_init()) return -1;

    theme_ef = eet_open(efreet_icon_theme_cache_file(), EET_FILE_MODE_READ);
    if (!theme_ef) return -1;

    if (argc > 1)
    {
        for (i = 1; i < argc; i++)
        {
            theme = eet_data_read(theme_ef, efreet_icon_theme_edd(EINA_FALSE), argv[i]);
            if (theme) l = eina_list_append(l, theme);
        }
    }
    else
    {
        char **keys;
        int num;

        keys = eet_list(theme_ef, "*", &num);
        if (keys)
        {
            for (i = 0; i < num; i++)
            {
                theme = eet_data_read(theme_ef, efreet_icon_theme_edd(EINA_FALSE), keys[i]);
                if (theme) l = eina_list_append(l, theme);
            }
            free(keys);
        }
    }

    EINA_LIST_FREE(l, theme)
    {
        void *data;

        dump(theme);

        /* free theme */
        eina_list_free(theme->paths);
        eina_list_free(theme->inherits);
        EINA_LIST_FREE(theme->directories, data)
        free(data);
        free(theme);
    }
Exemple #2
0
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 */
/*
 * @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;
}
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;
}
Exemple #5
0
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();
}
/* 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;
}
Exemple #7
0
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();
     }
}
SrcFile_List *
source_load(Eet_File *ef)
{
   SrcFile_List *s;

   s = eet_data_read(ef, _srcfile_list_edd, "edje_sources");
   return s;
}
Edje_Font_List *
source_fontmap_load(Eet_File *ef)
{
   Edje_Font_List *fl;

   fl = eet_data_read(ef, _font_list_edd, "edje_source_fontmap");
   return fl;
}
/* Get the input method configuration from the file */
EAPI E_Input_Method_Config *
e_intl_input_method_config_read(Eet_File *imc_file)
{
   E_Input_Method_Config *imc;

   imc = NULL;
   if (imc_file)
     {
	imc = (E_Input_Method_Config *) eet_data_read(imc_file, _e_intl_input_method_config_edd, "imc");
     }
   return imc;
}
/**
 * @brief Load the information about an interface from the configuration file
 * The information are saved in a Exalt_Eth_Save structure
 * @param file the configuration file
 * @param udi the hal udi of the interface
 * @return Returns the information
 */
Exalt_Eth_Save* _exalt_eet_eth_load(const char* file, const char* udi)
{
    Exalt_Eth_Save *data = NULL;
    Eet_Data_Descriptor *edd;
    Eet_File *f;

    edd = _exalt_eth_save_edd_new();

    f = eet_open(file, EET_FILE_MODE_READ);
    EXALT_ASSERT_RETURN(f!=NULL);

    data = eet_data_read(f, edd, udi);

    eet_close(f);
    eet_data_descriptor_free(edd);
    return data;
}
/**
 * @brief Load the connection associated to an essid from the configuration file
 * @param file the configuration file
 * @param essid the essid
 * @return Returns the connection if success, else NULL
 */
Exalt_Connection* _exalt_eet_wireless_conn_load(const char*file, const char* essid)
{
    Exalt_Connection *data = NULL;
    Eet_Data_Descriptor *edd;
    Eet_File *f;

    edd = exalt_conn_edd_new();

    f = eet_open(file, EET_FILE_MODE_READ);
    EXALT_ASSERT_RETURN(f!=NULL);

    data = eet_data_read(f, edd, essid);

    eet_close(f);
    eet_data_descriptor_free(edd);
    return data;
}
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.";
}
Session *
session_load(const char *filename)
{
    Session *session = NULL;
    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;
    }

    session = eet_data_read(ef, _session_descriptor, SESSION_ENTRY);
    if (!session) goto end;
    session->__eet_filename = eina_stringshare_add(filename);

end:
    eet_close(ef);
    return session;
}
Exemple #15
0
EINTERN int
e_icon_init(void)
{
#ifdef USE_ICON_CACHE

   Eet_File *ef;
   char buf[PATH_MAX];

#undef T
#undef D
#define T Cache_Item
#define D cache_item_edd
   D = E_CONFIG_DD_NEW("Cache_Item", T);
   E_CONFIG_VAL(D, T, timestamp, UINT);
#undef T
#undef D
#define T Cache
#define D cache_edd
   D = E_CONFIG_DD_NEW("Cache", T);
   E_CONFIG_HASH(D, T, hash, cache_item_edd);
#undef T
#undef D

   e_user_dir_concat_static(buf, "icon_cache.eet");

   ef = eet_open(buf, EET_FILE_MODE_READ_WRITE);
   if (!ef) return 1;  /* not critical */

   _cache = eet_data_read(ef, cache_edd, "idx");
   if (!_cache)
     _cache = E_NEW(Cache, 1);

   if (!_cache->hash)
     _cache->hash = eina_hash_string_superfast_new(_e_icon_cache_item_free);

   eet_close(ef);

   _cache->file = strdup(buf);

   _cache->ef = NULL;
#endif
   return 1;
}
Config *
config_load(const char *filename)
{
    Config *config = NULL;
    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;
    }

    config = eet_data_read(ef, _config_descriptor, CONFIG_ENTRY);
    if (!config) goto end;
    config->__eet_filename = eina_stringshare_add(filename);

end:
    eet_close(ef);
    return config;
}
Exemple #17
0
static Ems_Config *
_config_get(Eet_Data_Descriptor *edd)
{
	Ems_Config *config = NULL;
	Eet_File *file;

	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;
}
Hist *
hist_load(const char *filename)
{
    Hist *hist = NULL;
    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;
    }

    hist = eet_data_read(ef, _hist_descriptor, HIST_ENTRY);
    if (!hist) goto end;
    hist->__eet_filename = eina_stringshare_add(filename);

    if (!hist->items) hist->items = eina_hash_stringshared_new(EINA_FREE_CB(hist_item_free));

end:
    eet_close(ef);
    return hist;
}
Fav *
fav_load(const char *filename)
{
    Fav *fav = NULL;
    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;
    }

    fav = eet_data_read(ef, _fav_descriptor, FAV_ENTRY);
    if (!fav) goto end;
    fav->__eet_filename = eina_stringshare_add(filename);

    if (!fav->items) fav->items = eina_hash_stringshared_new(EINA_FREE_CB(fav_item_free));

end:
    eet_close(ef);
    return fav;
}
/**
 * @param file: The file to create the Efreet_Desktop from
 * @return Returns a new Efreet_Desktop on success, NULL on failure
 * @brief Creates a new Efreet_Desktop structure initialized from the
 * contents of @a file or NULL on failure
 *
 * By using efreet_desktop_new the caller will get a unique copy of a
 * Efreet_Desktop. The Efreet_Desktop should immidiatly after use be free'd,
 * as there is no guarantee how long the pointers will be valid.
 */
EAPI Efreet_Desktop *
efreet_desktop_new(const char *file)
{
    Efreet_Desktop *desktop = NULL;

    if (!file) return NULL;
    if (cache)
    {
        char rp[PATH_MAX];
        if (!realpath(file, rp)) return NULL;

        desktop = eet_data_read(cache, desktop_edd, rp);
        if (desktop && desktop->load_time == ecore_file_mod_time(desktop->orig_path))
        {
            desktop->ref = 1;
            desktop->eet = 1;
            return desktop;
        }
    }
    return efreet_desktop_uncached_new(file);
}
Exemple #21
0
Eina_Hash *read_histogram_file(char * input_file)
{
        histogram_cache_t *histo_cache;
        Eina_Hash *map_histo;
        Eet_File *ef = eet_open(input_file, EET_FILE_MODE_READ);
        if (!ef) {
                map_histo = eina_hash_string_small_new(
                                (void (*)(void *))&histogram_free);
                return map_histo;
        }

        histo_cache = eet_data_read(ef, _histogram_cache_descriptor
                        , CACHE_FILE_ENTRY);
        if(cache_file) {
                eet_close(cache_file);
        }
        cache_file = ef;
        map_histo = histo_cache->map_histo;
        free(histo_cache);
        return map_histo;
}
Exemple #22
0
static void
dump(Efreet_Icon_Theme *theme)
{
    Eet_File *ef;
    unsigned int count = 0;
    double start, avg;
    char **keys;
    int num, i;

    start = ecore_time_get();
    ef = eet_open(efreet_icon_cache_file(theme->name.internal), EET_FILE_MODE_READ);
    printf("open: %s %f\n", theme->name.internal, ecore_time_get() - start);

    start = ecore_time_get();
    keys = eet_list(ef, "*", &num);
    printf("list: %s %f\n", theme->name.internal, ecore_time_get() - start);
    if (!keys) return;

    start = ecore_time_get();
    for (i = 0; i < num; i++)
    {
        Efreet_Cache_Icon *icon;
        unsigned int j;

        icon = eet_data_read(ef, efreet_icon_edd(), keys[i]);
        if (!icon) continue;

        for (j = 0; j < icon->icons_count; ++j)
            count += icon->icons[j]->paths_count;
    }
    free(keys);

    start = ecore_time_get() - start;
    avg = 0;
    if (count > 0)
        avg = start / count;
    printf("read: %s - %u paths (time: %f) (avg %f)\n", theme->name.internal, count, start, avg);
    eet_close(ef);
    eet_clearcache();
}
Exemple #23
0
END_TEST

START_TEST(eet_test_file_data)
{
   Eet_Data_Descriptor *edd;
   Eet_Test_Ex_Type *result;
   Eet_Dictionary *ed;
   Eet_File *ef;
   char **list;
   char *file;
   Eet_Data_Descriptor_Class eddc;
   Eet_Test_Ex_Type etbt;
   int size;
   int test;
   int tmpfd;

   file = strdup("/tmp/eet_suite_testXXXXXX");

   eet_init();

   eet_test_ex_set(&etbt, 0);
   etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1));
   etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1));
   etbt.hash = eina_hash_string_superfast_new(NULL);
   eina_hash_add(etbt.hash, EET_TEST_KEY1, eet_test_ex_set(NULL, 2));
   etbt.hash = eina_hash_string_superfast_new(NULL);
   eina_hash_add(etbt.hash, EET_TEST_KEY2, eet_test_ex_set(NULL, 2));
   etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
   etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
   etbt.ihash = eina_hash_string_superfast_new(NULL);
   eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
   etbt.ihash = eina_hash_string_superfast_new(NULL);
   eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
   etbt.slist = eina_list_prepend(NULL, "test");
   etbt.shash = eina_hash_string_superfast_new(NULL);
   eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
   memset(&etbt.charray, 0, sizeof(etbt.charray));
   etbt.charray[0] = "test";

   eet_test_setup_eddc(&eddc);
   eddc.name = "Eet_Test_Ex_Type";
   eddc.size = sizeof(Eet_Test_Ex_Type);

   edd = eet_data_descriptor_file_new(&eddc);
   fail_if(!edd);

   eet_build_ex_descriptor(edd, EINA_FALSE);

   fail_if(-1 == (tmpfd = mkstemp(file)));
   fail_if(!!close(tmpfd));

   /* Insert an error in etbt. */
   etbt.i = 0;

   /* Save the encoded data in a file. */
   ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
   fail_if(!ef);

   fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));

   result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
   fail_if(!result);

   fail_if(eet_mode_get(ef) != EET_FILE_MODE_READ_WRITE);

   /* Test string space. */
   ed = eet_dictionary_get(ef);

   fail_if(!eet_dictionary_string_check(ed, result->str));
   fail_if(eet_dictionary_string_check(ed, result->istr));

   eet_close(ef);

   /* Attempt to replace etbt by the correct one. */
   etbt.i = EET_TEST_INT;

   ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
   fail_if(!ef);

   fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));

   result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
   fail_if(!result);

   /* Test the resulting data. */
   fail_if(eet_test_ex_check(result, 0, EINA_FALSE) != 0);

   eet_close(ef);

   /* Read back the data. */
   ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
   fail_if(!ef);

   fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY2, &etbt, 0));

   result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
   fail_if(!result);

   /* Test string space. */
   ed = eet_dictionary_get(ef);
   fail_if(!ed);

   fail_if(!eet_dictionary_string_check(ed, result->str));
   fail_if(eet_dictionary_string_check(ed, result->istr));

   /* Test the resulting data. */
   fail_if(eet_test_ex_check(result, 0, EINA_FALSE) != 0);
   fail_if(eet_test_ex_check(eina_list_data_get(result->list), 1, EINA_FALSE) != 0);
   fail_if(eina_list_data_get(result->ilist) == NULL);
   fail_if(*((int *)eina_list_data_get(result->ilist)) != 42);
   fail_if(eina_list_data_get(result->slist) == NULL);
   fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
   fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
   fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
   fail_if(strcmp(result->charray[0], "test") != 0);

   test = 0;
   if (result->hash)
     eina_hash_foreach(result->hash, func, &test);

   fail_if(test != 0);
   if (result->ihash)
     eina_hash_foreach(result->ihash, func7, &test);

   fail_if(test != 0);

   list = eet_list(ef, "keys/*", &size);
   fail_if(eet_num_entries(ef) != 2);
   fail_if(size != 2);
   fail_if(!(strcmp(list[0],
                    EET_TEST_FILE_KEY1) == 0 &&
             strcmp(list[1], EET_TEST_FILE_KEY2) == 0)
           && !(strcmp(list[0],
                       EET_TEST_FILE_KEY2) == 0 &&
                strcmp(list[1], EET_TEST_FILE_KEY1) == 0));
   free(list);

   fail_if(eet_delete(ef, NULL) != 0);
   fail_if(eet_delete(NULL, EET_TEST_FILE_KEY1) != 0);
   fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0);

   list = eet_list(ef, "keys/*", &size);
   fail_if(size != 1);
   fail_if(eet_num_entries(ef) != 1);

   /* Test some more wrong case */
   fail_if(eet_data_read(ef, edd, "plop") != NULL);
   fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) != NULL);

   /* Reinsert and reread data */
   fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
   fail_if(eet_data_read(ef, edd, EET_TEST_FILE_KEY1) == NULL);
   fail_if(eet_read_direct(ef, EET_TEST_FILE_KEY1, &size) == NULL);

   eet_close(ef);

   fail_if(unlink(file) != 0);

   eet_shutdown();
}
Exemple #24
0
static void*
config_load(Eet_Data_Descriptor *descriptor, const char *filename, const char *section)
{
  Eet_File *ef;
  void *result;
  char buffer[PATH_MAX];
  struct stat st_readable;
  struct stat st_binary;
  Eina_Bool stre;
  Eina_Bool stbe;
  Eina_Bool take_binary = EINA_TRUE;

  snprintf(buffer, PATH_MAX, "%s.eet", filename);
  stbe = !!stat(buffer, &st_binary);

  snprintf(buffer, PATH_MAX, "%s.%s", filename, section);
  stre = !!stat(buffer, &st_readable);

  if (stbe && stre) return NULL;

  if (!stre && !stbe && st_readable.st_mtime > st_binary.st_mtime)
    take_binary = EINA_FALSE;

  if (stbe) take_binary = EINA_FALSE;
  if (stre) take_binary = EINA_TRUE;
  
  if (take_binary)
    {
      fprintf(stderr, "Taking binary config\n");

      snprintf(buffer, PATH_MAX, "%s.eet", filename);
      ef = eet_open(buffer, EET_FILE_MODE_READ);
      result = eet_data_read(ef, descriptor, section);
      eet_close(ef);
    }
  else
    {
      char *tmp;
      struct stat st;
      int fd;

      fprintf(stderr, "Taking human readable config\n");

      snprintf(buffer, PATH_MAX, "%s.%s", filename, section);
      fd = open(filename, O_RDONLY);
      
      tmp = malloc(st_readable.st_size + 1);
      read(fd, tmp, st_readable.st_size);
      tmp[st_readable.st_size] = '\0';
      close(fd);

      snprintf(buffer, PATH_MAX, "%s.eet", filename);
      ef = eet_open(buffer, EET_FILE_MODE_READ_WRITE);
      eet_data_undump(ef, section, tmp, st_readable.st_size, 1);
      result = eet_data_read(ef, descriptor, section);
      
      eet_close(ef);
    }

  return result;
}
int
main(int argc, char **argv)
{
    /* TODO:
     * - Add file monitor on files, so that we catch changes on files
     *   during whilst this program runs.
     * - Maybe linger for a while to reduce number of cache re-creates.
     */
    Efreet_Cache_Hash hash;
    Efreet_Cache_Version version;
    Eina_List *dirs = NULL;
    Eina_List *systemdirs = NULL;
    Eina_List *extra_dirs = NULL;
    Eina_List *l = NULL;
    Eina_Inarray *stack = NULL;
    int priority = 0;
    char *dir = NULL;
    char *path;
    int lockfd = -1, tmpfd;
    int changed = 0;
    int i;
    char file[PATH_MAX] = { '\0' };
    char util_file[PATH_MAX] = { '\0' };
    mode_t um;

    if (!eina_init()) goto eina_error;
    _efreet_desktop_cache_log_dom =
        eina_log_domain_register("efreet_desktop_cache", EFREET_DEFAULT_LOG_COLOR);
    if (_efreet_desktop_cache_log_dom < 0)
    {
        EINA_LOG_ERR("Efreet: Could not create a log domain for efreet_desktop_cache.");
        return -1;
    }

    for (i = 1; i < argc; i++)
    {
        if (!strcmp(argv[i], "-v"))
            eina_log_domain_level_set("efreet_desktop_cache", EINA_LOG_LEVEL_DBG);
        else if ((!strcmp(argv[i], "-h")) ||
                 (!strcmp(argv[i], "-help")) ||
                 (!strcmp(argv[i], "--h")) ||
                 (!strcmp(argv[i], "--help")))
        {
            printf("Options:\n");
            printf("  -v              Verbose mode\n");
            printf("  -d dir1 dir2    Extra dirs\n");
            exit(0);
        }
        else if (!strcmp(argv[i], "-d"))
        {
            while ((i < (argc - 1)) && (argv[(i + 1)][0] != '-'))
                extra_dirs = eina_list_append(extra_dirs, argv[++i]);
        }
    }
    extra_dirs = eina_list_sort(extra_dirs, -1, EINA_COMPARE_CB(strcmp));

#ifdef HAVE_SYS_RESOURCE_H
    setpriority(PRIO_PROCESS, 0, 19);
#elif _WIN32
    SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
#endif

    /* init external subsystems */
    if (!eet_init()) goto eet_error;
    if (!ecore_init()) goto ecore_error;

    efreet_cache_update = 0;
    /* finish efreet init */
    if (!efreet_init()) goto efreet_error;

    /* create homedir */
    snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get());
    if (!ecore_file_exists(file))
    {
        if (!ecore_file_mkpath(file)) goto efreet_error;
        efreet_setowner(file);
    }

    /* lock process, so that we only run one copy of this program */
    lockfd = cache_lock_file();
    if (lockfd == -1) goto efreet_error;

    edd = efreet_desktop_edd();
    if (!edd) goto edd_error;

    /* read user dirs from old cache */
    ef = eet_open(efreet_desktop_util_cache_file(), EET_FILE_MODE_READ);
    if (ef)
    {
        old_file_ids = eet_data_read(ef, efreet_hash_string_edd(), "file_id");
        eet_close(ef);
    }

    /* create cache */
    snprintf(file, sizeof(file), "%s.XXXXXX", efreet_desktop_cache_file());
    /* set secure umask for temporary files */
    um = umask(0077);
    tmpfd = mkstemp(file);
    umask(um);
    if (tmpfd < 0) goto error;
    close(tmpfd);
    ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
    if (!ef) goto error;

    snprintf(util_file, sizeof(util_file), "%s.XXXXXX", efreet_desktop_util_cache_file());
    /* set secure umask for temporary files */
    um = umask(0077);
    tmpfd = mkstemp(util_file);
    umask(um);
    if (tmpfd < 0) goto error;
    close(tmpfd);
    util_ef = eet_open(util_file, EET_FILE_MODE_READ_WRITE);
    if (!util_ef) goto error;

    /* write cache version */
    version.major = EFREET_DESKTOP_UTILS_CACHE_MAJOR;
    version.minor = EFREET_DESKTOP_UTILS_CACHE_MINOR;
    eet_data_write(util_ef, efreet_version_edd(), EFREET_CACHE_VERSION, &version, 1);
    version.major = EFREET_DESKTOP_CACHE_MAJOR;
    version.minor = EFREET_DESKTOP_CACHE_MINOR;
    eet_data_write(ef, efreet_version_edd(), EFREET_CACHE_VERSION, &version, 1);

    desktops = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_desktop_free));

    file_ids = eina_hash_string_superfast_new(NULL);
    paths = eina_hash_string_superfast_new(NULL);

    mime_types = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
    categories = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
    startup_wm_class = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
    name = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
    generic_name = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
    comment = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
    exec = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));

    dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(),
                                                                    "applications");
    if (!dirs) goto error;
    stack = eina_inarray_new(sizeof(struct stat), 16);
    if (!stack) goto error;

    EINA_LIST_FREE(dirs, path)
     {
        char file_id[PATH_MAX] = { '\0' };

        eina_inarray_flush(stack);
        if (!cache_scan(stack, path, file_id, priority++, 1, &changed))
          goto error;
        systemdirs = eina_list_append(systemdirs, path);
     }
Exemple #26
0
int
ex_config_read(Extrackt *ex)
{
   Eet_File *ef;
   char      buf[PATH_MAX];
   char     *home;
   char    **matches;
   int       count;
   
   if(ex->config.cd)
     {
	/* FIXME: free everything! */
	E_FREE(ex->config.cd->cdrom);
	E_FREE(ex->config.cd);
     }
     
   home = getenv("HOME");
   if(!home)     
     return 0;     
   
   snprintf(buf, sizeof(buf), "%s/.e/extrackt/config.eet", home);
   
   if(!ecore_file_exists(buf) || ecore_file_size(buf) == 0)
     {
	/* default config values */
	return ex_config_defaults_apply(ex);
     }
   
   ef = eet_open(buf, EET_FILE_MODE_READ);
   if(!ef)
     {
	ERROR("Cant open configuration file! Using program defaults.");
	return ex_config_defaults_apply(ex);
     }

   /* Make sure we are compatible - same version numbers */
   ex->config.version = NULL;
   ex->config.version = eet_data_read(ef, _ex_config_version_edd, "config/version");
   if(!ex->config.version)
     {
	ERROR("Incompatible configuration file! Creating new one.");
	eet_close(ef);
	return ex_config_defaults_apply(ex);
     }
   else
     {
	Ex_Config_Version *v;
	
	v = ex_config_version_parse(VERSION);
	if(ex_config_version_compare(v, ex->config.version) != 0)
	  {
	     ERROR("Your version / configuration of Extrackt is not valid! Overwriting with program defaults");
	     return ex_config_defaults_apply(ex);
	  }
     }
	     
   
   /* Read config data for cdrom */
   ex->config.cd = NULL;
   ex->config.cd = eet_data_read(ef, _ex_config_cd_edd, "config/cd");      
   if(!ex->config.cd)
     {
	ERROR("Cant read config! Using program defaults.");
	eet_close(ef);
	return ex_config_defaults_apply(ex);
     }
   
   /* Read config data for cddb */
   ex->config.cddb = NULL;
   ex->config.cddb = eet_data_read(ef, _ex_config_cddb_edd, "config/cddb");
   if(!ex->config.cddb)
     {
	ERROR("Cant read config! Using program defaults.");
	eet_close(ef);
	return ex_config_defaults_apply(ex);
     }
   
   /* Read config data for rippers */
   matches = eet_list(ef, "config/rippers/*", &count);
   ex->config.rippers = NULL;
   if(count > 0)
     {
	int i;
	
	for(i = 0; i < count; i++)
	  {
	     char *match;
	     
	     match = matches[i];
	     ex->config.rippers = eina_list_append(ex->config.rippers,
				 eet_data_read(ef, _ex_config_exe_edd, match));
	  }
     }
   
   /* Read config data for encode */
   ex->config.encode = NULL;
   ex->config.encode = eet_data_read(ef, _ex_config_encode_edd, "config/encode");
      
   eet_close(ef);
   return 1;
}
Exemple #27
0
/**
 * @brief Loads Etk's config from disk
 * @return Returns ETK_TRUE on a successful load, ETK_FALSE otherwise.
 */
Etk_Bool etk_config_load(void)
{
   Eet_File *ef;
   char buf[PATH_MAX];
   char *home;

   home = getenv("HOME");
   if (!home)
     {
	_etk_config_defaults_apply();
	return ETK_FALSE;
     }

   snprintf(buf, sizeof(buf), "%s/.e/etk/config.eet", home);

   if (!ecore_file_exists(buf) || ecore_file_size(buf) == 0)
   {
      /* no saved config */
      _etk_config_defaults_apply();
      return ETK_FALSE;
   }

   ef = eet_open(buf, EET_FILE_MODE_READ);
   if (!ef)
   {
      ETK_WARNING("Cant open configuration file! Using program defaults.");
      return ETK_FALSE;
   }

   if (!_etk_config)
     _etk_config = malloc(sizeof(Etk_Config));
   else
   {
      free(_etk_config->version);
      if (_etk_config->general)
      {
	 free(_etk_config->general->wm_theme);
	 free(_etk_config->general->widget_theme);
	 free(_etk_config->general->font);
	 free(_etk_config->general->engine);
	 free(_etk_config->general);
      }
   }

   _etk_config->version = NULL;
   _etk_config->version = eet_data_read(ef, _etk_config_ver_edd, "config/version");
   if(!_etk_config->version)
     {
	ETK_WARNING("Incompatible configuration file! Creating new one.");
	eet_close(ef);
	_etk_config_defaults_apply();
	return ETK_FALSE;
     }
   else
     {
	Etk_Config_Version *v;

	v = _etk_config_version_parse(VERSION);
	if(_etk_config_version_compare(v, _etk_config->version) != 0)
	  {
	     ETK_WARNING("Your version / configuration of Etk is not valid!");
	     eet_close(ef);
	     free(v);
	     _etk_config_defaults_apply();
	     return ETK_FALSE;
	  }
	free(v);
     }

   _etk_config->general = eet_data_read(ef, _etk_config_gen_edd, "config/general");
   if (!_etk_config->general)
     _etk_config_defaults_apply();

   eet_close(ef);
   return ETK_TRUE;
}
Exemple #28
0
END_TEST

START_TEST(eet_test_file_fp)
{
   char *file;
   Eet_Data_Descriptor_Class eddc;
   Eet_Data_Descriptor *edd_5FP;
   Eet_Data_Descriptor *edd_5DBL;
   Eet_File *ef;
   Eet_5FP origin;
   Eet_5DBL *convert;
   Eet_5FP *build;
   int tmpfd;

   file = strdup("/tmp/eet_suite_testXXXXXX");

   eet_init();

   EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_5FP);
   edd_5FP = eet_data_descriptor_file_new(&eddc);

   EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp32", fp32, EET_T_F32P32);
   EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp16", fp16, EET_T_F16P16);
   EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "fp8", fp8, EET_T_F8P24);
   EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f1", f1, EET_T_F32P32);
   EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5FP, Eet_5FP, "f0", f0, EET_T_F32P32);

   eet_eina_file_data_descriptor_class_set(&eddc, sizeof (eddc), "Eet_5FP", sizeof (Eet_5DBL));
   edd_5DBL = eet_data_descriptor_file_new(&eddc);

   EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp32", fp32, EET_T_DOUBLE);
   EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp16", fp16, EET_T_DOUBLE);
   EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "fp8", fp8, EET_T_FLOAT);
   EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f1", f1, EET_T_DOUBLE);
   EET_DATA_DESCRIPTOR_ADD_BASIC(edd_5DBL, Eet_5DBL, "f0", f0, EET_T_DOUBLE);

   origin.fp32 = eina_f32p32_double_from(1.125);
   origin.fp16 = eina_f16p16_int_from(2000);
   origin.fp8 = eina_f8p24_int_from(125);
   origin.f1 = eina_f32p32_int_from(1);
   origin.f0 = 0;

   fail_if(-1 == (tmpfd = mkstemp(file)));
   fail_if(!!close(tmpfd));

   ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
   fail_if(!ef);

   fail_if(!eet_data_write(ef, edd_5FP, EET_TEST_FILE_KEY1, &origin, 1));

   build = eet_data_read(ef, edd_5FP, EET_TEST_FILE_KEY1);
   fail_if(!build);

   convert = eet_data_read(ef, edd_5DBL, EET_TEST_FILE_KEY1);
   fail_if(!convert);

   fail_if(build->fp32 != eina_f32p32_double_from(1.125));
   fail_if(build->fp16 != eina_f16p16_int_from(2000));
   fail_if(build->fp8 != eina_f8p24_int_from(125));
   fail_if(build->f1 != eina_f32p32_int_from(1));
   fail_if(build->f0 != 0);

   fail_if(convert->fp32 != 1.125);
   fail_if(convert->fp16 != 2000);
   fail_if(convert->fp8 != 125);
   fail_if(convert->f1 != 1);
   fail_if(convert->f0 != 0);

   eet_close(ef);

   fail_if(unlink(file) != 0);

   eet_shutdown();
}
Exemple #29
0
END_TEST

START_TEST(eet_test_file_data_dump)
{
   Eet_Data_Descriptor *edd;
   Eet_Test_Ex_Type *result;
   Eet_Data_Descriptor_Class eddc;
   Eet_Test_Ex_Type etbt;
   Eet_File *ef;
   char *string1;
   char *file;
   int test;
   int tmpfd;

   file = strdup("/tmp/eet_suite_testXXXXXX");

   eet_init();

   eet_test_ex_set(&etbt, 0);
   etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1));
   etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1));
   etbt.hash = eina_hash_string_superfast_new(NULL);
   eina_hash_add(etbt.hash, EET_TEST_KEY1, eet_test_ex_set(NULL, 2));
   eina_hash_add(etbt.hash, EET_TEST_KEY2, eet_test_ex_set(NULL, 2));
   etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
   etbt.ilist = eina_list_prepend(etbt.ilist, &i42);
   etbt.ihash = eina_hash_string_superfast_new(NULL);
   eina_hash_add(etbt.ihash, EET_TEST_KEY1, &i7);
   eina_hash_add(etbt.ihash, EET_TEST_KEY2, &i7);
   etbt.slist = eina_list_prepend(NULL, "test");
   etbt.shash = eina_hash_string_superfast_new(NULL);
   eina_hash_add(etbt.shash, EET_TEST_KEY1, "test");
   memset(&etbt.charray, 0, sizeof(etbt.charray));
   etbt.charray[0] = "test";

   eet_eina_file_data_descriptor_class_set(&eddc, sizeof (eddc),
                                           "Eet_Test_Ex_Type",
                                           sizeof(Eet_Test_Ex_Type));

   edd = eet_data_descriptor_file_new(&eddc);
   fail_if(!edd);

   eet_build_ex_descriptor(edd, EINA_FALSE);

   fail_if(-1 == (tmpfd = mkstemp(file)));
   fail_if(!!close(tmpfd));

   /* Save the encoded data in a file. */
   ef = eet_open(file, EET_FILE_MODE_WRITE);
   fail_if(!ef);

   fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));

   eet_close(ef);

   /* Use dump/undump in the middle */
   ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
   fail_if(!ef);

   string1 = NULL;
   fail_if(eet_data_dump(ef, EET_TEST_FILE_KEY1, append_string, &string1) != 1);
   fail_if(eet_delete(ef, EET_TEST_FILE_KEY1) == 0);
   fail_if(!eet_data_undump(ef, EET_TEST_FILE_KEY1, string1, strlen(string1), 1));

   eet_close(ef);

   /* Test the correctness of the reinsertion. */
   ef = eet_open(file, EET_FILE_MODE_READ);
   fail_if(!ef);

   result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
   fail_if(!result);

   eet_close(ef);

   /* Test the resulting data. */
   fail_if(eet_test_ex_check(result, 0, EINA_TRUE) != 0);
   fail_if(eet_test_ex_check(eina_list_data_get(result->list), 1, EINA_TRUE) != 0);
   fail_if(eina_list_data_get(result->ilist) == NULL);
   fail_if(*((int *)eina_list_data_get(result->ilist)) != 42);
   fail_if(eina_list_data_get(result->slist) == NULL);
   fail_if(strcmp(eina_list_data_get(result->slist), "test") != 0);
   fail_if(eina_hash_find(result->shash, EET_TEST_KEY1) == NULL);
   fail_if(strcmp(eina_hash_find(result->shash, EET_TEST_KEY1), "test") != 0);
   fail_if(strcmp(result->charray[0], "test") != 0);

   test = 0;
   _dump_call = EINA_TRUE;
   if (result->hash)
     eina_hash_foreach(result->hash, func, &test);
   _dump_call = EINA_FALSE;

   fail_if(test != 0);
   if (result->ihash)
     eina_hash_foreach(result->ihash, func7, &test);

   fail_if(test != 0);

   fail_if(unlink(file) != 0);

   eet_shutdown();
}
Exemple #30
0
int
main(int argc, char **argv)
{
   Edje_Part_Collection_Directory_Entry *ce;
   Old_Edje_File *oef;
   Edje_File *nef;
   Eina_Iterator *it;
   Eet_File *ef;

   setlocale(LC_NUMERIC, "C");

   ecore_app_no_system_modules();

   if (!eina_init())
     return -1;

   _edje_cc_log_dom = eina_log_domain_register
       ("edje_convert", EDJE_CC_DEFAULT_LOG_COLOR);
   if (_edje_cc_log_dom < 0)
     {
        EINA_LOG_ERR("Enable to create a log domain.");
        exit(-1);
     }

   eet_init();

   progname = argv[0];
   if (argc > 2 || argc < 2 || !strcmp(argv[1], "-h"))
     {
        main_help();
        return 0;
     }

   _edje_edd_old_init();
   _edje_edd_init();

   ef = eet_open(argv[1], EET_FILE_MODE_READ_WRITE);
   if (!ef)
     {
        EINA_LOG_ERR("Unable to open `%s'.", argv[1]);
        return -1;
     }

   oef = eet_data_read(ef, _edje_edd_old_edje_file, "edje_file");
   if (!oef)
     {
        EINA_LOG_ERR("Unable to get edje_file section from old file format, are you sure it's an old file ?");
        return -1;
     }

   nef = _edje_file_convert(ef, oef);
   _edje_file_set(nef);

   /* convert old structure to new one */
   it = eina_hash_iterator_data_new(nef->collection);

   EINA_ITERATOR_FOREACH(it, ce)
     {
        Old_Edje_Part_Collection *opc;
        Edje_Part_Collection *npc;
        char buf[1024];
        int bytes = 0;

        snprintf(buf, sizeof (buf), "collections/%i", ce->id);
        opc = eet_data_read(ef, _edje_edd_old_edje_part_collection, buf);
        if (!opc)
          {
             EINA_LOG_ERR("Unable to find collection `%s'[%i] in `%s'.", ce->entry, ce->id, argv[1]);
             return -1;
          }

        npc = _edje_collection_convert(ef, ce, opc);

        snprintf(buf, sizeof (buf), "edje/collections/%i", ce->id);
        bytes = eet_data_write(ef, _edje_edd_edje_part_collection, buf, npc, 1);
        if (bytes <= 0)
          {
             EINA_LOG_ERR("Unable to save `%s' in section `%s' of `%s'.", ce->entry, buf, argv[1]);
             return -1;
          }
     }