Exemplo n.º 1
0
CG2Packet* CLocalSearch::AlbumToPacket(CAlbumFolder* pFolder)
{
	if ( pFolder == NULL ) return NULL;
	if ( pFolder->m_pSchema != NULL && pFolder->m_pSchema->m_bPrivate ) return NULL;
	if ( pFolder->GetSharedCount( TRUE ) == 0 ) return NULL;

	CG2Packet* pPacket = CG2Packet::New( G2_PACKET_VIRTUAL_FOLDER, TRUE );
	if ( ! pPacket ) return NULL;

	if ( pFolder->m_pSchema != NULL )
	{
		auto_ptr< CXMLElement > pXML( pFolder->m_pSchema->Instantiate( TRUE ) );
		if ( ! pXML.get() ) return NULL;

		if ( pFolder->m_pXML != NULL )
		{
			pXML->AddElement( pFolder->m_pXML->Clone() );
		}
		else
		{
			if ( CXMLElement* pBody = pXML->AddElement( pFolder->m_pSchema->m_sSingular ) )
			{
				pBody->AddAttribute( pFolder->m_pSchema->GetFirstMemberName(), pFolder->m_sName );
			}
		}

		CString strXML = pXML->ToString();
		pPacket->WritePacket( G2_PACKET_METADATA, pPacket->GetStringLen( strXML ) );
		pPacket->WriteString( strXML, FALSE );
	}

	for ( POSITION pos = pFolder->GetFolderIterator() ; pos ; )
	{
		if ( CG2Packet* pChild = AlbumToPacket( pFolder->GetNextFolder( pos ) ) )
		{
			pPacket->WritePacket( pChild );
			pChild->Release();
		}
	}

	if ( DWORD nFiles = pFolder->GetSharedCount( FALSE ) )
	{
		pPacket->WritePacket( G2_PACKET_FILES, nFiles * 4u );

		for ( POSITION pos = pFolder->GetFileIterator() ; pos ; )
		{
			const CLibraryFile* pFile = pFolder->GetNextFile( pos );
			if ( pFile->IsShared() ) pPacket->WriteLongBE( pFile->m_nIndex );
		}
	}

	return pPacket;
}
Exemplo n.º 2
0
CG2Packet* CLocalSearch::AlbumToPacket(CAlbumFolder* pFolder)
{
	if ( pFolder == NULL ) return NULL;

	if ( pFolder->m_pSchema != NULL && pFolder->m_pSchema->m_bPrivate ) return NULL;
	if ( pFolder->GetSharedCount() == 0 ) return NULL;

	CG2Packet* pPacket = CG2Packet::New( "VF", TRUE );

	if ( pFolder->m_pSchema != NULL )
	{
		CXMLElement* pXML = pFolder->m_pSchema->Instantiate( TRUE );

		if ( pFolder->m_pXML != NULL )
		{
			pXML->AddElement( pFolder->m_pXML->Clone() );
		}
		else
		{
			CXMLElement* pBody = pXML->AddElement( pFolder->m_pSchema->m_sSingular );
			pBody->AddAttribute( pFolder->m_pSchema->GetFirstMemberName(), pFolder->m_sName );
		}

		CString strXML = pXML->ToString();
		delete pXML;

		pPacket->WritePacket( "MD", pPacket->GetStringLen( strXML ) );
		pPacket->WriteString( strXML, FALSE );
	}

	for ( POSITION pos = pFolder->GetFolderIterator() ; pos ; )
	{
		if ( CG2Packet* pChild = AlbumToPacket( pFolder->GetNextFolder( pos ) ) )
		{
			pPacket->WritePacket( pChild );
			pChild->Release();
		}
	}

	pPacket->WritePacket( "FILES", pFolder->GetFileCount() * 4 );

	for ( POSITION pos = pFolder->GetFileIterator() ; pos ; )
	{
		CLibraryFile* pFile = pFolder->GetNextFile( pos );
		pPacket->WriteLongBE( pFile->m_nIndex );
	}

	return pPacket;
}
Exemplo n.º 3
0
void CLocalSearch::WriteVirtualTree()
{
	CSingleLock oLock( &Library.m_pSection );
	if ( oLock.Lock( 100 ) )
	{
		m_pPacket = AlbumToPacket( Library.GetAlbumRoot() );
		oLock.Unlock();
		if ( m_pPacket != NULL ) DispatchPacket();
	}

	if ( oLock.Lock( 100 ) )
	{
		m_pPacket = FoldersToPacket();
		oLock.Unlock();
		if ( m_pPacket != NULL ) DispatchPacket();
	}
}
Exemplo n.º 4
0
bool CLocalSearch::ExecuteSharedFiles(INT_PTR nMaximum, INT_PTR& nHits)
{
	CSingleLock oLock( &Library.m_pSection );
	if ( ! oLock.Lock( 250 ) )
		return false;

	auto_ptr< CFileList > pFiles( Library.Search(
		m_pSearch, nMaximum, FALSE,
		// Ghost files only for G2
		m_nProtocol != PROTOCOL_G2 ) );

	if ( pFiles.get() )
	{
		CFileList oFilesInPacket;

		for ( POSITION pos = pFiles->GetHeadPosition() ;
			pos && ( ! nMaximum || ( nHits + oFilesInPacket.GetCount() < nMaximum ) ); )
		{
			CLibraryFile* pFile = pFiles->GetNext( pos );

			if ( IsValidForHit( pFile ) )
			{
				oFilesInPacket.AddTail( pFile );
			}
		}

		SendHits( oFilesInPacket );

		nHits += oFilesInPacket.GetCount();
	}

	// Is it a browser request?
	if ( ! m_pSearch && m_nProtocol == PROTOCOL_G2 )
	{
		// Send virtual tree		
		DispatchPacket( AlbumToPacket( Library.GetAlbumRoot() ) );

		// Send physical tree
		DispatchPacket( FoldersToPacket() );
	}

	return true;
}