Esempio n. 1
0
void winLocalFileScope::open( const char * inPath, file::ptr inReader, abort_callback & aborter) {
	close();
	if (inPath != NULL) {
		if (_extract_native_path_ptr( inPath ) ) {
			pfc::string8 prefixed;
			pfc::winPrefixPath( prefixed, inPath  );
			m_path = pfc::stringcvt::string_wide_from_utf8( prefixed );
			m_isTemp = false;
			return;
		}
	}

	pfc::string8 tempPath;
	if (!uGetTempPath( tempPath )) uBugCheck();
	tempPath.add_filename( PFC_string_formatter() << pfc::print_guid( pfc::createGUID() ) << ".rar" );

	m_path = pfc::stringcvt::string_wide_from_utf8( tempPath );

	if (inReader.is_empty()) {
		if (inPath == NULL) uBugCheck();
		inReader = fileOpenReadExisting( inPath, aborter, 1.0 );
	}

	file::ptr writer = fileOpenWriteNew( PFC_string_formatter() << "file://" << tempPath, aborter, 1.0 );
	file::g_transfer_file( inReader , writer, aborter );
	m_isTemp = true;
}
Esempio n. 2
0
	t_size MultiWaitAbortable_MsgLoop(const HANDLE * ev, t_size evCount, abort_callback & abort) {
		pfc::array_t<HANDLE> handles; handles.set_size(evCount + 1);
		handles[0] = abort.get_abort_event();
		pfc::memcpy_t(handles.get_ptr() + 1, ev, evCount);
		for(;;) {
			SetLastError(0);
			const DWORD status = MsgWaitForMultipleObjects(handles.get_count(), handles.get_ptr(), FALSE, INFINITE, QS_ALLINPUT);
			switch(status) {
				case WAIT_TIMEOUT:
					PFC_ASSERT(!"How did we get here?");
					uBugCheck();
				case WAIT_OBJECT_0:
					throw exception_aborted();
				case WAIT_FAILED:
					WIN32_OP_FAIL();
				default:
					{
						t_size index = (t_size)(status - (WAIT_OBJECT_0 + 1));
						if (index == evCount) {
							ProcessPendingMessages();
						} else if (index < evCount) {
							return index;
						} else {
							uBugCheck();
						}
					}
			}
		}
	}
Esempio n. 3
0
	virtual void
	context_command(
		unsigned int			index,
		metadb_handle_list_cref	tracks,
		const GUID&				/*caller*/
	)
	{
		switch(index)
		{
			case Items::GetArtistTopTracks:
			{
				generateArtistPlaylist(tracks);
				break;
			}

			case Items::GetSimilarTracks:
			{
				if(tracks.get_count() > 0)
				{
					generateSimilarTracksPlaylist(tracks.get_item(0));
				}
				break;
			}

			default:
			{
				uBugCheck();
			}
		}
	}
Esempio n. 4
0
	virtual void
	get_item_name(
		unsigned int		index,
		pfc::string_base&	out
	)
	{
		switch(index)
		{
			case Items::GetArtistTopTracks:
			{
				out = "Get artist top tracks";
				break;
			}

			case Items::GetSimilarTracks:
			{
				out = "Get similar tracks";
				break;
			}

			default:
			{
				uBugCheck();
			}
		}
	}
Esempio n. 5
0
	bool WaitAbortable_MsgLoop(HANDLE ev, abort_callback & abort, DWORD timeout /*must not be INFINITE*/) {
		PFC_ASSERT( timeout != INFINITE );
		const DWORD entry = GetTickCount();
		const HANDLE handles[2] = {ev, abort.get_abort_event()};
		for(;;) {
			const DWORD done = GetTickCount() - entry;
			if (done >= timeout) return false;
			SetLastError(0);
			const DWORD status = MsgWaitForMultipleObjects(2, handles, FALSE, timeout - done, QS_ALLINPUT);
			switch(status) {
				case WAIT_TIMEOUT:
					return false;
				case WAIT_OBJECT_0:
					return true;
				case WAIT_OBJECT_0 + 1:
					throw exception_aborted();
				case WAIT_OBJECT_0 + 2:
					ProcessPendingMessages();
					break;
				case WAIT_FAILED:
					WIN32_OP_FAIL();
				default:
					uBugCheck();
			}
		}
	}
