annotate src/cache.c @ 856:ff15a32ad17f

Only define ExifOrientationType if GQ_BUILD is not defined since it is already defined in exif.h.
author zas_
date Thu, 26 Jun 2008 11:48:40 +0000
parents e6ebae313d46
children 4fe8f9656107
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
475
48c8e49b571c updated copyright in source files
nadvornik
parents: 446
diff changeset
4 * Copyright (C) 2008 The Geeqie Team
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 * 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
11 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 196
diff changeset
13 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14 #include "cache.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16 #include "md5-util.h"
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
17 #include "secure_save.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
18 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20 #include <utime.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21 #include <errno.h>
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 /*
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 * Cache data file format:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27 *-------------------------------------------------------------------
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 333
diff changeset
28 *
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
29 * SIMcache
535
8123d713dd3f Typo fix.
zas_
parents: 517
diff changeset
30 * #comment
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31 * Dimensions=[<width> x <height>]
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
32 * 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
33 * Checksum=[<value>]
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34 * MD5sum=[<32 character ascii text digest>]
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 * SimilarityGrid[32 x 32]=<3072 bytes of data (1024 pixels in RGB format, 1 pixel is 24bits)>
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 333
diff changeset
36 *
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 333
diff changeset
37 *
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38 * 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
39 * Comment lines starting with a # are ignored up to a new line.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40 * All data lines should end with a new line char.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 * Format is very strict, data must begin with the char immediately following '='.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 * Currently SimilarityGrid is always assumed to be 32 x 32 RGB.
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 /*
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 * sim cache data
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 */
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 *cache_sim_data_new(void)
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 CacheData *cd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56 cd = g_new0(CacheData, 1);
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
57 cd->date = -1;
9
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 return cd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 }
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 void cache_sim_data_free(CacheData *cd)
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 if (!cd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66 g_free(cd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67 image_sim_free(cd->sim);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68 g_free(cd);
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 /*
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 * sim cache write
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 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
77 static gint cache_sim_write_dimensions(SecureSaveInfo *ssi, CacheData *cd)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78 {
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
79 if (!cd || !cd->dimensions) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
81 secure_fprintf(ssi, "Dimensions=[%d x %d]\n", cd->width, cd->height);
9
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 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
86 static gint cache_sim_write_date(SecureSaveInfo *ssi, CacheData *cd)
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
87 {
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
88 if (!cd || !cd->have_date) return FALSE;
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
89
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
90 secure_fprintf(ssi, "Date=[%ld]\n", cd->date);
37
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 return TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
93 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
94
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
95 static gint cache_sim_write_checksum(SecureSaveInfo *ssi, CacheData *cd)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 {
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
97 if (!cd || !cd->have_checksum) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
99 secure_fprintf(ssi, "Checksum=[%ld]\n", cd->checksum);
9
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 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
104 static gint cache_sim_write_md5sum(SecureSaveInfo *ssi, CacheData *cd)
9
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 gchar *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
108 if (!cd || !cd->have_md5sum) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110 text = md5_digest_to_text(cd->md5sum);
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
111 secure_fprintf(ssi, "MD5sum=[%s]\n", text);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112 g_free(text);
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 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
117 static gint cache_sim_write_similarity(SecureSaveInfo *ssi, CacheData *cd)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 {
539
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
119 guint x, y;
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
120 guint8 buf[3 * 32];
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121
539
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
122 if (!cd || !cd->similarity || !cd->sim || !cd->sim->filled) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123
539
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
124 secure_fprintf(ssi, "SimilarityGrid[32 x 32]=");
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
125 for (y = 0; y < 32; y++)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 {
539
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
127 guint s = y * 32;
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
128 guint8 *avg_r = &cd->sim->avg_r[s];
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
129 guint8 *avg_g = &cd->sim->avg_g[s];
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
130 guint8 *avg_b = &cd->sim->avg_b[s];
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
131 guint n = 0;
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
132
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
133 for (x = 0; x < 32; x++)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134 {
539
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
135 buf[n++] = avg_r[x];
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
136 buf[n++] = avg_g[x];
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
137 buf[n++] = avg_b[x];
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139
539
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
140 secure_fwrite(buf, sizeof(buf), 1, ssi);
9
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
539
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
143 secure_fputc(ssi, '\n');
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
144
58b7c38d5a5b cache_sim_write_similarity(): cleanup and simplification.
zas_
parents: 538
diff changeset
145 return TRUE;
9
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 gint cache_sim_data_save(CacheData *cd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149 {
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
150 SecureSaveInfo *ssi;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
152
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 if (!cd || !cd->path) return FALSE;
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 pathl = path_from_utf8(cd->path);
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
156 ssi = secure_open(pathl);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
159 if (!ssi)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
161 log_printf("Unable to save sim cache data: %s\n", cd->path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
165 secure_fprintf(ssi, "SIMcache\n#%s %s\n", PACKAGE, VERSION);
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
166 cache_sim_write_dimensions(ssi, cd);
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
167 cache_sim_write_date(ssi, cd);
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
168 cache_sim_write_checksum(ssi, cd);
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
169 cache_sim_write_md5sum(ssi, cd);
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
170 cache_sim_write_similarity(ssi, cd);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
172 if (secure_close(ssi))
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
173 {
694
a3218946bd2d Sort out log_printf() vs printf_term() mix up.
zas_
parents: 673
diff changeset
174 log_printf(_("error saving sim cache data: %s\nerror: %s\n"), cd->path,
538
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
175 secsave_strerror(secsave_errno));
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
176 return FALSE;
d0279926efea Use secure_save stuff to write .sim files.
zas_
parents: 535
diff changeset
177 }
9
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 return TRUE;
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
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 * sim cache read
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
188 static gint cache_sim_read_skipline(FILE *f, gint s)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 {
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
190 if (!f) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
192 if (fseek(f, 0 - s, SEEK_CUR) == 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 {
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
194 gchar b;
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
195 while (fread(&b, sizeof(b), 1, f) == 1)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 if (b == '\n') return TRUE;
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 TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
203 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
205 static gint cache_sim_read_comment(FILE *f, gchar *buf, gint s, CacheData *cd)
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
206 {
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
207 if (!f || !buf || !cd) return FALSE;
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
208
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
209 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
210
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
211 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
212 }
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
213
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
214 static gint cache_sim_read_dimensions(FILE *f, gchar *buf, gint s, CacheData *cd)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 if (!f || !buf || !cd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 if (s < 10 || strncmp("Dimensions", buf, 10) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220 if (fseek(f, - s, SEEK_CUR) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 {
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
222 gchar b;
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
223 gchar buf[1024];
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
224 gsize p = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 gint w, h;
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 b = 'X';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 while (b != '[')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 }
540
d4fe3a947929 Use sizeof() instead of hardcoded buffer sizes.
zas_
parents: 539
diff changeset
232 while (b != ']' && p < sizeof(buf) - 1)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 buf[p] = b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 p++;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239 while (b != '\n')
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 if (fread(&b, sizeof(b), 1, f) != 1) break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242 }
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 buf[p] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245 if (sscanf(buf, "%d x %d", &w, &h) != 2) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 cd->width = w;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248 cd->height = h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 cd->dimensions = TRUE;
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 TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
257 static gint cache_sim_read_date(FILE *f, gchar *buf, gint s, CacheData *cd)
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
258 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
259 if (!f || !buf || !cd) return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
260
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
261 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
262
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
263 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
264 {
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
265 gchar b;
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
266 gchar buf[1024];
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
267 gsize p = 0;
37
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 b = 'X';
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
270 while (b != '[')
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
271 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
272 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
273 }
540
d4fe3a947929 Use sizeof() instead of hardcoded buffer sizes.
zas_
parents: 539
diff changeset
274 while (b != ']' && p < sizeof(buf) - 1)
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
275 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
276 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
277 buf[p] = b;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
278 p++;
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
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
281 while (b != '\n')
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 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
284 }
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 buf[p] = '\0';
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
287 cd->date = strtol(buf, NULL, 10);
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
288
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
289 cd->have_date = TRUE;
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 TRUE;
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
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
294 return FALSE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
295 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
296
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
297 static gint cache_sim_read_checksum(FILE *f, gchar *buf, gint s, CacheData *cd)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 if (!f || !buf || !cd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 if (s < 8 || strncmp("Checksum", buf, 8) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 if (fseek(f, - s, SEEK_CUR) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 {
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
305 gchar b;
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
306 gchar buf[1024];
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
307 gsize p = 0;
9
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 b = 'X';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 while (b != '[')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313 }
540
d4fe3a947929 Use sizeof() instead of hardcoded buffer sizes.
zas_
parents: 539
diff changeset
314 while (b != ']' && p < sizeof(buf) - 1)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317 buf[p] = b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 p++;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321 while (b != '\n')
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 if (fread(&b, sizeof(b), 1, f) != 1) break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 }
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 buf[p] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 cd->checksum = strtol(buf, NULL, 10);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329 cd->have_checksum = TRUE;
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 TRUE;
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 return FALSE;
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
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
337 static gint cache_sim_read_md5sum(FILE *f, gchar *buf, gint s, CacheData *cd)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339 if (!f || !buf || !cd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 if (s < 8 || strncmp("MD5sum", buf, 6) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 if (fseek(f, - s, SEEK_CUR) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 {
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
345 gchar b;
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
346 gchar buf[64];
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
347 gsize p = 0;
9
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 b = 'X';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 while (b != '[')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 }
540
d4fe3a947929 Use sizeof() instead of hardcoded buffer sizes.
zas_
parents: 539
diff changeset
354 while (b != ']' && p < sizeof(buf) - 1)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357 buf[p] = b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 while (b != '\n')
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 if (fread(&b, sizeof(b), 1, f) != 1) break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 }
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 buf[p] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 cd->have_md5sum = md5_digest_from_text(buf, cd->md5sum);
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 TRUE;
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 return FALSE;
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
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
374 static gint cache_sim_read_similarity(FILE *f, gchar *buf, gint s, CacheData *cd)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 if (!f || !buf || !cd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378 if (s < 11 || strncmp("Similarity", buf, 10) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 if (strncmp("Grid[32 x 32]", buf + 10, 13) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 if (fseek(f, - s, SEEK_CUR) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383 {
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
384 gchar b;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 guint8 pixel_buf[3];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 ImageSimilarityData *sd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 gint x, y;
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 b = 'X';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390 while (b != '=')
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 (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 if (cd->sim)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 /* 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
398 sd = cd->sim;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 cd->sim = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 cd->similarity = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 else
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 sd = image_sim_new();
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407 for (y = 0; y < 32; y++)
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 gint s = y * 32;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 for (x = 0; x < 32; x++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 if (fread(&pixel_buf, sizeof(pixel_buf), 1, f) != 1)
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 image_sim_free(sd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 sd->avg_r[s + x] = pixel_buf[0];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 sd->avg_g[s + x] = pixel_buf[1];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 sd->avg_b[s + x] = pixel_buf[2];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 }
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 if (fread(&b, sizeof(b), 1, f) == 1)
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 if (b != '\n') fseek(f, -1, SEEK_CUR);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 cd->sim = sd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 cd->sim->filled = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 cd->similarity = TRUE;
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 TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
438 #define CACHE_LOAD_LINE_NOISE 8
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
439
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440 CacheData *cache_sim_data_load(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442 FILE *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443 CacheData *cd = NULL;
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
444 gchar buf[32];
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
445 gint success = CACHE_LOAD_LINE_NOISE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 f = fopen(pathl, "r");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454 if (!f) return NULL;
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 cd = cache_sim_data_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 cd->path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
459 if (fread(&buf, sizeof(gchar), 9, f) != 9 ||
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460 strncmp(buf, "SIMcache", 8) != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 {
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
462 DEBUG_1("%s is not a cache file", cd->path);
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
463 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
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
466 while (success > 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 {
734
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
468 gint s;
e6ebae313d46 Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents: 726
diff changeset
469 s = fread(&buf, sizeof(gchar), sizeof(buf), f);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
470
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471 if (s < 1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 {
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
473 success = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477 if (!cache_sim_read_comment(f, buf, s, cd) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478 !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
479 !cache_sim_read_date(f, buf, s, cd) &&
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 !cache_sim_read_checksum(f, buf, s, cd) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 !cache_sim_read_md5sum(f, buf, s, cd) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 !cache_sim_read_similarity(f, buf, s, cd))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483 {
65
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
484 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
485 {
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
486 success = 0;
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
487 }
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
488 else
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 success--;
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 }
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
493 else
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
494 {
322bb41c9b9e Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
gqview
parents: 39
diff changeset
495 success = CACHE_LOAD_LINE_NOISE;
9
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 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500 fclose(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501
39
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
502 if (!cd->dimensions &&
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
503 !cd->have_date &&
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
504 !cd->have_checksum &&
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
505 !cd->have_md5sum &&
64068b1bab89 Thu Apr 14 10:44:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 37
diff changeset
506 !cd->similarity)
9
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 cache_sim_data_free(cd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 cd = NULL;
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 return cd;
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
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 * sim cache setting
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518 *-------------------------------------------------------------------
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521 void cache_sim_data_set_dimensions(CacheData *cd, gint w, gint h)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523 if (!cd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 cd->width = w;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526 cd->height = h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
527 cd->dimensions = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529
37
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
530 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
531 {
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
532 if (!cd) return;
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 cd->date = date;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
535 cd->have_date = TRUE;
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
536 }
67ba4381497e Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
537
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 void cache_sim_data_set_checksum(CacheData *cd, long checksum)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540 if (!cd) return;
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 cd->checksum = checksum;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 cd->have_checksum = TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546 void cache_sim_data_set_md5sum(CacheData *cd, guchar digest[16])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548 gint i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
549
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
550 if (!cd) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552 for (i = 0; i < 16; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 cd->md5sum[i] = digest[i];
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 cd->have_md5sum = TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559 void cache_sim_data_set_similarity(CacheData *cd, ImageSimilarityData *sd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561 if (!cd || !sd || !sd->filled) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 if (!cd->sim) cd->sim = image_sim_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
565 memcpy(cd->sim->avg_r, sd->avg_r, 1024);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566 memcpy(cd->sim->avg_g, sd->avg_g, 1024);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567 memcpy(cd->sim->avg_b, sd->avg_b, 1024);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568 cd->sim->filled = TRUE;
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 cd->similarity = TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
573 gint cache_sim_data_filled(ImageSimilarityData *sd)
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 if (!sd) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 return sd->filled;
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
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 * cache path location utils
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
582 *-------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 */
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 /* 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
586 gint cache_ensure_dir_exists(gchar *path, mode_t mode)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
587 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
589
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
590 if (!isdir(path))
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 gchar *p = path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
593 while (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 p++;
726
a1dcef8cd1ae Use G_DIR_SEPARATOR where applicable.
zas_
parents: 706
diff changeset
596 if (p[0] == G_DIR_SEPARATOR || p[0] == '\0')
9
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 gint end = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
599 if (p[0] != '\0')
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 p[0] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602 end = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
603 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
604 if (!isdir(path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
605 {
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
606 DEBUG_1("creating sub dir:%s", path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 if (!mkdir_utf8(path, mode))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
608 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
609 log_printf("create dir failed: %s\n", path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 return FALSE;
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 }
726
a1dcef8cd1ae Use G_DIR_SEPARATOR where applicable.
zas_
parents: 706
diff changeset
613 if (!end) p[0] = G_DIR_SEPARATOR;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
614 }
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 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 }
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 static void cache_path_parts(CacheType type,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621 const gchar **cache_rc, const gchar **cache_local, const gchar **cache_ext)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623 switch (type)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
624 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
625 case CACHE_TYPE_THUMB:
283
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
626 *cache_rc = GQ_CACHE_RC_THUMB;
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
627 *cache_local = GQ_CACHE_LOCAL_THUMB;
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
628 *cache_ext = GQ_CACHE_EXT_THUMB;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
629 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
630 case CACHE_TYPE_SIM:
283
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
631 *cache_rc = GQ_CACHE_RC_THUMB;
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
632 *cache_local = GQ_CACHE_LOCAL_THUMB;
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
633 *cache_ext = GQ_CACHE_EXT_SIM;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
634 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
635 case CACHE_TYPE_METADATA:
283
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
636 *cache_rc = GQ_CACHE_RC_METADATA;
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
637 *cache_local = GQ_CACHE_LOCAL_METADATA;
e213fb025621 GQVIEW_* -> GQ_*
zas_
parents: 281
diff changeset
638 *cache_ext = GQ_CACHE_EXT_METADATA;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
639 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
640 }
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643 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
644 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
645 gchar *path = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
646 gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647 gchar *name = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
648 const gchar *cache_rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
649 const gchar *cache_local;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650 const gchar *cache_ext;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
652 if (!source) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
653
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
654 cache_path_parts(type, &cache_rc, &cache_local, &cache_ext);
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 base = remove_level_from_path(source);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
657 if (include_name)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
658 {
705
a7009e2c4a0b Use g_build_filename().
zas_
parents: 694
diff changeset
659 name = g_strconcat(filename_from_path(source), cache_ext, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
660 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661
333
767b53cd9ab7 Rename thumbnails related options.
zas_
parents: 318
diff changeset
662 if (((type != CACHE_TYPE_METADATA && options->thumbnails.cache_into_dirs) ||
318
b16b9b8979e5 Add a new struct ConfOptions to handle options.
zas_
parents: 283
diff changeset
663 (type == CACHE_TYPE_METADATA && options->enable_metadata_dirs)) &&
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
664 access_file(base, W_OK))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
665 {
705
a7009e2c4a0b Use g_build_filename().
zas_
parents: 694
diff changeset
666 path = g_build_filename(base, cache_local, name, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
667 if (mode) *mode = 0775;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
668 }
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 if (!path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671 {
705
a7009e2c4a0b Use g_build_filename().
zas_
parents: 694
diff changeset
672 path = g_build_filename(homedir(), cache_rc, base, name, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673 if (mode) *mode = 0755;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674 }
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 g_free(base);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677 if (name) g_free(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679 return path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681
706
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
682 static gchar *cache_build_path_local(const gchar *source, const gchar *cache_local, const gchar *cache_ext)
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
683 {
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
684 gchar *path;
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
685 gchar *base = remove_level_from_path(source);
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
686 gchar *name = g_strconcat(filename_from_path(source), cache_ext, NULL);
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
687 path = g_build_filename(base, cache_local, name, NULL);
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
688 g_free(name);
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
689 g_free(base);
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
690
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
691 return path;
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
692 }
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
693
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
694 static gchar *cache_build_path_rc(const gchar *source, const gchar *cache_rc, const gchar *cache_ext)
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
695 {
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
696 gchar *path;
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
697 gchar *name = g_strconcat(source, cache_ext, NULL);
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
698 path = g_build_filename(homedir(), cache_rc, name, NULL);
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
699 g_free(name);
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
700
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
701 return path;
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
702 }
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
703
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704 gchar *cache_find_location(CacheType type, const gchar *source)
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 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
707 const gchar *cache_rc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
708 const gchar *cache_local;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
709 const gchar *cache_ext;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
710 gint prefer_local;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
711
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
712 if (!source) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
714 cache_path_parts(type, &cache_rc, &cache_local, &cache_ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
715
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
716 if (type == CACHE_TYPE_METADATA)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
717 {
318
b16b9b8979e5 Add a new struct ConfOptions to handle options.
zas_
parents: 283
diff changeset
718 prefer_local = options->enable_metadata_dirs;
9
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 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
721 {
333
767b53cd9ab7 Rename thumbnails related options.
zas_
parents: 318
diff changeset
722 prefer_local = options->thumbnails.cache_into_dirs;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
723 }
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 if (prefer_local)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
726 {
706
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
727 path = cache_build_path_local(source, cache_local, cache_ext);
9
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 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730 {
706
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
731 path = cache_build_path_rc(source, cache_rc, cache_ext);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
732 }
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 if (!isfile(path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
735 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736 g_free(path);
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 /* try the opposite method if not found */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
739 if (!prefer_local)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
740 {
706
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
741 path = cache_build_path_local(source, cache_local, cache_ext);
9
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 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
744 {
706
066b90ad9925 cache_find_location(): use g_build_filename() and move redundant code to new functions.
zas_
parents: 705
diff changeset
745 path = cache_build_path_rc(source, cache_rc, cache_ext);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
746 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
747
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
748 if (!isfile(path))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
749 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
750 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
751 path = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
752 }
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
755 return 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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
758 gint cache_time_valid(const gchar *cache, const gchar *path)
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 struct stat cache_st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
761 struct stat path_st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
762 gchar *cachel;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
763 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
764 gint ret = FALSE;
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 if (!cache || !path) return FALSE;
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 cachel = path_from_utf8(cache);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
769 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
770
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
771 if (stat(cachel, &cache_st) == 0 &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
772 stat(pathl, &path_st) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
773 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
774 if (cache_st.st_mtime == path_st.st_mtime)
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 ret = TRUE;
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 else if (cache_st.st_mtime > path_st.st_mtime)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
779 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
780 struct utimbuf ut;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
781
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
782 ut.actime = ut.modtime = cache_st.st_mtime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
783 if (utime(cachel, &ut) < 0 &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
784 errno == EPERM)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
785 {
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
786 DEBUG_1("cache permission workaround: %s", cachel);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
787 ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
788 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
789 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
790 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
791
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
792 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
793 g_free(cachel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
794
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
795 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
796 }