Exemplo n.º 1
0
static void prepare_for_open(service_ptr_t<input_entry> & p_service,service_ptr_t<file> & p_file,const char * p_path,filesystem::t_open_mode p_open_mode,abort_callback & p_abort,bool p_from_redirect)
{
	if (p_file.is_empty())
	{
		service_ptr_t<filesystem> fs;
		if (filesystem::g_get_interface(fs,p_path)) {
			if (fs->supports_content_types()) {
				fs->open(p_file,p_path,p_open_mode,p_abort);
			}
		}
	}

	if (p_file.is_valid())
	{
		pfc::string8 content_type;
		if (p_file->get_content_type(content_type))
		{
			if (input_entry::g_find_service_by_content_type(p_service,content_type))
				return;
		}
	}

	if (input_entry::g_find_service_by_path(p_service,p_path))
	{
		if (p_from_redirect && p_service->is_redirect()) throw exception_io_unsupported_format();
		return;
	}

	throw exception_io_unsupported_format();
}
Exemplo n.º 2
0
service_ptr input_entry::g_open_from_list(input_entry_list_t const & p_list, const GUID & whatFor, service_ptr_t<file> p_filehint, const char * p_path, abort_callback & p_abort, GUID * outGUID) {
	const t_size count = p_list.get_count();
	if ( count == 0 ) {
		// sanity
		throw exception_io_unsupported_format();
	} else if (count == 1) {
		auto ret = p_list[0]->open(whatFor, p_filehint, p_path, p_abort);
		if ( outGUID != nullptr ) * outGUID = input_get_guid( p_list[0] );
		return ret;
	} else {
		unsigned bad_data_count = 0;
		pfc::string8 bad_data_message;
		for (t_size n = 0; n < count; n++) {
			try {
				auto ret = p_list[n]->open(whatFor, p_filehint, p_path, p_abort);
				if (outGUID != nullptr) * outGUID = input_get_guid(p_list[n]);
				return ret;
			} catch (exception_io_no_handler_for_path) {
				//do nothing, skip over
			} catch (exception_io_unsupported_format) {
				//do nothing, skip over
			} catch (exception_io_data const & e) {
				if (bad_data_count++ == 0) bad_data_message = e.what();
			}
		}
		if (bad_data_count > 1) throw exception_io_data();
		else if (bad_data_count == 0) pfc::throw_exception_with_message<exception_io_data>(bad_data_message);
		else throw exception_io_unsupported_format();
	}
}
Exemplo n.º 3
0
	void open(service_ptr_t<file> p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort) {
		if ( p_reason == input_open_info_write ) {
			throw exception_io_unsupported_format(); // our input does not support retagging.
		}
		m_file = p_filehint; // p_filehint may be null, hence next line
		input_open_file_helper(m_file,p_path,p_reason,p_abort); // if m_file is null, opens file with appropriate privileges for our operation (read/write for writing tags, read-only otherwise).
		if ( m_file->get_size( p_abort ) >= (std::numeric_limits<std::size_t>::max)() ) {
			throw exception_io_unsupported_format();
		}
		std::vector<char> data( static_cast<std::size_t>( m_file->get_size( p_abort ) ) );
		m_file->read( data.data(), data.size(), p_abort );
		try {
			std::map< std::string, std::string > ctls;
			ctls["seek.sync_samples"] = "1";
			mod = new openmpt::module( data, std::clog, ctls );
		} catch ( std::exception & /*e*/ ) {
			throw exception_io_data();
		}
		settings = foo_openmpt_settings();
		mod->set_repeat_count( settings.repeatcount );
		mod->set_render_param( openmpt::module::RENDER_MASTERGAIN_MILLIBEL, settings.mastergain_millibel );
		mod->set_render_param( openmpt::module::RENDER_STEREOSEPARATION_PERCENT, settings.stereoseparation );
		mod->set_render_param( openmpt::module::RENDER_INTERPOLATIONFILTER_LENGTH, settings.interpolationfilterlength );
		mod->set_render_param( openmpt::module::RENDER_VOLUMERAMPING_STRENGTH, settings.ramping );
		mod->ctl_set( "render.resampler.emulate_amiga", settings.use_amiga_resampler ? "1" : "0" );
	}
