예제 #1
0
gboolean copy_vfs (VFSFile * in, VFSFile * out)
{
    if (vfs_fseek (in, 0, SEEK_SET) < 0 || vfs_fseek (out, 0, SEEK_SET) < 0)
        return FALSE;

    gchar * buffer = g_malloc (COPY_BUF);
    gint64 size = 0, readed;

    while ((readed = vfs_fread (buffer, 1, COPY_BUF, in)) > 0)
    {
        if (vfs_fwrite (buffer, 1, readed, out) != readed)
            goto FAILED;

        size += readed;
    }

    if (vfs_ftruncate (out, size) < 0)
        goto FAILED;

    g_free (buffer);
    return TRUE;

FAILED:
    g_free (buffer);
    return FALSE;
}
예제 #2
0
static bool_t id3v24_write_tag (const Tuple * tuple, VFSFile * f)
{
    int version, header_size, data_size, footer_size;
    bool_t syncsafe;
    int64_t offset;

    if (! read_header (f, & version, & syncsafe, & offset, & header_size,
     & data_size, & footer_size))
        return FALSE;

    //read all frames into generic frames;
    GHashTable * dict = g_hash_table_new_full (g_str_hash, g_str_equal,
     (GDestroyNotify) str_unref, (GDestroyNotify) free_frame_list);
    read_all_frames (f, version, syncsafe, data_size, dict);

    //make the new frames from tuple and replace in the dictionary the old frames with the new ones
    add_frameFromTupleStr (tuple, FIELD_TITLE, ID3_TITLE, dict);
    add_frameFromTupleStr (tuple, FIELD_ARTIST, ID3_ARTIST, dict);
    add_frameFromTupleStr (tuple, FIELD_ALBUM, ID3_ALBUM, dict);
    add_frameFromTupleInt (tuple, FIELD_YEAR, ID3_YEAR, dict);
    add_frameFromTupleInt (tuple, FIELD_TRACK_NUMBER, ID3_TRACKNR, dict);
    add_frameFromTupleStr (tuple, FIELD_GENRE, ID3_GENRE, dict);

    char * comment = tuple_get_str (tuple, FIELD_COMMENT);
    add_comment_frame (comment, dict);
    str_unref (comment);

    if (! offset)
    {
        if (! cut_beginning_tag (f, header_size + data_size + footer_size))
            goto ERR;
    }
    else
    {
        if (offset + header_size + data_size + footer_size != vfs_fsize (f))
            goto ERR;
        if (vfs_ftruncate (f, offset))
            goto ERR;
    }

    offset = vfs_fsize (f);

    if (offset < 0 || vfs_fseek (f, offset, SEEK_SET) || ! write_header (f, 0,
     FALSE))
        goto ERR;

    data_size = write_all_frames (f, dict);

    if (! write_header (f, data_size, TRUE) || vfs_fseek (f, offset, SEEK_SET)
     || ! write_header (f, data_size, FALSE))
        goto ERR;

    g_hash_table_destroy (dict);
    return TRUE;

ERR:
    g_hash_table_destroy (dict);
    return FALSE;
}
예제 #3
0
static gboolean id3v24_write_tag (const Tuple * tuple, VFSFile * f)
{
    gint version, header_size, data_size, footer_size;
    gboolean syncsafe;
    gint64 offset;

    if (! read_header (f, & version, & syncsafe, & offset, & header_size,
     & data_size, & footer_size))
        return FALSE;

    //read all frames into generic frames;
    mowgli_dictionary_t * dict = mowgli_dictionary_create (strcasecmp);
    read_all_frames (f, version, syncsafe, data_size, dict);

    //make the new frames from tuple and replace in the dictionary the old frames with the new ones
    add_frameFromTupleStr (tuple, FIELD_TITLE, ID3_TITLE, dict);
    add_frameFromTupleStr (tuple, FIELD_ARTIST, ID3_ARTIST, dict);
    add_frameFromTupleStr (tuple, FIELD_ALBUM, ID3_ALBUM, dict);
    add_frameFromTupleInt (tuple, FIELD_YEAR, ID3_YEAR, dict);
    add_frameFromTupleInt (tuple, FIELD_TRACK_NUMBER, ID3_TRACKNR, dict);
    add_frameFromTupleStr (tuple, FIELD_GENRE, ID3_GENRE, dict);
    add_comment_frame (tuple_get_string (tuple, FIELD_COMMENT, NULL), dict);

    if (! offset)
    {
        if (! cut_beginning_tag (f, header_size + data_size + footer_size))
            goto ERR;
    }
    else
    {
        if (offset + header_size + data_size + footer_size != vfs_fsize (f))
            goto ERR;
        if (vfs_ftruncate (f, offset))
            goto ERR;
    }

    offset = vfs_fsize (f);

    if (offset < 0 || vfs_fseek (f, offset, SEEK_SET) || ! write_header (f, 0,
     FALSE))
        goto ERR;

    data_size = writeAllFramesToFile (f, dict);

    if (! write_header (f, data_size, TRUE) || vfs_fseek (f, offset, SEEK_SET)
     || ! write_header (f, data_size, FALSE))
        goto ERR;

    mowgli_dictionary_destroy (dict, free_frame_cb, NULL);
    return TRUE;

ERR:
    mowgli_dictionary_destroy (dict, free_frame_cb, NULL);
    return FALSE;
}
예제 #4
0
static gboolean update_song_tuple(const Tuple * tuple, VFSFile *file)
{
#if _AUD_PLUGIN_VERSION < 38
#define vfs_get_filename(file)  g_filename_from_uri(file->uri, NULL, NULL)
#define tuple_get_str  tuple_get_string
#define str_unref(s)
	const char *s;
#else
	char *s;
#endif
	/* read file */
	const char *filename = vfs_get_filename(file);
	unsigned char module[ASAPInfo_MAX_MODULE_LENGTH];
	int module_len = load_module(filename, file, module);
	ASAPInfo *info;
	int year;
	ByteWriter bw;
	gboolean ok;
	if (module_len <= 0)
		return FALSE;
	info = ASAPInfo_New();
	if (info == NULL)
		return FALSE;
	if (!ASAPInfo_Load(info, filename, module, module_len)) {
		ASAPInfo_Delete(info);
		return FALSE;
	}

	/* apply new tags */
	s = tuple_get_str(tuple, FIELD_ARTIST, NULL);
	if (s != NULL) {
		if (!ASAPInfo_SetAuthor(info, s)) {
			str_unref(s);
			ASAPInfo_Delete(info);
			return FALSE;
		}
		str_unref(s);
	}
	else
		ASAPInfo_SetAuthor(info, "");
	s = tuple_get_str(tuple, FIELD_TITLE, NULL);
	if (s != NULL) {
		if (!ASAPInfo_SetTitle(info, s)) {
			str_unref(s);
			ASAPInfo_Delete(info);
			return FALSE;
		}
		str_unref(s);
	}
	else
		ASAPInfo_SetTitle(info, "");
	year = tuple_get_int(tuple, FIELD_YEAR, NULL);
	if (year == 0)
		year = -1;
	/* check if year changed so that we don't lose other date parts */
	if (year != ASAPInfo_GetYear(info)) {
		if (year <= 0)
			ASAPInfo_SetDate(info, "");
		else {
			char d[16];
			sprintf(d, "%d", year);
			ASAPInfo_SetDate(info, d);
		}
	}

	/* write file */
	vfs_rewind(file);
	bw.obj = file;
	bw.func = write_byte;
	ok = ASAPWriter_Write(filename, bw, info, module, module_len, TRUE) && vfs_ftruncate(file, vfs_ftell(file)) == 0;
	ASAPInfo_Delete(info);
	return ok;
}