BOOL CAlbumFolder::MetaToFiles(BOOL bAggressive) { if ( m_pSchema == NULL || m_pXML == NULL ) return FALSE; for ( POSITION pos = GetFileIterator() ; pos ; ) { CLibraryFile* pFile = GetNextFile( pos ); CSchema* pSchema = pFile->m_pSchema; if ( pSchema == NULL ) continue; if ( CSchemaChild* pChild = m_pSchema->GetContained( pSchema->m_sURI ) ) { CXMLElement* pXML = pFile->m_pMetadata->Clone(); if ( pChild->MemberCopy( m_pXML, pXML, TRUE, bAggressive ) ) { CXMLElement* pRoot = pSchema->Instantiate( TRUE ); pRoot->AddElement( pXML ); pFile->SetMetadata( pRoot ); delete pRoot; } else { delete pXML; } } } return TRUE; }
void CLibraryFileView::OnUpdateMusicBrainzLookup(CCmdUI* pCmdUI) { if ( m_bGhostFolder || GetSelectedCount() != 1 || m_bRequestingService ) { pCmdUI->Enable( FALSE ); return; } CSingleLock pLock( &Library.m_pSection ); if ( ! pLock.Lock( 200 ) ) return; CLibraryFile* pFile = GetSelectedFile(); if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) || pFile->m_pMetadata == NULL ) { pCmdUI->Enable( FALSE ); return; } CMetaList* pMetaList = new CMetaList(); pMetaList->Setup( pFile->m_pSchema, FALSE ); pMetaList->Combine( pFile->m_pMetadata ); pLock.Unlock(); pCmdUI->Enable( pMetaList->IsMusicBrainz() ); delete pMetaList; }
BOOL CLibraryAlbumTrack::LockRating() { if ( m_nSetRating == 7 ) { CFilePropertiesSheet dlg; dlg.Add( m_nIndex ); return dlg.DoModal( 2 ) == IDOK; } else if ( m_nSetRating >= 0 && m_nSetRating <= 6 ) { CQuickLock oLock( Library.m_pSection ); CLibraryFile* pFile = Library.LookupFile( m_nIndex ); if ( pFile == NULL ) return FALSE; pFile->m_nRating = m_nRating = ( m_nSetRating > 1 ? m_nSetRating : 0 ); pFile->ModifyMetadata(); Library.Update(); return TRUE; } else { return FALSE; } }
CFileList* CLibraryMaps::WhatsNew(const CQuerySearch* pSearch, int nMaximum) const { ASSUME_LOCK( Library.m_pSection ); const DWORD tNow = static_cast< DWORD >( time( NULL ) ); CFileList* pHits = NULL; for ( POSITION pos = GetFileIterator() ; pos ; ) { CLibraryFile* pFile = GetNextFile( pos ); if ( pFile->IsAvailable() && pFile->IsShared() && pFile->m_oSHA1 && ( ! pSearch->m_pSchema || pSearch->m_pSchema->Equals( pFile->m_pSchema ) ) ) { const DWORD nTime = pFile->GetCreationTime(); if ( nTime && nTime + 12 * 60 * 60 > tNow ) // 12 hours { pFile->m_nHitsToday++; pFile->m_nHitsTotal++; if ( ! pHits ) pHits = new CFileList; pHits->AddTail( pFile ); if ( nMaximum && pHits->GetCount() >= nMaximum ) break; } } } return pHits; }
BOOL CFilesProfilePage::OnInitDialog() { CSettingsPage::OnInitDialog(); CRect rc; m_wndList.GetClientRect( &rc ); rc.right -= GetSystemMetrics( SM_CXVSCROLL ) + 1; m_wndList.InsertColumn( 0, _T("File"), LVCFMT_LEFT, rc.right, -1 ); ShellIcons.AttachTo( &m_wndList, 16 ); // m_wndList.SetImageList() { CQuickLock oLock( Library.m_pSection ); CAlbumFolder* pFolder = LibraryFolders.GetAlbumTarget( CSchema::uriFavouritesFolder, _T("Title"), NULL ); if ( pFolder != NULL ) { for ( POSITION pos = pFolder->GetFileIterator() ; pos ; ) { CLibraryFile* pFile = pFolder->GetNextFile( pos ); if ( pFile->IsShared() ) { m_wndList.InsertItem( LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM, m_wndList.GetItemCount(), pFile->m_sName, 0, 0, ShellIcons.Get( pFile->GetPath(), 16 ), pFile->m_nIndex ); } } } } UpdateData( FALSE ); return TRUE; }
void CAlbumFolder::SetCollection(SHA1* pSHA1, CCollectionFile* pCollection) { m_bCollSHA1 = TRUE; m_pCollSHA1 = *pSHA1; m_sBestView.Empty(); if ( m_pCollection != NULL ) { delete m_pCollection; m_pCollection = NULL; } if ( CXMLElement* pMetadata = pCollection->GetMetadata() ) { pMetadata = pMetadata->Clone(); SetMetadata( pMetadata ); delete pMetadata; } for ( POSITION pos = LibraryMaps.GetFileIterator() ; pos ; ) { CLibraryFile* pFile = LibraryMaps.GetNextFile( pos ); if ( pFile->IsAvailable() ) { if ( m_pCollSHA1 == pFile->m_pSHA1 || pCollection->FindFile( pFile, TRUE ) ) AddFile( pFile ); } } m_nUpdateCookie++; Library.m_nUpdateCookie++; }
void CLibraryFileView::OnLibraryDelete() { CSingleLock pTransfersLock( &Transfers.m_pSection, TRUE ); // Can clear uploads and downloads CSingleLock pLibraryLock( &Library.m_pSection, TRUE ); CLibraryListPtr pList( new CLibraryList() ); POSITION posSel = StartSelectedFileLoop(); while ( CLibraryFile* pFile = GetNextSelectedFile( posSel, FALSE, ! m_bGhostFolder ) ) { pList->AddTail( pFile ); } while ( ! pList->IsEmpty() ) { CLibraryFile* pFile = Library.LookupFile( pList->GetHead(), FALSE, ! m_bGhostFolder ); if ( pFile == NULL ) { pList->RemoveHead(); // Remove item from list to avoid endless loop continue; } if ( m_bGhostFolder ) { for ( INT_PTR nProcess = pList->GetCount() ; nProcess > 0 && pList->GetCount() > 0 ; nProcess-- ) { if ( ( pFile = Library.LookupFile( pList->RemoveHead() ) ) != NULL ) pFile->Delete( TRUE ); } } else { CDeleteFileDlg dlg( this ); dlg.m_sName = pFile->m_sName; dlg.m_sComments = pFile->m_sComments; dlg.m_nRateValue = pFile->m_nRating; dlg.m_bAll = pList->GetCount() > 1; pLibraryLock.Unlock(); pTransfersLock.Unlock(); if ( dlg.DoModal() != IDOK ) break; pTransfersLock.Lock(); pLibraryLock.Lock(); for ( INT_PTR nProcess = dlg.m_bAll ? pList->GetCount() : 1 ; nProcess > 0 && pList->GetCount() > 0 ; nProcess-- ) { if ( ( pFile = Library.LookupFile( pList->RemoveHead(), FALSE, TRUE ) ) != NULL ) { dlg.Apply( pFile ); pFile->Delete(); } } } Library.Update( true ); } }
void CLibraryDictionary::RemoveFile(CLibraryFile& oFile) { ASSUME_LOCK( Library.m_pSection ); ProcessFile( oFile, false, oFile.IsShared() ); // Always invalidate the table when removing a hashed file... // ToDo: Is this wise? It will happen all the time. if ( oFile.IsHashed() ) Invalidate(); }
CLibraryFile* CLibraryMaps::LookupFile(DWORD_PTR nIndex, BOOL bSharedOnly, BOOL bAvailableOnly) const { if ( ! nIndex ) return NULL; CLibraryFile* pFile = NULL; CQuickLock oLock( Library.m_pSection ); return ( m_pIndexMap.Lookup( nIndex, pFile ) && pFile->CheckFileAttributes( SIZE_UNKNOWN, bSharedOnly, bAvailableOnly ) ) ? pFile : NULL; }
// Called when the selection changes void CLibraryFileView::CheckDynamicBar() { bool bIsMusicBrainz = false; ClearServicePages(); CLibraryFrame* pFrame = GetFrame(); if ( _tcscmp( pFrame->GetDynamicBarName(), L"WebServices.MusicBrainz" ) == 0 ) bIsMusicBrainz = true; if ( GetSelectedCount() != 1 ) { if ( bIsMusicBrainz ) { pFrame->SetDynamicBar( NULL ); m_bRequestingService = FALSE; // ToDo: Abort operation } return; } CSingleLock pLock( &Library.m_pSection, TRUE ); CLibraryFile* pFile = GetSelectedFile(); if ( pFile == NULL ) // Ghost file { pFrame->SetDynamicBar( NULL ); m_bRequestingService = FALSE; return; } if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) || pFile->m_pMetadata == NULL ) { if ( bIsMusicBrainz ) pFrame->SetDynamicBar( NULL ); m_bRequestingService = FALSE; // ToDo: Abort operation return; } CMetaList* pMetaList = new CMetaList(); pMetaList->Setup( pFile->m_pSchema, FALSE ); pMetaList->Combine( pFile->m_pMetadata ); pLock.Unlock(); if ( ! pMetaList->IsMusicBrainz() && bIsMusicBrainz ) pFrame->SetDynamicBar( NULL ); else pFrame->HideDynamicBar(); m_bRequestingService = FALSE; // ToDo: Abort operation delete pMetaList; }
void CLibraryMaps::CullDeletedFiles(CLibraryFile* pMatch) { ASSUME_LOCK( Library.m_pSection ); if ( CFileList* pList = LookupFilesByHash( pMatch, FALSE, FALSE, 0 ) ) { for ( POSITION pos = pList->GetHeadPosition() ; pos ; ) { CLibraryFile* pFile = const_cast< CLibraryFile* >( pList->GetNext( pos ) ); if ( ! pFile->IsAvailable() ) pFile->Delete( TRUE ); } delete pList; } }
CLibraryFile* CLibraryMaps::LookupFileByName(LPCTSTR pszName, QWORD nSize, BOOL bSharedOnly, BOOL bAvailableOnly) const { ASSERT_VALID( this ); ASSERT( pszName && *pszName ); CLibraryFile* pFile = NULL; CString strName = PathFindFileName( pszName ); ToLower( strName ); CQuickLock oLock( Library.m_pSection ); return ( m_pNameMap.Lookup( strName, pFile ) && pFile->CheckFileAttributes( nSize, bSharedOnly, bAvailableOnly ) ) ? pFile : NULL; }
BOOL CWebServices::ShowBitprintsTicket(DWORD nIndex) { if ( ! Settings.WebServices.BitprintsOkay ) { if ( MsgBox( IDS_BITPRINTS_MESSAGE, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE; Settings.WebServices.BitprintsOkay = true; Settings.Save(); } CSingleLock pLock( &Library.m_pSection, TRUE ); CLibraryFile* pFile = Library.LookupFile( nIndex ); if ( pFile == NULL ) return FALSE; if ( ! pFile->m_oSHA1 || ! pFile->m_oTiger || ! pFile->m_oED2K ) { CString strMessage; strMessage.Format( LoadString( IDS_BITPRINTS_NOT_HASHED ), (LPCTSTR)pFile->m_sName ); pLock.Unlock(); MsgBox( strMessage, MB_ICONINFORMATION ); return FALSE; } CString str, strURL = Settings.WebServices.BitprintsWebView; CFile hFile; if ( hFile.Open( pFile->GetPath(), CFile::modeRead|CFile::shareDenyNone ) ) { strURL = Settings.WebServices.BitprintsWebSubmit; if ( hFile.GetLength() > 0 ) { static LPCTSTR pszHex = L"0123456789ABCDEF"; BYTE nBuffer[20]; int nPeek = hFile.Read( nBuffer, 20 ); hFile.Close(); for ( int nByte = 0; nByte < nPeek; nByte++ ) { str += pszHex[ (BYTE)nBuffer[ nByte ] >> 4 ]; str += pszHex[ (BYTE)nBuffer[ nByte ] & 15 ]; } strURL.Replace( L"(FIRST20)", str ); } else
int CAlbumFolder::GetSharedCount() const { int nCount = 0; for ( POSITION pos = GetFileIterator() ; pos ; ) { CLibraryFile* pFile = GetNextFile( pos ); if ( pFile->IsShared() ) nCount++; } for ( POSITION pos = GetFolderIterator() ; pos ; ) { nCount += GetNextFolder( pos )->GetSharedCount(); } return nCount; }
CLibraryFile* CLibraryMaps::LookupFileByPath(LPCTSTR pszPath, BOOL bSharedOnly, BOOL bAvailableOnly) const { ASSERT_VALID( this ); ASSERT( pszPath && *pszPath ); if ( ! pszPath ) return NULL; // Bad CLibraryFile* pFile = NULL; CString strPath( pszPath ); strPath.MakeLower(); CQuickLock oLock( Library.m_pSection ); return ( m_pPathMap.Lookup( strPath, pFile ) && pFile->CheckFileAttributes( SIZE_UNKNOWN, bSharedOnly, bAvailableOnly ) ) ? pFile : NULL; }
BOOL CBitprintsDownloader::SubmitMetaData(CXMLElement* pXML) { CQuickLock oLock( Library.m_pSection ); CLibraryFile* pFile = Library.LookupFile( m_nFileIndex ); if ( pFile == NULL ) { delete pXML; return FALSE; } BOOL bSuccess = pFile->MergeMetadata( pXML, TRUE ); delete pXML; return bSuccess; }
void CLibraryDictionary::AddFile(CLibraryFile& oFile) { ASSUME_LOCK( Library.m_pSection ); const bool bCanUpload = oFile.IsShared(); ProcessFile( oFile, true, bCanUpload ); if ( bCanUpload && m_bValid ) m_pTable->AddHashes( oFile ); }
CLibraryFile* CLibraryMaps::LookupFileByTiger(const Hashes::TigerHash& oTiger, BOOL bSharedOnly, BOOL bAvailableOnly) const { if ( ! oTiger ) return NULL; CQuickLock oLock( Library.m_pSection ); CLibraryFile* pFile = m_pTigerMap[ oTiger[ 0 ] & HASH_MASK ]; for ( ; pFile ; pFile = pFile->m_pNextTiger ) { if ( validAndEqual( oTiger, pFile->m_oTiger ) ) { if ( pFile->CheckFileAttributes( SIZE_UNKNOWN, bSharedOnly, bAvailableOnly ) ) return pFile; //return NULL; } } return NULL; }
CLibraryFile* CLibraryMaps::LookupFileBySHA1(const Hashes::Sha1Hash& oSHA1, BOOL bSharedOnly, BOOL bAvailableOnly) const { if ( ! oSHA1 ) return NULL; CQuickLock oLock( Library.m_pSection ); CLibraryFile* pFile = m_pSHA1Map[ oSHA1[ 0 ] & HASH_MASK ]; for ( ; pFile ; pFile = pFile->m_pNextSHA1 ) { if ( validAndEqual( oSHA1, pFile->m_oSHA1 ) ) { if ( pFile->CheckFileAttributes( SIZE_UNKNOWN, bSharedOnly, bAvailableOnly ) ) return pFile; //return NULL; // Note Ghost file would block matching physical file } } return NULL; }
CLibraryFile* CLibraryMaps::LookupFileByBTH(const Hashes::BtHash& oBTH, BOOL bSharedOnly, BOOL bAvailableOnly) const { if ( ! oBTH ) return NULL; CQuickLock oLock( Library.m_pSection ); CLibraryFile* pFile = m_pBTHMap[ oBTH[ 0 ] & HASH_MASK ]; for ( ; pFile ; pFile = pFile->m_pNextBTH ) { if ( validAndEqual( oBTH, pFile->m_oBTH ) ) { if ( pFile->CheckFileAttributes( SIZE_UNKNOWN, bSharedOnly, bAvailableOnly ) ) return pFile; //return NULL; } } return NULL; }
CLibraryFile* CLibraryMaps::LookupFileByMD5(const Hashes::Md5Hash& oMD5, BOOL bSharedOnly, BOOL bAvailableOnly) const { if ( ! oMD5 ) return NULL; CQuickLock oLock( Library.m_pSection ); CLibraryFile* pFile = m_pMD5Map[ oMD5[ 0 ] & HASH_MASK ]; for ( ; pFile ; pFile = pFile->m_pNextMD5 ) { if ( validAndEqual( oMD5, pFile->m_oMD5 ) ) { if ( pFile->CheckFileAttributes( SIZE_UNKNOWN, bSharedOnly, bAvailableOnly ) ) return pFile; //return NULL; } } return NULL; }
CLibraryFile* CLibraryMaps::LookupFileByED2K(const Hashes::Ed2kHash& oED2K, BOOL bSharedOnly, BOOL bAvailableOnly) const { if ( ! oED2K ) return NULL; CQuickLock oLock( Library.m_pSection ); CLibraryFile* pFile = m_pED2KMap[ oED2K[ 0 ] & HASH_MASK ]; for ( ; pFile ; pFile = pFile->m_pNextED2K ) { if ( validAndEqual( oED2K, pFile->m_oED2K ) ) { if ( pFile->CheckFileAttributes( SIZE_UNKNOWN, bSharedOnly, bAvailableOnly ) ) return pFile; //return NULL; } } return NULL; }
BOOL CFileGeneralPage::OnInitDialog() { CFilePropertiesPage::OnInitDialog(); { CQuickLock oLock( Library.m_pSection ); CLibraryFile* pFile = GetFile(); if ( ! pFile ) return TRUE; m_sPath = pFile->GetFolder(); m_sType = ShellIcons.GetTypeString( pFile->m_sName ); m_sSize.Format( _T("%s (%I64i)"), Settings.SmartVolume( pFile->GetSize() ), pFile->GetSize() ); m_sIndex.Format( _T("# %lu"), pFile->m_nIndex ); m_sSHA1 = pFile->m_oSHA1.toShortUrn(); m_sTiger = pFile->m_oTiger.toShortUrn(); m_sED2K = pFile->m_oED2K.toShortUrn(); m_sMD5 = pFile->m_oMD5.toShortUrn(); if ( m_sSHA1.IsEmpty() && m_sED2K.IsEmpty() && m_sTiger.IsEmpty() && m_sMD5.IsEmpty() ) LoadString( m_sSHA1, IDS_NO_URN_AVAILABLE ); SYSTEMTIME pTime; FileTimeToSystemTime( &pFile->m_pTime, &pTime ); SystemTimeToTzSpecificLocalTime( NULL, &pTime, &pTime ); CString strDate, strTime; GetDateFormat( LOCALE_USER_DEFAULT, DATE_LONGDATE, &pTime, NULL, strDate.GetBuffer( 64 ), 64 ); GetTimeFormat( LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT, &pTime, NULL, strTime.GetBuffer( 64 ), 64 ); strDate.ReleaseBuffer(); strTime.ReleaseBuffer(); m_sModified = strDate + _T(", ") + strTime; } UpdateData( FALSE ); return TRUE; }
CFileList* CLibraryMaps::Browse(int nMaximum) const { ASSUME_LOCK( Library.m_pSection ); CFileList* pHits = NULL; for ( POSITION pos = GetFileIterator() ; pos ; ) { CLibraryFile* pFile = GetNextFile( pos ); if ( pFile->IsAvailable() && pFile->IsShared() && pFile->m_oSHA1 ) { if ( ! pHits ) pHits = new CFileList; pHits->AddTail( pFile ); if ( nMaximum && pHits->GetCount() >= nMaximum ) break; } } return pHits; }
void CLibraryMetaPanel::Update() { CSingleLock pLock1( &Library.m_pSection, TRUE ); CSingleLock pLock2( &m_pSection, TRUE ); CLibraryListPtr pSel( GetViewSelection() ); m_nSelected = pSel ? static_cast< int >( pSel->GetCount() ) : 0; // Show info for library files only CLibraryFile* pFirst = NULL; if ( m_nSelected ) { const CLibraryListItem& pItem = pSel->GetHead(); if ( pItem.Type == CLibraryListItem::LibraryFile ) pFirst = Library.LookupFile( pItem ); if ( pFirst == NULL ) m_nSelected = 0; } m_nIcon32 = m_nIcon48 = -1; if ( m_nSelected == 1 ) { m_nIndex = pFirst->m_nIndex; m_sName = pFirst->m_sName; m_sPath = pFirst->GetPath(); m_sFolder = pFirst->GetFolder(); m_sSize = Settings.SmartVolume( pFirst->GetSize() ); m_sType = ShellIcons.GetTypeString( m_sName ); m_nIcon32 = ShellIcons.Get( pFirst->GetPath(), 32 ); m_nIcon48 = ShellIcons.Get( pFirst->GetPath(), 48 ); m_nRating = pFirst->m_nRating; } else if ( m_nSelected > 1 ) { CString strFormat; LoadString( strFormat, IDS_LIBPANEL_MULTIPLE_FILES ); m_sName.Format( strFormat, m_nSelected ); QWORD nSize = 0; m_sFolder = pFirst->GetFolder(); m_nIcon32 = ShellIcons.Get( pFirst->GetPath(), 32 ); m_nIcon48 = ShellIcons.Get( pFirst->GetPath(), 48 ); m_nRating = 0; for ( POSITION pos = pSel->GetHeadPosition() ; pos ; ) { CLibraryFile* pFile = Library.LookupFile( pSel->GetNext( pos ) ); if ( pFile == NULL ) continue; nSize += pFile->GetSize() / 1024; if ( pFile->IsAvailable() && pFile->GetFolder().CompareNoCase( m_sFolder ) ) { LoadString( m_sFolder, IDS_LIBPANEL_MULTIPLE_FOLDERS ); } int nIcon = ShellIcons.Get( pFile->GetPath(), 48 ); if ( nIcon != m_nIcon48 ) m_nIcon48 = -1; nIcon = ShellIcons.Get( pFile->GetPath(), 32 ); if ( nIcon != m_nIcon32 ) m_nIcon32 = -1; } m_sSize = Settings.SmartVolume( nSize ); m_sPath.Empty(); m_sType.Empty(); } m_pSchema = NULL; if ( pSel ) { for ( POSITION pos = pSel->GetHeadPosition() ; pos ; ) { const CLibraryListItem& pItem = pSel->GetNext( pos ); if ( pItem.Type != CLibraryListItem::LibraryFile ) continue; CLibraryFile* pFile = Library.LookupFile( pItem ); if ( pFile == NULL ) continue; m_pSchema = pFile->m_pSchema; if ( m_pSchema ) break; } } if ( m_pServiceData ) { m_pMetadata->Setup( m_pServiceData ); } else { m_pMetadata->Setup( m_pSchema ); if ( m_pSchema && pSel ) { for ( POSITION pos = pSel->GetHeadPosition() ; pos ; ) { const CLibraryListItem& pItem = pSel->GetNext( pos ); if ( pItem.Type != CLibraryListItem::LibraryFile ) continue; if ( CLibraryFile* pFile = Library.LookupFile( pItem ) ) { if ( pFile->m_pMetadata != NULL && m_pSchema->Equals( pFile->m_pSchema ) ) { m_pMetadata->Combine( pFile->m_pMetadata ); } } } } } m_pMetadata->CreateLinks(); m_pMetadata->Clean( 4096 ); CClientDC dc( this ); if ( Settings.General.LanguageRTL ) SetLayout( dc.m_hDC, LAYOUT_BITMAPORIENTATIONPRESERVED ); SCROLLINFO pInfo; CRect rc; GetClientRect( &rc ); int nThumbSize = min( max( rc.Height() - 16, 64 ), (int)Settings.Library.ThumbSize ); int nHeight = 54 + m_pMetadata->Layout( &dc, rc.Width() - 24 - nThumbSize ); pInfo.cbSize = sizeof(pInfo); pInfo.fMask = SIF_ALL & ~SIF_TRACKPOS; pInfo.nMin = 0; pInfo.nMax = nHeight; pInfo.nPage = rc.Height(); pInfo.nPos = GetScrollPos( SB_VERT ); pInfo.nPos = max( 0, min( pInfo.nPos, pInfo.nMax - (int)pInfo.nPage + 1 ) ); SetScrollInfo( SB_VERT, &pInfo, TRUE ); if ( m_bForceUpdate || ( m_sThumb != m_sPath ) ) { m_bForceUpdate = FALSE; if ( m_bmThumb.m_hObject ) m_bmThumb.DeleteObject(); if ( ! IsThreadAlive() ) { BeginThread( "CtrlLibraryMetaPanel" ); } } pLock2.Unlock(); pLock1.Unlock(); Invalidate(); }
void CLibraryDetailView::CacheItem(int nItem) { CLibraryFile* pFile = Library.LookupFile( m_pList[ nItem ].nIndex ); if ( ! pFile ) return; LDVITEM* pItem = &m_pList[ nItem ]; pItem->nCookie = m_nListCookie; if ( pItem->pText == NULL ) pItem->pText = new CStringArray(); CStringArray* pText = pItem->pText; pText->SetSize( m_nStyle == LVS_REPORT ? DETAIL_COLUMNS + m_pColumns.GetCount() : 1 ); CString strName( pFile->m_sName ); int nDot = strName.ReverseFind( '.' ); if ( nDot >= 0 ) strName.SetAt( nDot, 0 ); pText->SetAt( 0, strName ); if ( m_nStyle == LVS_ICON ) { pItem->nIcon = ShellIcons.Get( pFile->m_sName, 32 ); } else { if ( pFile->m_nIcon16 >= 0 ) pItem->nIcon = pFile->m_nIcon16; else pItem->nIcon = pFile->m_nIcon16 = ShellIcons.Get( pFile->m_sName, 16 ); } pItem->nState &= LDVI_SELECTED; if ( ! pFile->IsShared() ) pItem->nState |= LDVI_PRIVATE; if ( ! pFile->m_bSHA1 ) pItem->nState |= LDVI_UNSCANNED; if ( pFile->m_bVerify == TS_FALSE ) pItem->nState |= LDVI_UNSAFE; if ( m_nStyle != LVS_REPORT ) return; if ( LPCTSTR pszType = _tcsrchr( pFile->m_sName, '.' ) ) pText->SetAt( 1, pszType + 1 ); else pText->SetAt( 1, _T("") ); pText->SetAt( 2, Settings.SmartVolume( pFile->GetSize(), FALSE ) ); if ( pFile->m_pFolder != NULL ) pText->SetAt( 3, pFile->m_pFolder->m_sPath ); CString str; str.Format( _T("%lu (%lu)"), pFile->m_nHitsToday, pFile->m_nHitsTotal ); pText->SetAt( 4, str ); str.Format( _T("%lu (%lu)"), pFile->m_nUploadsToday, pFile->m_nUploadsTotal ); pText->SetAt( 5, str ); TCHAR szModified[ 64 ]; SYSTEMTIME pTime; FileTimeToSystemTime( &pFile->m_pTime, &pTime ); SystemTimeToTzSpecificLocalTime( NULL, &pTime, &pTime ); GetDateFormat( LOCALE_USER_DEFAULT, 0, &pTime, _T("yyyy-MM-dd"), szModified, 64 ); _tcscat( szModified, _T(" ") ); GetTimeFormat( LOCALE_USER_DEFAULT, 0, &pTime, _T("hh:mm tt"), szModified + _tcslen( szModified ), 64 - _tcslen( szModified ) ); pText->SetAt( 6, szModified ); if ( m_pSchema == NULL ) return; int nColumn = DETAIL_COLUMNS; BOOL bSource = pFile->m_pMetadata && m_pSchema->Equals( pFile->m_pSchema ) && m_pSchema->m_sSingular.CompareNoCase( pFile->m_pMetadata->GetName() ) == 0; for ( POSITION pos = m_pColumns.GetHeadPosition() ; pos ; nColumn++ ) { CSchemaMember* pMember = (CSchemaMember*)m_pColumns.GetNext( pos ); if ( pMember->m_sName.CompareNoCase( _T("SHA1") ) == 0 ) { if ( pFile->m_bSHA1 ) { pText->SetAt( nColumn, CSHA::HashToString( &pFile->m_pSHA1 ) ); } else pText->SetAt( nColumn, _T("") ); } else if ( bSource ) { pText->SetAt( nColumn, pMember->GetValueFrom( pFile->m_pMetadata, NULL, TRUE ) ); } else { pText->SetAt( nColumn, _T("") ); } } }
int CLibraryDetailView::ListCompare(LPCVOID pA, LPCVOID pB) { LDVITEM* ppA = (LDVITEM*)pA; LDVITEM* ppB = (LDVITEM*)pB; int nTest = 0; CLibraryFile* pfA = Library.LookupFile( ppA->nIndex ); CLibraryFile* pfB = Library.LookupFile( ppB->nIndex ); if ( ! pfA || ! pfB ) return 0; switch ( m_pThis->m_nSortColumn ) { case 0: nTest = _tcsicoll( pfA->m_sName, pfB->m_sName ); break; case 1: { LPCTSTR pszA = _tcsrchr( pfA->m_sName, '.' ); LPCTSTR pszB = _tcsrchr( pfB->m_sName, '.' ); if ( ! pszA || ! pszB ) return 0; nTest = _tcsicoll( pszA, pszB ); break; } case 2: if ( pfA->GetSize() == pfB->GetSize() ) nTest = 0; else if ( pfA->GetSize() < pfB->GetSize() ) nTest = -1; else nTest = 1; break; case 3: if ( pfA->m_pFolder == NULL || pfB->m_pFolder == NULL ) return 0; nTest = _tcsicoll( pfA->m_pFolder->m_sPath, pfB->m_pFolder->m_sPath ); break; case 4: if ( pfA->m_nHitsTotal == pfB->m_nHitsTotal ) nTest = 0; else if ( pfA->m_nHitsTotal < pfB->m_nHitsTotal ) nTest = -1; else nTest = 1; break; case 5: if ( pfA->m_nUploadsTotal == pfB->m_nUploadsTotal ) nTest = 0; else if ( pfA->m_nUploadsTotal < pfB->m_nUploadsTotal ) nTest = -1; else nTest = 1; break; case 6: nTest = CompareFileTime( &pfA->m_pTime, &pfB->m_pTime ); break; default: { int nColumn = m_pThis->m_nSortColumn - DETAIL_COLUMNS; if ( nColumn >= m_pThis->m_pColumns.GetCount() ) return 0; POSITION pos = m_pThis->m_pColumns.FindIndex( nColumn ); if ( pos == NULL ) return 0; CSchemaMember* pMember = (CSchemaMember*)m_pThis->m_pColumns.GetAt( pos ); CString strA, strB; if ( pfA->m_pMetadata ) strA = pMember->GetValueFrom( pfA->m_pMetadata, NULL, TRUE ); if ( pfB->m_pMetadata ) strB = pMember->GetValueFrom( pfB->m_pMetadata, NULL, TRUE ); if ( *(LPCTSTR)strA && *(LPCTSTR)strB && ( ((LPCTSTR)strA)[ _tcslen( strA ) - 1 ] == 'k' || ((LPCTSTR)strA)[ _tcslen( strA ) - 1 ] == '~' ) && ( ((LPCTSTR)strB)[ _tcslen( strB ) - 1 ] == 'k' || ((LPCTSTR)strB)[ _tcslen( strB ) - 1 ] == '~' ) ) { nTest = CLiveList::SortProc( strA, strB, TRUE ); } else { nTest = _tcsicoll( strA, strB ); } } } if ( ! m_pThis->m_bSortFlip ) nTest = -nTest; return nTest; }
void CLibraryMaps::OnFileRemove(CLibraryFile* pFile) { CLibraryFile* pOld; if ( pFile->m_nIndex ) { pOld = LookupFile( pFile->m_nIndex ); if ( pOld == pFile ) { m_pIndexMap.RemoveKey( pFile->m_nIndex ); if ( pOld->IsAvailable() ) { m_nFiles --; m_nVolume -= pFile->m_nSize; } } } pOld = LookupFileByName( pFile->GetNameLC(), pFile->m_nSize, FALSE, FALSE ); if ( pOld == pFile ) m_pNameMap.RemoveKey( pFile->GetNameLC() ); if ( pFile->IsAvailable() ) { CString strPath( pFile->GetPath() ); ToLower( strPath ); pOld = LookupFileByPath( strPath ); if ( pOld == pFile ) m_pPathMap.RemoveKey( strPath ); } if ( POSITION pos = m_pDeleted.Find( pFile ) ) m_pDeleted.RemoveAt( pos ); if ( pFile->m_oSHA1 ) { CLibraryFile** pPrev = &m_pSHA1Map[ pFile->m_oSHA1[ 0 ] & HASH_MASK ]; for ( CLibraryFile* pOther = *pPrev ; pOther ; pOther = pOther->m_pNextSHA1 ) { if ( pOther == pFile ) { *pPrev = pOther->m_pNextSHA1; break; } pPrev = &pOther->m_pNextSHA1; } pFile->m_pNextSHA1 = NULL; } if ( pFile->m_oTiger ) { CLibraryFile** pPrev = &m_pTigerMap[ pFile->m_oTiger[ 0 ] & HASH_MASK ]; for ( CLibraryFile* pOther = *pPrev ; pOther ; pOther = pOther->m_pNextTiger ) { if ( pOther == pFile ) { *pPrev = pOther->m_pNextTiger; break; } pPrev = &pOther->m_pNextTiger; } pFile->m_pNextTiger = NULL; } if ( pFile->m_oED2K ) { CLibraryFile** pPrev = &m_pED2KMap[ pFile->m_oED2K[ 0 ] & HASH_MASK ]; for ( CLibraryFile* pOther = *pPrev ; pOther ; pOther = pOther->m_pNextED2K ) { if ( pOther == pFile ) { *pPrev = pOther->m_pNextED2K; break; } pPrev = &pOther->m_pNextED2K; } pFile->m_pNextED2K = NULL; } if ( pFile->m_oBTH ) { CLibraryFile** pPrev = &m_pBTHMap[ pFile->m_oBTH[ 0 ] & HASH_MASK ]; for ( CLibraryFile* pOther = *pPrev ; pOther ; pOther = pOther->m_pNextBTH ) { if ( pOther == pFile ) { *pPrev = pOther->m_pNextBTH; break; } pPrev = &pOther->m_pNextBTH; } pFile->m_pNextBTH = NULL; } if ( pFile->m_oMD5 ) { CLibraryFile** pPrev = &m_pMD5Map[ pFile->m_oMD5[ 0 ] & HASH_MASK ]; for ( CLibraryFile* pOther = *pPrev ; pOther ; pOther = pOther->m_pNextMD5 ) { if ( pOther == pFile ) { *pPrev = pOther->m_pNextMD5; break; } pPrev = &pOther->m_pNextMD5; } pFile->m_pNextMD5 = NULL; } }
void CLibraryAlbumView::Update() { CLibraryTreeItem* pFolders = GetFolderSelection(); m_pStaticStyle = m_pStyle; m_pStyle = NULL; BOOL bGhostFolder = FALSE; if ( pFolders != NULL && pFolders->m_pVirtual != NULL && pFolders->m_pSelNext == NULL ) { CAlbumFolder* pFolder = pFolders->m_pVirtual; if ( CheckURI( pFolder->m_sSchemaURI, CSchema::uriMusicAlbum ) ) m_pStyle = CSchema::uriMusicAlbum; else if ( CheckURI( pFolder->m_sSchemaURI, CSchema::uriMusicArtist ) ) m_pStyle = CSchema::uriMusicArtist; else if ( CheckURI( pFolder->m_sSchemaURI, CSchema::uriMusicAll ) || CheckURI( pFolder->m_sSchemaURI, CSchema::uriMusicGenre ) ) m_pStyle = CSchema::uriMusicAll; else if ( CheckURI( pFolder->m_sSchemaURI, CSchema::uriGhostFolder ) ) bGhostFolder = TRUE; } CSchemaPtr pSchema = SchemaCache.Get( Settings.Library.FilterURI ); DWORD nCookie = GetFolderCookie(); BOOL bChanged = m_pStyle != m_pStaticStyle; if ( Settings.Library.ShowVirtual ) pSchema = NULL; CLibraryAlbumTrack** pList = m_pList + m_nCount - 1; for ( int nItem = m_nCount ; nItem ; nItem--, pList-- ) { CLibraryAlbumTrack* pTrack = *pList; CLibraryFile* pFile = Library.LookupFile( pTrack->m_nIndex ); if ( pFile != NULL && pFile->m_nSelectCookie == nCookie && ( pFile->IsAvailable() || bGhostFolder ) && ( ! pSchema || pSchema->Equals( pFile->m_pSchema ) || ( ! pFile->m_pMetadata && pSchema->FilterType( pFile->m_sName ) ) ) ) { bChanged |= pTrack->Update( pFile ); pFile->m_nListCookie = nCookie; } else { if ( pTrack == m_pFocus ) m_pFocus = NULL; if ( pTrack == m_pFirst ) m_pFirst = NULL; if ( pTrack->m_bSelected ) Select( pTrack, TRI_FALSE ); delete pTrack; MoveMemory( pList, pList + 1, ( m_nCount - nItem ) * sizeof *pList ); m_nCount--; bChanged = TRUE; } } if ( bChanged ) { CRect rcClient; GetClientRect( &rcClient ); int nMax = m_nCount * m_szTrack.cy; m_nScroll = max( 0, min( m_nScroll, nMax - rcClient.Height() + 1 ) ); } for ( POSITION pos = LibraryMaps.GetFileIterator() ; pos ; ) { CLibraryFile* pFile = LibraryMaps.GetNextFile( pos ); if ( pFile->m_nSelectCookie == nCookie && pFile->m_nListCookie != nCookie && ( pFile->IsAvailable() || bGhostFolder ) && ( ! pSchema || pSchema->Equals( pFile->m_pSchema ) || ( ! pFile->m_pMetadata && pSchema->FilterType( pFile->m_sName ) ) ) ) { CLibraryAlbumTrack* pTrack = new CLibraryAlbumTrack( pFile ); if ( m_nCount == m_nBuffer ) { m_nBuffer += 64; CLibraryAlbumTrack** pNewList = new CLibraryAlbumTrack*[ m_nBuffer ]; if ( m_nCount ) CopyMemory( pNewList, m_pList, m_nCount * sizeof( CLibraryAlbumTrack* ) ); delete [] m_pList; m_pList = pNewList; } m_pList[ m_nCount++ ] = pTrack; pFile->m_nListCookie = nCookie; bChanged = TRUE; } } if ( bChanged ) { m_pStaticStyle = m_pStyle; qsort( m_pList, m_nCount, sizeof *m_pList, SortList ); UpdateScroll(); } }
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 }