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
+15 -13
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,16 +1420,17 @@ 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,6 +1462,7 @@ void SongManager::UpdatePreferredSort()
} }
m_vPreferredSongSort.push_back( vpUnlockSongs ); m_vPreferredSongSort.push_back( vpUnlockSongs );
}
// prune empty groups // prune empty groups
for( int i=m_vPreferredSongSort.size()-1; i>=0; i-- ) for( int i=m_vPreferredSongSort.size()-1; i>=0; i-- )
@@ -1470,7 +1473,6 @@ void SongManager::UpdatePreferredSort()
FOREACH( Song*, *i, j ) FOREACH( Song*, *i, j )
ASSERT( *j ); ASSERT( *j );
} }
}
{ {
m_vPreferredCourseSort.clear(); m_vPreferredCourseSort.clear();