bool CCollectionFile::InitFromLink(CString sLink)
{
	CED2KLink* pLink = NULL;
	CED2KFileLink* pFileLink = NULL;
	try 
	{
		pLink = CED2KLink::CreateLinkFromUrl(sLink);
		if(!pLink)
			throw GetResString(IDS_ERR_NOTAFILELINK);
		pFileLink = pLink->GetFileLink();
		if (!pFileLink)
			throw GetResString(IDS_ERR_NOTAFILELINK);
	} 
	catch (CString error) 
	{
		CString strBuffer;
		strBuffer.Format(GetResString(IDS_ERR_INVALIDLINK),error);
		LogError(LOG_STATUSBAR, GetResString(IDS_ERR_LINKERROR), strBuffer);
		return false;
	}

	taglist.Add(new CTag(FT_FILEHASH, pFileLink->GetHashKey()));
	md4cpy(m_abyFileHash, pFileLink->GetHashKey());

	taglist.Add(new CTag(FT_FILESIZE, pFileLink->GetSize()));
	SetFileSize(pFileLink->GetSize());

	taglist.Add(new CTag(FT_FILENAME, pFileLink->GetName()));
	SetFileName(pFileLink->GetName(), false, false);

	delete pLink;
	return true;
}
示例#2
0
BOOL CAddTaskLinksEdit::FindLineByKey(const CFileHashKey &key, int &iStartPos, int &iEndPos)
{
	BOOL				bDone;
	int					iTmpStartPos;
	int					iTmpEndPos;
	CString				strLine;
	CED2KLink			*pLink = NULL;
	CFileHashKey		keyCmp;

	CString	str;
	GetWindowText(str);

	bDone = FALSE;
	iTmpStartPos = iTmpEndPos = 0;

	do {
		iStartPos = iTmpStartPos;

		iTmpEndPos = str.Find(_T("\r\n"), iTmpStartPos);
		if (-1 == iTmpEndPos)
		{
			iEndPos = str.GetLength() - 1;

			strLine = str.Mid(iTmpStartPos);
			bDone = TRUE;
		}
		else
		{
			iEndPos = iTmpEndPos - 1;

			strLine = str.Mid(iTmpStartPos, iTmpEndPos - iTmpStartPos);
			iTmpStartPos = iTmpEndPos + 2;
		}

		try
		{
			if (!strLine.IsEmpty())
			{
				pLink = CED2KLink::CreateLinkFromUrl(strLine);
				if (CED2KLink::kFile == pLink->GetKind())
					keyCmp = ((CED2KFileLink*)pLink)->GetHashKey();
				SAFE_DELETE(pLink);

				if (key == keyCmp)
				{
					return TRUE;
				}
			}
		}
		catch(...)
		{
		}

	} while(!bDone);

	return FALSE;
}
示例#3
0
void CServerWnd::OnBnClickedAddserver()
{
	CString serveraddr;
	GetDlgItem(IDC_IPADDRESS)->GetWindowText(serveraddr);
	serveraddr.Trim();
	if (serveraddr.IsEmpty()) {
		AfxMessageBox(GetResString(IDS_SRV_ADDR));
		return;
	}

	uint16 uPort = 0;
	if (_tcsnicmp(serveraddr, _T("ed2k://"), 7) == 0){
		CED2KLink* pLink = NULL;
		try{
			pLink = CED2KLink::CreateLinkFromUrl(serveraddr);
			serveraddr.Empty();
			if (pLink && pLink->GetKind() == CED2KLink::kServer){
				CED2KServerLink* pServerLink = pLink->GetServerLink();
				if (pServerLink){
					serveraddr = pServerLink->GetAddress();
					uPort = pServerLink->GetPort();
					SetDlgItemText(IDC_IPADDRESS, serveraddr);
					SetDlgItemInt(IDC_SPORT, uPort, FALSE);
				}
			}
		}
		catch(CString strError){
			AfxMessageBox(strError);
			serveraddr.Empty();
		}
		delete pLink;
	}
	else{
		if (!GetDlgItem(IDC_SPORT)->GetWindowTextLength()){
			AfxMessageBox(GetResString(IDS_SRV_PORT));
			return;
		}

		BOOL bTranslated = FALSE;
		uPort = (uint16)GetDlgItemInt(IDC_SPORT, &bTranslated, FALSE);
		if (!bTranslated){
			AfxMessageBox(GetResString(IDS_SRV_PORT));
			return;
		}
	}

	if (serveraddr.IsEmpty() || uPort == 0){
		AfxMessageBox(GetResString(IDS_SRV_ADDR));
		return;
	}

	CString strServerName;
	GetDlgItem(IDC_SNAME)->GetWindowText(strServerName);

	AddServer(uPort, serveraddr, strServerName);
}
示例#4
0
	void	AddEd2kLinksToDownload(CString strlink, int cat)
	{
		int curPos = 0;
		CString resToken = strlink.Tokenize(_T("\t\n\r"), curPos);
		while (resToken != _T(""))
		{
			if (resToken.Right(1) != _T("/"))
				resToken += _T("/");
			try
			{
				CED2KLink* pLink = CED2KLink::CreateLinkFromUrl(resToken.Trim());
				if (pLink)
				{
					
					if (pLink->GetKind() == CED2KLink::kFile)
					{
						/// CDlgAddTask::AddNewTask(pLink->GetFileLink(), cat);
						CDlgAddTask::AddNewTask(strlink, cat);
					}

					// added by VC-yavey on 2010-04-27 : 处理订阅 <begin>
					else if (pLink->GetKind() == CED2KLink::kRss)
					{
						ASSERT(pLink->GetRssLink() != NULL);
						CDlgAddTask::AddNewRssUrl(*pLink->GetRssLink());
					}
					// added by VC-yavey on 2010-04-27 : 处理订阅 <end>

					else
					{
						delete pLink;
						throw CString(_T("bad link"));
					}
					delete pLink;
				}
			}
			catch(CString error)
			{
				TCHAR szBuffer[200];
				_sntprintf(szBuffer, ARRSIZE(szBuffer), GetResString(IDS_ERR_INVALIDLINK), error);
				LogError(LOG_STATUSBAR, GetResString(IDS_ERR_LINKERROR), szBuffer);
			}
			resToken = strlink.Tokenize(_T("\t\n\r"), curPos);
		}

		//CDlgAddTask::AddNewTask(strlink, cat);
	}