Esempio n. 6
0
	// Execute n-th command.
	void execute(t_uint32 p_index, service_ptr_t<service_base> p_callback){
		switch (p_index) {
			case cmd_nowplaying:
				foo_snarl.on_playback_event(FooSnarl::MessageClass::Auto); break;
			default: uBugCheck();
		}
	}
Esempio n. 7
0
	virtual bool
	get_item_description(
		unsigned int		index,
		pfc::string_base&	out
	)
	{
		switch(index)
		{
			case Items::GetArtistTopTracks:
			{
				out = "Generate a playlist containing last.fm's top tracks for the selected artist.";
				return true;
			}

			case Items::GetSimilarTracks:
			{
				out = "Generate a playlist containing last.fm's most similar tracks for the selected track.";
				return true;
			}

			default:
			{
				uBugCheck();
			}
		}
	}
Esempio n. 8
0
	virtual GUID
	get_item_guid(
		unsigned int index
	)
	{
		// {6D1AF128-2C33-4214-BAB2-6119D43D968F}
		static const GUID GetArtistTopTracksGUID = { 0x6d1af128, 0x2c33, 0x4214, { 0xba, 0xb2, 0x61, 0x19, 0xd4, 0x3d, 0x96, 0x8f } };

		// {B15EE137-81D2-4CAD-9411-5E9C6373A1DD}
		static const GUID GetSimilarTracksGUID = { 0xb15ee137, 0x81d2, 0x4cad, { 0x94, 0x11, 0x5e, 0x9c, 0x63, 0x73, 0xa1, 0xdd } };

		switch(index)
		{
			case Items::GetArtistTopTracks:
			{
				return GetArtistTopTracksGUID;
			}

			case Items::GetSimilarTracks:
			{
				return GetSimilarTracksGUID;
			}

			default:
			{
				uBugCheck();
			}
		}
	}
Esempio n. 9
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();
}
Esempio n. 10
0
CMutexScope::CMutexScope(CMutex & mutex, DWORD timeOutMS, const char * timeOutBugMsg) : m_mutex(mutex) {
	SetLastError(0);
	const unsigned div = 4;
	for(unsigned walk = 0; walk < div; ++walk) {
		switch(WaitForSingleObject( m_mutex.Handle(), timeOutMS/div ) ) {
		case WAIT_FAILED:
			WIN32_OP_FAIL_CRITICAL("WaitForSingleObject");
		case WAIT_OBJECT_0:
			return;
		case WAIT_TIMEOUT:
			break;
		default:
			uBugCheck();
		}
	}
	TRACK_CODE(timeOutBugMsg, uBugCheck());
}
Esempio n. 11
0
	GUID get_command(t_uint32 p_index) {
		static const GUID guid_getlibrary = { 0x7c23644d, 0x7d31, 0x450d, { 0xb6, 0x56, 0xfc, 0x79, 0x44, 0xe3, 0xa4, 0x93 } };

		switch(p_index) {
			case cmd_library: return guid_getlibrary;
			default: uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
		}
	}
Esempio n. 12
0
	GUID get_command(t_uint32 p_index){
		// {E8D1828F-1AB8-4AC9-BDDC-F6DBB1456961}
		static const GUID guid_foo_snarl_showplaying = { 0xe8d1828f, 0x1ab8, 0x4ac9, { 0xbd, 0xdc, 0xf6, 0xdb, 0xb1, 0x45, 0x69, 0x61 } };
		
		switch (p_index) {
			case cmd_nowplaying: return guid_foo_snarl_showplaying;
			default: uBugCheck();
		}
	}
