All pastes #737167 Raw Edit

Someone

public text v1 · immutable
·published 2007-10-15 04:58 UTC
rendered paste body
std::string GetTorrentName( std::string filename )
{
	FILE *file = fopen( filename.c_str(), "rb" );

	if( file == NULL )
	{
		return "";
	}

	fseek( file, 0, SEEK_END );
	unsigned int size = ftell( file );
	rewind( file );
	char *content = new char[size];
	fread( content, 1, size, file );
	fclose( file );

	std::string data( content, size );
	delete content;

	std::string::size_type offset = 1;
	std::string::size_type sep = 0;

	// BIT OF A HACK TO GET STRAIGHT TO THE FILENAME
	// SINCE THERE IS NO POINT IN DECODING THE OTHER DATA
	offset = data.find( ":name", offset ) + 5;
	sep = data.find( ":", offset );
	size = atoi( data.substr( offset, sep - offset ).c_str() );
	offset = sep + 1;

	return data.substr( offset, size );
}