// part of dclib/cdownloadmanager.cpp// modified_by_frg because the original version has added files with same TTH MULTIPLE TIMES!#include <list>bool CDownloadManager::InitSearch( time_t ){ CStringList * StringList = 0; std::list<CString> *tthlist = new std::list<CString>; // added_by_frg to temp store unique TTHs m_pSearchList->Clear(); m_pSearchQueryList->Clear(); if ( !CSearchManager::Instance() ) return FALSE; m_pDownloadQueue->pQueue->Lock(); while( m_pDownloadQueue->pQueue->Next( (CObject *&) StringList) ) { DCTransferQueueObject * TransferObject = 0; while( StringList->Next( (CObject *&) TransferObject) ) { DCTransferFileObject * TransferFileObject = 0; while( TransferObject->pTransferFileList.Next( (CObject *&)TransferFileObject) ) { if ( (TransferFileObject->m_bMulti == TRUE) && // only if md enabled ( (TransferFileObject->m_stHash != "") || (TransferFileObject->m_sHash != "") ) && // only if we have allready a hash or a TTH (TransferFileObject->m_eMedium == eltFILE) ) // only if medium file { CMessageSearchResult * msg = new CMessageSearchResult(); CMessageSearchFile * smsg = new CMessageSearchFile(); msg->m_nSize = TransferFileObject->m_nSize; msg->m_sFile = TransferFileObject->m_sRemoteFile; msg->m_sNick = TransferObject->sNick; msg->m_sHubName = TransferObject->sHubName; smsg->m_eType = DC_MESSAGE_SEARCH_FILE; CDir dir; dir.SetPath(TransferFileObject->m_sRemoteFile); if ( TransferFileObject->m_sHash != "" ) { smsg->m_sString = "TTH:" + TransferFileObject->m_sHash; smsg->m_eFileType = eftHASH; msg->m_sHash = smsg->m_sString; } else // modded_by_frg: we don't download via filename, we have enough corrupted downloads already! { delete msg; delete smsg; continue; } // frg: now we search to see if a file with the same TTH is not already in the list bool isduplicate = FALSE; for (std::list<CString>::const_iterator i = tthlist->begin(); i != tthlist->end(); i++) if ( *i == smsg->m_sString ) isduplicate = TRUE; if (isduplicate) { // a tth duplicate was found - skip this entry delete msg; delete smsg; continue; } // adding this tth to the list tthlist->push_back(smsg->m_sString); if ( CConfig::Instance()->GetMode() == ecmPASSIVE ) { smsg->m_bLocal = TRUE; smsg->m_sSource = ""; } else { smsg->m_bLocal = FALSE; smsg->m_sSource = CConfig::Instance()->GetUDPHostString(); } m_pSearchList->Add(msg); m_pSearchQueryList->Add(smsg); } } } } delete tthlist; m_pDownloadQueue->pQueue->UnLock(); if ( m_pSearchList->Count() <= 0 ) return FALSE; if ( CSearchManager::Instance()->StartSearch(esmCONNECTEDALL,estyEXTERNAL,m_pSearchQueryList,0) != eseNONE ) return FALSE; return TRUE;}