Esempio n. 13
0
CMutexScope::CMutexScope(CMutex & mutex) : m_mutex(mutex) {
	SetLastError(0);
	switch(WaitForSingleObject( m_mutex.Handle(), INFINITE ) ) {
	case WAIT_FAILED:
		WIN32_OP_FAIL_CRITICAL("WaitForSingleObject");
	case WAIT_OBJECT_0:
		return;
	default:
		uBugCheck();
	}
}
Esempio n. 14
0
t_size reader_membuffer_base::read(void * p_buffer,t_size p_bytes,abort_callback & p_abort) {
	p_abort.check_e();
	t_size max = get_buffer_size();
	if (max < m_offset) uBugCheck();
	max -= m_offset;
	t_size delta = p_bytes;
	if (delta > max) delta = max;
	memcpy(p_buffer,(char*)get_buffer() + m_offset,delta);
	m_offset += delta;
	return delta;
}
Esempio n. 15
0
mutexScope::mutexScope(HANDLE hMutex_, abort_callback & abort) : hMutex(hMutex_) {
	HANDLE h[2] = {hMutex, abort.get_abort_event()};
	switch( WaitForMultipleObjects(2, h, FALSE, INFINITE) ) {
	case WAIT_OBJECT_0:
		break; // and enter
	case WAIT_OBJECT_0+1:
		throw exception_aborted();
	default:
		uBugCheck();			
	}
}
Esempio n. 16
0
	void WaitAbortable_MsgLoop(HANDLE ev, abort_callback & abort) {
		const HANDLE handles[2] = {ev, abort.get_abort_event()};
		for(;;) {
			SetLastError(0);
			const DWORD status = MsgWaitForMultipleObjects(2, handles, FALSE, INFINITE, QS_ALLINPUT);
			switch(status) {
				case WAIT_TIMEOUT:
					PFC_ASSERT(!"How did we get here?");
					uBugCheck();
				case WAIT_OBJECT_0:
					return;
				case WAIT_OBJECT_0 + 1:
					throw exception_aborted();
				case WAIT_OBJECT_0 + 2:
					ProcessPendingMessages();
					break;
				case WAIT_FAILED:
					WIN32_OP_FAIL();
				default:
					uBugCheck();
			}
		}
	}
Esempio n. 17
0
void CMutex::AcquireByHandle( HANDLE hMutex, abort_callback & aborter ) {
	SetLastError(0);
	HANDLE hWait[2] = {hMutex, aborter.get_abort_event()};
	switch(WaitForMultipleObjects( 2, hWait, FALSE, INFINITE ) ) {
	case WAIT_FAILED:
		WIN32_OP_FAIL_CRITICAL("WaitForSingleObject");
	case WAIT_OBJECT_0:
		return;
	case WAIT_OBJECT_0 + 1:
		PFC_ASSERT( aborter.is_aborting() );
		throw exception_aborted();
	default:
		uBugCheck();
	}
}
Esempio n. 18
0
	void execute(t_uint32 p_index,service_ptr_t<service_base> p_callback) {
		//Not sure if this is the best way of doing this...cannot create these in the switch statement
		PubNubTools pub;
		std::thread t;
		unsigned int myCounter = 0;
		int a = 0;
				
		switch(p_index) {
			case cmd_library:
				t = std::thread(&PubNubTools::PubNubSubscribe, pub);
				t.detach();
				break;
			default:
				uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
		}
	}
	HANDLE createFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile, abort_callback & abort) {
		abort.check();
		
		return CreateFile(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);

		// CancelSynchronousIo() doesn't f*****g work. Useless.
#if 0
		pCancelSynchronousIo_t pCancelSynchronousIo = (pCancelSynchronousIo_t) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "CancelSynchronousIo");
		if (pCancelSynchronousIo == NULL) {
#ifdef _DEBUG
			uDebugLog() << "Async CreateFile unavailable - using regular";
#endif
			return CreateFile(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
		} else {
#ifdef _DEBUG
			uDebugLog() << "Starting async CreateFile...";
			pfc::hires_timer t; t.start();
#endif
			createFileData_t data = {lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile, NULL, 0};
			HANDLE hThread = (HANDLE) _beginthreadex(NULL, 0, createFileProc, &data, 0, NULL);
			HANDLE waitHandles[2] = {hThread, abort.get_abort_event()};
			switch(WaitForMultipleObjects(2, waitHandles, FALSE, INFINITE)) {
			case WAIT_OBJECT_0: // succeeded
				break;
			case WAIT_OBJECT_0 + 1: // abort
#ifdef _DEBUG
				uDebugLog() << "Aborting async CreateFile...";
#endif
				pCancelSynchronousIo(hThread);
				WaitForSingleObject(hThread, INFINITE);
				break;
			default:
				uBugCheck();
			}
			CloseHandle(hThread);
			SetLastError(data.dwErrorCode);
#ifdef _DEBUG
			uDebugLog() << "Async CreateFile completed in " << pfc::format_time_ex(t.query(), 6) << ", status: " << (uint32_t) data.dwErrorCode;
#endif
			if (abort.is_aborting()) {
				if (data.hResult != INVALID_HANDLE_VALUE) CloseHandle(data.hResult);
				throw exception_aborted();
			}
			return data.hResult;
		}
#endif
	}