示例#5
0
void CDirectDownloadDlg::OnOK()
{
	CString strLinks;
	GetDlgItem(IDC_ELINK)->GetWindowText(strLinks);

	int curPos = 0;
	CString strTok = strLinks.Tokenize(_T(" \t\r\n"), curPos); // tokenize by whitespaces
	while (!strTok.IsEmpty())
	{
		if (strTok.Right(1) != _T("/"))
			strTok += _T("/");
		try
		{
			CED2KLink* pLink = CED2KLink::CreateLinkFromUrl(strTok);
			if (pLink)
			{
				if (pLink->GetKind() == CED2KLink::kFile)
				{
					theApp.downloadqueue->AddFileLinkToDownload(pLink->GetFileLink(), (thePrefs.GetCatCount() == 0) ? 0 : m_cattabs.GetCurSel());
				}
				else
				{
					delete pLink;
					throw CString(_T("bad link"));
				}
				delete pLink;
			}
		}
		catch(CString error)
		{
			TCHAR szBuffer[200];
			_sntprintf_s(szBuffer, _countof(szBuffer), _countof(szBuffer), GetResString(IDS_ERR_INVALIDLINK), error);
			szBuffer[_countof(szBuffer) - 1] = _T('\0');
			CString strError;
			strError.Format(GetResString(IDS_ERR_LINKERROR), szBuffer);
			AfxMessageBox(strError);
			return;
		}
		strTok = strLinks.Tokenize(_T(" \t\r\n"), curPos); // tokenize by whitespaces
	}

	CResizableDialog::OnOK();
}
示例#6
0
void CServerWnd::PasteServerFromClipboard()
{
	CString strServer = theApp.CopyTextFromClipboard();
	strServer.Trim();
	if (strServer.IsEmpty())
		return;

	int nPos = 0;
	CString strTok = strServer.Tokenize(_T(" \t\r\n"), nPos);
	while (!strTok.IsEmpty())
	{
		CString strAddress;
		uint16 nPort = 0;
		CED2KLink* pLink = NULL;
		try{
			pLink = CED2KLink::CreateLinkFromUrl(strTok);
			if (pLink && pLink->GetKind() == CED2KLink::kServer){
				CED2KServerLink* pServerLink = pLink->GetServerLink();
				if (pServerLink){
					strAddress = pServerLink->GetAddress();
					nPort = pServerLink->GetPort();
				}
			}
		}
		catch(CString strError){
			AfxMessageBox(strError);
		}
		delete pLink;

		if (strAddress.IsEmpty() || nPort == 0)
			break;

		(void)AddServer(nPort, strAddress, _T(""), false);
		strTok = strServer.Tokenize(_T(" \t\r\n"), nPos);
	}
}
示例#7
0
void CAddTaskLinksEdit::UpdateLinksByWindowText()
{
	if (NULL == m_pDoc)
		return;

	//AfxMessageBox(_T("abc"));
	set<CRssFeed*>	setRssUpdatefeed;//订阅
	//	取现在Doc里的所有ed2k的fileHash,组成set。
	set<CFileHashKey>	setKeysInDoc;
	setKeysInDoc = m_pDoc->GetAllKeysInDoc();

	//	把EditCtrl里的内容变成一行一行的字符串,并把每一行放入列表中。
	CString	strText;
	GetWindowText(strText);
	CList<CString>		lstLinks;
	::ConvertStrToStrList(&lstLinks, strText);


	CFileHashKey			key;
	CAddTaskDoc::SItem		docItem;
	CString					strLine;
	CED2KLink				*pLink = NULL;

	//CList<CString>			lstUrls;
	CMapStringToPtr			setUrls;
	CString					strPrefix;

	// Added by VC-yavey on 2010-04-16 <begin> 
	// 初始化rss url
	m_pDoc->GetRssUrlSet().clear();
	// Added by VC-yavey on 2010-04-16 <end>

	// 分析每一行,并做相应的处理。
	POSITION	pos = lstLinks.GetHeadPosition();

	if ( pos == NULL && !m_setLastRssfeed.empty() )
	{
		set<CRssFeed*>::iterator		it;//删除掉无用的rss订阅对象
		for ( it = m_setLastRssfeed.begin(); m_setLastRssfeed.end() != it; ++it )
		{
				delete *it;
		}
		m_setLastRssfeed.clear();
	}

	bool bHasRssLink = false;

	while (NULL != pos)
	{
		strLine = lstLinks.GetNext(pos);

		strLine = Decode3URL(strLine);
		
		strPrefix = strLine.Left(strLine.Find(_T(':')));

		if (0 == strPrefix.CompareNoCase(_T("ed2k")))
		{
			try
			{
				pLink = NULL;

				// MODIFIED by VC-yavey on 2010-04-16
				// 处理订阅协议
				pLink = CED2KLink::CreateLinkFromUrl(strLine);

			}
			catch (...)
			{
				SAFE_DELETE(pLink);
			}

			if (NULL != pLink)
			{
				// MODIFIED by VC-yavey on 2010-04-16
				// 处理订阅协议
				switch ( pLink->GetKind() )
				{
					case CED2KLink::kFile:
						key = ((CED2KFileLink*)pLink)->GetHashKey();

						// MODIFIED by VC-yavey on 2010-04-16, 统一放到最后删除
						//SAFE_DELETE(pLink);

						setKeysInDoc.erase(key);

						docItem.strLinkText = strLine;
						docItem.bCheck = TRUE;
						m_pDoc->SetItem(key, docItem, CAddTaskDoc::IM_TEXT | CAddTaskDoc::IM_CHECK, GetSafeHwnd());
						break;
					
					case CED2KLink::kRss:
						{
							bHasRssLink = true;

							CString strRssLink;
							CAddTaskDoc::RssUrlSet & setUrl = m_pDoc->GetRssUrlSet();
							strRssLink = ((CED2KRssLink*)pLink)->GetRssUrl();

							//added by lost		判断上次获取到订阅中的
							if ( !m_setLastRssfeed.empty() )
							{
								bool	bAlready = false;
								set<CRssFeed*>::iterator		it;
								for ( it = m_setLastRssfeed.begin(); m_setLastRssfeed.end() != it; it++ )
								{
									ASSERT( *it != NULL);
									CRssFeed * pFeed = *it;
									if ( pFeed->m_strFeedUrl  ==  strRssLink )
									{
										bAlready = true;
										setRssUpdatefeed.insert( (*it) );
										break;
									}
								}

								if (!bAlready)
								{
									setUrl.insert( strRssLink ) ;
								}
							}
							else
							{
								setUrl.insert( strRssLink ) ;
							}
							//added by lost

						}
						break;
				}
				SAFE_DELETE(pLink);
			}
		}
		else if (0 == strPrefix.CompareNoCase(_T("http"))
			|| 0 == strPrefix.CompareNoCase(_T("ftp")))
		{
			setUrls.SetAt(strLine, NULL);
			//lstUrls.AddTail(strLine);
		}
	}

	CAddTaskDoc::RssUrlSet & setUrl = m_pDoc->GetRssUrlSet();
	if (!setUrl.empty())
	{
		if (pThread == NULL)
		{
			UPDATERSS_PARAM * paramRSS = new UPDATERSS_PARAM;
			paramRSS->setRssLink		= setUrl;
			paramRSS->thisEdit		= this;

			pThread = AfxBeginThread( ThreadUpdateRSS, paramRSS );//线程获取FEED信息
		}
	}

	//从获取到的FEED集合中得到所有文件hash
	set<CFileHashKey>	setKeysInLastFeed;
	if ( !setRssUpdatefeed.empty() )
	{
		set<CRssFeed*>::iterator		itRss;
		for ( itRss = setRssUpdatefeed.begin(); setRssUpdatefeed.end() != itRss; itRss++ )
		{
			CRssFeed* pFeed = *itRss;
			CED2KLink				*pLinkRss = NULL;
			for ( CRssFeed::ItemIterator it = pFeed->GetItemIterBegin(); it != pFeed->GetItemIterEnd(); ++it )
			{
				CRssFeed::Item & item = it->second;

				try
				{
					pLinkRss = NULL;
					pLinkRss = CED2KLink::CreateLinkFromUrl(item.m_strEnclosure);
				}
				catch (...)
				{
					SAFE_DELETE(pLinkRss);
				}

				if (NULL != pLinkRss)
				{
					switch ( pLinkRss->GetKind() )
					{
					case CED2KLink::kFile:

						key = ((CED2KFileLink*)pLinkRss)->GetHashKey();
						setKeysInLastFeed.insert(key);
					}
				}
			}
			SAFE_DELETE(pLinkRss);
		}

		if ( !m_setRssHash.empty() )
		{
			m_setRssHash.clear();//直接清除set

			//set<CFileHashKey>::iterator		itKey;
			//for ( itKey = m_setRssHash.begin(); m_setRssHash.end() != itKey; itKey++ )//erase后就不可以再用itKey++了 切记
			//{
			//		itKey = m_setRssHash.erase(itKey);
			//}
		}
		m_setRssHash = setKeysInLastFeed;

		set<CRssFeed*>::iterator		it;//删除掉无用的rss订阅对象
		for ( it = m_setLastRssfeed.begin(); m_setLastRssfeed.end() != it; )
		{
			if (setRssUpdatefeed.find(*it) == setRssUpdatefeed.end())
			{
				delete *it;
				it = m_setLastRssfeed.erase(it);
			}
			else
			{
				++it;
			}
		}
		setRssUpdatefeed.clear();//清空set
	}

	// EditCtrl里没有的ed2k链接,则在doc里把它删除。
	set<CFileHashKey>::iterator		it;
	for (it = setKeysInDoc.begin();
		setKeysInDoc.end() != it;
		it++)
	{
		//docItem.bCheck = FALSE;
		//m_pDoc->SetItem(*it, docItem, CAddTaskDoc::IM_CHECK, GetSafeHwnd());
		if ( !setKeysInLastFeed.empty() && setKeysInLastFeed.find(*it) != setKeysInLastFeed.end() )
		{//与Feed中某hash值匹配
			continue;
		}

		m_pDoc->RemoveItem(*it);
	}

	if (bHasRssLink)
		(((CDlgAddTask*)GetParent())->m_chkboxRssAutoDown).ShowWindow(SW_SHOW);
	else
		(((CDlgAddTask*)GetParent())->m_chkboxRssAutoDown).ShowWindow(SW_HIDE);

	m_pDoc->UpdateUrlItems(&setUrls, GetSafeHwnd());
}
示例#8
0
LRESULT CAddTaskLinksEdit::OnUpdateRss(WPARAM wParam, LPARAM lParam)
{
	if ( (int)lParam <= 0 )
	{//没有成功获取到RSS
		return -1;
	}

	set<CRssFeed*> setGetRssfeed	=		*((set<CRssFeed*>*)wParam);
	if (!setGetRssfeed.empty())
	{
		CED2KLink				*pLinkRss = NULL;
		CFileHashKey			key;
		CAddTaskDoc::SItem		docItem;

		set<CFileHashKey>	setKeysInDoc;
		setKeysInDoc = m_pDoc->GetAllKeysInDoc();

		CString	strText;
		GetWindowText(strText);//edit中数据

		set<CRssFeed*>::iterator		itRss;
		for ( itRss = setGetRssfeed.begin(); setGetRssfeed.end() != itRss; itRss++ )
		{
			m_setLastRssfeed.insert(*itRss);//加入到全局set中去

			CRssFeed * pFeed	= *itRss;
			CString strFeedUrl = pFeed->m_strFeedUrl;
			if (strText.Find(strFeedUrl) == -1)//线程返回时 需确定edit中还存在这个url
			{
				continue;
			}

			for ( CRssFeed::ItemIterator it = pFeed->GetItemIterBegin(); it != pFeed->GetItemIterEnd(); ++it )
			{
				CRssFeed::Item & item = it->second;

				try
				{
					pLinkRss = NULL;
					pLinkRss = CED2KLink::CreateLinkFromUrl(item.m_strEnclosure);
				}
				catch (...)
				{
					SAFE_DELETE(pLinkRss);
				}

				if (NULL != pLinkRss)
				{
					switch ( pLinkRss->GetKind() )
					{
					case CED2KLink::kFile:

						key = ((CED2KFileLink*)pLinkRss)->GetHashKey();
						setKeysInDoc.erase(key);
						m_setRssHash.insert(key);//加入到全局key中 

						docItem.strLinkText = item.m_strEnclosure;
						docItem.bCheck = TRUE;
						m_pDoc->SetItem(key, docItem, CAddTaskDoc::IM_TEXT | CAddTaskDoc::IM_CHECK, GetSafeHwnd());
					}
				}
			}
		}
	}

	return 0;
}
BOOL CFriendListCtrl::OnCommand(WPARAM wParam, LPARAM /*lParam*/)
{
	wParam = LOWORD(wParam);

	CFriend* cur_friend = NULL;
	int iSel = GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
	if (iSel != -1) 
		cur_friend = (CFriend*)GetItemData(iSel);
	
	switch (wParam)
	{
		case MP_MESSAGE:
			if (cur_friend)
			{
				theApp.emuledlg->chatwnd->StartSession(cur_friend->GetClientForChatSession());
			}
			break;
		case MP_REMOVEFRIEND:
			if (cur_friend)
			{
				theApp.friendlist->RemoveFriend(cur_friend);
				// auto select next item after deleted one.
				if (iSel < GetItemCount()) {
					SetSelectionMark(iSel);
					SetItemState(iSel, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
				}
				theApp.emuledlg->chatwnd->UpdateSelectedFriendMsgDetails();
			}
			break;
		case MP_ADDFRIEND:{
			CAddFriend dialog2; 
			dialog2.DoModal();
			break;
		}
		case MP_DETAIL:
		case MPG_ALTENTER:
		case IDA_ENTER:
			if (cur_friend)
				ShowFriendDetails(cur_friend);
			break;
		case MP_SHOWLIST:
			if (cur_friend)
			{
				if (cur_friend->GetLinkedClient(true))
					cur_friend->GetLinkedClient()->RequestSharedFileList();
				else
				{
					CUpDownClient* newclient = new CUpDownClient(0, cur_friend->m_nLastUsedPort, cur_friend->m_dwLastUsedIP, 0, 0, true);
					newclient->SetUserName(cur_friend->m_strName);
					//Xman Code Improvement don't search new generated clients in lists
					/*
					theApp.clientlist->AddClient(newclient);
					*/
					theApp.clientlist->AddClient(newclient,true);
					//Xman end
					newclient->RequestSharedFileList();
				}
			}
			break;
		case MP_FRIENDSLOT:
			if (cur_friend)
			{
				bool bIsAlready = cur_friend->GetFriendSlot();
				theApp.friendlist->RemoveAllFriendSlots();
				if (!bIsAlready)
				{ //Xman
					cur_friend->SetFriendSlot(true);
					//Xman friend visualization
					UpdateFriend(iSel,cur_friend);
					//Xman end
				} //Xman
			}
			break;
		// - show requested files (sivka/Xman)
		case MP_LIST_REQUESTED_FILES:
			{ 
				if (cur_friend && cur_friend->GetLinkedClient())
				{
					cur_friend->GetLinkedClient()->ShowRequestedFiles(); 
				}
				break;
			}
		//Xman end
		// MORPH START - Added by Commander, Friendlinks [emulEspaa] - added by zz_fly
		case MP_PASTE:
		{
			CString link = theApp.CopyTextFromClipboard();
			link.Trim();
			if ( link.IsEmpty() )
				break;
			try{
				CED2KLink* pLink = CED2KLink::CreateLinkFromUrl(link);
		
				if (pLink && pLink->GetKind() == CED2KLink::kFriend )
				{
					// Better with dynamic_cast, but no RTTI enabled in the project
					CED2KFriendLink* pFriendLink = static_cast<CED2KFriendLink*>(pLink);
					uchar userHash[16];
					pFriendLink->GetUserHash(userHash);

					if ( ! theApp.friendlist->IsAlreadyFriend(userHash) )
						theApp.friendlist->AddFriend(userHash, 0U, 0U, 0U, 0U, pFriendLink->GetUserName(), 1U);
					else
					{
						CString msg;
						msg.Format(GetResString(IDS_USER_ALREADY_FRIEND), pFriendLink->GetUserName());
						AddLogLine(true, msg);
					}
				}
				if(pLink) delete pLink; //zz_fly :: memleak :: thanks DolphinX
			}
			catch(CString strError){
				AfxMessageBox(strError);
			}
		}
			break;
        case MP_GETFRIENDED2KLINK:
		{
			CString sCompleteLink;
			if ( cur_friend && cur_friend->HasUserhash() )
			{
				CString sLink;
				CED2KFriendLink friendLink(cur_friend->m_strName, cur_friend->m_abyUserhash);
				friendLink.GetLink(sLink);
				if ( !sCompleteLink.IsEmpty() )
					sCompleteLink.Append(_T("\r\n"));
				sCompleteLink.Append(sLink);
			}

			if ( !sCompleteLink.IsEmpty() )
				theApp.CopyTextToClipboard(sCompleteLink);
		}
			break;
		case MP_GETHTMLFRIENDED2KLINK:
		{
			CString sCompleteLink;
			
			if ( cur_friend && cur_friend->HasUserhash() )
			{
				CString sLink;
				CED2KFriendLink friendLink(cur_friend->m_strName, cur_friend->m_abyUserhash);
				friendLink.GetLink(sLink);
				sLink = _T("<a href=\"") + sLink + _T("\">") + StripInvalidFilenameChars(cur_friend->m_strName) + _T("</a>");
				if ( !sCompleteLink.IsEmpty() )
					sCompleteLink.Append(_T("\r\n"));
				sCompleteLink.Append(sLink);
			}
			
			if ( !sCompleteLink.IsEmpty() )
				theApp.CopyTextToClipboard(sCompleteLink);
		}
			break;
		// MORPH END - Added by Commander, Friendlinks [emulEspaa]

		case MP_FIND:
			OnFindStart();
			break;
	}
	return true;
}