예제 #1
0
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;
}
예제 #2
0
void CLibraryMaps::Clear()
{
	for ( POSITION pos = GetFileIterator() ; pos ; ) delete GetNextFile( pos );

	ASSERT( m_pIndexMap.IsEmpty() );
	ASSERT( m_pPathMap.IsEmpty() );
#ifdef _DEBUG
	for ( POSITION p = m_pPathMap.GetStartPosition() ; p ; )
	{
		CString k;
		CLibraryFile* v;
		m_pPathMap.GetNextAssoc( p, k, v );
		TRACE ( _T("m_pPathMap lost : %ls = 0x%08x\n"), (LPCTSTR)k, v );
	}
#endif

	ZeroMemory( m_pSHA1Map, HASH_SIZE * sizeof *m_pSHA1Map );
	ZeroMemory( m_pTigerMap, HASH_SIZE * sizeof *m_pTigerMap );
	ZeroMemory( m_pED2KMap, HASH_SIZE * sizeof *m_pED2KMap );
	ZeroMemory( m_pBTHMap, HASH_SIZE * sizeof *m_pBTHMap );
	ZeroMemory( m_pMD5Map, HASH_SIZE * sizeof *m_pMD5Map );

	m_nFiles  = 0;
	m_nVolume = 0;
}
예제 #3
0
CCollectionFile::File* CCollectionFile::FindByURN(LPCTSTR pszURN)
{
	Hashes::Sha1Hash oSHA1;
	Hashes::TigerHash oTiger;
	Hashes::Md5Hash oMD5;
	Hashes::Ed2kHash oED2K;
	Hashes::BtHash oBTH;

	oSHA1.fromUrn( pszURN );
	oMD5.fromUrn( pszURN );
	oTiger.fromUrn( pszURN );
	oED2K.fromUrn( pszURN );
	oBTH.fromUrn( pszURN ) || oBTH.fromUrn< Hashes::base16Encoding >( pszURN );

	for ( POSITION pos = GetFileIterator(); pos; )
	{
		File* pFile = GetNextFile( pos );

		if ( validAndEqual( oSHA1, pFile->m_oSHA1 ) ) return pFile;
		if ( validAndEqual( oMD5, pFile->m_oMD5 ) ) return pFile;
		if ( validAndEqual( oTiger, pFile->m_oTiger ) ) return pFile;
		if ( validAndEqual( oED2K, pFile->m_oED2K ) ) return pFile;
		if ( validAndEqual( oBTH, pFile->m_oBTH ) ) return pFile;
	}

	return NULL;
}
예제 #4
0
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;
}
예제 #5
0
int CCollectionFile::GetMissingCount() const
{
	int nCount = 0;

	for ( POSITION pos = GetFileIterator(); pos; )
	{
		const File* pFile = GetNextFile( pos );
		if ( ! pFile->IsComplete() && ! pFile->IsDownloading() ) nCount++;
	}

	return nCount;
}
예제 #6
0
void CCollectionFile::Close()
{
	for ( POSITION pos = GetFileIterator(); pos; )
		delete GetNextFile( pos );
	m_pFiles.RemoveAll();

	delete m_pMetadata;
	m_pMetadata = NULL;

	m_sTitle.Empty();
	m_sThisURI.Empty();
	m_sParentURI.Empty();
}
예제 #7
0
void CCollectionFile::Render(CString& strBuffer) const
{
	strBuffer.Preallocate( GetFileCount() * 128 + 256 );

	strBuffer.Format( L"<html>\n<head>\n"
		L"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"
		L"<title>%s</title>\n"
		L"<style type=\"text/css\">\n"
		L"body  { margin: 0px; padding: 0px; background-color: #ffffff; color: #000000; font-family: %s; font-size: %upx; }\n"
		L"h1    { text-align: left; color: #ffffff; height: 64px; margin: 0px; padding: 20px; font-size: 10pt; font-weight: bold; background-image: url(res://Envy.exe/312); }\n"
		L"table { font-size: 8pt; width: 100%%; }\n"
		L"td    { background-color: #e0e8f0; padding: 4px; }\n"
		L".num  { width: 40px; text-align: center; }\n"
		L".url  { text-align: left; cursor: hand; }\n"
		L".size { width: 100px; text-align: center; }\n"
		L"</style>\n</head>\n<body>\n<h1>%s</h1>\n<table>\n",
		(LPCTSTR)GetTitle(),
		(LPCTSTR)Settings.Fonts.DefaultFont, Settings.Fonts.DefaultSize,
		(LPCTSTR)GetTitle() );

	DWORD i = 1;
	for ( POSITION pos = GetFileIterator(); pos; ++i )
	{
		CCollectionFile::File* pFile = GetNextFile( pos );

		CString strURN;
		if ( pFile->m_oSHA1 )
			strURN = pFile->m_oSHA1.toUrn();
		else if ( pFile->m_oTiger )
			strURN = pFile->m_oTiger.toUrn();
		else if ( pFile->m_oED2K )
			strURN = pFile->m_oED2K.toUrn();
		else if ( pFile->m_oMD5 )
			strURN = pFile->m_oMD5.toUrn();
		else if ( pFile->m_oBTH )
			strURN = pFile->m_oBTH.toUrn();

		CString strTemp;
		strTemp.Format( L"<tr><td class=\"num\">%u</td>"
			L"<td class=\"url\" onclick=\"if ( ! window.external.open('%s') ) window.external.download('%s');\" onmouseover=\"window.external.hover('%s');\" onmouseout=\"window.external.hover('');\">%s</td>"
			L"<td class=\"size\">%s</td></tr>\n",
			i, (LPCTSTR)strURN, (LPCTSTR)strURN, (LPCTSTR)strURN, (LPCTSTR)pFile->m_sName,
			(LPCTSTR)Settings.SmartVolume( pFile->m_nSize ) );
		strBuffer += strTemp;
	}

	strBuffer += L"</table>\n</body>\n</html>";
}
예제 #8
0
void CAlbumFolder::Serialize(CArchive& ar, int nVersion)
{
	POSITION pos;

	if ( ar.IsStoring() )
	{
		ar << m_sSchemaURI;

		ar.WriteCount( m_pXML != NULL ? 1 : 0 );
		if ( m_pXML ) m_pXML->Serialize( ar );

		ar << m_bCollSHA1;
		if ( m_bCollSHA1 ) ar.Write( &m_pCollSHA1, sizeof(SHA1) );

		ar << m_sName;
		ar << m_bExpanded;
		ar << m_bAutoDelete;
		ar << m_sBestView;

		ar.WriteCount( GetFolderCount() );

		for ( pos = GetFolderIterator() ; pos ; )
		{
			CAlbumFolder* pFolder = GetNextFolder( pos );
			pFolder->Serialize( ar, nVersion );
		}

		ar.WriteCount( GetFileCount() );

		for ( pos = GetFileIterator() ; pos ; )
		{
			CLibraryFile* pFile = GetNextFile( pos );
			ar << pFile->m_nIndex;
		}
	}
	else
	{
		CLibraryFile* pCollection = NULL;

		if ( m_pParent != NULL )
		{
			ar >> m_sSchemaURI;
			m_pSchema = SchemaCache.Get( m_sSchemaURI );
		}
		else
		{
예제 #9
0
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;
}
예제 #10
0
BOOL CUploadsCtrl::GetAt(int nSelect, CUploadQueue** ppQueue, CUploadFile** ppFile)
{
	ASSUME_LOCK( Transfers.m_pSection );

	/*int nScroll =*/ GetScrollPos( SB_VERT );
	int nIndex = 0;
	
	if ( ppQueue != NULL ) *ppQueue = NULL;
	if ( ppFile != NULL ) *ppFile = NULL;

	CSingleLock pLock( &UploadQueues.m_pSection, FALSE );
	if ( ! pLock.Lock( 250 ) )
		return FALSE;
	
	for ( POSITION posQueue = GetQueueIterator() ; posQueue ; )
	{
		CUploadQueue* pQueue = GetNextQueue( posQueue );
		
		POSITION posFile = GetFileIterator( pQueue );
		if ( posFile == NULL ) continue;
		
		if ( nIndex++ == nSelect )
		{
			if ( ppQueue != NULL ) *ppQueue = pQueue;
			return TRUE;
		}
		
		if ( ! pQueue->m_bExpanded ) continue;
		
		while ( posFile )
		{
			CUploadFile* pFile = GetNextFile( pQueue, posFile );
			if ( pFile == NULL ) continue;
			
			if ( nIndex++ == nSelect )
			{
				if ( ppFile != NULL ) *ppFile = pFile;
				return TRUE;
			}
		}
	}
	
	return FALSE;
}
예제 #11
0
CCollectionFile::File* CCollectionFile::FindFile(CLibraryFile* pShared, BOOL bApply)
{
	File* pFile = NULL;

	for ( POSITION pos = GetFileIterator(); pos; )
	{
		pFile = GetNextFile( pos );
		if ( validAndEqual( pShared->m_oSHA1, pFile->m_oSHA1 ) ) break;
		if ( validAndEqual( pShared->m_oMD5, pFile->m_oMD5 ) ) break;
		if ( validAndEqual( pShared->m_oTiger, pFile->m_oTiger ) ) break;
		if ( validAndEqual( pShared->m_oED2K, pFile->m_oED2K ) ) break;
		if ( validAndEqual( pShared->m_oBTH, pFile->m_oBTH ) ) break;
		pFile = NULL;
	}

	if ( bApply && pFile != NULL )
		pFile->ApplyMetadata( pShared );

	return pFile;
}
예제 #12
0
int CAlbumFolder::GetFileList(CLibraryList* pList, BOOL bRecursive) const
{
	int nCount = 0;

	for ( POSITION pos = GetFileIterator() ; pos ; )
	{
		pList->CheckAndAdd( GetNextFile( pos )->m_nIndex );
		nCount++;
	}

	if ( bRecursive )
	{
		for ( POSITION pos = GetFolderIterator() ; pos ; )
		{
			GetNextFolder( pos )->GetFileList( pList, bRecursive );
		}
	}

	return nCount;
}
예제 #13
0
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;
}
예제 #14
0
void CUploadsCtrl::OnPaint()
{
	CRect rcClient, rcItem;
	CPaintDC dc( this );

	CSingleLock pTransfersLock( &Transfers.m_pSection, FALSE );
	if ( ! pTransfersLock.Lock( 250 ) )
		return;

	CSingleLock pUploadQueuesLock( &UploadQueues.m_pSection, FALSE );
	if ( ! pUploadQueuesLock.Lock( 250 ) )
		return;

	if ( Settings.General.LanguageRTL ) dc.SetTextAlign( TA_RTLREADING );

	GetClientRect( &rcClient );
	rcClient.top += HEADER_HEIGHT;
	
	rcItem.CopyRect( &rcClient );
	rcItem.left -= GetScrollPos( SB_HORZ );
	rcItem.bottom = rcItem.top + ITEM_HEIGHT;
	
	int nScroll = GetScrollPos( SB_VERT );
	int nIndex = 0;
	
	CFont* pfOld = (CFont*)dc.SelectObject( &CoolInterface.m_fntNormal );
	BOOL bFocus = ( GetFocus() == this );

	for ( POSITION posQueue = GetQueueIterator() ; posQueue && rcItem.top < rcClient.bottom ; )
	{
		CUploadQueue* pQueue = GetNextQueue( posQueue );
		
		POSITION posFile = GetFileIterator( pQueue );
		if ( posFile == NULL ) continue;
		
		if ( nScroll > 0 )
		{
			nScroll --;
		}
		else
		{
			if ( rcItem.bottom > rcClient.top )
				PaintQueue( dc, rcItem, pQueue, bFocus && ( m_nFocus == nIndex ) );
			rcItem.OffsetRect( 0, ITEM_HEIGHT );
		}
		
		nIndex ++;
		
		if ( ! pQueue->m_bExpanded ) continue;
		
		while ( posFile && rcItem.top < rcClient.bottom )
		{
			int nPosition;
			CUploadFile* pFile = GetNextFile( pQueue, posFile, &nPosition );
			if ( pFile == NULL ) continue;
			
			if ( nScroll > 0 )
			{
				nScroll --;
			}
			else
			{
				if ( rcItem.bottom > rcClient.top )
					PaintFile( dc, rcItem, pQueue, pFile, nPosition, bFocus && ( m_nFocus == nIndex ) );
				rcItem.OffsetRect( 0, ITEM_HEIGHT );
			}
			
			nIndex ++;
		}
	}

	pUploadQueuesLock.Unlock();
	pTransfersLock.Unlock();
	
	dc.SelectObject( pfOld );
	
	rcClient.top = rcItem.top;
	if ( rcClient.top < rcClient.bottom )
		dc.FillSolidRect( &rcClient, CoolInterface.m_crWindow );
}
예제 #15
0
void CUploadsCtrl::OnSize(UINT nType, int cx, int cy)
{
	int nWidth = 0, nHeight = 0;
	CRect rcClient;
	
	if ( nType != 1982 ) CWnd::OnSize( nType, cx, cy );
	
	GetClientRect( &rcClient );
	
	HDITEM pColumn ={};
	pColumn.mask = HDI_WIDTH;
	
	for ( int nColumn = 0 ; m_wndHeader.GetItem( nColumn, &pColumn ) ; nColumn ++ )
		nWidth += pColumn.cxy;
	
	SCROLLINFO pScroll = {};
	pScroll.cbSize	= sizeof(pScroll);
	pScroll.fMask	= SIF_RANGE|SIF_PAGE;
	pScroll.nMin	= 0;
	pScroll.nMax	= nWidth;
	pScroll.nPage	= rcClient.right;
	SetScrollInfo( SB_HORZ, &pScroll, TRUE );
	
	int nScroll = GetScrollPos( SB_HORZ );
	m_wndHeader.SetWindowPos( NULL, -nScroll, 0, rcClient.right + nScroll, HEADER_HEIGHT, SWP_SHOWWINDOW );
	
	CSingleLock pTransfersLock( &Transfers.m_pSection, FALSE );
	if ( ! pTransfersLock.Lock( 250 ) )
		return;

	CSingleLock pUploadQueuesLock( &UploadQueues.m_pSection, FALSE );
	if ( ! pUploadQueuesLock.Lock( 250 ) )
		return;
	
	for ( POSITION posQueue = GetQueueIterator() ; posQueue ; )
	{
		CUploadQueue* pQueue = GetNextQueue( posQueue );
		
		POSITION posFile = GetFileIterator( pQueue );
		
		if ( posFile == NULL )
		{
			pQueue->m_bSelected = FALSE;
			continue;
		}
		
		nHeight ++;
		
		if ( ! pQueue->m_bExpanded ) continue;

		while ( posFile )
		{
			if ( GetNextFile( pQueue, posFile ) ) nHeight ++;
		}
	}
	
	pUploadQueuesLock.Unlock();
	pTransfersLock.Unlock();
	
	ZeroMemory( &pScroll, sizeof(pScroll) );
	pScroll.cbSize	= sizeof(pScroll);
	pScroll.fMask	= SIF_RANGE|SIF_PAGE;
	pScroll.nMin	= 0;
	pScroll.nMax	= nHeight;
	pScroll.nPage	= ( rcClient.bottom - HEADER_HEIGHT ) / ITEM_HEIGHT + 1;
	SetScrollInfo( SB_VERT, &pScroll, TRUE );
	
	m_nFocus = min( m_nFocus, max( 0, nHeight - 1 ) );
	
	Invalidate();
}
예제 #16
0
BOOL CUploadsCtrl::HitTest(const CPoint& point, CUploadQueue** ppQueue, CUploadFile** ppFile, int* pnIndex, RECT* prcItem)
{
	ASSUME_LOCK( Transfers.m_pSection );

	CRect rcClient, rcItem;
	
	GetClientRect( &rcClient );
	rcClient.top += HEADER_HEIGHT;
	
	rcItem.CopyRect( &rcClient );
	rcItem.left -= GetScrollPos( SB_HORZ );
	rcItem.bottom = rcItem.top + ITEM_HEIGHT;
	
	int nScroll = GetScrollPos( SB_VERT );
	int nIndex = 0;
	
	if ( ppQueue != NULL ) *ppQueue = NULL;
	if ( ppFile != NULL ) *ppFile = NULL;
	
	CSingleLock pLock( &UploadQueues.m_pSection, FALSE );
	if ( ! pLock.Lock( 250 ) )
		return FALSE;

	for ( POSITION posQueue = GetQueueIterator() ; posQueue && rcItem.top < rcClient.bottom ; )
	{
		CUploadQueue* pQueue = GetNextQueue( posQueue );
		
		POSITION posFile = GetFileIterator( pQueue );
		if ( posFile == NULL ) continue;
		
		if ( nScroll > 0 )
		{
			nScroll --;
		}
		else
		{
			if ( rcItem.PtInRect( point ) )
			{
				if ( ppQueue != NULL ) *ppQueue = pQueue;
				if ( pnIndex != NULL ) *pnIndex = nIndex;
				if ( prcItem != NULL ) *prcItem = rcItem;
				return TRUE;
			}
			rcItem.OffsetRect( 0, ITEM_HEIGHT );
		}
		
		nIndex ++;
		if ( ! pQueue->m_bExpanded ) continue;
		
		while ( posFile && rcItem.top < rcClient.bottom )
		{
			CUploadFile* pFile = GetNextFile( pQueue, posFile );
			if ( pFile == NULL ) continue;
			
			if ( nScroll > 0 )
			{
				nScroll --;
			}
			else
			{
				if ( rcItem.PtInRect( point ) )
				{
					if ( ppFile != NULL ) *ppFile = pFile;
					if ( pnIndex != NULL ) *pnIndex = nIndex;
					if ( prcItem != NULL ) *prcItem = rcItem;
					return TRUE;
				}
				rcItem.OffsetRect( 0, ITEM_HEIGHT );
			}
			
			nIndex ++;
		}
	}
	
	return FALSE;
}