Esempio n. 20
0
	bool WaitAbortable(HANDLE ev, abort_callback & abort, DWORD timeout) {
		const HANDLE handles[2] = {ev, abort.get_abort_event()};
		SetLastError(0);
		const DWORD status = WaitForMultipleObjects(2, handles, FALSE, timeout);
		switch(status) {
			case WAIT_TIMEOUT:
				PFC_ASSERT( timeout != INFINITE );
				return false;
			case WAIT_OBJECT_0:
				return true;
			case WAIT_OBJECT_0 + 1:
				throw exception_aborted();
			case WAIT_FAILED:
				WIN32_OP_FAIL();
			default:
				uBugCheck();
		}
	}
Esempio n. 21
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);
	}
}
Esempio n. 22
0
	virtual void
	get_item_name(
		unsigned int		index,
		pfc::string_base&	out
	)
	{
		switch(index)
		{
			case Items::ReplaceWithBestVersion:
			{
				out = "Replace with best version of track";
				break;
			}

			default:
			{
				uBugCheck();
			}
		}
	}
Esempio n. 23
0
	virtual bool
	get_item_description(
		unsigned int		index,
		pfc::string_base&	out
	)
	{
		switch(index)
		{
			case Items::ReplaceWithBestVersion:
			{
				out = "Replace a track in a playlist with a better version of the track from the library.";
				return true;
			}

			default:
			{
				uBugCheck();
			}
		}
	}
Esempio n. 24
0
	virtual void
	context_command(
		unsigned int			index,
		metadb_handle_list_cref	tracks,
		const GUID&				/*caller*/
	)
	{
		switch(index)
		{
			case Items::ReplaceWithBestVersion:
			{
				replaceWithBestVersion(tracks);
				break;
			}

			default:
			{
				uBugCheck();
			}
		}
	}
Esempio n. 25
0
	virtual GUID
	get_item_guid(
		unsigned int index
	)
	{
		// {4CAA2F50-2818-4DE5-B682-FB36483C9A5E}
		static const GUID ReplaceWithBestVersionGUID = { 0x4caa2f50, 0x2818, 0x4de5, { 0xb6, 0x82, 0xfb, 0x36, 0x48, 0x3c, 0x9a, 0x5e } };

		switch(index)
		{
			case Items::ReplaceWithBestVersion:
			{
				return ReplaceWithBestVersionGUID;
			}

			default:
			{
				uBugCheck();
			}
		}
	}
Esempio n. 26
0
	bool get_description(t_uint32 p_index,pfc::string_base & p_out) {
		switch(p_index) {
			case cmd_library: p_out = "Subscribes to PubNub Channel."; return true;
			default: uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
		}
	}
Esempio n. 27
0
	void ensure_main_thread() {
		if (!is_main_thread()) uBugCheck();
	}
Esempio n. 28
0
	// Set p_out to the description for the n-th command.
	bool get_description(t_uint32 p_index, pfc::string_base & p_out){
		switch (p_index) {
			case cmd_nowplaying: p_out = "Displays current playback state as Snarl notification."; return true;
			default: uBugCheck();
		}
	}
Esempio n. 29
0
	//Set p_out to the name of the n-th command.
	//This name is used to identify the command and determines
	// the default position of the command in the menu.
	void get_name(t_uint32 p_index, pfc::string_base & p_out){
		switch (p_index) {
			case cmd_nowplaying: p_out = "Snarl Now Playing"; break;
			default: uBugCheck();
		}
	}
Esempio n. 30
0
	void get_name(t_uint32 p_index,pfc::string_base & p_out) {
		switch(p_index) {
			case cmd_library: p_out = "Subscribe To Channel"; break;
			default: uBugCheck(); // should never happen unless somebody called us with invalid parameters - bail
		}
	}