📄 albumfolder.cpp
字号:
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++;
}
//////////////////////////////////////////////////////////////////////
// CAlbumFolder fetch a colleciton
CCollectionFile* CAlbumFolder::GetCollection()
{
if ( ! m_bCollSHA1 ) return NULL;
if ( m_pCollection != NULL ) return m_pCollection;
if ( CLibraryFile* pFile = LibraryMaps.LookupFileBySHA1( &m_pCollSHA1, FALSE, FALSE, TRUE ) )
{
m_pCollection = new CCollectionFile();
if ( m_pCollection->Open( pFile->GetPath() ) )
{
return m_pCollection;
}
else
{
delete m_pCollection;
m_pCollection = NULL;
}
}
m_bCollSHA1 = FALSE;
m_nUpdateCookie++;
Library.m_nUpdateCookie++;
return NULL;
}
//////////////////////////////////////////////////////////////////////
// CAlbumFolder organising
BOOL CAlbumFolder::OrganiseFile(CLibraryFile* pFile)
{
BOOL bResult = FALSE;
if ( m_sSchemaURI == CSchema::uriAllFiles )
{
AddFile( pFile );
return TRUE;
}
if ( m_bCollSHA1 && ( m_pCollection != NULL || GetCollection() ) )
{
if ( m_pCollSHA1 == pFile->m_pSHA1 ||
m_pCollection->FindFile( pFile, TRUE ) )
{
AddFile( pFile );
return TRUE;
}
else
{
return FALSE;
}
}
if ( pFile->m_pMetadata == NULL && m_pParent != NULL ) return FALSE;
if ( m_sSchemaURI == CSchema::uriMusicRoot )
{
if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;
}
else if ( m_sSchemaURI == CSchema::uriMusicAlbumCollection )
{
if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;
CString strAlbum = pFile->m_pMetadata->GetAttributeValue( _T("album") );
CXMLNode::UniformString( strAlbum );
if ( strAlbum.IsEmpty() ) return FALSE;
if ( _tcsicmp( strAlbum, _T("tba") ) == 0 ) return FALSE;
if ( _tcsicmp( strAlbum, _T("na") ) == 0 ) return FALSE;
if ( _tcsicmp( strAlbum, _T("n/a") ) == 0 ) return FALSE;
if ( _tcsicmp( strAlbum, _T("none") ) == 0 ) return FALSE;
if ( _tcsicmp( strAlbum, _T("empty") ) == 0 ) return FALSE;
if ( _tcsicmp( strAlbum, _T("unknown") ) == 0 ) return FALSE;
if ( _tcsistr( strAlbum, _T("uploaded by") ) ) return FALSE;
if ( _tcsistr( strAlbum, _T("ripped by") ) ) return FALSE;
if ( _tcsistr( strAlbum, _T("downloaded") ) ) return FALSE;
if ( _tcsistr( strAlbum, _T("http") ) ) return FALSE;
if ( _tcsistr( strAlbum, _T("mp3") ) ) return FALSE;
if ( _tcsistr( strAlbum, _T("www.mp3sfinder.com") ) ) return FALSE;
if ( _tcsistr( strAlbum, _T("single") ) ) strAlbum = _T("Singles");
for ( POSITION pos = GetFolderIterator() ; pos ; )
{
CAlbumFolder* pAlbum = GetNextFolder( pos );
if ( pAlbum->m_sName.CompareNoCase( strAlbum ) == 0 )
{
bResult = pAlbum->OrganiseFile( pFile );
}
else if ( pAlbum->m_bAutoDelete )
{
pAlbum->RemoveFile( pFile );
}
}
if ( bResult ) return TRUE;
CAlbumFolder* pAlbum = AddFolder( CSchema::uriMusicAlbum, strAlbum, TRUE );
return pAlbum->OrganiseFile( pFile );
}
else if ( m_sSchemaURI == CSchema::uriMusicAlbum )
{
if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;
CString strAlbum = pFile->m_pMetadata->GetAttributeValue( _T("album") );
CXMLNode::UniformString( strAlbum );
if ( _tcsistr( strAlbum, _T("single") ) ) strAlbum = _T("Singles");
if ( strAlbum.CompareNoCase( m_sName ) ) return FALSE;
AddFile( pFile );
if ( _tcsistr( m_sName, _T("soundtrack") ) != NULL ||
_tcsistr( m_sName, _T("ost") ) != NULL )
{
// TODO: Scrap artist specific info !
MetaFromFile( pFile );
}
else
{
MetaFromFile( pFile );
}
return TRUE;
}
else if ( m_sSchemaURI == CSchema::uriMusicArtistCollection )
{
if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;
CString strArtist = pFile->m_pMetadata->GetAttributeValue( _T("artist") );
CXMLNode::UniformString( strArtist );
Replace( strArtist, _T(" (www.mp3sfinder.com)"), _T("") );
if ( strArtist.IsEmpty() ) return FALSE;
for ( POSITION pos = GetFolderIterator() ; pos ; )
{
CAlbumFolder* pAlbum = GetNextFolder( pos );
if ( pAlbum->m_sName.CompareNoCase( strArtist ) == 0 )
{
bResult = pAlbum->OrganiseFile( pFile );
}
else if ( pAlbum->m_bAutoDelete )
{
pAlbum->RemoveFile( pFile );
}
}
if ( bResult ) return TRUE;
CAlbumFolder* pAlbum = AddFolder( CSchema::uriMusicArtist, strArtist, TRUE );
return pAlbum->OrganiseFile( pFile );
}
else if ( m_sSchemaURI == CSchema::uriMusicArtist )
{
if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;
CString strArtist = pFile->m_pMetadata->GetAttributeValue( _T("artist") );
CXMLNode::UniformString( strArtist );
if ( strArtist.CompareNoCase( m_sName ) ) return FALSE;
AddFile( pFile );
MetaFromFile( pFile );
return TRUE;
}
else if ( m_sSchemaURI == CSchema::uriMusicGenreCollection )
{
if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;
CString strGenre = pFile->m_pMetadata->GetAttributeValue( _T("genre") );
if ( strGenre.IsEmpty() ) return FALSE;
for ( POSITION pos = GetFolderIterator() ; pos ; )
{
CAlbumFolder* pAlbum = GetNextFolder( pos );
if ( pAlbum->m_sName.CompareNoCase( strGenre ) == 0 )
{
bResult = pAlbum->OrganiseFile( pFile );
}
else if ( pAlbum->m_bAutoDelete )
{
pAlbum->RemoveFile( pFile );
}
}
if ( bResult ) return TRUE;
CAlbumFolder* pAlbum = AddFolder( CSchema::uriMusicGenre, strGenre, TRUE );
return pAlbum->OrganiseFile( pFile );
}
else if ( m_sSchemaURI == CSchema::uriMusicGenre )
{
if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;
CString strGenre = pFile->m_pMetadata->GetAttributeValue( _T("genre") );
if ( strGenre.CompareNoCase( m_sName ) ) return FALSE;
AddFile( pFile );
MetaFromFile( pFile );
return TRUE;
}
else if ( m_sSchemaURI == CSchema::uriMusicAll )
{
if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;
AddFile( pFile );
return TRUE;
}
else if ( m_sSchemaURI == CSchema::uriVideoRoot )
{
if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;
}
else if ( m_sSchemaURI == CSchema::uriVideoSeriesCollection )
{
if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;
CString strSeries = pFile->m_pMetadata->GetAttributeValue( _T("series") );
CXMLNode::UniformString( strSeries );
if ( strSeries.IsEmpty() ) return FALSE;
for ( POSITION pos = GetFolderIterator() ; pos ; )
{
CAlbumFolder* pAlbum = GetNextFolder( pos );
if ( pAlbum->m_sName.CompareNoCase( strSeries ) == 0 )
{
bResult = pAlbum->OrganiseFile( pFile );
}
else if ( pAlbum->m_bAutoDelete )
{
pAlbum->RemoveFile( pFile );
}
}
if ( bResult ) return TRUE;
CAlbumFolder* pAlbum = AddFolder( CSchema::uriVideoSeries, strSeries, TRUE );
return pAlbum->OrganiseFile( pFile );
}
else if ( m_sSchemaURI == CSchema::uriVideoSeries )
{
if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;
CString strSeries = pFile->m_pMetadata->GetAttributeValue( _T("series") );
CXMLNode::UniformString( strSeries );
if ( strSeries.CompareNoCase( m_sName ) ) return FALSE;
AddFile( pFile );
MetaFromFile( pFile );
return TRUE;
}
else if ( m_sSchemaURI == CSchema::uriVideoFilmCollection )
{
if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;
CString strType = pFile->m_pMetadata->GetAttributeValue( _T("type") );
if ( strType.CompareNoCase( _T("film") ) ) return FALSE;
CString strTitle = pFile->m_pMetadata->GetAttributeValue( _T("title") );
CXMLNode::UniformString( strTitle );
if ( strTitle.IsEmpty() ) return FALSE;
for ( POSITION pos = GetFolderIterator() ; pos ; )
{
CAlbumFolder* pAlbum = GetNextFolder( pos );
if ( pAlbum->m_sName.CompareNoCase( strTitle ) == 0 )
{
bResult = pAlbum->OrganiseFile( pFile );
}
else if ( pAlbum->m_bAutoDelete )
{
pAlbum->RemoveFile( pFile );
}
}
if ( bResult ) return TRUE;
CAlbumFolder* pAlbum = AddFolder( CSchema::uriVideoFilm, strTitle, TRUE );
return pAlbum->OrganiseFile( pFile );
}
else if ( m_sSchemaURI == CSchema::uriVideoFilm )
{
if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;
CString strType = pFile->m_pMetadata->GetAttributeValue( _T("type") );
if ( strType.CompareNoCase( _T("film") ) ) return FALSE;
CString strTitle = pFile->m_pMetadata->GetAttributeValue( _T("title") );
CXMLNode::UniformString( strTitle );
if ( strTitle.CompareNoCase( m_sName ) ) return FALSE;
AddFile( pFile );
MetaFromFile( pFile );
return TRUE;
}
else if ( m_sSchemaURI == CSchema::uriVideoMusicCollection )
{
if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;
CString strType = pFile->m_pMetadata->GetAttributeValue( _T("type") );
if ( strType.CompareNoCase( _T("music video") ) ) return FALSE;
AddFile( pFile );
return TRUE;
}
else if ( m_sSchemaURI == CSchema::uriVideoAll )
{
if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;
AddFile( pFile );
return TRUE;
}
else if ( m_sSchemaURI == CSchema::uriImageRoot )
{
if ( ! pFile->IsSchemaURI( CSchema::uriImage ) ) return FALSE;
}
else if ( m_sSchemaURI == CSchema::uriImageAll )
{
if ( ! pFile->IsSchemaURI( CSchema::uriImage ) ) return FALSE;
AddFile( pFile );
return TRUE;
}
else if ( m_sSchemaURI == CSchema::uriApplicationRoot )
{
if ( ! pFile->IsSchemaURI( CSchema::uriApplication ) ) return FALSE;
}
else if ( m_sSchemaURI == CSchema::uriApplicationAll )
{
if ( ! pFile->IsSchemaURI( CSchema::uriApplication ) ) return FALSE;
AddFile( pFile );
return TRUE;
}
else if ( m_sSchemaURI == CSchema::uriBookRoot )
{
if ( ! pFile->IsSchemaURI( CSchema::uriBook ) ) return FALSE;
}
else if ( m_sSchemaURI == CSchema::uriBookAll )
{
if ( ! pFile->IsSchemaURI( CSchema::uriBook ) ) return FALSE;
AddFile( pFile );
return TRUE;
}
for ( POSITION pos = GetFolderIterator() ; pos ; )
{
bResult |= GetNextFolder( pos )->OrganiseFile( pFile );
}
return bResult;
}
//////////////////////////////////////////////////////////////////////
// CAlbumFolder serialize
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
{
CString str;
ar >> str;
}
if ( ar.ReadCount() )
{
ASSERT( m_pXML == NULL );
m_pXML = new CXMLElement();
m_pXML->Serialize( ar );
}
if ( nVersion >= 19 )
{
ar >> m_bCollSHA1;
if ( m_bCollSHA1 )
{
ar.Read( &m_pCollSHA1, sizeof(SHA1) );
pCollection = LibraryMaps.LookupFileBySHA1( &m_pCollSHA1, FALSE, FALSE, TRUE );
if ( pCollection == NULL ) m_bCollSHA1 = FALSE;
}
}
ar >> m_sName;
ar >> m_bExpanded;
ar >> m_bAutoDelete;
if ( nVersion >= 9 ) ar >> m_sBestView;
int nCount = ar.ReadCount();
while ( nCount-- > 0 )
{
CAlbumFolder* pFolder = new CAlbumFolder( this, NULL, (LPCTSTR)1 );
pFolder->Serialize( ar, nVersion );
m_pFolders.AddTail( pFolder );
}
nCount = ar.ReadCount();
while ( nCount-- > 0 )
{
DWORD nIndex;
ar >> nIndex;
if ( CLibraryFile* pFile = Library.LookupFile( nIndex ) )
{
m_pFiles.AddTail( pFile );
if ( pCollection != NULL ) pFile->m_nCollIndex = pCollection->m_nIndex;
}
}
}
}
//////////////////////////////////////////////////////////////////////
// CAlbumFolder clear
void CAlbumFolder::Clear()
{
for ( POSITION pos = GetFolderIterator() ; pos ; )
{
delete GetNextFolder( pos );
}
m_pFolders.RemoveAll();
m_pFiles.RemoveAll();
if ( m_pXML != NULL ) delete m_pXML;
m_pXML = NULL;
if ( m_pCollection != NULL ) delete m_pCollection;
m_pCollection = NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -