annotate src/cache.c @ 244:7754bfc0d98a

Fix a signedness warning.
author zas_
date Thu, 03 Apr 2008 22:01:08 +0000
parents f6e307c7bad6
children 9995c5fb202a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
196
f6e307c7bad6 rename GQview -> Geeqie over the code
nadvornik
parents: 65
diff changeset
2 * Geeqie
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
3 * (C) 2004 John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
4 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12 #include "gqview.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13 #include "cache.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15 #include "md5-util.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
18 #include <utime.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include <errno.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24 * Cache data file format:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27 * SIMcache
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
28 * #coment
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
29 * Dimensions=[<width> x <height>]
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
30 * Date=[<value in time_t format, or -1 if no embedded date>]
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31 * Checksum=[<value>]
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32 * MD5sum=[<32 character ascii text digest>]
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 * SimilarityGrid[32 x 32]=<3072 bytes of data (1024 pixels in RGB format, 1 pixel is 24bits)>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36 * The first line (9 bytes) indicates it is a SIMcache format file. (new line char must exist)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37 * Comment lines starting with a # are ignored up to a new line.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38 * All data lines should end with a new line char.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39 * Format is very strict, data must begin with the char immediately following '='.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40 * Currently SimilarityGrid is always assumed to be 32 x 32 RGB.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46 * sim cache data
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 CacheData *cache_sim_data_new(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 CacheData *cd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 cd = g_new0(CacheData, 1);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
55 cd->date = -1;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57 return cd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 void cache_sim_data_free(CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62 if (!cd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64 g_free(cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65 image_sim_free(cd->sim);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66 g_free(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
70 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71 * sim cache write
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75 static gint cache_sim_write_dimensions(FILE *f, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77 if (!f || !cd || !cd->dimensions) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79 fprintf(f, "Dimensions=[%d x %d]\n", cd->width, cd->height);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
84 static gint cache_sim_write_date(FILE *f, CacheData *cd)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
85 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
86 if (!f || !cd || !cd->have_date) return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
87
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
88 fprintf(f, "Date=[%ld]\n", cd->date);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
89
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
90 return TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
91 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
92
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 static gint cache_sim_write_checksum(FILE *f, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 if (!f || !cd || !cd->have_checksum) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97 fprintf(f, "Checksum=[%ld]\n", cd->checksum);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102 static gint cache_sim_write_md5sum(FILE *f, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 gchar *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106 if (!f || !cd || !cd->have_md5sum) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108 text = md5_digest_to_text(cd->md5sum);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 fprintf(f, "MD5sum=[%s]\n", text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110 g_free(text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 static gint cache_sim_write_similarity(FILE *f, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117 gint success = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
119 if (!f || !cd || !cd->similarity) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
120
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121 if (cd->sim && cd->sim->filled)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123 gint x, y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 guint8 buf[96];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 fprintf(f, "SimilarityGrid[32 x 32]=");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 for (y = 0; y < 32; y++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
129 gint s;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130 guint8 *p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132 s = y * 32;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 p = buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134 for(x = 0; x < 32; x++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
136 *p = cd->sim->avg_r[s + x]; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 *p = cd->sim->avg_g[s + x]; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138 *p = cd->sim->avg_b[s + x]; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140 fwrite(buf, sizeof(buf), 1, f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
143 fprintf(f, "\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
144 success = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147 return success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150 gint cache_sim_data_save(CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
152 FILE *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 if (!cd || !cd->path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157 pathl = path_from_utf8(cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158 f = fopen(pathl, "w");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
161 if (!f)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163 printf("Unable to save sim cache data: %s\n", cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167 fprintf(f, "SIMcache\n#%s %s\n", PACKAGE, VERSION);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 cache_sim_write_dimensions(f, cd);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
169 cache_sim_write_date(f, cd);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170 cache_sim_write_checksum(f, cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171 cache_sim_write_md5sum(f, cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172 cache_sim_write_similarity(f, cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174 fclose (f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 * sim cache read
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
185 static gint cache_sim_read_skipline(FILE *f, int s)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 {
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
187 if (!f) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
189 if (fseek(f, 0 - s, SEEK_CUR) == 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 char b;
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
192 while (fread(&b, sizeof(b), 1, f) == 1)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194 if (b == '\n') return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
202 static gint cache_sim_read_comment(FILE *f, char *buf, int s, CacheData *cd)
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
203 {
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
204 if (!f || !buf || !cd) return FALSE;
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
205
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
206 if (s < 1 || buf[0] != '#') return FALSE;
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
207
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
208 return cache_sim_read_skipline(f, s - 1);
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
209 }
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
210
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
211 static gint cache_sim_read_dimensions(FILE *f, char *buf, int s, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213 if (!f || !buf || !cd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 if (s < 10 || strncmp("Dimensions", buf, 10) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 if (fseek(f, - s, SEEK_CUR) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 char b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220 char buf[1024];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 gint p = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 gint w, h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224 b = 'X';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 while (b != '[')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 while (b != ']' && p < 1023)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 buf[p] = b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 while (b != '\n')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 if (fread(&b, sizeof(b), 1, f) != 1) break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241 buf[p] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242 if (sscanf(buf, "%d x %d", &w, &h) != 2) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244 cd->width = w;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245 cd->height = h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 cd->dimensions = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
254 static gint cache_sim_read_date(FILE *f, char *buf, int s, CacheData *cd)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
255 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
256 if (!f || !buf || !cd) return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
257
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
258 if (s < 4 || strncmp("Date", buf, 4) != 0) return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
259
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
260 if (fseek(f, - s, SEEK_CUR) == 0)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
261 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
262 char b;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
263 char buf[1024];
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
264 gint p = 0;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
265
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
266 b = 'X';
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
267 while (b != '[')
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
268 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
269 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
270 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
271 while (b != ']' && p < 1023)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
272 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
273 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
274 buf[p] = b;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
275 p++;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
276 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
277
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
278 while (b != '\n')
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
279 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
280 if (fread(&b, sizeof(b), 1, f) != 1) break;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
281 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
282
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
283 buf[p] = '\0';
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
284 cd->date = strtol(buf, NULL, 10);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
285
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
286 cd->have_date = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
287
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
288 return TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
289 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
290
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
291 return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
292 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
293
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 static gint cache_sim_read_checksum(FILE *f, char *buf, int s, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296 if (!f || !buf || !cd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298 if (s < 8 || strncmp("Checksum", buf, 8) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 if (fseek(f, - s, SEEK_CUR) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302 char b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 char buf[1024];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 gint p = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306 b = 'X';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 while (b != '[')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 while (b != ']' && p < 1023)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 buf[p] = b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 while (b != '\n')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320 if (fread(&b, sizeof(b), 1, f) != 1) break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 buf[p] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 cd->checksum = strtol(buf, NULL, 10);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326 cd->have_checksum = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334 static gint cache_sim_read_md5sum(FILE *f, char *buf, int s, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
335 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336 if (!f || !buf || !cd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 if (s < 8 || strncmp("MD5sum", buf, 6) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340 if (fseek(f, - s, SEEK_CUR) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 char b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 char buf[64];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 gint p = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 b = 'X';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347 while (b != '[')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 while (b != ']' && p < 63)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354 buf[p] = b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357 while (b != '\n')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 if (fread(&b, sizeof(b), 1, f) != 1) break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
361
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362 buf[p] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 cd->have_md5sum = md5_digest_from_text(buf, cd->md5sum);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
365 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
367
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 static gint cache_sim_read_similarity(FILE *f, char *buf, int s, CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 if (!f || !buf || !cd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 if (s < 11 || strncmp("Similarity", buf, 10) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377 if (strncmp("Grid[32 x 32]", buf + 10, 13) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 if (fseek(f, - s, SEEK_CUR) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381 char b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 guint8 pixel_buf[3];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383 ImageSimilarityData *sd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 gint x, y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 b = 'X';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 while (b != '=')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392 if (cd->sim)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 /* use current sim that may already contain data we will not touch here */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 sd = cd->sim;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 cd->sim = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 cd->similarity = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 sd = image_sim_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 for (y = 0; y < 32; y++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 gint s = y * 32;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407 for (x = 0; x < 32; x++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 if (fread(&pixel_buf, sizeof(pixel_buf), 1, f) != 1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411 image_sim_free(sd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414 sd->avg_r[s + x] = pixel_buf[0];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 sd->avg_g[s + x] = pixel_buf[1];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 sd->avg_b[s + x] = pixel_buf[2];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 if (fread(&b, sizeof(b), 1, f) == 1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422 if (b != '\n') fseek(f, -1, SEEK_CUR);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425 cd->sim = sd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 cd->sim->filled = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 cd->similarity = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
435 #define CACHE_LOAD_LINE_NOISE 8
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
436
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 CacheData *cache_sim_data_load(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 FILE *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440 CacheData *cd = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 char buf[32];
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
442 gint success = CACHE_LOAD_LINE_NOISE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 f = fopen(pathl, "r");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 if (!f) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 cd = cache_sim_data_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454 cd->path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 if (fread(&buf, sizeof(char), 9, f) != 9 ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 strncmp(buf, "SIMcache", 8) != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 if (debug) printf("%s is not a cache file\n", cd->path);
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
460 success = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
463 while (success > 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 int s;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 s = fread(&buf, sizeof(char), sizeof(buf), f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
468 if (s < 1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 {
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
470 success = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 if (!cache_sim_read_comment(f, buf, s, cd) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475 !cache_sim_read_dimensions(f, buf, s, cd) &&
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
476 !cache_sim_read_date(f, buf, s, cd) &&
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477 !cache_sim_read_checksum(f, buf, s, cd) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478 !cache_sim_read_md5sum(f, buf, s, cd) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479 !cache_sim_read_similarity(f, buf, s, cd))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 {
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
481 if (!cache_sim_read_skipline(f, s))
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
482 {
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
483 success = 0;
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
484 }
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
485 else
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
486 {
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
487 success--;
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
488 }
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
489 }
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
490 else
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
491 {
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
492 success = CACHE_LOAD_LINE_NOISE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497 fclose(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498
39
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
499 if (!cd->dimensions &&
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
500 !cd->have_date &&
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
501 !cd->have_checksum &&
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
502 !cd->have_md5sum &&
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
503 !cd->similarity)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
504 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505 cache_sim_data_free(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 cd = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 return cd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
513 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
514 * sim cache setting
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
516 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
517
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518 void cache_sim_data_set_dimensions(CacheData *cd, gint w, gint h)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520 if (!cd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 cd->width = w;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523 cd->height = h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524 cd->dimensions = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
527 void cache_sim_data_set_date(CacheData *cd, time_t date)
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
528 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
529 if (!cd) return;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
530
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
531 cd->date = date;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
532 cd->have_date = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
533 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
534
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
535 void cache_sim_data_set_checksum(CacheData *cd, long checksum)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
537 if (!cd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539 cd->checksum = checksum;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540 cd->have_checksum = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 void cache_sim_data_set_md5sum(CacheData *cd, guchar digest[16])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
545 gint i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547 if (!cd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
549 for (i = 0; i < 16; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
550 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 cd->md5sum[i] = digest[i];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 cd->have_md5sum = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556 void cache_sim_data_set_similarity(CacheData *cd, ImageSimilarityData *sd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
557 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558 if (!cd || !sd || !sd->filled) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560 if (!cd->sim) cd->sim = image_sim_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562 memcpy(cd->sim->avg_r, sd->avg_r, 1024);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 memcpy(cd->sim->avg_g, sd->avg_g, 1024);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564 memcpy(cd->sim->avg_b, sd->avg_b, 1024);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
565 cd->sim->filled = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567 cd->similarity = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
569
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
570 gint cache_sim_data_filled(ImageSimilarityData *sd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572 if (!sd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
573 return sd->filled;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
578 * cache path location utils
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
581
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
582 /* warning: this func modifies path string contents!, on fail it is set to fail point */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 gint cache_ensure_dir_exists(gchar *path, mode_t mode)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
584 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
585 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
586
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
587 if (!isdir(path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
589 gchar *p = path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
590 while (p[0] != '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
591 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
592 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
593 if (p[0] == '/' || p[0] == '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
594 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
595 gint end = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
596 if (p[0] != '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
597 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
598 p[0] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
599 end = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
600 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 if (!isdir(path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
603 if (debug) printf("creating sub dir:%s\n", path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
604 if (!mkdir_utf8(path, mode))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
605 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
606 printf("create dir failed: %s\n", path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
608 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
609 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 if (!end) p[0] = '/';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
611 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
612 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
614 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
615 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
616
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
617 static void cache_path_parts(CacheType type,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 const gchar **cache_rc, const gchar **cache_local, const gchar **cache_ext)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
619 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620 switch (type)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622 case CACHE_TYPE_THUMB:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623 *cache_rc = GQVIEW_CACHE_RC_THUMB;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
624 *cache_local = GQVIEW_CACHE_LOCAL_THUMB;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
625 *cache_ext = GQVIEW_CACHE_EXT_THUMB;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
626 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
627 case CACHE_TYPE_SIM:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
628 *cache_rc = GQVIEW_CACHE_RC_THUMB;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
629 *cache_local = GQVIEW_CACHE_LOCAL_THUMB;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
630 *cache_ext = GQVIEW_CACHE_EXT_SIM;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
631 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
632 case CACHE_TYPE_METADATA:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
633 *cache_rc = GQVIEW_CACHE_RC_METADATA;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
634 *cache_local = GQVIEW_CACHE_LOCAL_METADATA;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
635 *cache_ext = GQVIEW_CACHE_EXT_METADATA;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
636 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
637 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
638 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
639
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
640 gchar *cache_get_location(CacheType type, const gchar *source, gint include_name, mode_t *mode)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
641 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
642 gchar *path = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643 gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
644 gchar *name = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
645 const gchar *cache_rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
646 const gchar *cache_local;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647 const gchar *cache_ext;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
648
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
649 if (!source) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651 cache_path_parts(type, &cache_rc, &cache_local, &cache_ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
652
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
653 base = remove_level_from_path(source);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
654 if (include_name)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
655 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
656 name = g_strconcat("/", filename_from_path(source), NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
657 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
658 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
659 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
660 cache_ext = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
662
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
663 if (((type != CACHE_TYPE_METADATA && enable_thumb_dirs) ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
664 (type == CACHE_TYPE_METADATA && enable_metadata_dirs)) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
665 access_file(base, W_OK))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
666 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
667 path = g_strconcat(base, "/", cache_local, name, cache_ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
668 if (mode) *mode = 0775;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
669 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
670
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671 if (!path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673 path = g_strconcat(homedir(), "/", cache_rc, base, name, cache_ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674 if (mode) *mode = 0755;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
675 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677 g_free(base);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678 if (name) g_free(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680 return path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
683 gchar *cache_find_location(CacheType type, const gchar *source)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
684 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
685 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
686 const gchar *name;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
687 gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
688 const gchar *cache_rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
689 const gchar *cache_local;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
690 const gchar *cache_ext;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
691 gint prefer_local;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
692
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
693 if (!source) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
694
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
695 cache_path_parts(type, &cache_rc, &cache_local, &cache_ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
696
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
697 name = filename_from_path(source);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
698 base = remove_level_from_path(source);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
699
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
700 if (type == CACHE_TYPE_METADATA)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
701 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
702 prefer_local = enable_metadata_dirs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
703 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
705 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
706 prefer_local = enable_thumb_dirs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
707 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
708
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
709 if (prefer_local)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
710 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
711 path = g_strconcat(base, "/", cache_local, "/", name, cache_ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
712 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
714 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
715 path = g_strconcat(homedir(), "/", cache_rc, source, cache_ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
716 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
717
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
718 if (!isfile(path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
719 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
720 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
721
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
722 /* try the opposite method if not found */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
723 if (!prefer_local)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
724 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
725 path = g_strconcat(base, "/", cache_local, "/", name, cache_ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
726 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
727 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
728 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
729 path = g_strconcat(homedir(), "/", cache_rc, source, cache_ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
731
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
732 if (!isfile(path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
733 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
734 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
735 path = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
737 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
738
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
739 g_free(base);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
740
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
741 return path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
742 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
743
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
744 gint cache_time_valid(const gchar *cache, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
745 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
746 struct stat cache_st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
747 struct stat path_st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
748 gchar *cachel;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
749 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
750 gint ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
751
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
752 if (!cache || !path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
753
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
754 cachel = path_from_utf8(cache);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
755 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
756
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
757 if (stat(cachel, &cache_st) == 0 &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
758 stat(pathl, &path_st) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
759 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
760 if (cache_st.st_mtime == path_st.st_mtime)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
761 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
762 ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
763 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
764 else if (cache_st.st_mtime > path_st.st_mtime)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
765 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
766 struct utimbuf ut;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
767
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
768 ut.actime = ut.modtime = cache_st.st_mtime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
769 if (utime(cachel, &ut) < 0 &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
770 errno == EPERM)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
771 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
772 if (debug) printf("cache permission workaround: %s\n", cachel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
773 ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
774 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
775 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
776 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
777
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
778 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
779 g_free(cachel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
780
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
781 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
782 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
783