edje: refactor _edje_object_file_set_internal() function

Summary:
move the file related function to edje_cache so that code
is easy to read and maintainable and we don't have to do unnecessary
stuff for each edje object creation.

Reviewers: Hermet

Reviewed By: Hermet

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D9761
This commit is contained in:
subhransu mohanty 2019-08-28 13:18:42 +09:00 committed by Hermet Park
parent 53739890ce
commit 4b2403d80c
2 changed files with 103 additions and 98 deletions

View File

@ -387,6 +387,93 @@ _edje_file_coll_open(Edje_File *edf, const char *coll)
return edc;
}
void
_edje_extract_mo_files(Edje_File *edf)
{
Eina_Strbuf *mo_id_str;
const void *data;
const char *cache_path;
const char *filename;
unsigned int crc;
time_t t;
size_t sz;
unsigned int i;
int len;
cache_path = efreet_cache_home_get();
t = eina_file_mtime_get(edf->f);
sz = eina_file_size_get(edf->f);
filename = eina_file_filename_get(edf->f);
crc = eina_crc(filename, strlen(filename), 0xffffffff, EINA_TRUE);
snprintf(edf->fid, sizeof(edf->fid), "%lld-%lld-%x",
(long long int)t,
(long long int)sz,
crc);
mo_id_str = eina_strbuf_new();
for (i = 0; i < edf->mo_dir->mo_entries_count; i++)
{
Edje_Mo *mo_entry;
char out[PATH_MAX + PATH_MAX + 128];
char outdir[PATH_MAX];
char *sub_str;
char *mo_src;
mo_entry = &edf->mo_dir->mo_entries[i];
eina_strbuf_append_printf(mo_id_str,
"edje/mo/%i/%s/LC_MESSAGES",
mo_entry->id,
mo_entry->locale);
data = eet_read_direct(edf->ef,
eina_strbuf_string_get(mo_id_str),
&len);
if (data)
{
snprintf(outdir, sizeof(outdir),
"%s/edje/%s/LC_MESSAGES",
cache_path, mo_entry->locale);
ecore_file_mkpath(outdir);
mo_src = strdup(mo_entry->mo_src);
sub_str = strstr(mo_src, ".po");
if (sub_str)
sub_str[1] = 'm';
snprintf(out, sizeof(out), "%s/%s-%s",
outdir, edf->fid, mo_src);
if (ecore_file_exists(out))
{
if (edf->mtime > ecore_file_mod_time(out))
ecore_file_remove(out);
}
if (!ecore_file_exists(out))
{
FILE *f;
f = fopen(out, "wb");
if (f)
{
if (fwrite(data, len, 1, f) != 1)
ERR("Could not write mo: %s: %s", out, strerror(errno));
fclose(f);
}
else
ERR("Could not open for writing mo: %s: %s", out, strerror(errno));
}
free(mo_src);
}
eina_strbuf_reset(mo_id_str);
}
eina_strbuf_free(mo_id_str);
}
// XXX: this is not pretty. some oooooold edje files do not store strings
// in their dictionary for hashes. this works around crashes loading such
// files
@ -542,6 +629,22 @@ _edje_file_open(const Eina_File *f, int *error_ret, time_t mtime, Eina_Bool coll
}
}
if (edf->external_dir)
{
unsigned int i;
for (i = 0; i < edf->external_dir->entries_count; ++i)
edje_module_load(edf->external_dir->entries[i].entry);
}
// this call is unnecessary as we are doing same opeartion
// inside _edje_textblock_style_parse_and_fix() function
// remove ??
//_edje_textblock_style_all_update(ed);
if (edf->mo_dir)
_edje_extract_mo_files(edf);
return edf;
}

View File

@ -52,93 +52,6 @@ _edje_smart_nested_smart_class_new(void)
return smart;
}
void
_edje_extract_mo_files(Edje_File *edf)
{
Eina_Strbuf *mo_id_str;
const void *data;
const char *cache_path;
const char *filename;
unsigned int crc;
time_t t;
size_t sz;
unsigned int i;
int len;
cache_path = efreet_cache_home_get();
t = eina_file_mtime_get(edf->f);
sz = eina_file_size_get(edf->f);
filename = eina_file_filename_get(edf->f);
crc = eina_crc(filename, strlen(filename), 0xffffffff, EINA_TRUE);
snprintf(edf->fid, sizeof(edf->fid), "%lld-%lld-%x",
(long long int)t,
(long long int)sz,
crc);
mo_id_str = eina_strbuf_new();
for (i = 0; i < edf->mo_dir->mo_entries_count; i++)
{
Edje_Mo *mo_entry;
char out[PATH_MAX + PATH_MAX + 128];
char outdir[PATH_MAX];
char *sub_str;
char *mo_src;
mo_entry = &edf->mo_dir->mo_entries[i];
eina_strbuf_append_printf(mo_id_str,
"edje/mo/%i/%s/LC_MESSAGES",
mo_entry->id,
mo_entry->locale);
data = eet_read_direct(edf->ef,
eina_strbuf_string_get(mo_id_str),
&len);
if (data)
{
snprintf(outdir, sizeof(outdir),
"%s/edje/%s/LC_MESSAGES",
cache_path, mo_entry->locale);
ecore_file_mkpath(outdir);
mo_src = strdup(mo_entry->mo_src);
sub_str = strstr(mo_src, ".po");
if (sub_str)
sub_str[1] = 'm';
snprintf(out, sizeof(out), "%s/%s-%s",
outdir, edf->fid, mo_src);
if (ecore_file_exists(out))
{
if (edf->mtime > ecore_file_mod_time(out))
ecore_file_remove(out);
}
if (!ecore_file_exists(out))
{
FILE *f;
f = fopen(out, "wb");
if (f)
{
if (fwrite(data, len, 1, f) != 1)
ERR("Could not write mo: %s: %s", out, strerror(errno));
fclose(f);
}
else
ERR("Could not open for writing mo: %s: %s", out, strerror(errno));
}
free(mo_src);
}
eina_strbuf_reset(mo_id_str);
}
eina_strbuf_free(mo_id_str);
}
Evas_Object *
edje_smart_nested_add(Evas *evas)
{
@ -835,19 +748,8 @@ _edje_object_file_set_internal(Evas_Object *obj, const Eina_File *file, const ch
_edje_file_add(ed, file);
ed->block_break = EINA_FALSE;
if (ed->file && ed->file->external_dir)
{
unsigned int i;
for (i = 0; i < ed->file->external_dir->entries_count; ++i)
edje_module_load(ed->file->external_dir->entries[i].entry);
}
_edje_textblock_style_all_update(ed);
ed->has_entries = EINA_FALSE;
if (ed->file && ed->file->mo_dir)
_edje_extract_mo_files(ed->file);
if (ed->collection)
{