Exemplo n.º 4
0
	void open(service_ptr_t<file> p_filehint, const char *p_path, t_input_open_reason p_reason, abort_callback &p_abort)
	{
		if (p_reason == input_open_info_write) {
			int len = strlen(p_path);
			if (len < 4 || _stricmp(p_path + len - 4, ".sap") != 0)
				throw exception_io_unsupported_format();
			filename = strdup(p_path);
		}
		if (p_filehint.is_empty())
			filesystem::g_open(p_filehint, p_path, filesystem::open_mode_read, p_abort);
		m_file = p_filehint;
		module_len = m_file->read(module, sizeof(module), p_abort);
		if (!ASAP_Load(asap, p_path, module, module_len))
			throw exception_io_unsupported_format();
	}
Exemplo n.º 5
0
	void decode_initialize(t_uint32 p_subsong, unsigned p_flags, abort_callback &p_abort)
	{
		int duration = get_song_duration(p_subsong, true);
		if (!ASAP_PlaySong(asap, p_subsong, duration))
			throw exception_io_unsupported_format();
		ASAP_MutePokeyChannels(asap, mute_mask);
	}
Exemplo n.º 6
0
	virtual bool open_path_internal(file::ptr p_filehint,const char * path,t_input_open_reason p_reason,abort_callback & p_abort,bool p_from_redirect,bool p_skip_hints) {
		if (p_reason == input_open_info_write) throw exception_io_unsupported_format();//our input does not support retagging.
		try {
			open_path_helper(m_input, p_filehint, path, p_abort, p_from_redirect,p_skip_hints);
		} catch (exception_io_not_found) {
			return false;
		}
		switch_input(m_input, path);
		file_info_impl p_info;
		get_input()->get_info(0, p_info, p_abort);
		m_points.remove_all();
		if (m_by_meta)
		{
			if (p_info.meta_get_count_by_name("LOOPSTART") != 1 ||
				p_info.meta_get_count_by_name("LOOPLENGTH") != 1)
				return false;
		}
		loop_event_point_simple * point = new service_impl_t<loop_event_point_simple>();
		if (m_by_meta)
		{
			m_loopstart = pfc::atoui64_ex(p_info.meta_get("LOOPSTART", 0), ~0);
			m_looplength = pfc::atoui64_ex(p_info.meta_get("LOOPLENGTH", 0), ~0);
		}
		point->from = m_loopstart + m_looplength;
		point->to = m_loopstart;
		m_points.add_item(point);
		switch_points(m_points);
		return true;
	}
Exemplo n.º 7
0
service_ptr input_entry::open(const GUID & whatFor, file::ptr hint, const char * path, abort_callback & aborter) {
	if (whatFor == input_decoder::class_guid) {
		input_decoder::ptr obj;
		open(obj, hint, path, aborter);
		return obj;
	}
	if (whatFor == input_info_reader::class_guid) {
		input_info_reader::ptr obj;
		open(obj, hint, path, aborter);
		return obj;
	}
	if (whatFor == input_info_writer::class_guid) {
		input_info_writer::ptr obj;
		open(obj, hint, path, aborter);
		return obj;
	}
#ifdef FOOBAR2000_DESKTOP
	if ( whatFor == input_stream_info_reader::class_guid ) {
		input_entry_v2::ptr v2;
		if ( v2 &= this ) {
			GUID g = v2->get_guid();
			service_enum_t<input_stream_info_reader_entry> e;
			service_ptr_t<input_stream_info_reader_entry> p;
			while (e.next(p)) {
				if (p->get_guid() == g) {
					return p->open( path, hint, aborter );
				}
			}
		}
		throw exception_io_unsupported_format();
	}
#endif
	uBugCheck();
}
Exemplo n.º 8
0
service_ptr input_entry::g_open(const GUID & whatFor, file::ptr p_filehint, const char * p_path, abort_callback & p_abort, bool p_from_redirect) {

#ifdef FOOBAR2000_DESKTOP

#if FOOBAR2000_TARGET_VERSION >= 79
	return input_manager::get()->open(whatFor, p_filehint, p_path, p_from_redirect, p_abort);
#endif

	{
		input_manager::ptr m;
		service_enum_t<input_manager> e;
		if (e.next(m)) {
			return m->open(whatFor, p_filehint, p_path, p_from_redirect, p_abort);
		}
	}
#endif

	const bool needWriteAcecss = !!(whatFor == input_info_writer::class_guid);

	service_ptr_t<file> l_file = p_filehint;
	if (l_file.is_empty()) {
		service_ptr_t<filesystem> fs;
		if (filesystem::g_get_interface(fs, p_path)) {
			if (fs->supports_content_types()) {
				fs->open(l_file, p_path, needWriteAcecss ? filesystem::open_mode_write_existing : filesystem::open_mode_read, p_abort);
			}
		}
	}

	if (l_file.is_valid()) {
		pfc::string8 content_type;
		if (l_file->get_content_type(content_type)) {
			pfc::list_t< input_entry::ptr > list;
#if PFC_DEBUG
			FB2K_DebugLog() << "attempting input open by content type: " << content_type;
#endif
			if (g_find_inputs_by_content_type(list, content_type, p_from_redirect)) {
				try {
					return g_open_from_list(list, whatFor, l_file, p_path, p_abort);
				} catch (exception_io_unsupported_format) {
#if PFC_DEBUG
					FB2K_DebugLog() << "Failed to open by content type, using fallback";
#endif
				}
			}
		}
	}

#if PFC_DEBUG
	FB2K_DebugLog() << "attempting input open by path: " << p_path;
#endif
	{
		pfc::list_t< input_entry::ptr > list;
		if (g_find_inputs_by_path(list, p_path, p_from_redirect)) {
			return g_open_from_list(list, whatFor, l_file, p_path, p_abort);
		}
	}

	throw exception_io_unsupported_format();
}
Exemplo n.º 9
0
	void retag_commit(abort_callback &p_abort)
	{
		m_file.release();
		filesystem::g_open(m_file, filename, filesystem::open_mode_write_new, p_abort);
		this->p_abort = &p_abort;
		ByteWriter bw = { this, static_write };
		if (!ASAPWriter_Write(filename, bw, ASAP_GetInfo(asap), module, module_len, FALSE))
			throw exception_io_unsupported_format();
	}
