Пример #1
0
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;
}
Пример #2
0
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);
}