CHttpDownload::~CHttpDownload()
{
	if( m_pThread )
	{
		TerminateThread( m_pThread->m_hThread, 0 );	
		WaitForSafeToClose();
	}
	HttpClose();
}
BOOL CHttpDownload::HttpConnect()
{
	HttpClose();

	m_hInternetSession	= InternetOpen( "FlyffPatch", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
	if( m_hInternetSession == NULL )
		return FALSE;

	DWORD dwTimeout	= 45000;
	InternetSetOption( m_hInternetSession, INTERNET_OPTION_RECEIVE_TIMEOUT, (void*)&dwTimeout, sizeof(dwTimeout) ); 

	m_hHttpConnection = InternetConnect( m_hInternetSession, 
		                                   (LPCTSTR)m_sServer, 
										   INTERNET_DEFAULT_HTTP_PORT, 
										   NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 );

	if( m_hHttpConnection == NULL )
		return FALSE;

	return TRUE;
}
Esempio n. 3
0
DWORD WINAPI LyricSearchThread(LPVOID param)
{
	MSG msg;

	while (GetMessage(&msg, 0, 0, 0))
	{
		switch (msg.message)
		{
		case ID_CMD_LYRIC:
			{				
				HWND hWnd = lyric_search.hWnd;
				HTTPREQ* httpreq = &lyric_search.httpreq;
				wchar_t* artist = NULL;
				UINT length = SendMessage(GetDlgItem(hWnd, IDC_EDIT_ARTIST), WM_GETTEXTLENGTH, 0, 0);
				if (length > 0)
				{
					artist = new wchar_t[length + 1];
					wmemset(artist, 0, length + 1);
					GetDlgItemText(hWnd, IDC_EDIT_ARTIST, artist, length + 1);
				}

				wchar_t* title = NULL;
				length = SendMessage(GetDlgItem(hWnd, IDC_EDIT_TITLE), WM_GETTEXTLENGTH, 0, 0);
				if (length > 0)
				{
					title = new wchar_t[length + 1];
					wmemset(title, 0, length + 1);
					GetDlgItemText(hWnd, IDC_EDIT_TITLE, title, length + 1);
				}

				LYRIC* lyric = GetLyric(artist, title, httpreq);
				SAFE_DELETE_ARRAY(artist);
				SAFE_DELETE_ARRAY(title);

				if (lyric != NULL)
				{
					DWORD lyricid = 0;
					PLAYERENTRY* player = lyric_search.player;
					if (player != NULL)
					{
						PLAYERINFO* playerinfo = player->current;
						if (playerinfo != NULL)
						{
							lyricid = playerinfo->lyricid;							
							LyricReset(lyric, playerinfo);
							LyricSearchList(lyric, lyricid);
						}
					}										
				}

				EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_LYRIC_SEARCH), TRUE);
			}
			break;

		case ID_CMD_LYRICINFO:
			{
				HTTPREQ* httpreq = &lyric_search.httpreq;
				LYRIC* lyric = (LYRIC*)msg.wParam;
				LYRICINFO* lyricinfo = SetLyricInfo(lyric, httpreq);
				if (lyricinfo != NULL)
				{
					PLAYERENTRY* player = lyric_search.player;
					if (player != NULL)
					{
						PLAYERINFO* playerinfo = player->current;
						if (playerinfo != NULL)
						{
							LyricInfoReset(lyricinfo, lyric, playerinfo, TRUE);
							HWND listview = GetDlgItem(lyric_search.hWnd, IDC_LIST_LYRIC);
							int n = lyric->n;							
							int total = ListView_GetItemCount(listview);
							for (int i = 0;i < total;i++)
							{
								if (i == n)
								{
									ListView_SetItemText(listview, i, 3, L"正在使用");
								}
								else
								{
									ListView_SetItemText(listview, i, 3, L"");
								}
							}

							SetLyricStatus(TRUE);
						}
						else
							LyricInfoClear(lyricinfo);
					}
					else					
						LyricInfoClear(lyricinfo);					
				}

				LyricClear(lyric);	
			}
			break;
		}

		DispatchMessage(&msg);
	}

	CloseHandle(lyric_search.thread);	
	HttpClose(&lyric_search.httpreq, TRUE);
	PostMessage(lyric_search.hWnd, WM_QUIT, 0, 0);		
	SetEvent(lyric_search.exit);
	return 1;
}