Exemplo n.º 10
0
void playlist_loader::g_load_playlist_filehint(file::ptr fileHint,const char * p_path,playlist_loader_callback & p_callback) {
	TRACK_CALL_TEXT("playlist_loader::g_load_playlist_filehint");
	pfc::string8 filepath;

	filesystem::g_get_canonical_path(p_path,filepath);
	
	pfc::string_extension extension(filepath);

	service_ptr_t<file> l_file = fileHint;

	if (l_file.is_empty()) {
		filesystem::ptr fs;
		if (filesystem::g_get_interface(fs,filepath)) {
			if (fs->supports_content_types()) {
				fs->open(l_file,filepath,filesystem::open_mode_read,p_callback);
			}
		}
	}

	{
		service_enum_t<playlist_loader> e;

		if (l_file.is_valid()) {
			pfc::string8 content_type;
			if (l_file->get_content_type(content_type)) {
				service_ptr_t<playlist_loader> l;
				e.reset(); while(e.next(l)) {
					if (l->is_our_content_type(content_type)) {
						try {
							TRACK_CODE("playlist_loader::open",l->open(filepath,l_file,p_callback));
							return;
						} catch(exception_io_unsupported_format) {
							l_file->reopen(p_callback);
						}
					}
				}
			}
		}

		if (extension.length()>0) {
			service_ptr_t<playlist_loader> l;
			e.reset(); while(e.next(l)) {
				if (stricmp_utf8(l->get_extension(),extension) == 0) {
					if (l_file.is_empty()) filesystem::g_open_read(l_file,filepath,p_callback);
					try {
						TRACK_CODE("playlist_loader::open",l->open(filepath,l_file,p_callback));
						return;
					} catch(exception_io_unsupported_format) {
						l_file->reopen(p_callback);
					}
				}
			}
		}
	}

	throw exception_io_unsupported_format();
}
Exemplo n.º 11
0
	void open(service_ptr_t<file> p_filehint, const char *p_path, t_input_open_reason p_reason, abort_callback &p_abort)
	{
		if (p_reason == input_open_info_write) {
			int len = strlen(p_path);
			if (len >= MAX_PATH || !ASAP_CanSetModuleInfo(p_path))
				throw exception_io_unsupported_format();
			memcpy(filename, p_path, len + 1);
		}
		if (p_filehint.is_empty())
			filesystem::g_open(p_filehint, p_path, filesystem::open_mode_read, p_abort);
		m_file = p_filehint;
		module_len = m_file->read(module, sizeof(module), p_abort);
		if (!ASAP_GetModuleInfo(&module_info, p_path, module, module_len))
			throw exception_io_unsupported_format();
		if (p_reason == input_open_decode)
			if (!ASAP_Load(&asap, p_path, module, module_len))
				throw exception_io_unsupported_format();
	}
