Beispiel #1
0
void tag_processor_id3v2::g_remove_ex(tag_write_callback & p_callback,const service_ptr_t<file> & p_file,t_uint64 & p_size_removed,abort_callback & p_abort)
{
	p_file->ensure_seekable();

	t_filesize len;
	
	len = p_file->get_size(p_abort);

	if (len == filesize_invalid) throw exception_io_no_length();
	
	p_file->seek(0,p_abort);
	
	t_uint64 offset;
	g_multiskip(p_file,offset,p_abort);
	
	if (offset>0 && offset<len)
	{
		len-=offset;
		service_ptr_t<file> temp;
		if (p_callback.open_temp_file(temp,p_abort)) {
			file::g_transfer_object(p_file,temp,len,p_abort);
		} else {
			if (len > 16*1024*1024) filesystem::g_open_temp(temp,p_abort);
			else filesystem::g_open_tempmem(temp,p_abort);
			file::g_transfer_object(p_file,temp,len,p_abort);
			p_file->seek(0,p_abort);
			p_file->set_eof(p_abort);
			temp->seek(0,p_abort);
			file::g_transfer_object(temp,p_file,len,p_abort);
		}
	}
	p_size_removed = offset;
}
Beispiel #2
0
void file::g_transfer_file(const service_ptr_t<file> & p_from,const service_ptr_t<file> & p_to,abort_callback & p_abort) {
	t_filesize length = p_from->get_size_ex(p_abort);
	p_from->seek(0,p_abort);
	p_to->seek(0,p_abort);
	p_to->set_eof(p_abort);
	if (length > 0) {
		g_transfer_object(p_from,p_to,length,p_abort);
	}
}
Beispiel #3
0
static void load_id666(service_ptr_t<file> & p_file, LPID666TAG lpTag, abort_callback & p_abort)//must be seeked to correct spot before calling
{
	t_uint8 szBuf[4];
	p_file->read_object( &szBuf, 4, p_abort );

	if( ! memcmp( szBuf, xid6_signature, 4 ) )
	{
		t_uint32 tag_size;
		p_file->read_lendian_t( tag_size, p_abort );

		t_filesize offset = p_file->get_position( p_abort );

		service_ptr_t< reader_limited > m_file = new service_impl_t< reader_limited >;
		m_file->init( p_file, offset, offset + tag_size, p_abort );

		service_ptr_t<file> p_file = m_file.get_ptr();

		try
		{
			parse_id666( p_file, lpTag, false, p_abort );
		}
		catch ( const exception_io_data & )
		{
			p_file->seek( 0, p_abort );

			memset( lpTag, 0, sizeof( *lpTag ) );

			parse_id666( p_file, lpTag, true, p_abort );
		}
	}
	else throw exception_tag_not_found();
}
Beispiel #4
0
void tag_processor_id3v2::g_skip_at(const service_ptr_t<file> & p_file,t_filesize p_base, t_filesize & p_size_skipped,abort_callback & p_abort) {

	unsigned char  tmp[10];

	p_file->seek ( p_base, p_abort );

	if (p_file->read( tmp, sizeof(tmp),  p_abort) != sizeof(tmp))  {
		p_file->seek ( p_base, p_abort );
		p_size_skipped = 0;
		return;
	}

	if ( 
		0 != memcmp ( tmp, "ID3", 3) ||
		( tmp[5] & 0x0F ) != 0 || 
		((tmp[6] | tmp[7] | tmp[8] | tmp[9]) & 0x80) != 0 
		) {
		p_file->seek ( p_base, p_abort );
		p_size_skipped = 0;
		return;
	}

	int FooterPresent     = tmp[5] & 0x10;

	t_uint32 ret;
	ret  = tmp[6] << 21;
	ret += tmp[7] << 14;
	ret += tmp[8] <<  7;
	ret += tmp[9]      ;
	ret += 10;
	if ( FooterPresent ) ret += 10;

	try {
		p_file->seek ( p_base + ret, p_abort );
	} catch(exception_io_seek_out_of_range) {
		p_file->seek( p_base, p_abort );
		p_size_skipped = 0;
		return;
	}

	p_size_skipped = ret;

}
	void write(const service_ptr_t<file> & p_file,abort_callback & p_abort,const char * p_string,bool is_utf8)
	{
		p_file->seek(0,p_abort);
		p_file->set_eof(p_abort);
		if (is_utf8)
		{
			p_file->write_object(utf8_header,sizeof(utf8_header),p_abort);
			p_file->write_object(p_string,strlen(p_string),p_abort);
		}
		else
		{
#ifdef _WIN32
			pfc::stringcvt::string_ansi_from_utf8 bah(p_string);
			p_file->write_object(bah,bah.length(),p_abort);
#else
            throw exception_io_data();
#endif
		}
	}
