Example #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();
}
Example #2
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();
	}
Example #3
0
static void index_tracks_helper(const char * p_path,const service_ptr_t<file> & p_reader,const t_filestats & p_stats,playlist_loader_callback::t_entry_type p_type,playlist_loader_callback::ptr p_callback, abort_callback & p_abort,bool & p_got_input)
{
	TRACK_CALL_TEXT("index_tracks_helper");
	if (p_reader.is_empty() && filesystem::g_is_remote_safe(p_path))
	{
		TRACK_CALL_TEXT("remote");
		metadb_handle_ptr handle;
		p_callback->handle_create(handle,make_playable_location(p_path,0));
		p_got_input = true;
		p_callback->on_entry(handle,p_type,p_stats,true);
	} else {
		TRACK_CALL_TEXT("hintable");
		service_ptr_t<input_info_reader> instance;
		input_entry::g_open_for_info_read(instance,p_reader,p_path,p_abort);

		t_filestats stats = instance->get_file_stats(p_abort);

		t_uint32 subsong,subsong_count = instance->get_subsong_count();
		bool bInfoGetError = false;
		for(subsong=0;subsong<subsong_count;subsong++)
		{
			TRACK_CALL_TEXT("subsong-loop");
			p_abort.check();
			metadb_handle_ptr handle;
			t_uint32 index = instance->get_subsong(subsong);
			p_callback->handle_create(handle,make_playable_location(p_path,index));

			p_got_input = true;
			if (! bInfoGetError && p_callback->want_info(handle,p_type,stats,true) )
			{
				file_info_impl info;
				try {
					TRACK_CODE("get_info",instance->get_info(index,info,p_abort));
				} catch(std::exception const & e) {
					bInfoGetError = true;
				}
				p_callback->on_entry_info(handle,p_type,stats,info,true);
			}
			else
			{
				p_callback->on_entry(handle,p_type,stats,true);
			}
		}
	}
}
Example #4
0
void input_open_file_helper(service_ptr_t<file> & p_file,const char * p_path,t_input_open_reason p_reason,abort_callback & p_abort)
{
	if (p_file.is_empty()) {
		switch(p_reason) {
		default:
			uBugCheck();
		case input_open_info_read:
		case input_open_decode:
			filesystem::g_open(p_file,p_path,filesystem::open_mode_read,p_abort);
			break;
		case input_open_info_write:
			filesystem::g_open(p_file,p_path,filesystem::open_mode_write_existing,p_abort);
			break;
		}
	} else {
		p_file->reopen(p_abort);
	}
}
Example #5
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();
	}
Example #6
0
static void process_fullbuffer(service_ptr_t<file> & p_file,const char * p_path,t_filesize p_fullbuffer,abort_callback & p_abort) {
	if (p_fullbuffer > 0) {
		if (p_file.is_empty()) {
			service_ptr_t<filesystem> fs;
			if (filesystem::g_get_interface(fs,p_path)) {
				fs->open(p_file,p_path,filesystem::open_mode_read,p_abort);
			}
		}

		if (p_file.is_valid()) {
			t_filesize size = p_file->get_size(p_abort);
			if (size != filesize_invalid && size <= p_fullbuffer) {
				service_ptr_t<file> l_file_buffered;
				if (reader_membuffer_mirror::g_create(l_file_buffered,p_file,p_abort)) {
					p_file = l_file_buffered;
				}
			}
		}
	}
}
Example #7
0
static void process_path_internal(const char * p_path,const service_ptr_t<file> & p_reader,playlist_loader_callback_v2 & p_callback,playlist_loader_callback::t_entry_type p_type,const t_filestats & p_stats)
{
	//p_path must be canonical

	p_callback.check();

	p_callback.on_progress(p_path);

	
	{
		if (p_reader.is_empty()) {
			directory_callback_impl directory_results(true);
			try {
				filesystem::g_list_directory(p_path,directory_results,p_callback);
				for(t_size n=0;n<directory_results.get_count();n++) {
					process_path_internal(directory_results.get_item(n),0,p_callback,playlist_loader_callback::entry_directory_enumerated,directory_results.get_item_stats(n));
				}
				return;
			} catch(exception_aborted) {throw;}
			catch(...) {
				//do nothing, fall thru
				//fixme - catch only filesystem exceptions?
			}
		}

		bool found = false;


		{
			archive_callback_impl archive_results(p_callback);
			service_enum_t<filesystem> e;
			service_ptr_t<filesystem> f;
			while(e.next(f)) {
				p_callback.check();
				service_ptr_t<archive> arch;
				if (f->service_query_t(arch)) {
					if (p_reader.is_valid()) p_reader->reopen(p_callback);

					try {
						TRACK_CODE("archive::archive_list",arch->archive_list(p_path,p_reader,archive_results,true));
						return;
					} catch(exception_aborted) {throw;} 
					catch(...) {}
				}
			} 
		}
	}

	

	{
		service_ptr_t<link_resolver> ptr;
		if (link_resolver::g_find(ptr,p_path))
		{
			if (p_reader.is_valid()) p_reader->reopen(p_callback);

			pfc::string8 temp;
			try {
				TRACK_CODE("link_resolver::resolve",ptr->resolve(p_reader,p_path,temp,p_callback));

				track_indexer__g_get_tracks_wrap(temp,0,filestats_invalid,playlist_loader_callback::entry_from_playlist,p_callback);
				return;//success
			} catch(exception_aborted) {throw;}
			catch(...) {}
		}
	}

	if (p_callback.is_path_wanted(p_path,p_type)) {
		track_indexer__g_get_tracks_wrap(p_path,p_reader,p_stats,p_type,p_callback);
	}
}