Exemplo n.º 12
0
	void retag_commit(abort_callback &p_abort)
	{
		byte out_module[ASAP_MODULE_MAX];
		int out_len = ASAP_SetModuleInfo(&module_info, module, module_len, out_module);
		if (out_len <= 0)
			throw exception_io_unsupported_format();
		m_file.release();
		filesystem::g_open(m_file, filename, filesystem::open_mode_write_new, p_abort);
		m_file->write(out_module, out_len, p_abort);
	}
Exemplo n.º 13
0
	void retag(const file_info & p_info,abort_callback & p_abort) {throw exception_io_unsupported_format();}
Exemplo n.º 14
0
	void open(service_ptr_t<file> p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort) {
		if (p_reason == input_open_info_write) throw exception_io_unsupported_format();//our input does not support retagging.
		m_file = p_filehint;//p_filehint may be null, hence next line
		input_open_file_helper(m_file,p_path,p_reason,p_abort);//if m_file is null, opens file with appropriate privileges for our operation (read/write for writing tags, read-only otherwise).
	}
Exemplo n.º 15
0
	virtual bool open_path_internal(file::ptr p_filehint,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort,bool p_from_redirect,bool p_skip_hints) {
		if (p_reason == input_open_info_write) throw exception_io_unsupported_format();//our input does not support retagging.
		pfc::string8 base, ext;
		base = p_path;
		t_size extpos = base.find_last('.');
		if (extpos >= base.scan_filename()) {
			// is ext
			ext.set_string(base + extpos);
			base.truncate(extpos);
		} else {
			ext = "";
		}
		if (m_autoprobe) {
			// try some known suffixes
			bool found = false;
			unsigned n;
			pfc::string8 work(base);
			t_size baselen = base.get_length();
			for(n=0;n<tabsize(g_known_suffix_table);n++)
			{
				const char *head_suffix = g_known_suffix_table[n].head_suffix;
				const char *body_suffix = g_known_suffix_table[n].body_suffix;
				work.truncate(baselen);
				work << head_suffix << ext;
				if (!filesystem::g_exists(work, p_abort)) continue;
				work.truncate(baselen);
				work << body_suffix << ext;
				if (!filesystem::g_exists(work, p_abort)) continue;
				m_head.suffix = head_suffix;
				m_body.suffix = body_suffix;
				found = true;
				break;
			}
			if (!found) return false;
		}
		m_head.path.reset();
		m_head.path << base << m_head.suffix << ext;
		filesystem::g_get_canonical_path(m_head.path, m_head.path);
		try {
			open_path_helper(m_head.input, NULL, m_head.path, p_abort, p_from_redirect, p_skip_hints);
		} catch (exception_io_not_found) {
			return false;
		}
		m_body.path.reset();
		m_body.path << base << m_body.suffix << ext;
		filesystem::g_get_canonical_path(m_body.path, m_body.path);
		try {
			open_path_helper(m_body.input, NULL, m_body.path, p_abort, p_from_redirect, p_skip_hints);
		} catch (exception_io_not_found) {
			console::formatter() << "loop twofiles: body file not found: \"" << file_path_display(m_body.path) << "\"";
			return false;
		}
		if (m_head.input.is_empty() || m_body.input.is_empty()) return false;
		m_points.remove_all();
		loop_event_point_twofiles_eof * point = new service_impl_t<loop_event_point_twofiles_eof>();
		m_points.add_item(point);
		switch_points(m_points);
		file_info_impl p_info;
		m_head.input->get_info(0, p_info, p_abort);
		m_head.samples = p_info.info_get_length_samples();
		p_info.reset();
		m_body.input->get_info(0, p_info, p_abort);
		m_body.samples = p_info.info_get_length_samples();
		switch_to(m_head);
		return true;
	}
Exemplo n.º 16
0
void playlist_loader::g_load_playlist_filehint(file::ptr fileHint,const char * p_path,playlist_loader_callback::ptr p_callback, abort_callback & p_abort) {
	if (!g_try_load_playlist(fileHint, p_path, p_callback, p_abort)) throw exception_io_unsupported_format();
}