8
#ifdef HAVE_SYS_RESOURCE_H
10
#include <sys/resource.h>
14
# include <evil_private.h>
20
#include <Ecore_File.h>
22
#define EFREET_MODULE_LOG_DOM _efreet_icon_cache_log_dom
23
static int _efreet_icon_cache_log_dom = -1;
26
#include "efreet_private.h"
27
#include "efreet_cache_private.h"
33
static Eina_Array *exts = NULL;
34
static Eina_Array *extra_dirs = NULL;
35
static Eina_Array *strs = NULL;
36
static Eina_Hash *icon_themes = NULL;
39
cache_directory_modified(Eina_Hash *dirs, const char *dir)
41
Efreet_Cache_Directory *dcache;
42
Efreet_Cache_Check check;
44
if (!dirs) return EINA_TRUE;
45
if (!efreet_file_cache_fill(dir, &check)) return EINA_FALSE;
46
dcache = eina_hash_find(dirs, dir);
49
dcache = malloc(sizeof (Efreet_Cache_Directory));
50
if (!dcache) return EINA_TRUE;
51
dcache->check = check;
52
eina_hash_add(dirs, dir, dcache);
54
else if (efreet_file_cache_check(&check, &dcache->check))
57
dcache->check = check;
62
cache_extension_lookup(const char *ext)
66
for (i = 0; i < exts->count; ++i)
68
if (!strcmp(exts->data[i], ext)) return EINA_TRUE;
74
cache_fallback_scan_dir(Eina_Hash *icons, Eina_Hash *dirs, const char *dir)
77
Eina_File_Direct_Info *entry;
79
if (!cache_directory_modified(dirs, dir)) return EINA_TRUE;
81
it = eina_file_stat_ls(dir);
82
if (!it) return EINA_TRUE;
84
EINA_ITERATOR_FOREACH(it, entry)
86
Efreet_Cache_Fallback_Icon *icon;
92
if (entry->type == EINA_FILE_DIR)
95
ext = strrchr(entry->path + entry->name_start, '.');
96
if (!ext || !cache_extension_lookup(ext))
100
name = entry->path + entry->name_start;
103
icon = eina_hash_find(icons, name);
106
icon = NEW(Efreet_Cache_Fallback_Icon, 1);
108
eina_hash_add(icons, name, icon);
113
for (i = 0; i < icon->icons_count; ++i)
114
if (!strcmp(icon->icons[i], entry->path))
117
if (i != icon->icons_count)
120
p = realloc(icon->icons, sizeof (char *) * (icon->icons_count + 1));
123
ERR("Out of memory");
127
icon->icons[icon->icons_count] = eina_stringshare_add(entry->path);
128
eina_array_push(strs, icon->icons[icon->icons_count++]);
131
eina_iterator_free(it);
137
cache_fallback_scan(Eina_Hash *icons, Eina_Hash *dirs)
140
Eina_List *xdg_dirs, *l;
144
for (i = 0; i < extra_dirs->count; i++)
145
cache_fallback_scan_dir(icons, dirs, extra_dirs->data[i]);
147
cache_fallback_scan_dir(icons, dirs, efreet_icon_deprecated_user_dir_get());
148
cache_fallback_scan_dir(icons, dirs, efreet_icon_user_dir_get());
150
xdg_dirs = efreet_data_dirs_get();
151
EINA_LIST_FOREACH(xdg_dirs, l, dir)
153
snprintf(path, sizeof(path), "%s/icons", dir);
154
cache_fallback_scan_dir(icons, dirs, path);
158
EINA_LIST_FOREACH(xdg_dirs, l, dir)
160
snprintf(path, sizeof(path), "%s/pixmaps", dir);
161
cache_fallback_scan_dir(icons, dirs, path);
165
cache_fallback_scan_dir(icons, dirs, "/usr/local/share/pixmaps");
166
cache_fallback_scan_dir(icons, dirs, "/usr/share/pixmaps");
172
check_fallback_changed(Efreet_Cache_Icon_Theme *theme)
175
Eina_List *xdg_dirs, *l;
183
Eina_Bool changed = EINA_FALSE;
185
it = eina_hash_iterator_key_new(theme->dirs);
186
EINA_ITERATOR_FOREACH(it, dir)
188
changed = !ecore_file_exists(dir);
190
changed = cache_directory_modified(theme->dirs, dir);
193
eina_iterator_free(it);
194
if (changed) return EINA_TRUE;
198
for (i = 0; i < extra_dirs->count; i++)
199
if (cache_directory_modified(theme->dirs, extra_dirs->data[i])) return EINA_TRUE;
201
if (cache_directory_modified(theme->dirs, efreet_icon_deprecated_user_dir_get())) return EINA_TRUE;
202
if (cache_directory_modified(theme->dirs, efreet_icon_user_dir_get())) return EINA_TRUE;
204
xdg_dirs = efreet_data_dirs_get();
205
EINA_LIST_FOREACH(xdg_dirs, l, dir)
207
snprintf(path, sizeof(path), "%s/icons", dir);
208
if (cache_directory_modified(theme->dirs, path)) return EINA_TRUE;
212
EINA_LIST_FOREACH(xdg_dirs, l, dir)
214
snprintf(path, sizeof(path), "%s/pixmaps", dir);
215
if (cache_directory_modified(theme->dirs, path)) return EINA_TRUE;
219
if (cache_directory_modified(theme->dirs, "/usr/local/share/pixmaps")) return EINA_TRUE;
220
if (cache_directory_modified(theme->dirs, "/usr/share/pixmaps")) return EINA_TRUE;
230
static Eina_Hash *already_scanned_path = NULL;
233
cache_theme_change_verify(Efreet_Cache_Icon_Theme *theme)
235
Eina_Bool changed = EINA_FALSE;
237
Efreet_Icon_Theme_Directory *d;
238
char buf[PATH_MAX], *tdir, *sep;
240
tdir = strdup(theme->path);
241
sep = strrchr(tdir, '/');
243
EINA_LIST_FOREACH(theme->theme.directories, l, d)
245
snprintf(buf, sizeof(buf), "%s/%s", tdir, d->name);
246
if (cache_directory_modified(theme->dirs, buf))
252
if (changed) theme->changed = changed;
256
cache_scan_path_dir(Efreet_Icon_Theme *theme,
258
Efreet_Icon_Theme_Directory *dir,
263
Eina_File_Direct_Info *entry;
264
Eina_List *dirs = NULL;
267
Scanned_Entry *scentry;
269
snprintf(buf, sizeof(buf), "%s/%s", path, dir->name);
271
if (!already_scanned_path)
272
already_scanned_path = eina_hash_string_superfast_new(NULL);
273
dirs = eina_hash_find(already_scanned_path, buf);
274
if ((intptr_t)dirs == (intptr_t)(-1L)) return EINA_TRUE;
277
it = eina_file_stat_ls(buf);
280
eina_hash_add(already_scanned_path, buf, (void *)(intptr_t)(-1L));
284
EINA_ITERATOR_FOREACH(it, entry)
286
if (entry->type == EINA_FILE_DIR) continue;
287
ext = strrchr(entry->path + entry->name_start, '.');
288
if (!ext || !cache_extension_lookup(ext)) continue;
289
scentry = malloc(sizeof(Scanned_Entry));
292
ERR("Out of memory");
295
scentry->name_start = entry->name_start;
296
scentry->path = strdup(entry->path);
299
ERR("Out of memory");
302
dirs = eina_list_append(dirs, scentry);
304
eina_iterator_free(it);
306
eina_hash_add(already_scanned_path, buf, dirs);
308
eina_hash_add(already_scanned_path, buf, (void *)(intptr_t)(-1L));
311
EINA_LIST_FOREACH(dirs, l, scentry)
313
Efreet_Cache_Icon *icon;
318
ext = strrchr(scentry->path + scentry->name_start, '.');
321
name = scentry->path + scentry->name_start;
324
icon = eina_hash_find(icons, name);
327
icon = NEW(Efreet_Cache_Icon, 1);
328
icon->theme = eina_stringshare_add(theme->name.internal);
329
eina_array_push(strs, icon->theme);
330
eina_hash_add(icons, name, icon);
334
for (i = 0; i < icon->icons_count; ++i)
336
if ((icon->icons[i]->type == dir->type) &&
337
(icon->icons[i]->normal == dir->size.normal) &&
338
(icon->icons[i]->max == dir->size.max) &&
339
(icon->icons[i]->min == dir->size.min))
345
if (i != icon->icons_count)
350
for (j = 0; j < icon->icons[i]->paths_count; ++j)
351
if (!strcmp(icon->icons[i]->paths[j], scentry->path))
354
if (j != icon->icons[i]->paths_count)
358
if (strcmp(icon->theme, theme->name.internal))
362
for (j = 0; j < icon->icons[i]->paths_count; ++j)
364
ext2 = strrchr(icon->icons[i]->paths[j], '.');
368
has_ext = !strcmp((ext + 1), ext2);
381
else if (!strcmp(icon->theme, theme->name.internal))
383
Efreet_Cache_Icon_Element **tmp2;
385
tmp2 = realloc(icon->icons,
386
sizeof(Efreet_Cache_Icon_Element *) * (++icon->icons_count));
389
ERR("Out of memory");
393
icon->icons[i] = NEW(Efreet_Cache_Icon_Element, 1);
394
icon->icons[i]->type = dir->type;
395
icon->icons[i]->normal = dir->size.normal;
396
icon->icons[i]->min = dir->size.min;
397
icon->icons[i]->max = dir->size.max;
398
icon->icons[i]->paths = NULL;
399
icon->icons[i]->paths_count = 0;
407
tmp = realloc(icon->icons[i]->paths,
408
sizeof(char *) * (icon->icons[i]->paths_count + 1));
411
ERR("Out of memory");
414
icon->icons[i]->paths = tmp;
415
icon->icons[i]->paths[icon->icons[i]->paths_count] = eina_stringshare_add(scentry->path);
416
eina_array_push(strs, icon->icons[i]->paths[icon->icons[i]->paths_count++]);
422
cache_scan_path(Efreet_Icon_Theme *theme, Eina_Hash *icons, const char *path)
425
Efreet_Icon_Theme_Directory *dir;
427
EINA_LIST_FOREACH(theme->directories, l, dir)
429
if (!cache_scan_path_dir(theme, path, dir, icons)) return EINA_FALSE;
436
cache_scan(Efreet_Icon_Theme *theme, Eina_Hash *themes, Eina_Hash *icons)
442
if (!theme) return EINA_TRUE;
443
if (eina_hash_find(themes, theme->name.internal)) return EINA_TRUE;
444
eina_hash_direct_add(themes, theme->name.internal, theme);
447
EINA_LIST_FOREACH(theme->paths, l, path)
448
if (!cache_scan_path(theme, icons, path)) return EINA_FALSE;
453
EINA_LIST_FOREACH(theme->inherits, l, name)
455
Efreet_Icon_Theme *inherit;
457
inherit = eina_hash_find(icon_themes, name);
459
INF("Theme `%s` not found for `%s`.",
460
name, theme->name.internal);
461
if (!cache_scan(inherit, themes, icons)) return EINA_FALSE;
464
else if (strcmp(theme->name.internal, "hicolor"))
466
theme = eina_hash_find(icon_themes, "hicolor");
467
if (!cache_scan(theme, themes, icons)) return EINA_FALSE;
474
check_changed(Efreet_Cache_Icon_Theme *theme)
479
if (!theme) return EINA_FALSE;
481
if (theme->changed) return EINA_TRUE;
482
if (theme->theme.inherits)
484
EINA_LIST_FOREACH(theme->theme.inherits, l, name)
486
Efreet_Cache_Icon_Theme *inherit;
488
inherit = eina_hash_find(icon_themes, name);
490
INF("Theme `%s` not found for `%s`.",
491
name, theme->theme.name.internal);
492
if (check_changed(inherit)) return EINA_TRUE;
495
else if (strcmp(theme->theme.name.internal, "hicolor"))
497
theme = eina_hash_find(icon_themes, "hicolor");
498
if (check_changed(theme)) return EINA_TRUE;
503
static Efreet_Icon_Theme_Directory *
504
icon_theme_directory_new(Efreet_Ini *ini, const char *name)
506
Efreet_Icon_Theme_Directory *dir;
510
if (!ini) return NULL;
512
dir = NEW(Efreet_Icon_Theme_Directory, 1);
513
if (!dir) return NULL;
514
dir->name = eina_stringshare_add(name);
515
eina_array_push(strs, dir->name);
517
efreet_ini_section_set(ini, name);
519
tmp = efreet_ini_string_get(ini, "Context");
522
if (!strcasecmp(tmp, "Actions"))
523
dir->context = EFREET_ICON_THEME_CONTEXT_ACTIONS;
525
else if (!strcasecmp(tmp, "Devices"))
526
dir->context = EFREET_ICON_THEME_CONTEXT_DEVICES;
528
else if (!strcasecmp(tmp, "FileSystems"))
529
dir->context = EFREET_ICON_THEME_CONTEXT_FILESYSTEMS;
531
else if (!strcasecmp(tmp, "MimeTypes"))
532
dir->context = EFREET_ICON_THEME_CONTEXT_MIMETYPES;
536
dir->type = EFREET_ICON_SIZE_TYPE_THRESHOLD;
538
tmp = efreet_ini_string_get(ini, "Type");
541
if (!strcasecmp(tmp, "Fixed"))
542
dir->type = EFREET_ICON_SIZE_TYPE_FIXED;
544
else if (!strcasecmp(tmp, "Scalable"))
545
dir->type = EFREET_ICON_SIZE_TYPE_SCALABLE;
548
dir->size.normal = efreet_ini_int_get(ini, "Size");
550
if (dir->type == EFREET_ICON_SIZE_TYPE_THRESHOLD)
552
val = efreet_ini_int_get(ini, "Threshold");
553
if (val < 0) val = 2;
554
dir->size.max = dir->size.normal + val;
555
dir->size.min = dir->size.normal - val;
557
else if (dir->type == EFREET_ICON_SIZE_TYPE_SCALABLE)
559
val = efreet_ini_int_get(ini, "MinSize");
560
if (val < 0) dir->size.min = dir->size.normal;
561
else dir->size.min = val;
563
val = efreet_ini_int_get(ini, "MaxSize");
564
if (val < 0) dir->size.max = dir->size.normal;
565
else dir->size.max = val;
572
icon_theme_index_read(Efreet_Cache_Icon_Theme *theme, const char *path)
575
Efreet_Icon_Theme_Directory *dir;
577
Efreet_Cache_Check check;
579
if (!theme || !path) return EINA_FALSE;
581
if (!efreet_file_cache_fill(path, &check)) return EINA_FALSE;
582
if (theme->path && !strcmp(theme->path, path) &&
583
efreet_file_cache_check(&check, &(theme->check)))
589
if (!theme->path || strcmp(theme->path, path))
591
theme->path = eina_stringshare_add(path);
592
eina_array_push(strs, theme->path);
594
theme->check = check;
597
ini = efreet_ini_new(path);
598
if (!ini) return EINA_FALSE;
601
efreet_ini_free(ini);
605
efreet_ini_section_set(ini, "Icon Theme");
606
tmp = efreet_ini_localestring_get(ini, "Name");
609
theme->theme.name.name = eina_stringshare_add(tmp);
610
eina_array_push(strs, theme->theme.name.name);
613
tmp = efreet_ini_localestring_get(ini, "Comment");
616
theme->theme.comment = eina_stringshare_add(tmp);
617
eina_array_push(strs, theme->theme.comment);
620
tmp = efreet_ini_string_get(ini, "Example");
623
theme->theme.example_icon = eina_stringshare_add(tmp);
624
eina_array_push(strs, theme->theme.example_icon);
627
theme->hidden = efreet_ini_boolean_get(ini, "Hidden");
632
tmp = efreet_ini_string_get(ini, "Inherits");
639
len = strlen(tmp) + 1;
649
i = eina_stringshare_add(s);
650
theme->theme.inherits = eina_list_append(theme->theme.inherits, i);
651
eina_array_push(strs, i);
655
i = eina_stringshare_add(s);
656
theme->theme.inherits = eina_list_append(theme->theme.inherits, i);
657
eina_array_push(strs, i);
662
tmp = efreet_ini_string_get(ini, "Directories");
668
len = strlen(tmp) + 1;
680
dir = icon_theme_directory_new(ini, s);
681
if (!dir) goto error;
682
theme->theme.directories = eina_list_append(theme->theme.directories, dir);
689
efreet_ini_free(ini);
695
cache_theme_scan(const char *dir)
698
Eina_File_Direct_Info *entry;
700
it = eina_file_stat_ls(dir);
701
if (!it) return EINA_TRUE;
703
EINA_ITERATOR_FOREACH(it, entry)
706
Efreet_Cache_Icon_Theme *theme;
709
Efreet_Cache_Check check;
710
Efreet_Cache_Directory *d;
712
if (!efreet_file_cache_fill(entry->path, &check)) continue;
714
if ((entry->type != EINA_FILE_DIR) &&
715
(entry->type != EINA_FILE_LNK))
718
if ((entry->type == EINA_FILE_LNK) &&
719
(!ecore_file_is_dir(entry->path)))
722
name = entry->path + entry->name_start;
723
theme = eina_hash_find(icon_themes, name);
727
theme = NEW(Efreet_Cache_Icon_Theme, 1);
728
theme->theme.name.internal = eina_stringshare_add(name);
729
eina_array_push(strs, theme->theme.name.internal);
730
eina_hash_direct_add(icon_themes,
731
(void *)theme->theme.name.internal, theme);
737
d = eina_hash_find(theme->dirs, entry->path);
741
theme->dirs = eina_hash_string_superfast_new(NULL);
743
d = NEW(Efreet_Cache_Directory, 1);
745
eina_hash_add(theme->dirs, entry->path, d);
749
if (!efreet_file_cache_check(&check, &(d->check)))
757
if (!eina_list_search_unsorted(theme->theme.paths, EINA_COMPARE_CB(strcmp), entry->path))
759
path = eina_stringshare_add(entry->path);
760
theme->theme.paths = eina_list_append(theme->theme.paths, path);
761
eina_array_push(strs, path);
766
if (theme->valid) continue;
769
memcpy(buf, entry->path, entry->path_length);
770
memcpy(buf + entry->path_length, "/index.theme", sizeof("/index.theme"));
771
if (ecore_file_exists(buf))
773
if (!icon_theme_index_read(theme, buf))
777
eina_iterator_free(it);
788
snprintf(file, sizeof(file), "%s/efreet/icon_data.lock", efreet_cache_home_get());
789
lockfd = open(file, O_CREAT | O_BINARY | O_RDWR, S_IRUSR | S_IWUSR);
790
if (lockfd < 0) return -1;
791
efreet_fsetowner(lockfd);
793
memset(&fl, 0, sizeof(struct flock));
795
fl.l_whence = SEEK_SET;
796
if (fcntl(lockfd, F_SETLK, &fl) < 0)
798
WRN("LOCKED! You may want to delete %s if this persists", file);
807
icon_theme_free(Efreet_Cache_Icon_Theme *theme)
811
eina_list_free(theme->theme.paths);
812
eina_list_free(theme->theme.inherits);
813
EINA_LIST_FREE(theme->theme.directories, data) free(data);
814
if (theme->dirs) efreet_hash_free(theme->dirs, free);
819
main(int argc, char **argv)
827
Efreet_Cache_Version *icon_version;
828
Efreet_Cache_Version *theme_version;
829
Efreet_Cache_Icon_Theme *theme;
830
Eet_Data_Descriptor *theme_edd;
831
Eet_Data_Descriptor *icon_edd;
832
Eet_Data_Descriptor *fallback_edd;
835
Eina_List *xdg_dirs = NULL;
840
Eina_Bool changed = EINA_FALSE;
841
Eina_Bool flush = EINA_FALSE;
847
if (!eina_init()) return -1;
848
_efreet_icon_cache_log_dom =
849
eina_log_domain_register("efreet_icon_cache", EFREET_DEFAULT_LOG_COLOR);
850
if (_efreet_icon_cache_log_dom < 0)
852
EINA_LOG_ERR("Efreet: Could not create a log domain for efreet_icon_cache.");
856
eina_log_domain_level_set("efreet_icon_cache", EINA_LOG_LEVEL_ERR);
858
exts = eina_array_new(10);
859
extra_dirs = eina_array_new(10);
861
for (i = 1; i < argc; i++)
863
if (!strcmp(argv[i], "-v"))
864
eina_log_domain_level_set("efreet_icon_cache", EINA_LOG_LEVEL_DBG);
865
else if ((!strcmp(argv[i], "-h")) ||
866
(!strcmp(argv[i], "-help")) ||
867
(!strcmp(argv[i], "--h")) ||
868
(!strcmp(argv[i], "--help")))
870
printf("Options:\n");
871
printf(" -v Verbose mode\n");
872
printf(" -e .ext1 .ext2 Extensions\n");
873
printf(" -d dir1 dir2 Extra dirs\n");
874
printf(" -f Flush\n");
877
else if (!strcmp(argv[i], "-e"))
879
while ((i < (argc - 1)) && (argv[(i + 1)][0] != '-'))
880
eina_array_push(exts, argv[++i]);
882
else if (!strcmp(argv[i], "-d"))
884
while ((i < (argc - 1)) && (argv[(i + 1)][0] != '-'))
885
eina_array_push(extra_dirs, argv[++i]);
887
else if (!strcmp(argv[i], "-f"))
891
#ifdef HAVE_SYS_RESOURCE_H
892
setpriority(PRIO_PROCESS, 0, 19);
894
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
897
if (!eet_init()) return -1;
898
if (!ecore_init()) return -1;
900
efreet_cache_update = 0;
902
if (!efreet_init()) goto on_error;
904
strs = eina_array_new(32);
907
snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get());
908
if (!ecore_file_exists(file))
910
if (!ecore_file_mkpath(file)) return -1;
911
efreet_setowner(file);
915
lockfd = cache_lock_file();
916
if (lockfd == -1) goto on_error;
919
icon_edd = efreet_icon_edd();
920
fallback_edd = efreet_icon_fallback_edd();
921
theme_edd = efreet_icon_theme_edd(EINA_TRUE);
923
icon_themes = eina_hash_string_superfast_new(EINA_FREE_CB(icon_theme_free));
925
INF("opening theme cache");
927
theme_ef = eet_open(efreet_icon_theme_cache_file(), EET_FILE_MODE_READ_WRITE);
928
if (!theme_ef) goto on_error_efreet;
929
theme_version = eet_data_read(theme_ef, efreet_version_edd(), EFREET_CACHE_VERSION);
931
((theme_version->major != EFREET_ICON_CACHE_MAJOR) ||
932
(theme_version->minor != EFREET_ICON_CACHE_MINOR)))
936
if (unlink(efreet_icon_theme_cache_file()) < 0)
938
if (errno != ENOENT) goto on_error_efreet;
940
theme_ef = eet_open(efreet_icon_theme_cache_file(), EET_FILE_MODE_READ_WRITE);
941
if (!theme_ef) goto on_error_efreet;
944
theme_version = NEW(Efreet_Cache_Version, 1);
946
theme_version->major = EFREET_ICON_CACHE_MAJOR;
947
theme_version->minor = EFREET_ICON_CACHE_MINOR;
952
if (exts->count == 0)
954
ERR("Need to pass extensions to icon cache create process");
955
goto on_error_efreet;
958
keys = eet_list(theme_ef, "*", &num);
961
for (i = 0; i < num; i++)
963
if (!strncmp(keys[i], "__efreet", 8)) continue;
964
theme = eet_data_read(theme_ef, theme_edd, keys[i]);
968
eina_hash_direct_add(icon_themes, theme->theme.name.internal, theme);
974
INF("scan for themes");
976
cache_theme_scan(efreet_icon_deprecated_user_dir_get());
977
cache_theme_scan(efreet_icon_user_dir_get());
979
xdg_dirs = efreet_data_dirs_get();
980
EINA_LIST_FOREACH(xdg_dirs, l, dir)
982
snprintf(file, sizeof(file), "%s/icons", dir);
983
cache_theme_scan(file);
987
EINA_LIST_FOREACH(xdg_dirs, l, dir)
989
snprintf(file, sizeof(file), "%s/pixmaps", dir);
990
cache_theme_scan(file);
994
cache_theme_scan("/usr/local/share/pixmaps");
995
cache_theme_scan("/usr/share/pixmaps");
998
it = eina_hash_iterator_data_new(icon_themes);
999
EINA_ITERATOR_FOREACH(it, theme)
1001
if (!theme->valid) continue;
1003
if (!theme->theme.name.name) continue;
1005
INF("scan theme %s", theme->theme.name.name);
1006
cache_theme_change_verify(theme);
1007
theme->changed = check_changed(theme);
1009
theme->changed = EINA_TRUE;
1011
INF("open icon file");
1013
icon_ef = eet_open(efreet_icon_cache_file(theme->theme.name.internal), EET_FILE_MODE_READ_WRITE);
1014
if (!icon_ef) goto on_error_efreet;
1015
icon_version = eet_data_read(icon_ef, efreet_version_edd(), EFREET_CACHE_VERSION);
1016
if ((theme->changed) || (!icon_version) ||
1017
((icon_version->major != EFREET_ICON_CACHE_MAJOR) ||
1018
(icon_version->minor != EFREET_ICON_CACHE_MINOR)))
1022
if (unlink(efreet_icon_cache_file(theme->theme.name.internal)) < 0)
1024
if (errno != ENOENT) goto on_error_efreet;
1026
icon_ef = eet_open(efreet_icon_cache_file(theme->theme.name.internal), EET_FILE_MODE_READ_WRITE);
1027
if (!icon_ef) goto on_error_efreet;
1028
theme->changed = EINA_TRUE;
1032
changed = EINA_TRUE;
1035
icon_version = NEW(Efreet_Cache_Version, 1);
1037
icon_version->major = EFREET_ICON_CACHE_MAJOR;
1038
icon_version->minor = EFREET_ICON_CACHE_MINOR;
1045
themes = eina_hash_string_superfast_new(NULL);
1046
icons = eina_hash_string_superfast_new(NULL);
1048
INF("scan icons\n");
1049
if (cache_scan(&(theme->theme), themes, icons))
1051
Eina_Iterator *icons_it;
1052
Eina_Hash_Tuple *tuple;
1054
INF("generated: '%s' %i (%i)",
1055
theme->theme.name.internal,
1057
eina_hash_population(icons));
1059
icons_it = eina_hash_iterator_tuple_new(icons);
1060
EINA_ITERATOR_FOREACH(icons_it, tuple)
1061
eet_data_write(icon_ef, icon_edd, tuple->key, tuple->data, EET_COMPRESSION_SUPERFAST);
1062
eina_iterator_free(icons_it);
1064
INF("theme change: %s %lld", theme->theme.name.internal, theme->check.mtime);
1065
eet_data_write(theme_ef, theme_edd, theme->theme.name.internal, theme, EET_COMPRESSION_SUPERFAST);
1067
eina_hash_free(themes);
1068
eina_hash_free(icons);
1069
changed = EINA_TRUE;
1072
eet_data_write(icon_ef, efreet_version_edd(), EFREET_CACHE_VERSION, icon_version, EET_COMPRESSION_SUPERFAST);
1074
efreet_setowner(efreet_icon_cache_file(theme->theme.name.internal));
1077
eina_iterator_free(it);
1079
INF("scan fallback icons");
1080
theme = eet_data_read(theme_ef, theme_edd, EFREET_CACHE_ICON_FALLBACK);
1083
theme = NEW(Efreet_Cache_Icon_Theme, 1);
1084
theme->changed = EINA_TRUE;
1087
theme->changed = EINA_TRUE;
1089
INF("open fallback file");
1091
icon_ef = eet_open(efreet_icon_cache_file(EFREET_CACHE_ICON_FALLBACK), EET_FILE_MODE_READ_WRITE);
1092
if (!icon_ef) goto on_error_efreet;
1093
icon_version = eet_data_read(icon_ef, efreet_version_edd(), EFREET_CACHE_VERSION);
1094
if (theme->changed || (icon_version &&
1095
((icon_version->major != EFREET_ICON_CACHE_MAJOR) ||
1096
(icon_version->minor != EFREET_ICON_CACHE_MINOR))))
1100
if (unlink(efreet_icon_cache_file(EFREET_CACHE_ICON_FALLBACK)) < 0)
1102
if (errno != ENOENT) goto on_error_efreet;
1104
icon_ef = eet_open(efreet_icon_cache_file(EFREET_CACHE_ICON_FALLBACK), EET_FILE_MODE_READ_WRITE);
1105
if (!icon_ef) goto on_error_efreet;
1106
theme->changed = EINA_TRUE;
1108
if (!theme->changed)
1109
theme->changed = check_fallback_changed(theme);
1110
if (theme->changed && theme->dirs)
1112
efreet_hash_free(theme->dirs, free);
1116
theme->dirs = eina_hash_string_superfast_new(NULL);
1119
changed = EINA_TRUE;
1122
icon_version = NEW(Efreet_Cache_Version, 1);
1124
icon_version->major = EFREET_ICON_CACHE_MAJOR;
1125
icon_version->minor = EFREET_ICON_CACHE_MINOR;
1131
icons = eina_hash_string_superfast_new(NULL);
1133
INF("scan fallback icons");
1135
if (cache_fallback_scan(icons, theme->dirs))
1137
Eina_Iterator *icons_it;
1138
Eina_Hash_Tuple *tuple;
1140
INF("generated: fallback %i (%i)", theme->changed, eina_hash_population(icons));
1142
icons_it = eina_hash_iterator_tuple_new(icons);
1143
EINA_ITERATOR_FOREACH(icons_it, tuple)
1144
eet_data_write(icon_ef, fallback_edd, tuple->key, tuple->data, EET_COMPRESSION_SUPERFAST);
1145
eina_iterator_free(icons_it);
1147
eina_hash_free(icons);
1149
eet_data_write(theme_ef, theme_edd, EFREET_CACHE_ICON_FALLBACK, theme, EET_COMPRESSION_SUPERFAST);
1152
icon_theme_free(theme);
1154
eet_data_write(icon_ef, efreet_version_edd(), EFREET_CACHE_VERSION, icon_version, EET_COMPRESSION_SUPERFAST);
1156
efreet_setowner(efreet_icon_cache_file(EFREET_CACHE_ICON_FALLBACK));
1159
eina_hash_free(icon_themes);
1162
eet_data_write(theme_ef, efreet_version_edd(), EFREET_CACHE_VERSION, theme_version, EET_COMPRESSION_SUPERFAST);
1164
eet_close(theme_ef);
1166
efreet_setowner(efreet_icon_theme_cache_file());
1167
free(theme_version);
1172
if (changed) c = 'c';
1179
if (theme_ef) eet_close(theme_ef);
1182
if (lockfd >= 0) close(lockfd);
1184
while ((path = eina_array_pop(strs)))
1185
eina_stringshare_del(path);
1186
eina_array_free(strs);
1187
eina_array_free(exts);
1188
eina_array_free(extra_dirs);
1192
eina_log_domain_unregister(_efreet_icon_cache_log_dom);