Beispiel #6
0
	write_xid6( service_ptr_t<file> & p_file, const file_info & p_info, abort_callback & p_abort )
		: m_file( p_file ), m_abort( p_abort )
	{
		pfc::stringcvt::string_ansi_from_utf8 converter;
		t_filesize offset_tag_start;
		const char * value;
		t_uint32 int32 = 0;

		p_file->seek_ex( 0, file::seek_from_eof, p_abort );

		p_file->write_object( xid6_signature, 4, p_abort );
		p_file->write_object_t( int32, p_abort );

		offset_tag_start = p_file->get_position( p_abort );

		value = p_info.meta_get( "title", 0 );
		if ( value )
		{
			converter.convert( value );
			if ( strlen( converter ) > 32 ) write_string( XID_SONG, converter );
		}

		value = p_info.meta_get( "album", 0 );
		if ( value )
		{
			converter.convert( value );
			if ( strlen( converter ) > 32 ) write_string( XID_GAME, converter );
		}

		value = p_info.meta_get( "artist", 0 );
		if ( value )
		{
			converter.convert( value );
			if ( strlen( converter ) > 32 ) write_string( XID_ARTIST, converter );
		}

		value = p_info.meta_get( "dumper", 0 );
		if ( value )
		{
			converter.convert( value );
			if ( strlen( converter ) > 16 ) write_string( XID_DUMPER, converter );
		}

		value = p_info.meta_get( "comment", 0 );
		if ( value )
		{
			converter.convert( value );
			if ( strlen( converter ) > 32 ) write_string( XID_CMNTS, converter );
		}

		value = p_info.meta_get( "OST", 0 );
		if ( value )
		{
			converter.convert( value );
			write_string( XID_OST, converter );
		}

		value = p_info.meta_get( "discnumber", 0 );
		if ( value )
		{
			char * end;
			unsigned disc = strtoul( value, &end, 10 );
			if ( !*end && disc > 0 && disc <= 9 )
				write_data( XID_DISC, disc );
		}

		value = p_info.meta_get( "tracknumber", 0 );
		if ( value )
		{
			char * end;
			unsigned track = strtoul( value, &end, 10 );
			if ( track > 0 && track < 100 )
				write_data( XID_TRACK, track * 0x100 + *end );
		}

		value = p_info.meta_get( "copyright", 0 );
		if ( value )
		{
			char * end;
			unsigned copyright_year = strtoul( value, &end, 10 );
			if ( copyright_year > 0 && copyright_year < 65536 )
				write_data( XID_COPY, copyright_year );

			while ( *end && *end == ' ' ) end++;
			if ( *end )
			{
				converter.convert( end );
				write_string( XID_PUB, converter );
			}
		}

		value = p_info.info_get( field_length );
		if ( value )
		{
			char * end;
			unsigned length = strtoul( value, &end, 10 );
			if ( !*end && length > 0 && ( length % 1000 || length > 999000 ) )
				write_int( XID_INTRO, length * 64 );
		}

		value = p_info.info_get( field_fade );
		if ( value )
		{
			char * end;
			unsigned fade = strtoul( value, &end, 10 );
			if ( !*end && fade > 99999 )
				write_int( XID_FADE, fade * 64 );
		}

		t_filesize offset = p_file->get_position( p_abort );
		offset -= offset_tag_start;
		if ( offset > ( 1 << 30 ) ) throw exception_io_data();

		if ( offset )
		{
			int32 = t_uint32( offset );
			p_file->seek( offset_tag_start - 4, p_abort );
			p_file->write_lendian_t( int32, p_abort );
		}
		else
		{
			p_file->seek( offset_tag_start - 8, p_abort );
			p_file->set_eof( p_abort );
		}
	}
Beispiel #7
0
static void write_id666( service_ptr_t<file> & p_file, const file_info & p_info, abort_callback & p_abort )
{
	char buffer[32];
	const char * value;
	pfc::stringcvt::string_ansi_from_utf8 converter;

	p_file->seek( 0x23, p_abort );
	buffer [0] = 26;
	p_file->write_object( buffer, 1, p_abort );

	p_file->seek( offsetof( Spc_Emu::header_t, song ), p_abort );

	memset( buffer, 0, sizeof( buffer ) );
	value = p_info.meta_get( "title", 0 );
	if ( value )
	{
		converter.convert( value );
		strncpy( buffer, converter, 32 );
	}
	p_file->write_object( buffer, 32, p_abort );

	memset( buffer, 0, sizeof( buffer ) );
	value = p_info.meta_get( "album", 0 );
	if ( value )
	{
		converter.convert( value );
		strncpy( buffer, converter, 32 );
	}
	p_file->write_object( buffer, 32, p_abort );

	memset( buffer, 0, 16 );
	value = p_info.meta_get( "dumper", 0 );
	if ( value )
	{
		converter.convert( value );
		strncpy( buffer, converter, 16 );
	}
	p_file->write_object( buffer, 16, p_abort );

	memset( buffer, 0, sizeof( buffer ) );
	value = p_info.meta_get( "comment", 0 );
	if ( value )
	{
		converter.convert( value );
		strncpy( buffer, converter, 32 );
	}
	p_file->write_object( buffer, 32, p_abort );

	memset( buffer, 0, 11 );
	value = p_info.meta_get( "date", 0 );
	if ( value )
	{
		converter.convert( value );
		strncpy( buffer, converter, 11 );
	}
	p_file->write_object( buffer, 11, p_abort );

	memset( buffer, 0, 3 );
	value = p_info.info_get( field_length );
	if ( value )
	{
		size_t length = strlen( value );
		if ( length > 3 )
		{
			length -= 3;
			strncpy( buffer, value, min( 3, length ) );
		}
	}
	p_file->write_object( buffer, 3, p_abort );

	memset( buffer, 0, 5 );
	value = p_info.info_get( field_fade );
	if ( value ) strncpy( buffer, value, 5 );
	p_file->write_object( buffer, 5, p_abort );

	memset( buffer, 0, sizeof( buffer ) );
	value = p_info.meta_get( "artist", 0 );
	if ( value )
	{
		converter.convert( value );
		strncpy( buffer, converter, 32 );
	}
	p_file->write_object( buffer, 32, p_abort );
}