Beispiel #1
0
gboolean cache_sim_data_save(CacheData *cd)
{
	SecureSaveInfo *ssi;
	gchar *pathl;

	if (!cd || !cd->path) return FALSE;

	pathl = path_from_utf8(cd->path);
	ssi = secure_open(pathl);
	g_free(pathl);

	if (!ssi)
		{
		log_printf("Unable to save sim cache data: %s\n", cd->path);
		return FALSE;
		}

	secure_fprintf(ssi, "SIMcache\n#%s %s\n", PACKAGE, VERSION);
	cache_sim_write_dimensions(ssi, cd);
	cache_sim_write_date(ssi, cd);
	cache_sim_write_checksum(ssi, cd);
	cache_sim_write_md5sum(ssi, cd);
	cache_sim_write_similarity(ssi, cd);

	if (secure_close(ssi))
		{
		log_printf(_("error saving sim cache data: %s\nerror: %s\n"), cd->path,
			    secsave_strerror(secsave_errno));
		return FALSE;
		}

	return TRUE;
}
Beispiel #2
0
static gboolean cache_sim_write_similarity(SecureSaveInfo *ssi, CacheData *cd)
{
	guint x, y;
	guint8 buf[3 * 32];

	if (!cd || !cd->similarity || !cd->sim || !cd->sim->filled) return FALSE;

	secure_fprintf(ssi, "SimilarityGrid[32 x 32]=");
	for (y = 0; y < 32; y++)
		{
		guint s = y * 32;
		guint8 *avg_r = &cd->sim->avg_r[s];
		guint8 *avg_g = &cd->sim->avg_g[s];
		guint8 *avg_b = &cd->sim->avg_b[s];
		guint n = 0;
			
		for (x = 0; x < 32; x++)
			{
			buf[n++] = avg_r[x];
			buf[n++] = avg_g[x];
			buf[n++] = avg_b[x];
			}

		secure_fwrite(buf, sizeof(buf), 1, ssi);
		}

	secure_fputc(ssi, '\n');

	return TRUE;
}
Beispiel #3
0
static gboolean cache_sim_write_checksum(SecureSaveInfo *ssi, CacheData *cd)
{
	if (!cd || !cd->have_checksum) return FALSE;

	secure_fprintf(ssi, "Checksum=[%ld]\n", cd->checksum);

	return TRUE;
}
Beispiel #4
0
static gboolean cache_sim_write_date(SecureSaveInfo *ssi, CacheData *cd)
{
	if (!cd || !cd->have_date) return FALSE;

	secure_fprintf(ssi, "Date=[%ld]\n", cd->date);

	return TRUE;
}
Beispiel #5
0
static gboolean cache_sim_write_dimensions(SecureSaveInfo *ssi, CacheData *cd)
{
	if (!cd || !cd->dimensions) return FALSE;

	secure_fprintf(ssi, "Dimensions=[%d x %d]\n", cd->width, cd->height);

	return TRUE;
}
Beispiel #6
0
static gboolean cache_sim_write_md5sum(SecureSaveInfo *ssi, CacheData *cd)
{
	gchar *text;

	if (!cd || !cd->have_md5sum) return FALSE;

	text = md5_digest_to_text(cd->md5sum);
	secure_fprintf(ssi, "MD5sum=[%s]\n", text);
	g_free(text);

	return TRUE;
}
Beispiel #7
0
static gboolean metadata_file_write(gchar *path, const GList *keywords, const gchar *comment)
{
	SecureSaveInfo *ssi;

	ssi = secure_open(path);
	if (!ssi) return FALSE;

	secure_fprintf(ssi, "#%s comment (%s)\n\n", GQ_APPNAME, VERSION);

	secure_fprintf(ssi, "[keywords]\n");
	while (keywords && secsave_errno == SS_ERR_NONE)
		{
		const gchar *word = keywords->data;
		keywords = keywords->next;

		secure_fprintf(ssi, "%s\n", word);
		}
	secure_fputc(ssi, '\n');

	secure_fprintf(ssi, "[comment]\n");
	secure_fprintf(ssi, "%s\n", (comment) ? comment : "");

	secure_fprintf(ssi, "#end\n");

	return (secure_close(ssi) == 0);
}
Beispiel #8
0
static gboolean collection_save_private(CollectionData *cd, const gchar *path)
{
	SecureSaveInfo *ssi;
	GList *work;
	gchar *pathl;

	if (!path && !cd->path) return FALSE;

	if (!path)
		{
		path = cd->path;
		}


	pathl = path_from_utf8(path);
	ssi = secure_open(pathl);
	g_free(pathl);
	if (!ssi)
		{
		log_printf(_("failed to open collection (write) \"%s\"\n"), path);
		return FALSE;
		}

	secure_fprintf(ssi, "%s collection\n", GQ_COLLECTION_MARKER);
	secure_fprintf(ssi, "#created with %s version %s\n", GQ_APPNAME, VERSION);

	collection_update_geometry(cd);
	if (cd->window_read)
		{
		secure_fprintf(ssi, "#geometry: %d %d %d %d\n", cd->window_x, cd->window_y, cd->window_w, cd->window_h);
		}

	work = cd->list;
	while (work && secsave_errno == SS_ERR_NONE)
		{
		CollectInfo *ci = work->data;
		secure_fprintf(ssi, "\"%s\"\n", ci->fd->path);
		work = work->next;
		}

	secure_fprintf(ssi, "#end\n");

	if (secure_close(ssi))
		{
		log_printf(_("error saving collection file: %s\nerror: %s\n"), path,
			    secsave_strerror(secsave_errno));
		return FALSE;
		}

	if (!cd->path || strcmp(path, cd->path) != 0)
		{
		gchar *buf = cd->path;
		cd->path = g_strdup(path);
		path = cd->path;
		g_free(buf);

		g_free(cd->name);
		cd->name = g_strdup(filename_from_path(cd->path));

		collection_path_changed(cd);
		}

	cd->changed = FALSE;

	return TRUE;
}