void CFileContainerArc::List(CFileList &list, const char *mask, unsigned flags) { TString<256> Path; Path = mask; char *name = Path.rchr('/'); FDirInfo *Dir; if (name) { *name++ = 0; Dir = FindDir(Path); if (!Dir) return; // directory not found } else { name = Path; Dir = &Root; } // list directories and files #if FS_DIR != FS_FILE<<1 #error Check FS_DIR / FS_FILE relationship #endif for (unsigned Flag = FS_FILE; Flag <= FS_DIR; Flag <<= 1) { if (!(flags & Flag)) continue; CListIterator it; if (Flag == FS_FILE) // cannot write this as "it = (Flag == FS_FILE) ? ..." it = Dir->Files; else it = Dir->Dirs; for ( ; it; ++it) { if (!appMatchWildcard(it->name, name)) continue; TString<256> Name; Name = it->name; // process NOEXT if (flags & FS_NOEXT) { char *s = Name.rchr('.'); if (s) *s = 0; } CFileItem *item, *place; if (!(item = list.Find(Name, &place))) { item = new (Name, &list) CFileItem; // here: item->flags=0 list.InsertAfter(item, place); } item->flags |= containFlags|Flag; } } }
void CLibraryDictionary::ProcessWord(CLibraryFile& oFile, const CString& strWord, bool bAdd, bool bCanUpload) { ASSUME_LOCK( Library.m_pSection ); CFileList* pList = NULL; if ( m_oWordMap.Lookup( strWord, pList ) ) { if ( POSITION pos = pList->Find( &oFile ) ) { if ( ! bAdd ) { pList->RemoveAt( pos ); if ( pList->IsEmpty() ) { delete pList; VERIFY( m_oWordMap.RemoveKey( strWord ) ); if ( bCanUpload && m_bValid ) Invalidate(); } } } else { if ( bAdd ) { pList->AddTail( &oFile ); if ( bCanUpload && m_bValid ) m_pTable->AddExactString( strWord ); } } } else if ( bAdd ) { pList = new CFileList; if ( pList ) { pList->AddTail( &oFile ); m_oWordMap.SetAt( strWord, pList ); if ( bCanUpload && m_bValid ) m_pTable->AddExactString( strWord ); } } }
CFileList* CLibraryMaps::LookupFilesByHash(const CPeerProjectFile* pFilter, BOOL bSharedOnly, BOOL bAvailableOnly, int nMaximum) const { CQuickLock oLock( Library.m_pSection ); CFileList* pFiles = NULL; if ( pFilter->m_oSHA1 ) { for ( CLibraryFile* pFile = m_pSHA1Map[ pFilter->m_oSHA1[ 0 ] & HASH_MASK ] ; pFile ; pFile = pFile->m_pNextSHA1 ) { if ( validAndEqual( pFile->m_oSHA1, pFilter->m_oSHA1 ) && *pFile == *pFilter && pFile->CheckFileAttributes( pFilter->m_nSize, bSharedOnly, bAvailableOnly ) ) { if ( ! pFiles ) pFiles = new CFileList; if ( pFiles->Find( pFile ) == NULL ) { if ( bSharedOnly ) { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; } pFiles->AddTail( pFile ); if ( nMaximum && pFiles->GetCount() >= nMaximum ) break; } } } return pFiles; } if ( pFilter->m_oED2K ) { for ( CLibraryFile* pFile = m_pED2KMap[ pFilter->m_oED2K[ 0 ] & HASH_MASK ] ; pFile ; pFile = pFile->m_pNextED2K ) { if ( validAndEqual( pFile->m_oED2K, pFilter->m_oED2K ) && *pFile == *pFilter && pFile->CheckFileAttributes( pFilter->m_nSize, bSharedOnly, bAvailableOnly ) ) { if ( ! pFiles ) pFiles = new CFileList; if ( pFiles->Find( pFile ) == NULL ) { if ( bSharedOnly ) { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; } pFiles->AddTail( pFile ); if ( nMaximum && pFiles->GetCount() >= nMaximum ) return pFiles; } } } return pFiles; } if ( pFilter->m_oTiger ) { for ( CLibraryFile* pFile = m_pTigerMap[ pFilter->m_oTiger[ 0 ] & HASH_MASK ] ; pFile ; pFile = pFile->m_pNextTiger ) { if ( validAndEqual( pFile->m_oTiger, pFilter->m_oTiger ) && *pFile == *pFilter && pFile->CheckFileAttributes( pFilter->m_nSize, bSharedOnly, bAvailableOnly ) ) { if ( ! pFiles ) pFiles = new CFileList; if ( pFiles->Find( pFile ) == NULL ) { if ( bSharedOnly ) { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; } pFiles->AddTail( pFile ); if ( nMaximum && pFiles->GetCount() >= nMaximum ) break; } } } return pFiles; } if ( pFilter->m_oBTH ) { for ( CLibraryFile* pFile = m_pBTHMap[ pFilter->m_oBTH[ 0 ] & HASH_MASK ] ; pFile ; pFile = pFile->m_pNextBTH ) { if ( validAndEqual( pFile->m_oBTH, pFilter->m_oBTH ) && *pFile == *pFilter && pFile->CheckFileAttributes( pFilter->m_nSize, bSharedOnly, bAvailableOnly ) ) { if ( ! pFiles ) pFiles = new CFileList; if ( pFiles->Find( pFile ) == NULL ) { if ( bSharedOnly ) { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; } pFiles->AddTail( pFile ); if ( nMaximum && pFiles->GetCount() >= nMaximum ) return pFiles; } } } return pFiles; } if ( pFilter->m_oMD5 ) { // Since MD5 is not commonly used for searches we use it for the duplicate file search // which requires getting a list of files not to return only 1 file. See CLibrary::CheckDuplicates for ( CLibraryFile* pFile = m_pMD5Map[ pFilter->m_oMD5[ 0 ] & HASH_MASK ] ; pFile ; pFile = pFile->m_pNextMD5 ) { if ( validAndEqual( pFile->m_oMD5, pFilter->m_oMD5 ) && *pFile == *pFilter && pFile->CheckFileAttributes( pFilter->m_nSize, bSharedOnly, bAvailableOnly ) ) { if ( ! pFiles ) pFiles = new CFileList; if ( pFiles->Find( pFile ) == NULL ) { if ( bSharedOnly ) { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; } pFiles->AddTail( pFile ); if ( nMaximum && pFiles->GetCount() >= nMaximum ) break; } } } return pFiles; } if ( ! pFilter->m_sName.IsEmpty() && pFilter->m_nSize != SIZE_UNKNOWN && pFilter->m_nSize != 0 ) { if ( CLibraryFile* pFile = LibraryMaps.LookupFileByName( pFilter->m_sName, pFilter->m_nSize, bSharedOnly, bAvailableOnly ) ) { if ( ! pFiles ) pFiles = new CFileList; if ( pFiles->Find( pFile ) == NULL ) { if ( bSharedOnly ) { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; } pFiles->AddTail( pFile ); } } return pFiles; } return pFiles; // Null }