support change: read PreferredSongs.txt all at once (easier to read multiple files); always clear empty groups; simplify

This commit is contained in:
Glenn Maynard
2008-05-23 22:48:14 +00:00
parent e865844dc4
commit 9fb1994b47
+24 -22
View File
@@ -1401,17 +1401,18 @@ void SongManager::UpdatePreferredSort()
{ {
m_vPreferredSongSort.clear(); m_vPreferredSongSort.clear();
vector<RString> asLines;
RString sFile = THEME->GetPathO( "SongManager", "PreferredSongs.txt" ); RString sFile = THEME->GetPathO( "SongManager", "PreferredSongs.txt" );
RageFile file; GetFileContents( sFile, asLines );
if( !file.Open( sFile ) ) if( asLines.empty() )
return; return;
vector<Song*> vpSongs; vector<Song*> vpSongs;
RString sLine; FOREACH( RString, asLines, s )
while( file.GetLine(sLine) )
{ {
bool bSectionDivider = sLine.find("---") != RString::npos; RString sLine = *s;
bool bSectionDivider = sLine.find("---") == 0;
if( bSectionDivider ) if( bSectionDivider )
{ {
if( !vpSongs.empty() ) if( !vpSongs.empty() )
@@ -1419,15 +1420,16 @@ void SongManager::UpdatePreferredSort()
m_vPreferredSongSort.push_back( vpSongs ); m_vPreferredSongSort.push_back( vpSongs );
vpSongs.clear(); vpSongs.clear();
} }
continue;
} }
else
{ Song *pSong = FindSong( sLine );
Song *pSong = NULL; if( pSong == NULL )
if( !sLine.empty() ) continue;
pSong = FindSong( sLine ); if( UNLOCKMAN->SongIsLocked(pSong) & LOCKED_SELECTABLE )
if( pSong && !(UNLOCKMAN->SongIsLocked(pSong) & LOCKED_SELECTABLE) ) continue;
vpSongs.push_back( pSong );
} vpSongs.push_back( pSong );
} }
if( !vpSongs.empty() ) if( !vpSongs.empty() )
@@ -1460,16 +1462,16 @@ void SongManager::UpdatePreferredSort()
} }
m_vPreferredSongSort.push_back( vpUnlockSongs ); m_vPreferredSongSort.push_back( vpUnlockSongs );
// prune empty groups
for( int i=m_vPreferredSongSort.size()-1; i>=0; i-- )
if( m_vPreferredSongSort[i].empty() )
m_vPreferredSongSort.erase( m_vPreferredSongSort.begin()+i );
FOREACH( SongPointerVector, m_vPreferredSongSort, i )
FOREACH( Song*, *i, j )
ASSERT( *j );
} }
// prune empty groups
for( int i=m_vPreferredSongSort.size()-1; i>=0; i-- )
if( m_vPreferredSongSort[i].empty() )
m_vPreferredSongSort.erase( m_vPreferredSongSort.begin()+i );
FOREACH( SongPointerVector, m_vPreferredSongSort, i )
FOREACH( Song*, *i, j )
ASSERT( *j );
} }
{ {